Adding tests for decompose function
Added scale and rotation decompose test
This commit is contained in:
parent
c640ac574b
commit
817d0bdca9
@ -1,4 +1,5 @@
|
||||
#include <YoggieEngine.h>
|
||||
#include <ImGuizmo.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
|
||||
@ -23,6 +24,42 @@ TEST(TRANSFORM_COMPONENT_TESTS , CAN_EXTRACT_TRANSLATION_FROM_TRANSFORM_MATRIX)
|
||||
|
||||
}
|
||||
|
||||
TEST(TRANSFORM_COMPONENT_TESTS, CAN_EXTRACT_SCALE_FROM_TRANSFORM_MATRIX) {
|
||||
auto component = YoggieEngine::TransformComponent{};
|
||||
|
||||
component.Scale = glm::vec3(1.0f, 2.0f, 3.0f);
|
||||
|
||||
auto tranformationMatrix = component.GetTransform();
|
||||
|
||||
auto newComponent = YoggieEngine::TransformComponent{};
|
||||
|
||||
newComponent.Decompose(tranformationMatrix);
|
||||
|
||||
EXPECT_EQ(newComponent.Scale.x, component.Scale.x);
|
||||
EXPECT_EQ(newComponent.Scale.y, component.Scale.y);
|
||||
EXPECT_EQ(newComponent.Scale.z, component.Scale.z);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST(TRANSFORM_COMPONENT_TESTS, CAN_EXTRACT_ROTATION_FROM_TRANSFORM_MATRIX) {
|
||||
auto component = YoggieEngine::TransformComponent{};
|
||||
component.Rotation = glm::vec3(2.0f, 10.0f, 20.0f);
|
||||
|
||||
auto transformMatrix = component.GetTransform();
|
||||
|
||||
auto newComponent = YoggieEngine::TransformComponent{};
|
||||
|
||||
newComponent.Decompose(transformMatrix);
|
||||
|
||||
|
||||
EXPECT_EQ(newComponent.Rotation.x, component.Rotation.x);
|
||||
EXPECT_EQ(newComponent.Rotation.y, component.Rotation.y);
|
||||
EXPECT_EQ(newComponent.Rotation.z, component.Rotation.z);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
|
@ -30,6 +30,8 @@ namespace YoggieEngine {
|
||||
|
||||
void Decompose(glm::mat4& transformationMatrix) {
|
||||
|
||||
|
||||
|
||||
auto& a = transformationMatrix[0][0];
|
||||
auto& b = transformationMatrix[1][0];
|
||||
auto& c = transformationMatrix[2][0];
|
||||
@ -46,6 +48,8 @@ namespace YoggieEngine {
|
||||
auto& l = transformationMatrix[3][2];
|
||||
|
||||
Position = glm::vec3(transformationMatrix[3]);
|
||||
|
||||
// Remove the position from the matrix
|
||||
d = 0;
|
||||
h = 0;
|
||||
l = 0;
|
||||
@ -56,6 +60,7 @@ namespace YoggieEngine {
|
||||
|
||||
Scale = glm::vec3(sx, sy, sz);
|
||||
|
||||
// Remove the scale from the matrix;
|
||||
a/= sx;
|
||||
e /= sx;
|
||||
i /= sx;
|
||||
|
Loading…
Reference in New Issue
Block a user