Class Transform
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
matrixMatrix4
Transform(Vector2, Vector2)
Initializes a new instance of the Transform class with a 2D position and scale.
public Transform(Vector2 position, Vector2 scale)
Parameters
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
positionVector2The 2D position.
rotationZfloatThe rotation around the Z-axis in degrees.
scaleVector2The 2D scale.
Transform(Vector3, Vector3)
Initializes a new instance of the Transform class with position and scale.
public Transform(Vector3 position, Vector3 scale)
Parameters
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
positionVector3The 3D position.
rotationVector3The rotation in degrees.
scaleVector3The 3D scale.
Properties
Forward
Gets the forward direction based on the current rotation.
public Vector3 Forward { get; }
Property Value
Matrix
Gets the transformation matrix representing the position, rotation, and scale of the transform.
public Matrix4 Matrix { get; }
Property Value
Position
The position of the transformation.
public Vector3 Position { get; set; }
Property Value
Right
Gets the Right direction based on the current rotation.
public Vector3 Right { get; }
Property Value
Rotation
The rotation of the transformation.
public Quaternion Rotation { get; set; }
Property Value
Scale
The scale of the transformation.
public Vector3 Scale { get; set; }
Property Value
Up
Gets the Up direction based on the current rotation.
public Vector3 Up { get; }
Property Value
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
Returns
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
objJObjectserializationContextSerializationContextcallbackFunc<JObject, bool>
GetEulerAngles()
Gets the rotation in Euler angles (degrees).
public Vector3 GetEulerAngles()
Returns
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
invertedbool
Returns
GetMatrix()
Gets the transformation matrix.
public Matrix4 GetMatrix()
Returns
GetPitchAngle()
Gets the pitch angle in radians based on the current rotation.
public float GetPitchAngle()
Returns
GetPitchQuat()
Gets the pitch rotation as a quaternion.
public Quaternion GetPitchQuat()
Returns
GetRight()
Gets the right direction based on the current rotation.
public Vector3 GetRight()
Returns
GetRightFlat()
Gets the right direction based on the current rotation, but flattens it to the XZ plane.
public Vector3 GetRightFlat()
Returns
GetRollAngle()
Gets the roll angle in radians based on the current rotation.
public float GetRollAngle()
Returns
GetRollQuat()
Gets the roll rotation as a quaternion.
public Quaternion GetRollQuat()
Returns
GetUp()
Gets the up direction based on the current rotation.
public Vector3 GetUp()
Returns
GetYawAngle()
Gets the yaw angle in radians based on the current rotation.
public float GetYawAngle()
Returns
GetYawQuat()
Gets the yaw rotation as a quaternion.
public Quaternion GetYawQuat()
Returns
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
Returns
Rotate(Vector2)
Rotates by a specified 2D vector in degrees.
public void Rotate(Vector2 rotation)
Parameters
rotationVector2The rotation vector in degrees.
Rotate(Vector3)
Rotates by a specified 3D vector in degrees.
public void Rotate(Vector3 rotation)
Parameters
rotationVector3The rotation vector in degrees.
Rotate(float)
Rotates around all axis by the specified degrees.
public void Rotate(float rotation)
Parameters
rotationfloatThe 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
pitchfloatRotation around the X-axis in degrees.
yawfloatRotation around the Y-axis in degrees.
rollfloatRotation around the Z-axis in degrees.
ScaleBy(Vector2)
Scales by a 2D vector.
public void ScaleBy(Vector2 scale)
Parameters
scaleVector2
ScaleBy(Vector3)
Scales by a 3D vector.
public void ScaleBy(Vector3 scale)
Parameters
scaleVector3
ScaleBy(float, float, float)
Scales by specified X, Y, and Z values.
public void ScaleBy(float x, float y, float z)
Parameters
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
writerJsonWriterserializationContextSerializationContextThe context that provides information and settings required for the serialization process.
callbackAction<JsonWriter>
SetPosition(Matrix4)
public void SetPosition(Matrix4 matrix)
Parameters
matrixMatrix4
SetRotation(Vector2)
Sets the rotation in degrees using a 2D vector.
public void SetRotation(Vector2 rotation)
Parameters
rotationVector2The rotation vector in degrees.
SetRotation(Vector3)
Sets the rotation in degrees using a 3D vector.
public void SetRotation(Vector3 rotation)
Parameters
rotationVector3The 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
rotationfloatThe rotation in degrees.
ToDegrees(Vector3)
Converts radians to degrees.
public static Vector3 ToDegrees(Vector3 input)
Parameters
inputVector3
Returns
ToRadians(Vector3)
Converts degrees to radians.
public static Vector3 ToRadians(Vector3 input)
Parameters
inputVector3
Returns
Towards(Vector3)
Rotates the transform to look at a specific target point.
public void Towards(Vector3 target)
Parameters
targetVector3
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
Returns
Translate(Vector2)
Translates by a 2D vector.
public void Translate(Vector2 translation)
Parameters
translationVector2The translation vector.
Translate(Vector3)
Translates by a 3D vector.
public void Translate(Vector3 translation)
Parameters
translationVector3
Translate(float, float, float)
Translates by specified X, Y, and Z values.
public void Translate(float x, float y, float z)
Parameters
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
Returns
Events
Changed
Occurs when the transform has changed.
public event Action<Transform> Changed
Event Type
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.