Adding tests for decompose function

Added scale and rotation decompose test
This commit is contained in:
Nigel Barink 2023-05-16 20:43:05 +02:00
parent c640ac574b
commit 817d0bdca9
2 changed files with 42 additions and 0 deletions

View File

@ -1,4 +1,5 @@
#include <YoggieEngine.h> #include <YoggieEngine.h>
#include <ImGuizmo.h>
#include <gtest/gtest.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) { int main(int argc, char** argv) {

View File

@ -30,6 +30,8 @@ namespace YoggieEngine {
void Decompose(glm::mat4& transformationMatrix) { void Decompose(glm::mat4& transformationMatrix) {
auto& a = transformationMatrix[0][0]; auto& a = transformationMatrix[0][0];
auto& b = transformationMatrix[1][0]; auto& b = transformationMatrix[1][0];
auto& c = transformationMatrix[2][0]; auto& c = transformationMatrix[2][0];
@ -46,6 +48,8 @@ namespace YoggieEngine {
auto& l = transformationMatrix[3][2]; auto& l = transformationMatrix[3][2];
Position = glm::vec3(transformationMatrix[3]); Position = glm::vec3(transformationMatrix[3]);
// Remove the position from the matrix
d = 0; d = 0;
h = 0; h = 0;
l = 0; l = 0;
@ -56,6 +60,7 @@ namespace YoggieEngine {
Scale = glm::vec3(sx, sy, sz); Scale = glm::vec3(sx, sy, sz);
// Remove the scale from the matrix;
a/= sx; a/= sx;
e /= sx; e /= sx;
i /= sx; i /= sx;