Skip to content

Commit 9b60bf4

Browse files
authored
Merge branch 'ign-rendering3' into ahcorde/3/coverage/mesh
2 parents c4a1c2d + 3522325 commit 9b60bf4

File tree

1 file changed

+92
-14
lines changed

1 file changed

+92
-14
lines changed

src/TransformController_TEST.cc

+92-14
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)
217217

218218
TransformController transformControl;
219219

220+
// test invalid callas and make sure no exceptions are thrown
221+
EXPECT_NO_THROW(transformControl.SetCamera(nullptr));
222+
EXPECT_NO_THROW(transformControl.Attach(nullptr));
223+
EXPECT_NO_THROW(transformControl.Start());
224+
EXPECT_NO_THROW(transformControl.Translate(math::Vector3d::Zero));
225+
EXPECT_NO_THROW(transformControl.Rotate(math::Quaterniond::Identity));
226+
EXPECT_NO_THROW(transformControl.Translate(math::Vector3d::One));
227+
EXPECT_EQ(math::Vector3d::Zero, transformControl.AxisById(0u));
228+
220229
// test setting camera
221230
transformControl.SetCamera(camera);
222231
EXPECT_EQ(camera, transformControl.Camera());
@@ -236,29 +245,65 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)
236245
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
237246
transformControl.SetActiveAxis(math::Vector3d::UnitZ);
238247
transformControl.Translate(math::Vector3d(0, 0, 2));
239-
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
240-
EXPECT_EQ(visual->WorldRotation(), initialRot);
241-
EXPECT_EQ(visual->WorldScale(), math::Vector3d::One);
248+
transformControl.Update();
249+
EXPECT_EQ(math::Vector3d(0, -2, 0), visual->WorldPosition());
250+
EXPECT_EQ(initialRot, visual->WorldRotation());
251+
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());
252+
253+
// test translation when snapping is enabled
254+
transformControl.SetActiveAxis(math::Vector3d::UnitY);
255+
transformControl.SetTransformSpace(TransformSpace::TS_WORLD);
256+
transformControl.Translate(math::Vector3d(0, 1, 0), true);
257+
transformControl.Update();
258+
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
259+
EXPECT_EQ(initialRot, visual->WorldRotation());
260+
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());
242261

243262
// test rotation in local space
244263
transformControl.SetTransformMode(TransformMode::TM_ROTATION);
245264
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
246265
transformControl.SetActiveAxis(math::Vector3d::UnitX);
247266
transformControl.Rotate(math::Quaterniond(IGN_PI, 0, 0));
248-
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
249-
EXPECT_EQ(visual->WorldRotation(),
250-
math::Quaterniond(IGN_PI, 0, 0) * initialRot);
251-
EXPECT_EQ(visual->WorldScale(), math::Vector3d::One);
267+
transformControl.Update();
268+
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
269+
EXPECT_EQ(math::Quaterniond(IGN_PI, 0, 0) * initialRot,
270+
visual->WorldRotation());
271+
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());
272+
273+
// test rotation when snapping is enabled
274+
transformControl.SetActiveAxis(math::Vector3d::UnitY);
275+
transformControl.SetTransformSpace(TransformSpace::TS_WORLD);
276+
transformControl.Rotate(math::Quaterniond(0, IGN_PI, 0), true);
277+
transformControl.Update();
278+
EXPECT_EQ( math::Vector3d(0, -1, 0), visual->WorldPosition());
279+
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
280+
initialRot, visual->WorldRotation());
281+
EXPECT_EQ(math::Vector3d::One, visual->WorldScale());
252282

253283
// test scaling in local space
254284
transformControl.SetTransformMode(TransformMode::TM_SCALE);
255285
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
256286
transformControl.SetActiveAxis(math::Vector3d::UnitY);
257287
transformControl.Scale(math::Vector3d(1.0, 0.3, 1.0));
258-
EXPECT_EQ(visual->WorldPosition(), math::Vector3d(0, -2, 0));
259-
EXPECT_EQ(visual->WorldRotation(),
260-
math::Quaterniond(IGN_PI, 0, 0) * initialRot);
261-
EXPECT_EQ(visual->WorldScale(), math::Vector3d(1.0, 0.3, 1.0));
288+
transformControl.Update();
289+
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
290+
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
291+
initialRot, visual->WorldRotation());
292+
293+
auto expectedScale = math::Vector3d(1.0, 0.3, 1.0);
294+
EXPECT_EQ(expectedScale, visual->WorldScale());
295+
296+
// test scaling when snapping is enabled
297+
auto newScale = math::Vector3d(2.0, 6.0, 1.2);
298+
transformControl.Scale(newScale, true);
299+
transformControl.Update();
300+
EXPECT_EQ(math::Vector3d(0, -1, 0), visual->WorldPosition());
301+
EXPECT_EQ(math::Quaterniond(0, IGN_PI, 0) * math::Quaterniond(IGN_PI, 0, 0) *
302+
initialRot, visual->WorldRotation());
303+
math::Vector3d snappedScale(std::round(newScale.X() * expectedScale.X()),
304+
std::round(newScale.Y() * expectedScale.Y()),
305+
std::round(newScale.Z() * expectedScale.Z()));
306+
EXPECT_EQ(snappedScale, visual->WorldScale());
262307

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

289334
TransformController transformControl;
290335

291-
// test setting camera
292-
transformControl.SetCamera(camera);
293-
EXPECT_EQ(camera, transformControl.Camera());
336+
// test translation and scale without a node
337+
math::Vector2d start0(0.5, 0.5);
338+
math::Vector2d end0(0.5, 0.8);
339+
EXPECT_EQ(math::Vector3d::Zero,
340+
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start0, end0));
341+
EXPECT_EQ(math::Vector3d::Zero,
342+
transformControl.ScaleFrom2d(math::Vector3d::UnitY, start0, end0));
294343

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

350+
// test translation and scale without a camera
351+
EXPECT_EQ(math::Vector3d::Zero,
352+
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start0, end0));
353+
EXPECT_EQ(math::Vector3d::Zero,
354+
transformControl.ScaleFrom2d(math::Vector3d::UnitY, start0, end0));
355+
356+
// test setting camera
357+
transformControl.SetCamera(camera);
358+
EXPECT_EQ(camera, transformControl.Camera());
359+
301360
// test translation from 2d
302361
transformControl.SetTransformMode(TransformMode::TM_TRANSLATION);
303362
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
304363
transformControl.SetActiveAxis(math::Vector3d::UnitZ);
305364
transformControl.Start();
306365
math::Vector2d start(0.5, 0.5);
307366
math::Vector2d end(0.5, 0.8);
367+
// translation in z
308368
math::Vector3d translation =
309369
transformControl.TranslationFrom2d(math::Vector3d::UnitZ, start, end);
310370
transformControl.Stop();
311371
EXPECT_DOUBLE_EQ(translation.X(), 0);
312372
EXPECT_DOUBLE_EQ(translation.Y(), 0);
313373
EXPECT_GT(translation.Z(), 0);
314374

375+
// translation in y
376+
transformControl.SetActiveAxis(math::Vector3d::UnitY);
377+
transformControl.Start();
378+
math::Vector2d starty(0.5, 0.5);
379+
math::Vector2d endy(0.2, 0.5);
380+
translation =
381+
transformControl.TranslationFrom2d(math::Vector3d::UnitY, starty, endy);
382+
transformControl.Stop();
383+
EXPECT_DOUBLE_EQ(translation.X(), 0);
384+
EXPECT_GT(translation.Y(), 0);
385+
EXPECT_DOUBLE_EQ(translation.Z(), 0);
386+
315387
// test rotation from 2d
316388
transformControl.SetTransformMode(TransformMode::TM_ROTATION);
317389
transformControl.SetTransformSpace(TransformSpace::TS_LOCAL);
@@ -339,6 +411,12 @@ void TransformControllerTest::Control2d(const std::string &_renderEngine)
339411
EXPECT_GT(scale.Y(), 0);
340412
EXPECT_DOUBLE_EQ(scale.Z(), 1);
341413

414+
// test snapping with invalid args
415+
EXPECT_EQ(math::Vector3d::Zero,
416+
transformControl.SnapPoint(math::Vector3d::One, -1));
417+
EXPECT_EQ(math::Vector3d::Zero,
418+
transformControl.SnapPoint(math::Vector3d::One, 1, -1));
419+
342420
// Clean up
343421
engine->DestroyScene(scene);
344422
unloadEngine(engine->Name());

0 commit comments

Comments
 (0)