Skip to content

Transform

namespace Griff.Scenes;
public sealed class Transform : Component

Position, rotation and scale relative to the parent entity. Every entity has exactly one. Values are 3D so 2D and 3D share one model: 2D games use X/Y and rotate around Z.

public Matrix4x4 LocalMatrix { get; }

Transform from this entity’s space to its parent’s space.

public Vector3 Position { get; set; }

Where it is, in world units, from its parent’s position (or the world’s middle, with none). Y is up.

public Vector3 Rotation { get; set; }

Euler angles in degrees, applied Z, then X, then Y. In 2D, Z is the rotation angle.

public Vector3 RotationDrawn { get; }

Its own Rotation (in its parent’s space) in the frame being drawn: between how it was turned as the last step began and how it is, as WorldMatrix turns it.

public Quaternion RotationQuaternion { get; set; }
public Vector3 Scale { get; set; }

How many times its own size it’s drawn and collides: 2 is twice as big, -1 flips it. Children scale with it.

public Matrix4x4 WorldMatrix { get; }

Transform from this entity’s space to world space. Kept until it, or something it’s inside, moves. While a running game’s frame is being drawn, it’s where the entity is drawn: part way from where it was at the game’s last step but one to where it is (see Blend).

public Vector3 WorldPosition { get; }
public static Vector3 EulerDegrees(Quaternion rotation)

A rotation as angles in degrees about X, Y and Z, as Rotation holds them (none for an empty quaternion).

public static Quaternion FromEulerDegrees(Vector3 degrees)

The rotation that angles in degrees about X, Y and Z make, as Rotation holds them.

public void Teleport(Vector3 position)

Moves it straight to position (in its parent’s space), drawn there from the next frame on rather than glided there over the step as ordinary movement is: for a respawn, a portal, wrapping round the screen. (Moves too far to have been made in one step are drawn that way anyway.)

public void Teleport(Vector2 position)

Like Teleport, keeping its Z.