Fix world rotation extraction with scaled parents
This commit is contained in:
@@ -96,6 +96,35 @@ TEST(TransformComponent_Test, WorldRotation_WithParent) {
|
||||
EXPECT_TRUE(worldRot.Magnitude() > 0.0f);
|
||||
}
|
||||
|
||||
TEST(TransformComponent_Test, WorldRotation_WithScaledParentPreservesRotation) {
|
||||
TransformComponent parent;
|
||||
TransformComponent child;
|
||||
|
||||
parent.SetLocalScale(Vector3(0.38912f, 0.38912f, 0.38912f));
|
||||
parent.SetLocalRotation(Quaternion::FromAxisAngle(Vector3::Up(), PI * 0.25f));
|
||||
child.SetParent(&parent);
|
||||
child.SetLocalRotation(Quaternion::FromAxisAngle(Vector3::Right(), PI * 0.125f));
|
||||
|
||||
const Quaternion expectedWorldRotation = parent.GetLocalRotation() * child.GetLocalRotation();
|
||||
const Quaternion actualWorldRotation = child.GetRotation();
|
||||
|
||||
EXPECT_GT(std::abs(actualWorldRotation.Dot(expectedWorldRotation)), 0.999f);
|
||||
}
|
||||
|
||||
TEST(TransformComponent_Test, SetWorldRotation_WithScaledParentPreservesTargetRotation) {
|
||||
TransformComponent parent;
|
||||
TransformComponent child;
|
||||
|
||||
parent.SetLocalScale(Vector3(0.38912f, 0.38912f, 0.38912f));
|
||||
child.SetParent(&parent);
|
||||
|
||||
const Quaternion targetWorldRotation = Quaternion::FromAxisAngle(Vector3::Forward(), PI * 0.33f);
|
||||
child.SetRotation(targetWorldRotation);
|
||||
|
||||
const Quaternion actualWorldRotation = child.GetRotation();
|
||||
EXPECT_GT(std::abs(actualWorldRotation.Dot(targetWorldRotation)), 0.999f);
|
||||
}
|
||||
|
||||
TEST(TransformComponent_Test, WorldScale_WithParent) {
|
||||
TransformComponent parent;
|
||||
TransformComponent child;
|
||||
@@ -301,4 +330,4 @@ TEST(TransformComponent_Test, SetAsLastSibling) {
|
||||
EXPECT_EQ(child1.GetSiblingIndex(), 1);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user