From b86f107396a0023729a02cb35a8001adf5312e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 24 Jan 2013 18:51:33 +0100 Subject: [PATCH] SceneGraph: split object transformations test into more functions. --- src/SceneGraph/Test/ObjectTest.cpp | 55 +++++++++++++++++++----------- 1 file changed, 35 insertions(+), 20 deletions(-) diff --git a/src/SceneGraph/Test/ObjectTest.cpp b/src/SceneGraph/Test/ObjectTest.cpp index 09248ac5d..0ee556cb1 100644 --- a/src/SceneGraph/Test/ObjectTest.cpp +++ b/src/SceneGraph/Test/ObjectTest.cpp @@ -30,6 +30,8 @@ class ObjectTest: public Corrade::TestSuite::Tester { void scene(); void absoluteTransformation(); void transformations(); + void transformationsRelative(); + void transformationsOrphan(); void setClean(); void bulkSetClean(); }; @@ -56,6 +58,8 @@ ObjectTest::ObjectTest() { &ObjectTest::scene, &ObjectTest::absoluteTransformation, &ObjectTest::transformations, + &ObjectTest::transformationsRelative, + &ObjectTest::transformationsOrphan, &ObjectTest::setClean, &ObjectTest::bulkSetClean); } @@ -164,32 +168,43 @@ void ObjectTest::transformations() { initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), initial*Matrix4::rotationZ(deg(30.0f)), })); +} - { - CORRADE_EXPECT_FAIL("Transformations not relative to scene are not yet implemented."); - - /* Transformation relative to another object */ - CORRADE_COMPARE(second.transformations({&third}), std::vector{ - Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) - }); - - /* Transformation relative to another object, not part of any scene (but should work) */ - Object3D orphanParent1; - orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); - Object3D orphanParent(&orphanParent1); - Object3D orphan1(&orphanParent); - orphan1.scale(Vector3::xScale(3.0f)); - Object3D orphan2(&orphanParent); - orphan2.translate(Vector3::zAxis(5.0f)); - CORRADE_COMPARE(orphan1.transformations({&orphan2}), std::vector{ - Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) - }); - } +void ObjectTest::transformationsRelative() { + CORRADE_EXPECT_FAIL("Transformations not relative to scene are not yet implemented."); + Scene3D s; + Object3D first(&s); + first.rotateZ(deg(30.0f)); + Object3D second(&first); + second.scale(Vector3(0.5f)); + Object3D third(&first); + third.translate(Vector3::xAxis(5.0f)); + + /* Transformation relative to another object */ + CORRADE_COMPARE(second.transformations({&third}), std::vector{ + Matrix4::scaling(Vector3(0.5f)).inverted()*Matrix4::translation(Vector3::xAxis(5.0f)) + }); + + /* Transformation relative to another object, not part of any scene (but should work) */ + Object3D orphanParent1; + orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); + Object3D orphanParent(&orphanParent1); + Object3D orphan1(&orphanParent); + orphan1.scale(Vector3::xScale(3.0f)); + Object3D orphan2(&orphanParent); + orphan2.translate(Vector3::zAxis(5.0f)); + CORRADE_COMPARE(orphan1.transformations({&orphan2}), std::vector{ + Matrix4::scaling(Vector3::xScale(3.0f)).inverted()*Matrix4::translation(Vector3::zAxis(5.0f)) + }); +} + +void ObjectTest::transformationsOrphan() { std::ostringstream o; Error::setOutput(&o); /* Transformation of objects not part of the same scene */ + Scene3D s; Object3D orphan; CORRADE_COMPARE(s.transformations({&orphan}), std::vector()); CORRADE_COMPARE(o.str(), "SceneGraph::Object::transformations(): the objects are not part of the same tree\n");