Browse Source

adding Matrix MatrixCompose( translate, rotation, scale ) to raymath.h (#5324)

pull/5325/head
EDBC_REPO 1 month ago
committed by GitHub
parent
commit
81004135a4
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 32 additions and 0 deletions
  1. +32
    -0
      src/raymath.h

+ 32
- 0
src/raymath.h View File

@ -2552,6 +2552,38 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
return result;
}
// Compose a transformation matrix from rotational, translational and scaling components
RMAPI Matrix MatrixCompose( Vector3 translation, Quaternion rotation, Vector3 scale )
{
//Initialize Vectors
Vector3 right = { 1, 0, 0 };
Vector3 up = { 0, 1, 0 };
Vector3 forward = { 0, 0, 1 };
//Scale Vectors
right = Vector3Scale( right , scale.x );
up = Vector3Scale( up , scale.y );
forward = Vector3Scale( forward , scale.z );
//Rotate Vectors
right = Vector3RotateByQuaternion( right , rotation );
up = Vector3RotateByQuaternion( up , rotation );
forward = Vector3RotateByQuaternion( forward, rotation );
// Set matrix output
Matrix result = {
right.x, up.x, forward.x, position.x,
right.y, up.y, forward.y, position.y,
right.z, up.z, forward.z, position.z,
0, 0, 0, 1
};
// Return matrix output
return result;
}
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
{

Loading…
Cancel
Save