diff --git a/Tests/EngineTest.cpp b/Tests/EngineTest.cpp index 9347e20..e907897 100644 --- a/Tests/EngineTest.cpp +++ b/Tests/EngineTest.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -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) { diff --git a/YoggieEngine/src/Scene/Components.h b/YoggieEngine/src/Scene/Components.h index cd22ff7..5061dd1 100644 --- a/YoggieEngine/src/Scene/Components.h +++ b/YoggieEngine/src/Scene/Components.h @@ -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;