Class TransformExtensions
Extension methods for TransformComponent.
public static class TransformExtensions
- Inheritance
-
TransformExtensions
Properties
WorldUp
The world up vector used by the LookAt overloads that do not take an explicit up vector. The default is UnitY; set it once at start-up for projects that use a different up axis (for example Z-up).
public static Vector3 WorldUp { get; set; }
Property Value
Remarks
Not synchronised. Set it during start-up, before the game loop runs; like the transform APIs it feeds, it is intended for the update thread. Overloads that take an explicit up vector ignore this value.
Methods
FaceDirection(TransformComponent, Vector3, Vector3?, float)
Turns the transform so that its forward axis (-Z) points along a direction, the way a character faces the way it moves or a projectile faces its velocity.
public static void FaceDirection(this TransformComponent transform, Vector3 direction, Vector3? worldUp = null, float smooth = 1)
Parameters
transformTransformComponentThe transform to turn.
directionVector3The direction to face, in world space. It need not be normalised; a zero vector leaves the transform as it is.
worldUpVector3?The up direction that keeps the roll level; world Y when omitted.
smoothfloat1 snaps to the direction; a value between 0 and 1 turns that fraction of the way, for a turn that eases over several frames.
Remarks
The same as LookAt(TransformComponent, Vector3, Vector3, float) at a target one unit along the direction from the entity's world position, so a parented entity faces the world direction, not its parent's. Updates the world matrix afterwards.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformDirection(TransformComponent, Vector3)
Performs a direction transformation using the inverse of the given WorldMatrix.
public static Vector3 InverseTransformDirection(this TransformComponent transform, Vector3 direction)
Parameters
transformTransformComponentThe transform to get the world matrix from.
directionVector3The direction vector to transform.
Returns
- Vector3
The transformed direction.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformDirection(TransformComponent, ref Vector3, out Vector3)
Performs a direction transformation using the inverse of the given WorldMatrix.
public static void InverseTransformDirection(this TransformComponent transform, ref Vector3 direction, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
directionVector3The direction vector to transform.
resultVector3The transformed direction.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformPosition(TransformComponent, Vector3)
Performs a coordinate transformation using the inverse of the given WorldMatrix.
public static Vector3 InverseTransformPosition(this TransformComponent transform, Vector3 position)
Parameters
transformTransformComponentThe transform to get the world matrix from.
positionVector3The coordinate vector to transform.
Returns
- Vector3
The transformed coordinate.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformPosition(TransformComponent, ref Vector3, out Vector3)
Performs a coordinate transformation using the inverse of the given WorldMatrix.
public static void InverseTransformPosition(this TransformComponent transform, ref Vector3 position, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
positionVector3The coordinate vector to transform.
resultVector3The transformed coordinate.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformVector(TransformComponent, Vector3)
Performs a normal transformation using the inverse of the given WorldMatrix.
public static Vector3 InverseTransformVector(this TransformComponent transform, Vector3 vector)
Parameters
transformTransformComponentThe transform to get the world matrix from.
vectorVector3The normal vector to transform.
Returns
- Vector3
The transformed normal.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
InverseTransformVector(TransformComponent, ref Vector3, out Vector3)
Performs a normal transformation using the inverse of the given WorldMatrix.
public static void InverseTransformVector(this TransformComponent transform, ref Vector3 vector, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
vectorVector3The normal vector to transform.
resultVector3The transformed normal.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
LookAt(TransformComponent, Vector3, Vector3, float)
Sets the transform's rotation so its forward vector points at the target.
public static void LookAt(this TransformComponent transform, Vector3 target, Vector3 worldUp, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetVector3The target to point towards
worldUpVector3A Vector specifying the upward direction.
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
LookAt(TransformComponent, Vector3, float)
Sets the transform's rotation so its forward vector points at the target. The world up vector used is defined by WorldUp.
public static void LookAt(this TransformComponent transform, Vector3 target, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetVector3The target to point towards
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
LookAt(TransformComponent, ref Vector3, ref Vector3, float)
Sets the transform's rotation so its forward vector points at the target.
public static void LookAt(this TransformComponent transform, ref Vector3 target, ref Vector3 worldUp, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetVector3The target to point towards
worldUpVector3A Vector specifying the upward direction.
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
LookAt(TransformComponent, ref Vector3, float)
Sets the transform's rotation so its forward vector points at the target. The world up vector used is defined by WorldUp.
public static void LookAt(this TransformComponent transform, ref Vector3 target, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetVector3The target to point towards
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
LookAt(TransformComponent, TransformComponent, Vector3, float)
Sets the transform's rotation so its forward vector points at the target.
public static void LookAt(this TransformComponent transform, TransformComponent target, Vector3 worldUp, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetTransformComponentThe target to point towards
worldUpVector3A Vector specifying the upward direction.
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformortargetis null.- ArgumentException
LookAt(TransformComponent, TransformComponent, ref Vector3, float)
Sets the transform's rotation so its forward vector points at the target.
public static void LookAt(this TransformComponent transform, TransformComponent target, ref Vector3 worldUp, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetTransformComponentThe target to point towards
worldUpVector3A Vector specifying the upward direction.
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformortargetis null.- ArgumentException
LookAt(TransformComponent, TransformComponent, float)
Sets the transform's rotation so its forward vector points at the target. The world up vector used is defined by WorldUp.
public static void LookAt(this TransformComponent transform, TransformComponent target, float smooth = 1)
Parameters
transformTransformComponentThe TransformComponent to update.
targetTransformComponentThe target to point towards
smoothfloatValue between 0 and 1 indicating the weight of target orientation. The default is 1.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformortargetis null.- ArgumentException
Rotate(TransformComponent, Vector3, Space)
Rotates the given TransformComponent by the specified eulerAngles in the coordinate space defined by relativeTo.
public static void Rotate(this TransformComponent transform, Vector3 eulerAngles, Space relativeTo = Space.Self)
Parameters
transformTransformComponentThe TransformComponent to update.
eulerAnglesVector3The euler angles in radians to rotate by.
relativeToSpaceThe coordinate space to perform the rotation in.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
Rotate(TransformComponent, ref Vector3, Space)
Rotates the given TransformComponent by the specified eulerAngles in the coordinate space defined by relativeTo.
public static void Rotate(this TransformComponent transform, ref Vector3 eulerAngles, Space relativeTo = Space.Self)
Parameters
transformTransformComponentThe TransformComponent to update.
eulerAnglesVector3The euler angles in radians to rotate by.
relativeToSpaceThe coordinate space to perform the rotation in.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
RotateAround(TransformComponent, Vector3, Vector3, float)
Rotates the transform about an axis through a point: the position swings round the point and the orientation turns by the same angle, as a moon orbits while keeping one face inward.
public static void RotateAround(this TransformComponent transform, Vector3 point, Vector3 axis, float angle)
Parameters
transformTransformComponentThe transform to rotate.
pointVector3The point the axis passes through, in the parent's space: world space for a root entity.
axisVector3The axis to rotate about, in the same space. It need not be normalised.
anglefloatThe angle in radians; positive is counter-clockwise looking down the axis.
Remarks
Updates the world matrix afterwards. Call it every frame with angle = speed * deltaTime for a continuous orbit; a body under physics should be moved by its velocity instead.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
If
axishas no length.
RotateAround(TransformComponent, ref Vector3, ref Vector3, float)
Rotates the transform about an axis through a point: the position swings round the point and the orientation turns by the same angle, as a moon orbits while keeping one face inward.
public static void RotateAround(this TransformComponent transform, ref Vector3 point, ref Vector3 axis, float angle)
Parameters
transformTransformComponentThe transform to rotate.
pointVector3The point the axis passes through, in the parent's space: world space for a root entity.
axisVector3The axis to rotate about, in the same space. It need not be normalised.
anglefloatThe angle in radians; positive is counter-clockwise looking down the axis.
Remarks
Updates the world matrix afterwards. Call it every frame with angle = speed * deltaTime for a continuous orbit; a body under physics should be moved by its velocity instead.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
If
axishas no length.
TransformDirection(TransformComponent, Vector3)
Performs a direction transformation using the given WorldMatrix.
public static Vector3 TransformDirection(this TransformComponent transform, Vector3 direction)
Parameters
transformTransformComponentThe transform to get the world matrix from.
directionVector3The direction vector to transform.
Returns
- Vector3
The transformed direction.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
TransformDirection(TransformComponent, ref Vector3, out Vector3)
Performs a direction transformation using the given WorldMatrix.
public static void TransformDirection(this TransformComponent transform, ref Vector3 direction, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
directionVector3The direction vector to transform.
resultVector3The transformed direction.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
TransformPosition(TransformComponent, Vector3)
Performs a coordinate transformation using the given WorldMatrix.
public static Vector3 TransformPosition(this TransformComponent transform, Vector3 position)
Parameters
transformTransformComponentThe transform to get the world matrix from.
positionVector3The coordinate vector to transform.
Returns
- Vector3
The transformed coordinate.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
TransformPosition(TransformComponent, ref Vector3, out Vector3)
Performs a coordinate transformation using the given WorldMatrix.
public static void TransformPosition(this TransformComponent transform, ref Vector3 position, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
positionVector3The coordinate vector to transform.
resultVector3The transformed coordinate.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
TransformVector(TransformComponent, Vector3)
Performs a normal transformation using the given WorldMatrix.
public static Vector3 TransformVector(this TransformComponent transform, Vector3 vector)
Parameters
transformTransformComponentThe transform to get the world matrix from.
vectorVector3The normal vector to transform.
Returns
- Vector3
The transformed normal.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
TransformVector(TransformComponent, ref Vector3, out Vector3)
Performs a normal transformation using the given WorldMatrix.
public static void TransformVector(this TransformComponent transform, ref Vector3 vector, out Vector3 result)
Parameters
transformTransformComponentThe transform to get the world matrix from.
vectorVector3The normal vector to transform.
resultVector3The transformed normal.
Remarks
This method does not update the WorldMatrix before performing the transformation. If the TransformComponent has been modified since the last frame you may need to call the UpdateWorldMatrix() method first.
Exceptions
- ArgumentNullException
If
transformis null.
Translate(TransformComponent, Vector3, Space)
Moves the given TransformComponent position by the specified translation in the coordinate space defined by relativeTo.
public static void Translate(this TransformComponent transform, Vector3 translation, Space relativeTo = Space.Self)
Parameters
transformTransformComponentThe TransformComponent to update.
translationVector3The translation vector to move by.
relativeToSpaceThe coordinate space to perform the translation in.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
Translate(TransformComponent, Vector3, TransformComponent)
Moves the given TransformComponent position by the specified translation relative to the local coordinate space of another TransformComponent.
public static void Translate(this TransformComponent transform, Vector3 translation, TransformComponent relativeTo)
Parameters
transformTransformComponentThe TransformComponent to update.
translationVector3The translation vector to move by.
relativeToTransformComponentThe TransformComponent to perform the translation relative to.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformorrelativeTois null.- ArgumentException
Translate(TransformComponent, ref Vector3, Space)
Moves the given TransformComponent position by the specified translation in the coordinate space defined by relativeTo.
public static void Translate(this TransformComponent transform, ref Vector3 translation, Space relativeTo = Space.Self)
Parameters
transformTransformComponentThe TransformComponent to update.
translationVector3The translation vector to move by.
relativeToSpaceThe coordinate space to perform the translation in.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformis null.- ArgumentException
Translate(TransformComponent, ref Vector3, TransformComponent)
Moves the given TransformComponent position by the specified translation relative to the local coordinate space of another TransformComponent.
public static void Translate(this TransformComponent transform, ref Vector3 translation, TransformComponent relativeTo)
Parameters
transformTransformComponentThe TransformComponent to update.
translationVector3The translation vector to move by.
relativeToTransformComponentThe TransformComponent to perform the translation relative to.
Remarks
This method updates the LocalMatrix and WorldMatrix after transformation.
Exceptions
- ArgumentNullException
If
transformorrelativeTois null.- ArgumentException
UpdateTRSFromLocal(TransformComponent)
Sets Position, Rotation and Scale by decomposing LocalMatrix.
public static void UpdateTRSFromLocal(this TransformComponent transform)
Parameters
transformTransformComponentThe TransformComponent to update.
Exceptions
- ArgumentNullException
If
transformis null.