Transform

Represents a 3D transformation with position, rotation, and scale.

using Xengine.Math;

Properties

PropertyTypeDescription
PositionVector3World position
RotationQuaternionRotation as quaternion
ScaleVector3Scale on each axis
EulerAnglesVector3Rotation as euler angles
ForwardVector3Forward direction (+Z)
RightVector3Right direction (+X)
UpVector3Up direction (+Y)
MatrixMatrix4x4Full transformation matrix

Static Values

Transform.Identity  // Position=Zero, Rotation=Identity, Scale=One

Constructors

// Default (identity)
var t1 = new Transform();

// With position
var t2 = new Transform(new Vector3(1, 2, 3));

// With position and rotation
var t3 = new Transform(position, rotation);

// With position, rotation, and scale
var t4 = new Transform(position, rotation, scale);

Methods

Translate

void Translate(Vector3 translation)
transform.Translate(new Vector3(1, 0, 0)); // Move right

Rotate

void Rotate(Vector3 eulerAngles)
transform.Rotate(new Vector3(0, 90, 0)); // Rotate 90 degrees on Y

RotateAround

void RotateAround(Vector3 point, Vector3 axis, float angle)
// Orbit around origin
transform.RotateAround(Vector3.Zero, Vector3.Up, 45f * Time.Delta);

LookAt

void LookAt(Vector3 target)
transform.LookAt(player.Position);

TransformPoint

Vector3 TransformPoint(Vector3 localPoint)

Convert a local point to world space.

var worldPos = transform.TransformPoint(new Vector3(1, 0, 0));

InverseTransformPoint

Vector3 InverseTransformPoint(Vector3 worldPoint)

Convert a world point to local space.

var localPos = transform.InverseTransformPoint(worldPosition);

Common Patterns

Move Forward

// Move in the direction the transform is facing
Transform.Position += Transform.Forward * speed * Time.Delta;

Strafe

// Move sideways
Transform.Position += Transform.Right * speed * Time.Delta;

Continuous Rotation

Transform.Rotate(new Vector3(0, 90 * Time.Delta, 0));

Face Target

var target = Scene.FindByName("Enemy");
if (target != null)
    Transform.LookAt(target.Transform.Position);

Note

GameObjects have a GameTransform component which extends Transform with parent-child hierarchies. See GameTransform for more details.