Skip to content

Commit 8100413

Browse files
authored
adding Matrix MatrixCompose( translate, rotation, scale ) to raymath.h (#5324)
1 parent cc83b2b commit 8100413

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/raymath.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2552,6 +2552,38 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
25522552
return result;
25532553
}
25542554

2555+
// Compose a transformation matrix from rotational, translational and scaling components
2556+
RMAPI Matrix MatrixCompose( Vector3 translation, Quaternion rotation, Vector3 scale )
2557+
{
2558+
2559+
//Initialize Vectors
2560+
Vector3 right = { 1, 0, 0 };
2561+
Vector3 up = { 0, 1, 0 };
2562+
Vector3 forward = { 0, 0, 1 };
2563+
2564+
//Scale Vectors
2565+
right = Vector3Scale( right , scale.x );
2566+
up = Vector3Scale( up , scale.y );
2567+
forward = Vector3Scale( forward , scale.z );
2568+
2569+
//Rotate Vectors
2570+
right = Vector3RotateByQuaternion( right , rotation );
2571+
up = Vector3RotateByQuaternion( up , rotation );
2572+
forward = Vector3RotateByQuaternion( forward, rotation );
2573+
2574+
// Set matrix output
2575+
Matrix result = {
2576+
right.x, up.x, forward.x, position.x,
2577+
right.y, up.y, forward.y, position.y,
2578+
right.z, up.z, forward.z, position.z,
2579+
0, 0, 0, 1
2580+
};
2581+
2582+
// Return matrix output
2583+
return result;
2584+
2585+
}
2586+
25552587
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
25562588
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
25572589
{

0 commit comments

Comments
 (0)