Skip to content

Commit

Permalink
Merge branch 'ign-rendering6' into marker_test
Browse files Browse the repository at this point in the history
  • Loading branch information
iche033 authored Jul 25, 2022
2 parents 5513fe1 + ef9b76f commit 6fce8d1
Showing 1 changed file with 92 additions and 14 deletions.
106 changes: 92 additions & 14 deletions src/TransformController_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)

TransformController transformControl;

// test invalid callas and make sure no exceptions are thrown
EXPECT_NO_THROW(transformControl.SetCamera(nullptr));
EXPECT_NO_THROW(transformControl.Attach(nullptr));
EXPECT_NO_THROW(transformControl.Start());
EXPECT_NO_THROW(transformControl.Translate(math::Vector3d::Zero));
EXPECT_NO_THROW(transformControl.Rotate(math::Quaterniond::Identity));
EXPECT_NO_THROW(transformControl.Translate(math::Vector3d::One));
EXPECT_EQ(math::Vector3d::Zero, transformControl.AxisById(0u));

// test setting camera
transformControl.SetCamera(camera);
EXPECT_EQ(camera, transformControl.Camera());
Expand All @@ -236,29 +245,65 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
transformControl.SetActiveAxis(math::Vector3d::UnitZ);
transformControl.Translate(math::Vector3d(0, 0, 2));
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
EXPECT_EQ(visual->WorldRotation(), initialRot);
EXPECT_EQ(visual->WorldScale(), math::Vector3d::One);
transformControl.Update();
EXPECT_EQ(math::Vector3d(0, -2, 0), visual->WorldPosition());
EXPECT_EQ(initialRot, visual->WorldRotation());
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());

// test translation when snapping is enabled
transformControl.SetActiveAxis(math::Vector3d::UnitY);
transformControl.SetTransformSpace(TransformSpace::TS_WORLD);
transformControl.Translate(math::Vector3d(0, 1, 0), true);
transformControl.Update();
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
EXPECT_EQ(initialRot, visual->WorldRotation());
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());

// test rotation in local space
transformControl.SetTransformMode(TransformMode::TM_ROTATION);
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
transformControl.SetActiveAxis(math::Vector3d::UnitX);
transformControl.Rotate(math::Quaterniond(IGN_PI, 0, 0));
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
EXPECT_EQ(visual->WorldRotation(),
math::Quaterniond(IGN_PI, 0, 0) * initialRot);
EXPECT_EQ(visual->WorldScale(), math::Vector3d::One);
transformControl.Update();
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
EXPECT_EQ(math::Quaterniond(IGN_PI, 0, 0) * initialRot,
visual->WorldRotation());
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());

// test rotation when snapping is enabled
transformControl.SetActiveAxis(math::Vector3d::UnitY);
transformControl.SetTransformSpace(TransformSpace::TS_WORLD);
transformControl.Rotate(math::Quaterniond(0, IGN_PI, 0), true);
transformControl.Update();
EXPECT_EQ( math::Vector3d(0, -1, 0), visual->WorldPosition());
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
initialRot, visual->WorldRotation());
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());

// test scaling in local space
transformControl.SetTransformMode(TransformMode::TM_SCALE);
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
transformControl.SetActiveAxis(math::Vector3d::UnitY);
transformControl.Scale(math::Vector3d(1.0, 0.3, 1.0));
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
EXPECT_EQ(visual->WorldRotation(),
math::Quaterniond(IGN_PI, 0, 0) * initialRot);
EXPECT_EQ(visual->WorldScale(), math::Vector3d(1.0, 0.3, 1.0));
transformControl.Update();
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
initialRot, visual->WorldRotation());

auto expectedScale = math::Vector3d(1.0, 0.3, 1.0);
EXPECT_EQ(expectedScale, visual->WorldScale());

// test scaling when snapping is enabled
auto newScale = math::Vector3d(2.0, 6.0, 1.2);
transformControl.Scale(newScale, true);
transformControl.Update();
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
initialRot, visual->WorldRotation());
math::Vector3d snappedScale(std::round(newScale.X() * expectedScale.X()),
std::round(newScale.Y() * expectedScale.Y()),
std::round(newScale.Z() * expectedScale.Z()));
EXPECT_EQ(snappedScale, visual->WorldScale());

// Clean up
engine->DestroyScene(scene);
Expand Down Expand Up @@ -288,30 +333,57 @@ void TransformControllerTest::Control2d(const std::string &_renderEngine)

TransformController transformControl;

// test setting camera
transformControl.SetCamera(camera);
EXPECT_EQ(camera, transformControl.Camera());
// test translation and scale without a node
math::Vector2d start0(0.5, 0.5);
math::Vector2d end0(0.5, 0.8);
EXPECT_EQ(math::Vector3d::Zero,
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start0, end0));
EXPECT_EQ(math::Vector3d::Zero,
transformControl.ScaleFrom2d(math::Vector3d::UnitY, start0, end0));

// create a dummy node visual node and attach to the controller
VisualPtr visual = scene->CreateVisual();
ASSERT_NE(nullptr, visual);
transformControl.Attach(visual);
EXPECT_EQ(visual, transformControl.Node());

// test translation and scale without a camera
EXPECT_EQ(math::Vector3d::Zero,
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start0, end0));
EXPECT_EQ(math::Vector3d::Zero,
transformControl.ScaleFrom2d(math::Vector3d::UnitY, start0, end0));

// test setting camera
transformControl.SetCamera(camera);
EXPECT_EQ(camera, transformControl.Camera());

// test translation from 2d
transformControl.SetTransformMode(TransformMode::TM_TRANSLATION);
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
transformControl.SetActiveAxis(math::Vector3d::UnitZ);
transformControl.Start();
math::Vector2d start(0.5, 0.5);
math::Vector2d end(0.5, 0.8);
// translation in z
math::Vector3d translation =
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start, end);
transformControl.Stop();
EXPECT_DOUBLE_EQ(translation.X(), 0);
EXPECT_DOUBLE_EQ(translation.Y(), 0);
EXPECT_GT(translation.Z(), 0);

// translation in y
transformControl.SetActiveAxis(math::Vector3d::UnitY);
transformControl.Start();
math::Vector2d starty(0.5, 0.5);
math::Vector2d endy(0.2, 0.5);
translation =
transformControl.TranslationFrom2d(math::Vector3d::UnitY, starty, endy);
transformControl.Stop();
EXPECT_DOUBLE_EQ(translation.X(), 0);
EXPECT_GT(translation.Y(), 0);
EXPECT_DOUBLE_EQ(translation.Z(), 0);

// test rotation from 2d
transformControl.SetTransformMode(TransformMode::TM_ROTATION);
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
Expand Down Expand Up @@ -339,6 +411,12 @@ void TransformControllerTest::Control2d(const std::string &_renderEngine)
EXPECT_GT(scale.Y(), 0);
EXPECT_DOUBLE_EQ(scale.Z(), 1);

// test snapping with invalid args
EXPECT_EQ(math::Vector3d::Zero,
transformControl.SnapPoint(math::Vector3d::One, -1));
EXPECT_EQ(math::Vector3d::Zero,
transformControl.SnapPoint(math::Vector3d::One, 1, -1));

// Clean up
engine->DestroyScene(scene);
rendering::unloadEngine(engine->Name());
Expand Down

0 comments on commit 6fce8d1

Please sign in to comment.