Table of Contents

Class TransformExtensions

Namespace
Stride.CommunityToolkit.Engine
Assembly
Stride.CommunityToolkit.dll

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

Vector3

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

transform TransformComponent

The transform to turn.

direction Vector3

The direction to face, in world space. It need not be normalised; a zero vector leaves the transform as it is.

worldUp Vector3?

The up direction that keeps the roll level; world Y when omitted.

smooth float

1 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

direction Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

direction Vector3

The direction vector to transform.

result 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

position Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

position Vector3

The coordinate vector to transform.

result 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

vector Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

vector Vector3

The normal vector to transform.

result 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 transform is 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

transform TransformComponent

The TransformComponent to update.

target Vector3

The target to point towards

worldUp Vector3

A Vector specifying the upward direction.

smooth float

Value 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 transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target Vector3

The target to point towards

smooth float

Value 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 transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target Vector3

The target to point towards

worldUp Vector3

A Vector specifying the upward direction.

smooth float

Value 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 transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target Vector3

The target to point towards

smooth float

Value 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 transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target TransformComponent

The target to point towards

worldUp Vector3

A Vector specifying the upward direction.

smooth float

Value 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 transform or target is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target TransformComponent

The target to point towards

worldUp Vector3

A Vector specifying the upward direction.

smooth float

Value 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 transform or target is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

target TransformComponent

The target to point towards

smooth float

Value 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 transform or target is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

eulerAngles Vector3

The euler angles in radians to rotate by.

relativeTo Space

The coordinate space to perform the rotation in.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

eulerAngles Vector3

The euler angles in radians to rotate by.

relativeTo Space

The coordinate space to perform the rotation in.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The transform to rotate.

point Vector3

The point the axis passes through, in the parent's space: world space for a root entity.

axis Vector3

The axis to rotate about, in the same space. It need not be normalised.

angle float

The 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 transform is null.

ArgumentException

If axis has 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

transform TransformComponent

The transform to rotate.

point Vector3

The point the axis passes through, in the parent's space: world space for a root entity.

axis Vector3

The axis to rotate about, in the same space. It need not be normalised.

angle float

The 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 transform is null.

ArgumentException

If axis has no length.

TransformDirection(TransformComponent, Vector3)

Performs a direction transformation using the given WorldMatrix.

public static Vector3 TransformDirection(this TransformComponent transform, Vector3 direction)

Parameters

transform TransformComponent

The transform to get the world matrix from.

direction Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

direction Vector3

The direction vector to transform.

result 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 transform is null.

TransformPosition(TransformComponent, Vector3)

Performs a coordinate transformation using the given WorldMatrix.

public static Vector3 TransformPosition(this TransformComponent transform, Vector3 position)

Parameters

transform TransformComponent

The transform to get the world matrix from.

position Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

position Vector3

The coordinate vector to transform.

result 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 transform is null.

TransformVector(TransformComponent, Vector3)

Performs a normal transformation using the given WorldMatrix.

public static Vector3 TransformVector(this TransformComponent transform, Vector3 vector)

Parameters

transform TransformComponent

The transform to get the world matrix from.

vector Vector3

The 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 transform is 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

transform TransformComponent

The transform to get the world matrix from.

vector Vector3

The normal vector to transform.

result 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 transform is 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

transform TransformComponent

The TransformComponent to update.

translation Vector3

The translation vector to move by.

relativeTo Space

The coordinate space to perform the translation in.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

translation Vector3

The translation vector to move by.

relativeTo TransformComponent

The TransformComponent to perform the translation relative to.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform or relativeTo is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

translation Vector3

The translation vector to move by.

relativeTo Space

The coordinate space to perform the translation in.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform is null.

ArgumentException

If transform has UseTRS set to false.

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

transform TransformComponent

The TransformComponent to update.

translation Vector3

The translation vector to move by.

relativeTo TransformComponent

The TransformComponent to perform the translation relative to.

Remarks

This method updates the LocalMatrix and WorldMatrix after transformation.

Exceptions

ArgumentNullException

If transform or relativeTo is null.

ArgumentException

If transform has UseTRS set to false.

UpdateTRSFromLocal(TransformComponent)

Sets Position, Rotation and Scale by decomposing LocalMatrix.

public static void UpdateTRSFromLocal(this TransformComponent transform)

Parameters

transform TransformComponent

The TransformComponent to update.

Exceptions

ArgumentNullException

If transform is null.