Skip to content

Commit 87d4926

Browse files
committed
REVIEWED: raymath: MatrixCompose()
1 parent 8100413 commit 87d4926

File tree

1 file changed

+21
-25
lines changed

1 file changed

+21
-25
lines changed

src/raymath.h

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2553,38 +2553,37 @@ RMAPI int QuaternionEquals(Quaternion p, Quaternion q)
25532553
}
25542554

25552555
// 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 );
2556+
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
2557+
RMAPI Matrix MatrixCompose(Vector3 translation, Quaternion rotation, Vector3 scale)
2558+
{
2559+
// Initialize vectors
2560+
Vector3 right = { 1.0f, 0.0f, 0.0f };
2561+
Vector3 up = { 0.0f, 1.0f, 0.0f };
2562+
Vector3 forward = { 0.0f, 0.0f, 1.0f };
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);
25732573

2574-
// Set matrix output
2574+
// Set result matrix output
25752575
Matrix result = {
25762576
right.x, up.x, forward.x, position.x,
25772577
right.y, up.y, forward.y, position.y,
25782578
right.z, up.z, forward.z, position.z,
2579-
0, 0, 0, 1
2579+
0.0f, 0.0f, 0.0f, 1.0f
25802580
};
25812581

2582-
// Return matrix output
25832582
return result;
2584-
25852583
}
25862584

25872585
// Decompose a transformation matrix into its rotational, translational and scaling components and remove shear
2586+
// TODO: This function is not following raymath conventions defined in header: NOT self-contained
25882587
RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotation, Vector3 *scale)
25892588
{
25902589
float eps = (float)1e-9;
@@ -2619,10 +2618,7 @@ RMAPI void MatrixDecompose(Matrix mat, Vector3 *translation, Quaternion *rotatio
26192618

26202619
// X Scale
26212620
scl.x = Vector3Length(matColumns[0]);
2622-
if (scl.x > eps)
2623-
{
2624-
matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
2625-
}
2621+
if (scl.x > eps) matColumns[0] = Vector3Scale(matColumns[0], 1.0f / scl.x);
26262622

26272623
// Compute XY shear and make col2 orthogonal
26282624
shear[0] = Vector3DotProduct(matColumns[0], matColumns[1]);

0 commit comments

Comments
 (0)