diff --git a/src/Object.cpp b/src/Object.cpp index 55d778e77..6a201e05e 100644 --- a/src/Object.cpp +++ b/src/Object.cpp @@ -22,9 +22,10 @@ using namespace std; namespace Magnum { void Object::setParent(Object* parent) { - if(_parent == parent) return; + /* Skip if nothing to do or this is scene */ + if(_parent == parent || _parent == this) return; - /* Set new parent and add the object to new parent children list */ + /* Add the object to children list of new parent */ if(parent != nullptr) { /* Only Fry can be his own grandfather */ @@ -41,6 +42,7 @@ void Object::setParent(Object* parent) { if(_parent != nullptr) _parent->_children.erase(this); + /* Set new parent */ _parent = parent; setDirty(); @@ -91,6 +93,13 @@ Scene* Object::scene() { return nullptr; } +void Object::setTransformation(const Matrix4& transformation) { + if(_parent == this) return; + + _transformation = transformation; + setDirty(); +} + void Object::setDirty() { /* The object (and all its children) are already dirty, nothing to do */ if(dirty) return; diff --git a/src/Object.h b/src/Object.h index cd0302254..1a3232172 100644 --- a/src/Object.h +++ b/src/Object.h @@ -96,10 +96,7 @@ class MAGNUM_EXPORT Object { virtual Matrix4 absoluteTransformation(Camera* camera = nullptr); /** @brief Set transformation matrix */ - inline void setTransformation(const Matrix4& transformation) { - _transformation = transformation; - setDirty(); - } + void setTransformation(const Matrix4& transformation); /** * @brief Multiply transformation matrix diff --git a/src/Scene.h b/src/Scene.h index 24b575fd4..1ea23a899 100644 --- a/src/Scene.h +++ b/src/Scene.h @@ -25,18 +25,6 @@ namespace Magnum { /** @brief %Scene */ class MAGNUM_EXPORT Scene: public Object { - private: - void setParent(Object* parent) = delete; - void setTransformation(const Matrix4& transformation) = delete; - void multiplyTransformation(const Matrix4& transformation, bool global = true) = delete; - void setTransformationFrom(Object* another) = delete; - void translate(Vector3 vec, bool global = true) = delete; - void translate(GLfloat x, GLfloat y, GLfloat z, bool global = true) = delete; - void scale(Vector3 vec, bool global = true) = delete; - void scale(GLfloat x, GLfloat y, GLfloat z, bool global = true) = delete; - void rotate(GLfloat angle, Vector3 vec, bool global = true) = delete; - void rotate(GLfloat angle, GLfloat x, GLfloat y, GLfloat z, bool global = true) = delete; - public: /** @brief Features */ enum Feature { @@ -59,6 +47,14 @@ class MAGNUM_EXPORT Scene: public Object { */ inline ~Scene() { glDeleteVertexArrays(1, &vao); } + void setParent(Object* parent) = delete; + void setTransformation(const Matrix4& transformation) = delete; + void multiplyTransformation(const Matrix4& transformation, bool global = true) = delete; + void setTransformationFrom(Object* another) = delete; + void translate(Vector3 vec, bool global = true) = delete; + void scale(Vector3 vec, bool global = true) = delete; + void rotate(GLfloat angle, Vector3 vec, bool global = true) = delete; + /** @brief Which features are set */ inline unsigned int features() const { return _features; } diff --git a/src/Test/SceneTest.cpp b/src/Test/SceneTest.cpp index 9bc8fef52..3a236a88e 100644 --- a/src/Test/SceneTest.cpp +++ b/src/Test/SceneTest.cpp @@ -23,6 +23,14 @@ QTEST_APPLESS_MAIN(Magnum::Test::SceneTest) namespace Magnum { namespace Test { +void SceneTest::transformation() { + Scene scene; + + Object* scenePointer = &scene; + scenePointer->setTransformation(Matrix4::translation({1.0f, 1.0f, 1.0f})); + QVERIFY(scene.transformation() == Matrix4()); +} + void SceneTest::parent() { Scene scene; @@ -30,9 +38,11 @@ void SceneTest::parent() { /* Scene parent cannot be changed */ Object* scenePointer = &scene; - Object* object = new Object; - scenePointer->setParent(object); + Object object; + scenePointer->setParent(&object); QVERIFY(scene.parent() == &scene); + QVERIFY(scene.children().empty()); + QVERIFY(object.children().empty()); } }} diff --git a/src/Test/SceneTest.h b/src/Test/SceneTest.h index 03995f49a..145676ca6 100644 --- a/src/Test/SceneTest.h +++ b/src/Test/SceneTest.h @@ -25,6 +25,7 @@ class SceneTest: public QObject { Q_OBJECT private slots: + void transformation(); void parent(); };