Skip to content

Commit

Permalink
Merge pull request godotengine#61013 from Calinou/test-add-transform3d
Browse files Browse the repository at this point in the history
Add rotation unit tests for Transform3D
  • Loading branch information
akien-mga committed Apr 19, 2024
2 parents 9bc49a6 + 4e6de25 commit 0f7452f
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/core/math/test_transform_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,35 @@ TEST_CASE("[Transform3D] Finite number checks") {
"Transform3D with two components infinite should not be finite.");
}

TEST_CASE("[Transform3D] Rotate around global origin") {
// Start with the default orientation, but not centered on the origin.
// Rotating should rotate both our basis and the origin.
Transform3D transform = Transform3D();
transform.origin = Vector3(0, 0, 1);

Transform3D expected = Transform3D();
expected.origin = Vector3(0, 0, -1);
expected.basis[0] = Vector3(-1, 0, 0);
expected.basis[2] = Vector3(0, 0, -1);

const Transform3D rotated_transform = transform.rotated(Vector3(0, 1, 0), Math_PI);
CHECK_MESSAGE(rotated_transform.is_equal_approx(expected), "The rotated transform should have a new orientation and basis.");
}

TEST_CASE("[Transform3D] Rotate in-place (local rotation)") {
// Start with the default orientation.
// Local rotation should not change the origin, only the basis.
Transform3D transform = Transform3D();
transform.origin = Vector3(1, 2, 3);

Transform3D expected = Transform3D();
expected.origin = Vector3(1, 2, 3);
expected.basis[0] = Vector3(-1, 0, 0);
expected.basis[2] = Vector3(0, 0, -1);

const Transform3D rotated_transform = Transform3D(transform.rotated_local(Vector3(0, 1, 0), Math_PI));
CHECK_MESSAGE(rotated_transform.is_equal_approx(expected), "The rotated transform should have a new orientation but still be based on the same origin.");
}
} // namespace TestTransform3D

#endif // TEST_TRANSFORM_3D_H

0 comments on commit 0f7452f

Please sign in to comment.