Table of Contents

Class Transform

Namespace
LibGFX.Math
Assembly
LibGFX.dll

Represents a 3D transformation.

public class Transform : ISerialization
Inheritance
Transform
Implements
Inherited Members

Constructors

Transform()

Creates a new instance of the Transform class.

public Transform()

Transform(Matrix4)

Initializes a new instance of the Transform class from a transformation matrix.

public Transform(Matrix4 matrix)

Parameters

matrix Matrix4

Transform(Vector2, Vector2)

Initializes a new instance of the Transform class with a 2D position and scale.

public Transform(Vector2 position, Vector2 scale)

Parameters

position Vector2

The 2D position.

scale Vector2

The 2D scale.

Transform(Vector2, float, Vector2)

Initializes a new instance of the Transform class with a 2D position, rotation around the Z-axis in degrees, and scale.

public Transform(Vector2 position, float rotationZ, Vector2 scale)

Parameters

position Vector2

The 2D position.

rotationZ float

The rotation around the Z-axis in degrees.

scale Vector2

The 2D scale.

Transform(Vector3, Vector3)

Initializes a new instance of the Transform class with position and scale.

public Transform(Vector3 position, Vector3 scale)

Parameters

position Vector3

The 3D position.

scale Vector3

The 3D scale.

Transform(Vector3, Vector3, Vector3)

Initializes a new instance of the Transform class with position, rotation in degrees, and scale.

public Transform(Vector3 position, Vector3 rotation, Vector3 scale)

Parameters

position Vector3

The 3D position.

rotation Vector3

The rotation in degrees.

scale Vector3

The 3D scale.

Properties

Forward

Gets the forward direction based on the current rotation.

public Vector3 Forward { get; }

Property Value

Vector3

Matrix

Gets the transformation matrix representing the position, rotation, and scale of the transform.

public Matrix4 Matrix { get; }

Property Value

Matrix4

Position

The position of the transformation.

public Vector3 Position { get; set; }

Property Value

Vector3

Right

Gets the Right direction based on the current rotation.

public Vector3 Right { get; }

Property Value

Vector3

Rotation

The rotation of the transformation.

public Quaternion Rotation { get; set; }

Property Value

Quaternion

Scale

The scale of the transformation.

public Vector3 Scale { get; set; }

Property Value

Vector3

Up

Gets the Up direction based on the current rotation.

public Vector3 Up { get; }

Property Value

Vector3

Methods

Attach(Transform, Transform)

Attaches a child transform to a parent transform, returning the child's local transform relative to the parent.

public static Transform Attach(Transform parent, Transform child)

Parameters

parent Transform
child Transform

Returns

Transform

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Populates the current object with values from the specified JSON object.

public void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)

Parameters

obj JObject
serializationContext SerializationContext
callback Func<JObject, bool>

GetEulerAngles()

Gets the rotation in Euler angles (degrees).

public Vector3 GetEulerAngles()

Returns

Vector3

GetFront(bool)

Gets the forward direction based on the current rotation. Inverted is used to get the opposite direction. Used for bullet physics.

public Vector3 GetFront(bool inverted = false)

Parameters

inverted bool

Returns

Vector3

GetMatrix()

Gets the transformation matrix.

public Matrix4 GetMatrix()

Returns

Matrix4

GetPitchAngle()

Gets the pitch angle in radians based on the current rotation.

public float GetPitchAngle()

Returns

float

GetPitchQuat()

Gets the pitch rotation as a quaternion.

public Quaternion GetPitchQuat()

Returns

Quaternion

GetRight()

Gets the right direction based on the current rotation.

public Vector3 GetRight()

Returns

Vector3

GetRightFlat()

Gets the right direction based on the current rotation, but flattens it to the XZ plane.

public Vector3 GetRightFlat()

Returns

Vector3

GetRollAngle()

Gets the roll angle in radians based on the current rotation.

public float GetRollAngle()

Returns

float

GetRollQuat()

Gets the roll rotation as a quaternion.

public Quaternion GetRollQuat()

Returns

Quaternion

GetUp()

Gets the up direction based on the current rotation.

public Vector3 GetUp()

Returns

Vector3

GetYawAngle()

Gets the yaw angle in radians based on the current rotation.

public float GetYawAngle()

Returns

float

GetYawQuat()

Gets the yaw rotation as a quaternion.

public Quaternion GetYawQuat()

Returns

Quaternion

LocalToWorldPositon(Transform, Vector3)

Converts a local position to a world position using the transform's position, rotation, and scale.

public static Vector3 LocalToWorldPositon(Transform transform, Vector3 localPosition)

Parameters

transform Transform
localPosition Vector3

Returns

Vector3

Rotate(Vector2)

Rotates by a specified 2D vector in degrees.

public void Rotate(Vector2 rotation)

Parameters

rotation Vector2

The rotation vector in degrees.

Rotate(Vector3)

Rotates by a specified 3D vector in degrees.

public void Rotate(Vector3 rotation)

Parameters

rotation Vector3

The rotation vector in degrees.

Rotate(float)

Rotates around all axis by the specified degrees.

public void Rotate(float rotation)

Parameters

rotation float

The rotation in degrees.

Rotate(float, float, float)

Rotates by specified pitch, yaw, and roll values in degrees.

public void Rotate(float pitch, float yaw, float roll)

Parameters

pitch float

Rotation around the X-axis in degrees.

yaw float

Rotation around the Y-axis in degrees.

roll float

Rotation around the Z-axis in degrees.

ScaleBy(Vector2)

Scales by a 2D vector.

public void ScaleBy(Vector2 scale)

Parameters

scale Vector2

ScaleBy(Vector3)

Scales by a 3D vector.

public void ScaleBy(Vector3 scale)

Parameters

scale Vector3

ScaleBy(float, float, float)

Scales by specified X, Y, and Z values.

public void ScaleBy(float x, float y, float z)

Parameters

x float
y float
z float

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the current object's position, rotation, and scale into a JSON representation.

public void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
serializationContext SerializationContext

The context that provides information and settings required for the serialization process.

callback Action<JsonWriter>

SetPosition(Matrix4)

public void SetPosition(Matrix4 matrix)

Parameters

matrix Matrix4

SetRotation(Vector2)

Sets the rotation in degrees using a 2D vector.

public void SetRotation(Vector2 rotation)

Parameters

rotation Vector2

The rotation vector in degrees.

SetRotation(Vector3)

Sets the rotation in degrees using a 3D vector.

public void SetRotation(Vector3 rotation)

Parameters

rotation Vector3

The rotation vector in degrees.

SetRotation(float)

Sets the rotation in degrees using a single float value representing rotation around the Z-axis.

public void SetRotation(float rotation)

Parameters

rotation float

The rotation in degrees.

ToDegrees(Vector3)

Converts radians to degrees.

public static Vector3 ToDegrees(Vector3 input)

Parameters

input Vector3

Returns

Vector3

ToRadians(Vector3)

Converts degrees to radians.

public static Vector3 ToRadians(Vector3 input)

Parameters

input Vector3

Returns

Vector3

Towards(Vector3)

Rotates the transform to look at a specific target point.

public void Towards(Vector3 target)

Parameters

target Vector3

TransformDirection(Transform, Vector3, bool)

Transforms a direction vector using the transform's rotation and scale.

public static Vector3 TransformDirection(Transform transform, Vector3 direction, bool rotationSpaceOnly = true)

Parameters

transform Transform
direction Vector3
rotationSpaceOnly bool

Returns

Vector3

Translate(Vector2)

Translates by a 2D vector.

public void Translate(Vector2 translation)

Parameters

translation Vector2

The translation vector.

Translate(Vector3)

Translates by a 3D vector.

public void Translate(Vector3 translation)

Parameters

translation Vector3

Translate(float, float, float)

Translates by specified X, Y, and Z values.

public void Translate(float x, float y, float z)

Parameters

x float
y float
z float

WorldToLocalPosition(Transform, Vector3)

Converts a world position to a local position using the transform's position, rotation, and scale.

public static Vector3 WorldToLocalPosition(Transform transform, Vector3 worldPosition)

Parameters

transform Transform
worldPosition Vector3

Returns

Vector3

Events

Changed

Occurs when the transform has changed.

public event Action<Transform> Changed

Event Type

Action<Transform>

Remarks

Subscribe to this event to be notified whenever the associated transform is modified. The event provides the updated transform as an argument to the event handler. Handlers are invoked in the order in which they were added.