16 ExpectNear(component.
GetScale(), glm::vec3(1));
20 ExpectNear(component.
GetForward(), glm::vec3(1, 0, 0));
21 ExpectNear(component.
GetRight(), glm::vec3(0, 1, 0));
22 ExpectNear(component.
GetUp(), glm::vec3(0, 0, 1));
30 component.
SetScale(glm::vec3(2, 3, 4));
31 ExpectNear(component.
GetPosition(), glm::vec3(3, -4, 5));
33 ExpectNear(component.
GetScale(), glm::vec3(2, 3, 4));
35 glm::mat4 expected(1);
39 expected[3] = glm::vec4(3, -4, 5, 1);
52 const Case cases[] = {
53 {{90, 0, 0}, {0, 0, 1}, {0, 1, 0}, {-1, 0, 0}},
54 {{0, 90, 0}, {0, -1, 0}, {1, 0, 0}, {0, 0, 1}},
55 {{0, 0, 90}, {1, 0, 0}, {0, 0, -1}, {0, 1, 0}}
58 for (
const auto& item : cases)
60 SCOPED_TRACE(::testing::Message() <<
"Euler " << item.angles.x <<
", "
61 << item.angles.y <<
", " << item.angles.z);
64 ExpectNear(component.
GetForward(), item.forward);
65 ExpectNear(component.
GetRight(), item.right);
66 ExpectNear(component.
GetUp(), item.up);
73 const auto rotation = glm::angleAxis(glm::radians(90.0f), glm::vec3(0, 0, 1));
76 EXPECT_NEAR(glm::abs(glm::dot(component.
GetRotationQuat(), rotation)), 1.0f, 1e-5f);
77 ExpectNear(component.
GetForward(), glm::vec3(0, 1, 0));
78 ExpectNear(component.
GetRight(), glm::vec3(-1, 0, 0));
79 ExpectNear(component.
GetUp(), glm::vec3(0, 0, 1));
80 ExpectNear(glm::mat4_cast(component.
GetWorldRotation()), glm::mat4_cast(rotation));
89 component.
SetScale(glm::vec3(2, 3, 4));
91 ExpectNear(component.
GetWorldMatrix() * glm::vec4(1, 2, 3, 1), glm::vec4(16, 18, 42, 1));
92 ExpectNear(component.
GetWorldMatrix() * glm::vec4(1, 2, 3, 0), glm::vec4(6, -2, 12, 0));
114 parent.
SetScale(glm::vec3(2, 3, 4));
139 glm::mat4 expected(1);
143 expected[3] = glm::vec4(4, 18, 30, 1);
153 expected[3] = glm::vec4(14, 28, 40, 1);
167 glm::mat4 expected(1);
168 expected[0] = glm::vec4(0, -1, 0, 0);
169 expected[1] = glm::vec4(0, 0, -1, 0);
170 expected[2] = glm::vec4(1, 0, 0, 0);
189 ExpectNear(child.
GetPosition(), glm::vec3(1, 2, 3));
190 ExpectNear(child.
GetRotation(), glm::vec3(10, 20, 30));
191 ExpectNear(child.
GetScale(), glm::vec3(2, 3, 4));
Represents a 3D transformable scene component with position, rotation, and scale.
glm::vec3 GetRight() const
Returns the right (local Y+) direction vector in world space.
const glm::vec3 & GetPosition() const
Gets the current position.
void AttachTo(SceneComponent *parent)
Attaches this scene component to a parent scene component.
const glm::vec3 & GetRotation() const
Gets the current rotation as Euler angles (in degrees).
const glm::mat4 & GetWorldMatrix()
Returns the world transformation matrix (model matrix).
void SetRotation(const glm::quat &rotation)
Sets the rotation using a quaternion.
glm::vec3 GetWorldPosition() const
Returns the world-space position of this component.
void SetPosition(const glm::vec3 &position)
Sets the position of the component in world space.
const glm::vec3 & GetScale() const
Gets the current scale.
glm::vec3 GetForward() const
Returns the forward (local X+) direction vector in world space.
glm::quat GetWorldRotation() const
Returns the world-space rotation of this component.
void SetScale(const glm::vec3 &scale)
Sets the scale for each dimension.
glm::vec3 GetWorldScale() const
Returns the world-space scale of this component.
const glm::quat & GetRotationQuat() const
Gets the current rotation as a quaternion.
glm::vec3 GetUp() const
Returns the up (local Z+) direction vector in world space.
void ExpectNear(const glm::vec< N, T, Q > &actual, const glm::vec< N, T, Q > &expected, float tolerance=1e-5f)
TEST(SceneComponent, DefaultsToIdentityAndEngineAxes)