mirror of
https://github.com/raysan5/raylib.git
synced 2025-11-12 21:38:47 +00:00
REVIEWED: raymath: MatrixCompose()
This commit is contained in:
@@ -2553,38 +2553,37 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compose a transformation matrix from rotational, translational and scaling components
|
// Compose a transformation matrix from rotational, translational and scaling components
|
||||||
|
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
|
||||||
RMAPI Matrix MatrixCompose(Vector3 translation, Quaternion rotation, Vector3 scale)
|
RMAPI Matrix MatrixCompose(Vector3 translation, Quaternion rotation, Vector3 scale)
|
||||||
{
|
{
|
||||||
|
// Initialize vectors
|
||||||
|
Vector3 right = { 1.0f, 0.0f, 0.0f };
|
||||||
|
Vector3 up = { 0.0f, 1.0f, 0.0f };
|
||||||
|
Vector3 forward = { 0.0f, 0.0f, 1.0f };
|
||||||
|
|
||||||
//Initialize Vectors
|
// Scale vectors
|
||||||
Vector3 right = { 1, 0, 0 };
|
|
||||||
Vector3 up = { 0, 1, 0 };
|
|
||||||
Vector3 forward = { 0, 0, 1 };
|
|
||||||
|
|
||||||
//Scale Vectors
|
|
||||||
right = Vector3Scale(right, scale.x);
|
right = Vector3Scale(right, scale.x);
|
||||||
up = Vector3Scale(up, scale.y);
|
up = Vector3Scale(up, scale.y);
|
||||||
forward = Vector3Scale(forward , scale.z);
|
forward = Vector3Scale(forward , scale.z);
|
||||||
|
|
||||||
//Rotate Vectors
|
// Rotate vectors
|
||||||
right = Vector3RotateByQuaternion(right, rotation);
|
right = Vector3RotateByQuaternion(right, rotation);
|
||||||
up = Vector3RotateByQuaternion(up, rotation);
|
up = Vector3RotateByQuaternion(up, rotation);
|
||||||
forward = Vector3RotateByQuaternion(forward, rotation);
|
forward = Vector3RotateByQuaternion(forward, rotation);
|
||||||
|
|
||||||
// Set matrix output
|
// Set result matrix output
|
||||||
Matrix result = {
|
Matrix result = {
|
||||||
right.x, up.x, forward.x, position.x,
|
right.x, up.x, forward.x, position.x,
|
||||||
right.y, up.y, forward.y, position.y,
|
right.y, up.y, forward.y, position.y,
|
||||||
right.z, up.z, forward.z, position.z,
|
right.z, up.z, forward.z, position.z,
|
||||||
0, 0, 0, 1
|
0.0f, 0.0f, 0.0f, 1.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
// Return matrix output
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
|
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
|
||||||
|
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
|
||||||
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
|
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
|
||||||
{
|
{
|
||||||
float eps = (float)1e-9;
|
float eps = (float)1e-9;
|
||||||
@@ -2619,10 +2618,7 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio
|
|||||||
|
|
||||||
// X Scale
|
// X Scale
|
||||||
scl.x = Vector3Length(matColumns[0]);
|
scl.x = Vector3Length(matColumns[0]);
|
||||||
if (scl.x > eps)
|
if (scl.x > eps) matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
|
||||||
{
|
|
||||||
matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compute XY shear and make col2 orthogonal
|
// Compute XY shear and make col2 orthogonal
|
||||||
shear[0] = Vector3DotProduct(matColumns[0], matColumns[1]);
|
shear[0] = Vector3DotProduct(matColumns[0], matColumns[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user