Skip to content

Commit aeae81d

Browse files
committed
Prevent degenerate scaling matrix (Fixes #643)
1 parent 5c37ca2 commit aeae81d

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Sources/OvMaths/src/OvMaths/FMatrix4.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,15 @@ OvMaths::FMatrix4 OvMaths::FMatrix4::RotateYXZ(const FMatrix4& p_matrix, float p
446446

447447
OvMaths::FMatrix4 OvMaths::FMatrix4::Scaling(const FVector3& p_scale)
448448
{
449-
return FMatrix4(p_scale.x, 0, 0, 0,
450-
0, p_scale.y, 0, 0,
451-
0, 0, p_scale.z, 0,
449+
// NOTE: 0-scaled axis produce degenerate matrices, so we want to avoid that!
450+
FVector3 safeScale = p_scale;
451+
if (safeScale.x == 0.0f) safeScale.x = kEpsilon;
452+
if (safeScale.y == 0.0f) safeScale.y = kEpsilon;
453+
if (safeScale.z == 0.0f) safeScale.z = kEpsilon;
454+
455+
return FMatrix4(safeScale.x, 0, 0, 0,
456+
0, safeScale.y, 0, 0,
457+
0, 0, safeScale.z, 0,
452458
0, 0, 0, 1);
453459
}
454460

0 commit comments

Comments
 (0)