mirror of
https://github.com/raysan5/raylib.git
synced 2025-12-25 10:22:33 -05:00
adding Matrix MatrixCompose( translate, rotation, scale ) to raymath.h (#5324)
This commit is contained in:
@ -2552,6 +2552,38 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
|
|||||||
return result;
|
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
|
// 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)
|
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user