Browse Source

Scene parent and transformation is now really immutable.

Improved parenting test, added test for transformation. Moved deleted
functions to public section, so the compiler prints error about deleted
functions, not about private functions.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
c996e89fe7
  1. 13
      src/Object.cpp
  2. 5
      src/Object.h
  3. 20
      src/Scene.h
  4. 14
      src/Test/SceneTest.cpp
  5. 1
      src/Test/SceneTest.h

13
src/Object.cpp

@ -22,9 +22,10 @@ using namespace std;
namespace Magnum { namespace Magnum {
void Object::setParent(Object* parent) { 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) { if(parent != nullptr) {
/* Only Fry can be his own grandfather */ /* Only Fry can be his own grandfather */
@ -41,6 +42,7 @@ void Object::setParent(Object* parent) {
if(_parent != nullptr) if(_parent != nullptr)
_parent->_children.erase(this); _parent->_children.erase(this);
/* Set new parent */
_parent = parent; _parent = parent;
setDirty(); setDirty();
@ -91,6 +93,13 @@ Scene* Object::scene() {
return nullptr; return nullptr;
} }
void Object::setTransformation(const Matrix4& transformation) {
if(_parent == this) return;
_transformation = transformation;
setDirty();
}
void Object::setDirty() { void Object::setDirty() {
/* The object (and all its children) are already dirty, nothing to do */ /* The object (and all its children) are already dirty, nothing to do */
if(dirty) return; if(dirty) return;

5
src/Object.h

@ -96,10 +96,7 @@ class MAGNUM_EXPORT Object {
virtual Matrix4 absoluteTransformation(Camera* camera = nullptr); virtual Matrix4 absoluteTransformation(Camera* camera = nullptr);
/** @brief Set transformation matrix */ /** @brief Set transformation matrix */
inline void setTransformation(const Matrix4& transformation) { void setTransformation(const Matrix4& transformation);
_transformation = transformation;
setDirty();
}
/** /**
* @brief Multiply transformation matrix * @brief Multiply transformation matrix

20
src/Scene.h

@ -25,18 +25,6 @@ namespace Magnum {
/** @brief %Scene */ /** @brief %Scene */
class MAGNUM_EXPORT Scene: public Object { 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: public:
/** @brief Features */ /** @brief Features */
enum Feature { enum Feature {
@ -59,6 +47,14 @@ class MAGNUM_EXPORT Scene: public Object {
*/ */
inline ~Scene() { glDeleteVertexArrays(1, &vao); } 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 */ /** @brief Which features are set */
inline unsigned int features() const { return _features; } inline unsigned int features() const { return _features; }

14
src/Test/SceneTest.cpp

@ -23,6 +23,14 @@ QTEST_APPLESS_MAIN(Magnum::Test::SceneTest)
namespace Magnum { namespace Test { 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() { void SceneTest::parent() {
Scene scene; Scene scene;
@ -30,9 +38,11 @@ void SceneTest::parent() {
/* Scene parent cannot be changed */ /* Scene parent cannot be changed */
Object* scenePointer = &scene; Object* scenePointer = &scene;
Object* object = new Object; Object object;
scenePointer->setParent(object); scenePointer->setParent(&object);
QVERIFY(scene.parent() == &scene); QVERIFY(scene.parent() == &scene);
QVERIFY(scene.children().empty());
QVERIFY(object.children().empty());
} }
}} }}

1
src/Test/SceneTest.h

@ -25,6 +25,7 @@ class SceneTest: public QObject {
Q_OBJECT Q_OBJECT
private slots: private slots:
void transformation();
void parent(); void parent();
}; };

Loading…
Cancel
Save