Browse Source

SceneGraph: testing everything in transformations.

pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
c52f64b381
  1. 82
      src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp
  2. 98
      src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp
  3. 108
      src/SceneGraph/Test/MatrixTransformation2DTest.cpp
  4. 124
      src/SceneGraph/Test/MatrixTransformation3DTest.cpp

82
src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp

@ -17,9 +17,13 @@
#include "Math/Constants.h"
#include "SceneGraph/EuclideanMatrixTransformation2D.h"
#include "SceneGraph/Scene.h"
namespace Magnum { namespace SceneGraph { namespace Test {
typedef Object<EuclideanMatrixTransformation2D<>> Object2D;
typedef Scene<EuclideanMatrixTransformation2D<>> Scene2D;
class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester {
public:
explicit EuclideanMatrixTransformation2DTest();
@ -28,13 +32,25 @@ class EuclideanMatrixTransformation2DTest: public Corrade::TestSuite::Tester {
void toMatrix();
void compose();
void inverted();
void setTransformation();
void translate();
void rotate();
void reflect();
void normalizeRotation();
};
EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() {
addTests(&EuclideanMatrixTransformation2DTest::fromMatrix,
&EuclideanMatrixTransformation2DTest::toMatrix,
&EuclideanMatrixTransformation2DTest::compose,
&EuclideanMatrixTransformation2DTest::inverted);
&EuclideanMatrixTransformation2DTest::inverted,
&EuclideanMatrixTransformation2DTest::setTransformation,
&EuclideanMatrixTransformation2DTest::translate,
&EuclideanMatrixTransformation2DTest::rotate,
&EuclideanMatrixTransformation2DTest::reflect,
&EuclideanMatrixTransformation2DTest::normalizeRotation);
}
void EuclideanMatrixTransformation2DTest::fromMatrix() {
@ -58,6 +74,70 @@ void EuclideanMatrixTransformation2DTest::inverted() {
CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3());
}
void EuclideanMatrixTransformation2DTest::setTransformation() {
/* Dirty after setting transformation */
Object2D o;
o.setClean();
o.rotate(deg(17.0f));
CORRADE_VERIFY(o.isDirty());
/* Scene cannot be transformed */
Scene2D s;
s.setClean();
s.rotate(deg(17.0f));
CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix3());
}
void EuclideanMatrixTransformation2DTest::translate() {
{
Object2D o;
o.rotate(deg(17.0f));
o.translate({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.rotate(deg(17.0f));
o.translate({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
}
}
void EuclideanMatrixTransformation2DTest::rotate() {
{
Object2D o;
o.translate({1.0f, -0.3f});
o.rotate(deg(17.0f));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} {
Object2D o;
o.translate({1.0f, -0.3f});
o.rotate(deg(17.0f), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
}
}
void EuclideanMatrixTransformation2DTest::reflect() {
{
Object2D o;
o.rotate(deg(17.0f));
o.reflect(Vector2(-1.0f/Constants::sqrt2()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.rotate(deg(17.0f));
o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2())));
}
}
void EuclideanMatrixTransformation2DTest::normalizeRotation() {
Object2D o;
o.rotate(deg(17.0f));
o.normalizeRotation();
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f)));
}
}}}
CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation2DTest)

98
src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp

@ -17,9 +17,13 @@
#include "Math/Constants.h"
#include "SceneGraph/EuclideanMatrixTransformation3D.h"
#include "SceneGraph/Scene.h"
namespace Magnum { namespace SceneGraph { namespace Test {
typedef Object<EuclideanMatrixTransformation3D<>> Object3D;
typedef Scene<EuclideanMatrixTransformation3D<>> Scene3D;
class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester {
public:
explicit EuclideanMatrixTransformation3DTest();
@ -28,13 +32,25 @@ class EuclideanMatrixTransformation3DTest: public Corrade::TestSuite::Tester {
void toMatrix();
void compose();
void inverted();
void setTransformation();
void translate();
void rotate();
void reflect();
void normalizeRotation();
};
EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() {
addTests(&EuclideanMatrixTransformation3DTest::fromMatrix,
&EuclideanMatrixTransformation3DTest::toMatrix,
&EuclideanMatrixTransformation3DTest::compose,
&EuclideanMatrixTransformation3DTest::inverted);
&EuclideanMatrixTransformation3DTest::inverted,
&EuclideanMatrixTransformation3DTest::setTransformation,
&EuclideanMatrixTransformation3DTest::translate,
&EuclideanMatrixTransformation3DTest::rotate,
&EuclideanMatrixTransformation3DTest::reflect,
&EuclideanMatrixTransformation3DTest::normalizeRotation);
}
void EuclideanMatrixTransformation3DTest::fromMatrix() {
@ -58,6 +74,86 @@ void EuclideanMatrixTransformation3DTest::inverted() {
CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4());
}
void EuclideanMatrixTransformation3DTest::setTransformation() {
/* Dirty after setting transformation */
Object3D o;
o.setClean();
o.rotateX(deg(17.0f));
CORRADE_VERIFY(o.isDirty());
/* Scene cannot be transformed */
Scene3D s;
s.setClean();
s.rotateX(deg(17.0f));
CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix4());
}
void EuclideanMatrixTransformation3DTest::translate() {
{
Object3D o;
o.rotateX(deg(17.0f));
o.translate({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.rotateX(deg(17.0f));
o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
}
}
void EuclideanMatrixTransformation3DTest::rotate() {
{
Object3D o;
o.translate({1.0f, -0.3f, 2.3f});
o.rotateX(deg(17.0f))
->rotateY(deg(25.0f))
->rotateZ(deg(-23.0f))
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))*
Matrix4::rotationZ(deg(-23.0f))*
Matrix4::rotationY(deg(25.0f))*
Matrix4::rotationX(deg(17.0f))*
Matrix4::translation({1.0f, -0.3f, 2.3f}));
} {
Object3D o;
o.translate({1.0f, -0.3f, 2.3f});
o.rotateX(deg(17.0f), TransformationType::Local)
->rotateY(deg(25.0f), TransformationType::Local)
->rotateZ(deg(-23.0f), TransformationType::Local)
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::translation({1.0f, -0.3f, 2.3f})*
Matrix4::rotationX(deg(17.0f))*
Matrix4::rotationY(deg(25.0f))*
Matrix4::rotationZ(deg(-23.0f))*
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3())));
}
}
void EuclideanMatrixTransformation3DTest::reflect() {
{
Object3D o;
o.rotateX(deg(17.0f));
o.reflect(Vector3(-1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.rotateX(deg(17.0f));
o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3())));
}
}
void EuclideanMatrixTransformation3DTest::normalizeRotation() {
Object3D o;
o.rotateX(deg(17.0f));
o.normalizeRotation();
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f)));
}
}}}
CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::EuclideanMatrixTransformation3DTest)

108
src/SceneGraph/Test/MatrixTransformation2DTest.cpp

@ -17,9 +17,13 @@
#include "Math/Constants.h"
#include "SceneGraph/MatrixTransformation2D.h"
#include "SceneGraph/Scene.h"
namespace Magnum { namespace SceneGraph { namespace Test {
typedef Object<MatrixTransformation2D<>> Object2D;
typedef Scene<MatrixTransformation2D<>> Scene2D;
class MatrixTransformation2DTest: public Corrade::TestSuite::Tester {
public:
explicit MatrixTransformation2DTest();
@ -28,13 +32,27 @@ class MatrixTransformation2DTest: public Corrade::TestSuite::Tester {
void toMatrix();
void compose();
void inverted();
void setTransformation();
void transform();
void translate();
void rotate();
void scale();
void reflect();
};
MatrixTransformation2DTest::MatrixTransformation2DTest() {
addTests(&MatrixTransformation2DTest::fromMatrix,
&MatrixTransformation2DTest::toMatrix,
&MatrixTransformation2DTest::compose,
&MatrixTransformation2DTest::inverted);
&MatrixTransformation2DTest::inverted,
&MatrixTransformation2DTest::setTransformation,
&MatrixTransformation2DTest::transform,
&MatrixTransformation2DTest::translate,
&MatrixTransformation2DTest::rotate,
&MatrixTransformation2DTest::scale,
&MatrixTransformation2DTest::reflect);
}
void MatrixTransformation2DTest::fromMatrix() {
@ -58,6 +76,94 @@ void MatrixTransformation2DTest::inverted() {
CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3());
}
void MatrixTransformation2DTest::setTransformation() {
/* Dirty after setting transformation */
Object2D o;
o.setClean();
CORRADE_VERIFY(!o.isDirty());
o.setTransformation(Matrix3::rotation(deg(17.0f)));
CORRADE_VERIFY(o.isDirty());
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f)));
/* Scene cannot be transformed */
Scene2D s;
s.setClean();
CORRADE_VERIFY(!s.isDirty());
s.setTransformation(Matrix3::rotation(deg(17.0f)));
CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix3());
}
void MatrixTransformation2DTest::transform() {
{
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.transform(Matrix3::translation({1.0f, -0.3f}));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.transform(Matrix3::translation({1.0f, -0.3f}), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
}
}
void MatrixTransformation2DTest::translate() {
{
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.translate({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.translate({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
}
}
void MatrixTransformation2DTest::rotate() {
{
Object2D o;
o.setTransformation(Matrix3::translation({1.0f, -0.3f}));
o.rotate(deg(17.0f));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} {
Object2D o;
o.setTransformation(Matrix3::translation({1.0f, -0.3f}));
o.rotate(deg(17.0f), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
}
}
void MatrixTransformation2DTest::scale() {
{
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.scale({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.scale({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::scaling({1.0f, -0.3f}));
}
}
void MatrixTransformation2DTest::reflect() {
{
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.reflect(Vector2(-1.0f/Constants::sqrt2()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f)));
} {
Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f)));
o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2())));
}
}
}}}
CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation2DTest)

124
src/SceneGraph/Test/MatrixTransformation3DTest.cpp

@ -17,9 +17,13 @@
#include "Math/Constants.h"
#include "SceneGraph/MatrixTransformation3D.h"
#include "SceneGraph/Scene.h"
namespace Magnum { namespace SceneGraph { namespace Test {
typedef Object<MatrixTransformation3D<>> Object3D;
typedef Scene<MatrixTransformation3D<>> Scene3D;
class MatrixTransformation3DTest: public Corrade::TestSuite::Tester {
public:
explicit MatrixTransformation3DTest();
@ -28,13 +32,27 @@ class MatrixTransformation3DTest: public Corrade::TestSuite::Tester {
void toMatrix();
void compose();
void inverted();
void setTransformation();
void transform();
void translate();
void rotate();
void scale();
void reflect();
};
MatrixTransformation3DTest::MatrixTransformation3DTest() {
addTests(&MatrixTransformation3DTest::fromMatrix,
&MatrixTransformation3DTest::toMatrix,
&MatrixTransformation3DTest::compose,
&MatrixTransformation3DTest::inverted);
&MatrixTransformation3DTest::inverted,
&MatrixTransformation3DTest::setTransformation,
&MatrixTransformation3DTest::transform,
&MatrixTransformation3DTest::translate,
&MatrixTransformation3DTest::rotate,
&MatrixTransformation3DTest::scale,
&MatrixTransformation3DTest::reflect);
}
void MatrixTransformation3DTest::fromMatrix() {
@ -58,6 +76,110 @@ void MatrixTransformation3DTest::inverted() {
CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4());
}
void MatrixTransformation3DTest::setTransformation() {
/* Dirty after setting transformation */
Object3D o;
o.setClean();
CORRADE_VERIFY(!o.isDirty());
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
CORRADE_VERIFY(o.isDirty());
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f)));
/* Scene cannot be transformed */
Scene3D s;
s.setClean();
CORRADE_VERIFY(!s.isDirty());
s.setTransformation(Matrix4::rotationX(deg(17.0f)));
CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix4());
}
void MatrixTransformation3DTest::transform() {
{
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}));
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
}
}
void MatrixTransformation3DTest::translate() {
{
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.translate({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
}
}
void MatrixTransformation3DTest::rotate() {
{
Object3D o;
o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f}));
o.rotateX(deg(17.0f))
->rotateY(deg(25.0f))
->rotateZ(deg(-23.0f))
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))*
Matrix4::rotationZ(deg(-23.0f))*
Matrix4::rotationY(deg(25.0f))*
Matrix4::rotationX(deg(17.0f))*
Matrix4::translation({1.0f, -0.3f, 2.3f}));
} {
Object3D o;
o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f}));
o.rotateX(deg(17.0f), TransformationType::Local)
->rotateY(deg(25.0f), TransformationType::Local)
->rotateZ(deg(-23.0f), TransformationType::Local)
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::translation({1.0f, -0.3f, 2.3f})*
Matrix4::rotationX(deg(17.0f))*
Matrix4::rotationY(deg(25.0f))*
Matrix4::rotationZ(deg(-23.0f))*
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3())));
}
}
void MatrixTransformation3DTest::scale() {
{
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.scale({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.scale({1.0f, -0.3f, 2.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f}));
}
}
void MatrixTransformation3DTest::reflect() {
{
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.reflect(Vector3(-1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f)));
} {
Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f)));
o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3())));
}
}
}}}
CORRADE_TEST_MAIN(Magnum::SceneGraph::Test::MatrixTransformation3DTest)

Loading…
Cancel
Save