Skip to content

Commit

Permalink
Expand entity transformation unit tests
Browse files Browse the repository at this point in the history
Add tests for rotating and translating a light node, which is working correctly
unlike func_static.
  • Loading branch information
Matthew Mott committed Nov 30, 2021
1 parent 3080043 commit 79c1f77
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions test/Entity.cpp
Expand Up @@ -423,9 +423,9 @@ TEST_F(EntityTest, SelectEntity)
// Confirm that setting entity node's selection status propagates to the
// selection system
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0);
Node_getSelectable(light)->setSelected(true);
scene::node_cast<ISelectable>(light)->setSelected(true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1);
Node_getSelectable(light)->setSelected(false);
scene::node_cast<ISelectable>(light)->setSelected(false);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0);
}

Expand All @@ -436,7 +436,7 @@ TEST_F(EntityTest, DestroySelectedEntity)
// Confirm that setting entity node's selection status propagates to the
// selection system
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 0);
Node_getSelectable(light)->setSelected(true);
scene::node_cast<ISelectable>(light)->setSelected(true);
EXPECT_EQ(GlobalSelectionSystem().countSelected(), 1);

// Destructor called here and should not crash
Expand Down Expand Up @@ -723,7 +723,7 @@ TEST_F(EntityTest, TranslateFuncStatic)
torch.args().setKeyValue("model", "models/torch.lwo");

// Set translation via the ITransformable interface
auto transformable = Node_getTransformable(torch.node);
auto transformable = scene::node_cast<ITransformable>(torch.node);
ASSERT_TRUE(transformable);
transformable->setTranslation(Vector3(128, 56, -64));

Expand All @@ -740,7 +740,7 @@ TEST_F(EntityTest, RotateFuncStatic)
torch.args().setKeyValue("model", "models/torch.lwo");

// Set rotation via the ITransformable interface
auto transformable = Node_getTransformable(torch.node);
auto transformable = scene::node_cast<ITransformable>(torch.node);
ASSERT_TRUE(transformable);
transformable->setRotation(Quaternion::createForEulerXYZDegrees(Vector3(0, 0, 45)));

Expand All @@ -750,18 +750,40 @@ TEST_F(EntityTest, RotateFuncStatic)
EXPECT_EQ(torch.args().getKeyValue("rotation"),
"0.707107 0.707107 0 -0.707107 0.707107 0 0 0 1");

// Applying the transform should be idempotent
transformable->freezeTransform();
EXPECT_EQ(torch.args().getKeyValue("rotation"),
"0.707107 0.707107 0 -0.707107 0.707107 0 0 0 1");

// Rotation does not change origin
EXPECT_EQ(torch.args().getKeyValue("origin"), "0 0 0");
}

TEST_F(EntityTest, RotateLight)
{
auto light = TestEntity::create("light");
light.args().setKeyValue("origin", "0 0 0");

// Rotate the light via ITransformable
auto transformable = scene::node_cast<ITransformable>(light.node);
ASSERT_TRUE(transformable);
transformable->setRotation(Quaternion::createForEulerXYZDegrees(Vector3(0, 0, 75)));

// Rotation appears after freezing transform
EXPECT_EQ(light.args().getKeyValue("rotation"), "");
transformable->freezeTransform();
EXPECT_EQ(light.args().getKeyValue("rotation"),
"0.258819 0.965926 0 -0.965926 0.258819 0 0 0 1");
}

TEST_F(EntityTest, TranslateFuncStaticAfterRotation)
{
auto torch = TestEntity::create("func_static");
torch.args().setKeyValue("origin", "0 0 0");
torch.args().setKeyValue("model", "models/torch.lwo");

// Set rotation via the ITransformable interface and freeze the transform
auto transformable = Node_getTransformable(torch.node);
auto transformable = scene::node_cast<ITransformable>(torch.node);
ASSERT_TRUE(transformable);
transformable->setRotation(Quaternion::createForEulerXYZDegrees(Vector3(0, 0, 90)));
transformable->freezeTransform();
Expand All @@ -770,11 +792,33 @@ TEST_F(EntityTest, TranslateFuncStaticAfterRotation)
// Now add a translation
transformable->setTranslation(Vector3(-1200, 45, 962));
transformable->freezeTransform();
EXPECT_EQ(torch.args().getKeyValue("origin"), "-1200 45 962");

// Rotation must not have changed
EXPECT_EQ(torch.args().getKeyValue("rotation"), "0 1 0 -1 0 0 0 0 1");
}

TEST_F(EntityTest, TranslateLightAfterRotation)
{
auto light = TestEntity::create("light");
light.args().setKeyValue("origin", "0 0 0");

// Set rotation via the ITransformable interface and freeze the transform
auto transformable = scene::node_cast<ITransformable>(light.node);
ASSERT_TRUE(transformable);
transformable->setRotation(Quaternion::createForEulerXYZDegrees(Vector3(0, 0, 90)));
transformable->freezeTransform();
EXPECT_EQ(light.args().getKeyValue("rotation"), "0 1 0 -1 0 0 0 0 1");

// Now add a translation
transformable->setTranslation(Vector3(565.25, -450, 35.2));
transformable->freezeTransform();
EXPECT_EQ(light.args().getKeyValue("origin"), "565.25 -450 35.2");

// Rotation must not have changed
EXPECT_EQ(light.args().getKeyValue("rotation"), "0 1 0 -1 0 0 0 0 1");
}

TEST_F(EntityTest, LightTransformedByParent)
{
// Parent a light to another entity (this isn't currently how the attachment
Expand Down Expand Up @@ -833,7 +877,7 @@ TEST_F(EntityTest, RenderSelectedLightEntity)
RenderFixture renderF;

// Select the light then render it in wireframe mode
Node_getSelectable(light)->setSelected(true);
scene::node_cast<ISelectable>(light)->setSelected(true);
light->setRenderSystem(renderF.backend);
light->renderWireframe(renderF.collector, renderF.volumeTest);

Expand Down

0 comments on commit 79c1f77

Please sign in to comment.