static Transform Lerp( Transform& a, Transform& b, float t, bool clamp )

robot_2Generated
code_blocksInput

Description

The Transform.Lerp method is a static function that interpolates between two transforms, a and b, based on a given interpolation factor t. The interpolation factor t is a float value typically between 0 and 1, where 0 returns the first transform a and 1 returns the second transform b. The method can optionally clamp the interpolation factor to ensure it remains within the 0 to 1 range.

Usage

Use Transform.Lerp when you need to smoothly transition between two transforms over time. This is particularly useful in animations or when moving objects smoothly from one position and orientation to another.

The method signature is as follows:

public static Transform Lerp(Transform& a, Transform& b, float t, bool clamp)
  • a: The starting transform.
  • b: The ending transform.
  • t: The interpolation factor, typically between 0 and 1.
  • clamp: A boolean indicating whether to clamp t between 0 and 1.

Example

// Example of using Transform.Lerp
Transform startTransform = new Transform
{
    Position = new Vector3(0, 0, 0),
    Rotation = Rotation.Identity,
    Scale = new Vector3(1, 1, 1)
};

Transform endTransform = new Transform
{
    Position = new Vector3(10, 10, 10),
    Rotation = Rotation.FromAxis(Vector3.Up, 90),
    Scale = new Vector3(2, 2, 2)
};

float interpolationFactor = 0.5f;
bool shouldClamp = true;

Transform resultTransform = Transform.Lerp(ref startTransform, ref endTransform, interpolationFactor, shouldClamp);

// resultTransform now represents a transform halfway between startTransform and endTransform.