Browse Source

Using Object::Transformation enum instead of bool.

Added just-to-be-sure unit test.
vectorfields
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.
*/
/** @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 */
inline Matrix4 transformation() const {
return _transformation;
@ -111,12 +120,11 @@ class MAGNUM_EXPORT Object {
/**
* @brief Multiply transformation
* @param transformation Transformation
* @param global Whether to apply transformation as global
* (multiply from left side) or as local (multiply from right
* side)
* @param type Transformation type
*/
inline Object* multiplyTransformation(const Matrix4& transformation, bool global = true) {
setTransformation(global ? transformation*_transformation : _transformation*transformation);
inline Object* multiplyTransformation(const Matrix4& transformation, Transformation type = Transformation::Global) {
setTransformation(type == Transformation::Global ?
transformation*_transformation : _transformation*transformation);
return this;
}
@ -125,8 +133,8 @@ class MAGNUM_EXPORT Object {
*
* Same as calling multiplyTransformation() with Matrix4::translation().
*/
inline Object* translate(Vector3 vec, bool global = true) {
multiplyTransformation(Matrix4::translation(vec), global);
inline Object* translate(Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::translation(vec), type);
return this;
}
@ -135,8 +143,8 @@ class MAGNUM_EXPORT Object {
*
* Same as calling multiplyTransformation() with Matrix4::scaling().
*/
inline Object* scale(Vector3 vec, bool global = true) {
multiplyTransformation(Matrix4::scaling(vec), global);
inline Object* scale(Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::scaling(vec), type);
return this;
}
@ -145,8 +153,8 @@ class MAGNUM_EXPORT Object {
*
* Same as calling multiplyTransformation() with Matrix4::rotation().
*/
inline Object* rotate(GLfloat angle, Vector3 vec, bool global = true) {
multiplyTransformation(Matrix4::rotation(angle, vec), global);
inline Object* rotate(GLfloat angle, Vector3 vec, Transformation type = Transformation::Global) {
multiplyTransformation(Matrix4::rotation(angle, vec), type);
return this;
}

8
src/Scene.h

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

21
src/Test/ObjectTest.cpp

@ -49,6 +49,27 @@ void ObjectTest::parenting() {
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() {
Scene scene;

1
src/Test/ObjectTest.h

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

Loading…
Cancel
Save