Include some operations or properties for TRS UnityEngine.Matrix4x4
.
More...
Static Public Member Functions | |
static Matrix4x4 | Create (Vector3 position, Vector3 scale, Vector3 axisX, Vector3 axisY, Vector3 axisZ) |
Create a TRS matrix with position, abs scale and normalized axes. More... | |
static Matrix4x4 | Create (Vector3 position, Vector3 axisX, Vector3 axisY, Vector3 axisZ) |
Create a TRS matrix, directly fill up the columns with position and axes. More... | |
static Matrix4x4 | Convert (ref Matrix4x4 matrix, ref Matrix4x4 from, ref Matrix4x4 to, bool scale=true) |
Get converted matrix from a parent matrix to another. More... | |
static Matrix4x4 | LocalToWorld (ref Matrix4x4 matrix, ref Matrix4x4 parent, bool scale=true) |
Get converted matrix from local in parent to world space. More... | |
static Matrix4x4 | WorldToLocal (ref Matrix4x4 matrix, ref Matrix4x4 parent, bool scale=true) |
Get converted matrix from world to local in parent space. More... | |
static float | GetDeterminant (ref Matrix4x4 matrix) |
Get the determinant of the matrix. More... | |
static Vector3 | GetAxisX (ref Matrix4x4 matrix) |
Get the X axis from TRS matrix. More... | |
static void | SetAxisX (ref Matrix4x4 matrix, Vector3 value) |
Set the X axis to TRS matrix. More... | |
static Vector3 | GetAxisY (ref Matrix4x4 matrix) |
Get the Y axis from TRS matrix. More... | |
static void | SetAxisY (ref Matrix4x4 matrix, Vector3 value) |
Set the Y axis to TRS matrix. More... | |
static Vector3 | GetAxisZ (ref Matrix4x4 matrix) |
Get the Z axis from TRS matrix. More... | |
static void | SetAxisZ (ref Matrix4x4 matrix, Vector3 value) |
Set the Z axis to TRS matrix. More... | |
static Vector3 | GetPosition (ref Matrix4x4 matrix) |
Get the position from TRS matrix. More... | |
static void | SetPosition (ref Matrix4x4 matrix, Vector3 value) |
Set the position to TRS matrix. More... | |
static Quaternion | GetRotation (ref Matrix4x4 matrix) |
Get the rotation from TRS matrix. More... | |
static Quaternion | GetRotation (ref Matrix4x4 matrix, Vector3 scale) |
Get the rotation from TRS matrix. More... | |
static void | SetRotation (ref Matrix4x4 matrix, Quaternion value) |
Set the rotation to TRS matrix. More... | |
static Vector3 | GetScale (ref Matrix4x4 matrix) |
Get the scale from TRS matrix. More... | |
static Vector3 | GetScale (ref Matrix4x4 matrix, Quaternion rotation) |
Get the scale from TRS matrix. More... | |
static void | SetScale (ref Matrix4x4 matrix, Vector3 value) |
Set the scale from TRS matrix. More... | |
static bool | IsSkew (ref Matrix4x4 matrix, float approx=1e-6f) |
Determine if the specified TRS matrix skewed. More... | |
static bool | IsSkew (Vector3 axisX, Vector3 axisY, Vector3 axisZ, float approx=1e-6f) |
Determine if the matrix skewed by axes. More... | |
Include some operations or properties for TRS UnityEngine.Matrix4x4
.
Basically use ref
to reduce lots of data copying.
|
static |
Create a TRS matrix with position, abs scale and normalized axes.
A normalized axis multiplies the scale as length to fill up the matrix. Different from Matrix4x4.TRS()
, using axes to include skew.
position | Position. |
scale | Scale. |
axisX | X-Axis. |
axisY | Y-Axis. |
axisZ | Z-Axis. |
|
static |
Create a TRS matrix, directly fill up the columns with position and axes.
An axis is a segment with direction and length. Different from Matrix4x4.TRS()
, using axes to include skew.
position | Position. |
axisX | X-Axis. |
axisY | Y-Axis. |
axisZ | Z-Axis. |
|
static |
Get converted matrix from a parent matrix to another.
If set scale false
, treat the parent space with scale one. This will NOT modify the referred matrix.
matrix | Matrix. |
from | Parent from. |
to | Parent to. |
scale | If set to true scale. |
|
static |
Get converted matrix from local in parent to world space.
If set scale false
, treat the parent space with scale one. This will NOT modify the referred matrix.
matrix | Matrix. |
parent | Parent from. |
scale | If set to true scale. |
|
static |
Get converted matrix from world to local in parent space.
If set scale false
, treat the parent space with scale one. This will NOT modify the referred matrix.
matrix | Matrix. |
parent | Parent to. |
scale | If set to true scale. |
|
static |
Get the determinant of the matrix.
This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Get the X axis from TRS matrix.
The axis vector means direction and magnitude. This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Set the X axis to TRS matrix.
The axis vector means direction and magnitude. This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Get the Y axis from TRS matrix.
The axis vector means direction and magnitude. This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Set the Y axis to TRS matrix.
The axis vector means direction and magnitude. This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Get the Z axis from TRS matrix.
The axis vector means direction and magnitude. This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Set the Z axis to TRS matrix.
The axis vector means direction and magnitude. This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Get the position from TRS matrix.
This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Set the position to TRS matrix.
This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Get the rotation from TRS matrix.
Note first, UnityEngine.Quaternion
can't represent the correct axes if matrix skewed. Second, the directions might be incorrect if matrix made from negative or zero scale. The other, the sign might differ from the rotation passed to Matrix4x4.TRS()
. If you wanna compare the rotation, for use, you could compare eulerAngles instead. This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Get the rotation from TRS matrix.
Correct direction with signed scale of matrix to handle with negative value. This will NOT modify the referred matrix.
matrix | Matrix. |
scale | Signed scale. |
|
static |
Set the rotation to TRS matrix.
Rotates all axes in once to make new z-axis face to new rotation. This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Get the scale from TRS matrix.
This method can only calculate scale into positive value. It might not the same as the scale passed to Matrix4x4.TRS()
if with negative. Since it's able to generate the same matrix by different scale and rotation pair. There's not enough information to know the correct signs of scale components. This will NOT modify the referred matrix.
matrix | Matrix. |
|
static |
Get the scale from TRS matrix.
This corrects the sign with known rotation of the matrix. If the matrix is made from UnityEngine.Transform
, the return is lossyScale
. Calculating might cause little tolerance, it's better to compare by approx. This will NOT modify the referred matrix.
matrix | Matrix. |
rotation | Rotation. |
|
static |
Set the scale from TRS matrix.
Modify the length of the axes, reverse if assigning negative. Nothing happens if an axis zero. This WILL modify the referred matrix.
matrix | Matrix. |
value | Value. |
|
static |
Determine if the specified TRS matrix skewed.
Return false
if all the axes pairs are perpendicular or zero. This will NOT modify the referred matrix.
matrix | Matrix. |
approx | Approx to judge. |
true
if is skewed matrix; otherwise, false
.
|
static |
Determine if the matrix skewed by axes.
Return true
if anyone of pairs axes includes non-right angle, means skewed. Otherwise, the vectors are perpendicular or zero.
axisX | X-Axis. |
axisY | Y-Axis. |
axisZ | Z-Axis. |
approx | Approx to judge. |
true
if is skewed axes; otherwise, false
.