@@ -217,6 +217,15 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)
217
217
218
218
TransformController transformControl;
219
219
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
+
220
229
// test setting camera
221
230
transformControl.SetCamera (camera);
222
231
EXPECT_EQ (camera, transformControl.Camera ());
@@ -236,29 +245,65 @@ void TransformControllerTest::LocalSpace(const std::string &_renderEngine)
236
245
transformControl.SetTransformSpace (TransformSpace::TS_LOCAL);
237
246
transformControl.SetActiveAxis (math::Vector3d::UnitZ);
238
247
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 ());
242
261
243
262
// test rotation in local space
244
263
transformControl.SetTransformMode (TransformMode::TM_ROTATION);
245
264
transformControl.SetTransformSpace (TransformSpace::TS_LOCAL);
246
265
transformControl.SetActiveAxis (math::Vector3d::UnitX);
247
266
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 ());
252
282
253
283
// test scaling in local space
254
284
transformControl.SetTransformMode (TransformMode::TM_SCALE);
255
285
transformControl.SetTransformSpace (TransformSpace::TS_LOCAL);
256
286
transformControl.SetActiveAxis (math::Vector3d::UnitY);
257
287
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 ());
262
307
263
308
// Clean up
264
309
engine->DestroyScene (scene);
@@ -288,30 +333,57 @@ void TransformControllerTest::Control2d(const std::string &_renderEngine)
288
333
289
334
TransformController transformControl;
290
335
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));
294
343
295
344
// create a dummy node visual node and attach to the controller
296
345
VisualPtr visual = scene->CreateVisual ();
297
346
ASSERT_NE (nullptr , visual);
298
347
transformControl.Attach (visual);
299
348
EXPECT_EQ (visual, transformControl.Node ());
300
349
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
+
301
360
// test translation from 2d
302
361
transformControl.SetTransformMode (TransformMode::TM_TRANSLATION);
303
362
transformControl.SetTransformSpace (TransformSpace::TS_LOCAL);
304
363
transformControl.SetActiveAxis (math::Vector3d::UnitZ);
305
364
transformControl.Start ();
306
365
math::Vector2d start (0.5 , 0.5 );
307
366
math::Vector2d end (0.5 , 0.8 );
367
+ // translation in z
308
368
math::Vector3d translation =
309
369
transformControl.TranslationFrom2d (math::Vector3d::UnitZ, start, end);
310
370
transformControl.Stop ();
311
371
EXPECT_DOUBLE_EQ (translation.X (), 0 );
312
372
EXPECT_DOUBLE_EQ (translation.Y (), 0 );
313
373
EXPECT_GT (translation.Z (), 0 );
314
374
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
+
315
387
// test rotation from 2d
316
388
transformControl.SetTransformMode (TransformMode::TM_ROTATION);
317
389
transformControl.SetTransformSpace (TransformSpace::TS_LOCAL);
@@ -339,6 +411,12 @@ void TransformControllerTest::Control2d(const std::string &_renderEngine)
339
411
EXPECT_GT (scale.Y (), 0 );
340
412
EXPECT_DOUBLE_EQ (scale.Z (), 1 );
341
413
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
+
342
420
// Clean up
343
421
engine->DestroyScene (scene);
344
422
unloadEngine (engine->Name ());
0 commit comments