Class Transform
Describes transformation in a 3D space.
Inheritance
Implements
Namespace: FlaxEngine
Assembly: FlaxEngine.CSharp.dll
Syntax
[Unmanaged]
public sealed class Transform : ValueType, IEquatable<Transform>, IFormattable
Constructors
Transform(Matrix)
Creates a new Transform from a matrix
Declaration
public Transform(Matrix transform)
Parameters
Matrix
transform
World matrix |
Transform(ref Matrix)
Creates a new Transform from a matrix
Declaration
public Transform(ref Matrix transform)
Parameters
Matrix
transform
World matrix |
Transform(Vector3)
Init
Declaration
public Transform(Vector3 position)
Parameters
Vector3
position
Position in 3D space |
Transform(Vector3, Quaternion)
Init
Declaration
public Transform(Vector3 position, Quaternion rotation)
Parameters
Vector3
position
Position in 3D space |
Quaternion
rotation
Rotation in 3D space |
Transform(Vector3, Quaternion, Float3)
Init
Declaration
public Transform(Vector3 position, Quaternion rotation, Float3 scale)
Parameters
Vector3
position
Position in 3D space |
Quaternion
rotation
Rotation in 3D space |
Float3
scale
Transform scale |
Fields
Identity
A identity Transform with all default values
Declaration
public static readonly Transform Identity
Field Value
Transform
|
Orientation
The rotation of the transform.
Declaration
[EditorOrder(20)]
[EditorDisplay(null, "Rotation")]
[ValueCategory]
public Quaternion Orientation
Field Value
Quaternion
|
Scale
The scale vector of the transform.
Declaration
[EditorOrder(30)]
[Limit(-3.40282347E+38F, 3.40282347E+38F, 0.01F)]
public Float3 Scale
Field Value
Float3
|
SizeInBytes
The size of the Transform type, in bytes
Declaration
public static readonly int SizeInBytes
Field Value
System.Int32
|
Translation
The translation vector of the transform.
Declaration
[EditorOrder(10)]
[EditorDisplay(null, "Position")]
[ValueCategory]
public Vector3 Translation
Field Value
Vector3
|
Properties
Backward
Default
The default Transform.
Declaration
public static Transform Default { get; }
Property Value
Transform
|
Down
Forward
IsIdentity
Gets a value indicting whether this transform is identity
Declaration
public bool IsIdentity { get; }
Property Value
System.Boolean
|
Left
Right
Up
Methods
Add(Transform, Transform)
Adds two transforms.
Declaration
public static Transform Add(Transform left, Transform right)
Parameters
Transform
left
The first transform to add. |
Transform
right
The second transform to add. |
Returns
Transform
The sum of the two transforms. |
AlignRotationToNormalAndSnapToGrid(Vector3, Vector3, Vector3, Transform, Vector3)
Combines the functions: Example code:
SnapToGrid(Vector3, Vector3),
GetRotationFromNormal(Vector3, Transform).
langword_csharp_public langword_csharp_class AlignRotationToObjectAndSnapToGridExample : Script
langword_csharp_public Vector3 Offset = new Vector3(0, 0, 50f);
langword_csharp_public Vector3 GridSize = One * 20.0f;
langword_csharp_public Actor RayOrigin;
langword_csharp_public Actor SomeObject;
langword_csharp_public langword_csharp_override langword_csharp_void OnFixedUpdate()
{
langword_csharp_if (Physics.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out RayCastHit hit)
{
Transform transform = hit.Collider.Transform;
Vector3 point = hit.Point;
Vector3 normal = hit.Normal;
SomeObject.Transform = Transform.AlignRotationToNormalAndSnapToGrid
(
point,
normal,
Offset,
transform,
GridSize
);
}
}
}
Declaration
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 point, Vector3 normal, Vector3 normalOffset, Transform relativeTo, Vector3 gridSize)
Parameters
Vector3
point
The position to snap. |
Vector3
normal
The normal vector. |
Vector3
normalOffset
The local grid offset to apply after snapping. |
Transform
relativeTo
The relative transform. |
Vector3
gridSize
The size of the grid. |
Returns
Transform
The rotated and snapped transform with scale One. |
AlignRotationToNormalAndSnapToGrid(Vector3, Vector3, Vector3, Transform, Vector3, Float3)
Combines the functions: Example code:
SnapToGrid(Vector3, Vector3),
GetRotationFromNormal(Vector3, Transform).
langword_csharp_public langword_csharp_class AlignRotationToObjectAndSnapToGridExample : Script
langword_csharp_public Vector3 Offset = new Vector3(0, 0, 50f);
langword_csharp_public Vector3 GridSize = One * 20.0f;
langword_csharp_public Actor RayOrigin;
langword_csharp_public Actor SomeObject;
langword_csharp_public langword_csharp_override langword_csharp_void OnFixedUpdate()
{
langword_csharp_if (Physics.RayCast(RayOrigin.Position, RayOrigin.Transform.Forward, out RayCastHit hit)
{
Transform transform = hit.Collider.Transform;
Vector3 point = hit.Point;
Vector3 normal = hit.Normal;
SomeObject.Transform = Transform.AlignRotationToNormalAndSnapToGrid
(
point,
normal,
Offset,
transform,
SomeObject.Scale,
GridSize,
Float3.One
);
}
}
}
Declaration
public static Transform AlignRotationToNormalAndSnapToGrid(Vector3 point, Vector3 normal, Vector3 normalOffset, Transform relativeTo, Vector3 gridSize, Float3 scale)
Parameters
Vector3
point
The position to snap. |
Vector3
normal
The normal vector. |
Vector3
normalOffset
The local grid offset to apply after snapping. |
Transform
relativeTo
The relative transform. |
Vector3
gridSize
The size of the grid. |
Float3
scale
The scale to apply to the transform. |
Returns
Transform
The rotated and snapped transform. |
Equals(Transform)
Determines whether the specified Transform is equal to this instance.
Declaration
public bool Equals(Transform other)
Parameters
Transform
other
The Transform to compare with this instance. |
Returns
System.Boolean
|
Equals(ref Transform)
Determines whether the specified Transform is equal to this instance.
Declaration
public bool Equals(ref Transform other)
Parameters
Transform
other
The Transform to compare with this instance. |
Returns
System.Boolean
|
Equals(Object)
Determines whether the specified System.Object is equal to this instance.
Declaration
public override bool Equals(object value)
Parameters
System.Object
value
The System.Object to compare with this instance. |
Returns
System.Boolean
|
GetHashCode()
Returns a hash code for this instance.
Declaration
public override int GetHashCode()
Returns
System.Int32
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table. |
GetRotation()
Gets rotation matrix (from Orientation).
Declaration
public Matrix GetRotation()
Returns
Matrix
Rotation matrix |
GetRotation(out Matrix)
Gets rotation matrix (from Orientation).
Declaration
public void GetRotation(out Matrix result)
Parameters
Matrix
result
Matrix to set |
GetWorld()
Gets world matrix that describes transformation as a 4 by 4 matrix.
Declaration
public Matrix GetWorld()
Returns
Matrix
World matrix |
Remarks
Doesn't work in large worlds because Matrix contains 32-bit precision while Translation can have 64-bit precision.
GetWorld(out Matrix)
Gets world matrix that describes transformation as a 4 by 4 matrix.
Declaration
public void GetWorld(out Matrix result)
Parameters
Matrix
result
World matrix |
Remarks
Doesn't work in large worlds because Matrix contains 32-bit precision while Translation can have 64-bit precision.
Lerp(Transform, Transform, Single)
Performs a linear interpolation between two transformations.
Declaration
public static Transform Lerp(Transform start, Transform end, float amount)
Parameters
Transform
start
Start transformation. |
Transform
end
End transformation. |
System.Single
amount
Value between 0 and 1 indicating the weight of |
Returns
Transform
The linear interpolation of the two transformations. |
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
Lerp(ref Transform, ref Transform, Single, out Transform)
Performs a linear interpolation between two transformations.
Declaration
public static void Lerp(ref Transform start, ref Transform end, float amount, out Transform result)
Parameters
Transform
start
Start transformation. |
Transform
end
End transformation. |
System.Single
amount
Value between 0 and 1 indicating the weight of |
Transform
result
When the method completes, contains the linear interpolation of the two transformations. |
Remarks
Passing amount
a value of 0 will cause start
to be returned; a value of 1 will cause end
to be returned.
LocalToWorld(Transform)
Perform transformation of the given transform in local space
Declaration
public Transform LocalToWorld(Transform other)
Parameters
Transform
other
Local space transform |
Returns
Transform
World space transform |
LocalToWorld(ref Transform, out Transform)
Perform transformation of the given transform in local space
Declaration
public void LocalToWorld(ref Transform other, out Transform result)
Parameters
Transform
other
Local space transform |
Transform
result
World space transform |
LocalToWorld(Vector3)
Perform transformation of the given point in local space
Declaration
public Vector3 LocalToWorld(Vector3 point)
Parameters
Vector3
point
Local space point |
Returns
Vector3
World space point |
LocalToWorld(ref Vector3, out Vector3)
Perform transformation of the given point in local space
Declaration
public void LocalToWorld(ref Vector3 point, out Vector3 result)
Parameters
Vector3
point
Local space point |
Vector3
result
World space point |
LocalToWorld(Vector3[], Vector3[])
Perform transformation of the given points in local space
Declaration
public void LocalToWorld(Vector3[] points, Vector3[] result)
Parameters
Vector3[]
points
Local space points |
Vector3[]
result
World space points |
LocalToWorldVector(Vector3)
Performs transformation of the given vector in local space to the world space of this transform.
Declaration
public Vector3 LocalToWorldVector(Vector3 vector)
Parameters
Vector3
vector
The local space vector. |
Returns
Vector3
The world space vector. |
LocalToWorldVector(ref Vector3, out Vector3)
Performs transformation of the given vector in local space to the world space of this transform.
Declaration
public void LocalToWorldVector(ref Vector3 vector, out Vector3 result)
Parameters
Vector3
vector
The local space vector. |
Vector3
result
World space vector |
NearEqual(Transform, Transform, Single)
Tests whether one transform is near another transform.
Declaration
public static bool NearEqual(Transform left, Transform right, float epsilon = 1E-06F)
Parameters
Transform
left
The left transform. |
Transform
right
The right transform. |
System.Single
epsilon
The epsilon. |
Returns
System.Boolean
|
NearEqual(ref Transform, ref Transform, Single)
Tests whether one transform is near another transform.
Declaration
public static bool NearEqual(ref Transform left, ref Transform right, float epsilon = 1E-06F)
Parameters
Transform
left
The left transform. |
Transform
right
The right transform. |
System.Single
epsilon
The epsilon. |
Returns
System.Boolean
|
SetRotation(Matrix)
Sets rotation matrix (from Orientation).
Declaration
public void SetRotation(Matrix value)
Parameters
Matrix
value
Rotation matrix |
SetRotation(ref Matrix)
Sets rotation matrix (from Orientation).
Declaration
public void SetRotation(ref Matrix value)
Parameters
Matrix
value
Rotation matrix |
Subtract(Transform, Transform)
Subtracts two transforms.
Declaration
public static Transform Subtract(Transform left, Transform right)
Parameters
Transform
left
The first transform to subtract from. |
Transform
right
The second transform to subtract. |
Returns
Transform
The difference of the two transforms. |
ToString()
Returns a System.String that represents this instance.
Declaration
public override string ToString()
Returns
System.String
A System.String that represents this instance. |
ToString(IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(IFormatProvider formatProvider)
Parameters
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
ToString(String)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format)
Parameters
System.String
format
The format. |
Returns
System.String
A System.String that represents this instance. |
ToString(String, IFormatProvider)
Returns a System.String that represents this instance.
Declaration
public string ToString(string format, IFormatProvider formatProvider)
Parameters
System.String
format
The format. |
System.IFormatProvider
formatProvider
The format provider. |
Returns
System.String
A System.String that represents this instance. |
TransformDirection(Vector3)
Transforms the direction vector from the local space to the world space.
Declaration
public Vector3 TransformDirection(Vector3 direction)
Parameters
Vector3
direction
The direction. |
Returns
Vector3
The transformed direction vector. |
Remarks
This operation is not affected by scale or position of the transform. The returned vector has the same length as direction. Use TransformPoint(Vector3) for the conversion if the vector represents a position rather than a direction.
TransformPoint(Vector3)
Transforms the position from the local space to the world space.
Declaration
public Vector3 TransformPoint(Vector3 position)
Parameters
Vector3
position
The position. |
Returns
Vector3
The transformed position. |
Remarks
Use TransformDirection(Vector3) for the conversion if the vector represents a direction rather than a position.
WorldToLocal(Transform)
Perform transformation of the given transform in world space
Declaration
public Transform WorldToLocal(Transform other)
Parameters
Transform
other
World space transform |
Returns
Transform
Local space transform |
WorldToLocal(Vector3)
Perform transformation of the given point in world space
Declaration
public Vector3 WorldToLocal(Vector3 point)
Parameters
Vector3
point
World space point |
Returns
Vector3
Local space point |
WorldToLocal(ref Vector3, out Vector3)
Perform transformation of the given point in world space
Declaration
public void WorldToLocal(ref Vector3 point, out Vector3 result)
Parameters
Vector3
point
World space point |
Vector3
result
When the method completes, contains the local space point. |
WorldToLocal(Vector3[], Vector3[])
Perform transformation of the given points in world space
Declaration
public void WorldToLocal(Vector3[] points, Vector3[] result)
Parameters
Vector3[]
points
World space points |
Vector3[]
result
Local space points |
WorldToLocalVector(Vector3)
Perform transformation of the given vector in world space
Declaration
public Vector3 WorldToLocalVector(Vector3 vector)
Parameters
Vector3
vector
World space vector |
Returns
Vector3
Local space vector |
WorldToLocalVector(ref Vector3, out Vector3)
Perform transformation of the given vector in world space
Declaration
public void WorldToLocalVector(ref Vector3 vector, out Vector3 result)
Parameters
Vector3
vector
World space vector |
Vector3
result
Local space vector |
Operators
Addition(Transform, Transform)
Adds two transformations.
Declaration
public static Transform operator +(Transform left, Transform right)
Parameters
Transform
left
The first transform to add. |
Transform
right
The second transform to add. |
Returns
Transform
The sum of the two transformations. |
Equality(Transform, Transform)
Tests for equality between two objects.
Declaration
public static bool operator ==(Transform left, Transform right)
Parameters
Transform
left
The first value to compare. |
Transform
right
The second value to compare. |
Returns
System.Boolean
|
Inequality(Transform, Transform)
Tests for inequality between two objects.
Declaration
public static bool operator !=(Transform left, Transform right)
Parameters
Transform
left
The first value to compare. |
Transform
right
The second value to compare. |
Returns
System.Boolean
|
Subtraction(Transform, Transform)
Subtracts two transformations.
Declaration
public static Transform operator -(Transform left, Transform right)
Parameters
Transform
left
The first transform to subtract from. |
Transform
right
The second transform to subtract. |
Returns
Transform
The difference of the two transformations. |