Browse Source

Using Object::Transformation enum instead of bool.

Added just-to-be-sure unit test.
pull/279/head
Vladimír Vondruš 14 years ago
parent
commit
0ee95d51eb
  1. 30
      src/Object.h
  2. 8
      src/Scene.h
  3. 21
      src/Test/ObjectTest.cpp
  4. 1
      src/Test/ObjectTest.h

30
src/Object.h

@ -86,6 +86,15 @@ class MAGNUM_EXPORT Object {
* to parent. * to parent.
*/ */
/** @brief Transformation type */
enum class Transformation: char {
/** Global transformation, applied after all other transformations. */
Global = 0x00,
/** Local transformation, applied before all other transformations. */
Local = 0x01
};
/** @brief Transformation */ /** @brief Transformation */
inline Matrix4 transformation() const { inline Matrix4 transformation() const {
return _transformation; return _transformation;
@ -111,12 +120,11 @@ class MAGNUM_EXPORT Object {
/** /**
* @brief Multiply transformation * @brief Multiply transformation
* @param transformation Transformation * @param transformation Transformation
* @param global Whether to apply transformation as global * @param type Transformation type
* (multiply from left side) or as local (multiply from right
* side)
*/ */
inline Object* multiplyTransformation(const Matrix4& transformation, bool global = true) { inline Object* multiplyTransformation(const Matrix4& transformation, Transformation type = Transformation::Global) {
setTransformation(global ? transformation*_transformation : _transformation*transformation); setTransformation(type == Transformation::Global ?
transformation*_transformation : _transformation*transformation);
return this; return this;
} }
@ -125,8 +133,8 @@ class MAGNUM_EXPORT Object {
* *
* Same as calling multiplyTransformation() with Matrix4::translation(). * Same as calling multiplyTransformation() with Matrix4::translation().
*/ */
inline Object* translate(Vector3 vec, bool global = true) { inline Object* translate(Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::translation(vec), global); multiplyTransformation(Matrix4::translation(vec), type);
return this; return this;
} }
@ -135,8 +143,8 @@ class MAGNUM_EXPORT Object {
* *
* Same as calling multiplyTransformation() with Matrix4::scaling(). * Same as calling multiplyTransformation() with Matrix4::scaling().
*/ */
inline Object* scale(Vector3 vec, bool global = true) { inline Object* scale(Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::scaling(vec), global); multiplyTransformation(Matrix4::scaling(vec), type);
return this; return this;
} }
@ -145,8 +153,8 @@ class MAGNUM_EXPORT Object {
* *
* Same as calling multiplyTransformation() with Matrix4::rotation(). * Same as calling multiplyTransformation() with Matrix4::rotation().
*/ */
inline Object* rotate(GLfloat angle, Vector3 vec, bool global = true) { inline Object* rotate(GLfloat angle, Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::rotation(angle, vec), global); multiplyTransformation(Matrix4::rotation(angle, vec), type);
return this; return this;
} }

8
src/Scene.h

@ -38,10 +38,10 @@ class MAGNUM_EXPORT Scene: public Object {
void setParent(Object* parent) = delete; void setParent(Object* parent) = delete;
void setTransformation(const Matrix4& transformation) = delete; void setTransformation(const Matrix4& transformation) = delete;
void multiplyTransformation(const Matrix4& transformation, bool global = true) = delete; void multiplyTransformation(const Matrix4& transformation, Transformation type = Transformation::Global) = delete;
void translate(Vector3 vec, bool global = true) = delete; void translate(Vector3 vec, Transformation type = Transformation::Global) = delete;
void scale(Vector3 vec, bool global = true) = delete; void scale(Vector3 vec, Transformation type = Transformation::Global) = delete;
void rotate(GLfloat angle, Vector3 vec, bool global = true) = delete; void rotate(GLfloat angle, Vector3 vec, Transformation type = Transformation::Global) = 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; }

21
src/Test/ObjectTest.cpp

@ -49,6 +49,27 @@ void ObjectTest::parenting() {
QVERIFY(childOne->children().size() == 0); QVERIFY(childOne->children().size() == 0);
} }
void ObjectTest::transformation() {
Object o;
Object o2;
o.setTransformation(Matrix4::translation(Vector3::xAxis(1.0f)));
o2.translate(Vector3::xAxis(1.0f));
o.multiplyTransformation(Matrix4::rotation(deg(35.0f), Vector3::zAxis()));
o2.rotate(deg(35.0f), Vector3::zAxis());
QVERIFY(o.transformation() == Matrix4::rotation(deg(35.0f), Vector3::zAxis())*
Matrix4::translation(Vector3::xAxis(1.0f)));
QVERIFY(o2.transformation() == o.transformation());
o.multiplyTransformation(Matrix4::scaling(Vector3(2.0f)), Object::Transformation::Local);
o2.scale(Vector3(2.0f), Object::Transformation::Local);
QVERIFY(o.transformation() == Matrix4::rotation(deg(35.0f), Vector3::zAxis())*
Matrix4::translation(Vector3::xAxis(1.0f))*
Matrix4::scaling(Vector3(2.0f)));
QVERIFY(o2.transformation() == o.transformation());
}
void ObjectTest::scene() { void ObjectTest::scene() {
Scene scene; Scene scene;

1
src/Test/ObjectTest.h

@ -26,6 +26,7 @@ class ObjectTest: public QObject {
private slots: private slots:
void parenting(); void parenting();
void transformation();
void scene(); void scene();
void dirty(); void dirty();
}; };

Loading…
Cancel
Save