Skip to content

Commit a9f2809

Browse files
committed
Cleaned up degenerate scaling matrix prevention implementation
1 parent aeae81d commit a9f2809

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

Sources/OvMaths/src/OvMaths/FMatrix4.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -447,15 +447,18 @@ OvMaths::FMatrix4 OvMaths::FMatrix4::RotateYXZ(const FMatrix4& p_matrix, float p
447447
OvMaths::FMatrix4 OvMaths::FMatrix4::Scaling(const FVector3& p_scale)
448448
{
449449
// 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,
458-
0, 0, 0, 1);
450+
const FVector3 safeScale{
451+
p_scale.x == 0.0f ? kEpsilon : p_scale.x,
452+
p_scale.y == 0.0f ? kEpsilon : p_scale.y,
453+
p_scale.z == 0.0f ? kEpsilon : p_scale.z
454+
};
455+
456+
return FMatrix4(
457+
safeScale.x, 0, 0, 0,
458+
0, safeScale.y, 0, 0,
459+
0, 0, safeScale.z, 0,
460+
0, 0, 0, 1
461+
);
459462
}
460463

461464
OvMaths::FMatrix4 OvMaths::FMatrix4::Scale(const FMatrix4& p_matrix, const FVector3& p_scale)

0 commit comments

Comments
 (0)