Skip to content

Latest commit

 

History

History
45 lines (26 loc) · 2.63 KB

transforms-helpers.md

File metadata and controls

45 lines (26 loc) · 2.63 KB

Transform helper overview

The TransformHelpers class contains extensions to the math library that make it easier for you to work with transformation matrices.

In particular, the extensions help you work with the float4x4 contained in the LocalToWorld component.

Extension methods

You can use the extension methods in TransformHelpers to minimize the usage of matrix math in your code. For example, to transform a point from local space into world space you can use TransformPoint:

float3 myWorldPoint = myLocalToWorld.Value.TransformPoint(myLocalPoint);

Or, to transform a point from world space into local space you can use InverseTransformPoint:

float3 myLocalPoint = myLocalToWorld.Value.InverseTransformPoint(myWorldPoint);

The transformation of rotation and direction are handled in a similar way.

Other methods

There are a few methods that aren't extensions outlined below.

LookAtRotation

The LookAtRotation method computes a rotation so that "forward" points to the target:

[!code-csconversion]

ComputeWorldTransformMatrix

You can use the ComputeWorldTransformMatrix method to immediately use an entity's precise world-space transformation matrix. For example:

  • When performing a raycast from an entity which might be part of an entity hierarchy, such as the wheel of a car object. The ray origin must be in world-space, but the entity's LocalTransform component might be relative to its parent.
  • When an entity's transform needs to track another entity's transform in world-space, and the targeting entity or the targeted entity are in a transform hierarchy.
  • When an entity's transform is modified in the LateSimulationSystemGroup (after the TransformSystemGroup has updated, but before the PresentationSystemGroup runs), you can use ComputeWorldTransformMatrix to compute a new LocalToWorld value for the affected entity.

[!code-csconversion]

Additional resources

  • TransformHelpers API documentation