Browse Source

Math: using Rad in Matrix*::rotation*().

Also updated dependent functions and tests.
pull/7/head
Vladimír Vondruš 13 years ago
parent
commit
830ce69da0
  1. 4
      doc/matrix-vector.dox
  2. 2
      doc/scenegraph.dox
  3. 11
      src/Math/Matrix3.h
  4. 51
      src/Math/Matrix4.h
  5. 11
      src/Math/Test/Matrix3Test.cpp
  6. 26
      src/Math/Test/Matrix4Test.cpp
  7. 2
      src/Math/Vector3.h
  8. 2
      src/Physics/Test/CapsuleTest.cpp
  9. 2
      src/Physics/Test/LineTest.cpp
  10. 2
      src/Physics/Test/PlaneTest.cpp
  11. 2
      src/Physics/Test/SphereTest.cpp
  12. 6
      src/SceneGraph/AbstractTranslationRotation2D.h
  13. 22
      src/SceneGraph/AbstractTranslationRotation3D.h
  14. 2
      src/SceneGraph/Animable.h
  15. 2
      src/SceneGraph/Drawable.h
  16. 8
      src/SceneGraph/EuclideanMatrixTransformation2D.h
  17. 39
      src/SceneGraph/EuclideanMatrixTransformation3D.h
  18. 2
      src/SceneGraph/MatrixTransformation2D.h
  19. 17
      src/SceneGraph/MatrixTransformation3D.h
  20. 2
      src/SceneGraph/Test/CameraTest.cpp
  21. 40
      src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp
  22. 64
      src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp
  23. 54
      src/SceneGraph/Test/MatrixTransformation2DTest.cpp
  24. 78
      src/SceneGraph/Test/MatrixTransformation3DTest.cpp
  25. 36
      src/SceneGraph/Test/ObjectTest.cpp

4
doc/matrix-vector.dox

@ -74,7 +74,7 @@ Vectors are commonly used to specify various axes and scaling coefficients in
transformations, you can use convenience functions instead of typing out all transformations, you can use convenience functions instead of typing out all
other elements: other elements:
@code @code
Matrix4::rotation(deg(5.0f), Vector3::xAxis()); // {1.0f, 0.0f, 0.0f} Matrix4::rotation(5.0_degf, Vector3::xAxis()); // {1.0f, 0.0f, 0.0f}
Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f} Matrix3::translation(Vector2::yAxis(2.0f)); // {0.0f, 2.0f}
Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f} Matrix4::scaling(Vector3::zScale(-10.0f)); // {1.0f, 1.0f, -10.0f}
@endcode @endcode
@ -144,7 +144,7 @@ transformation:
Matrix4<float> a = Matrix4<float>::translation(Vector3::yAxis(4.0f)); Matrix4<float> a = Matrix4<float>::translation(Vector3::yAxis(4.0f));
Vector3<float> translation = a.translation(); Vector3<float> translation = a.translation();
Matrix3<float> b = Matrix3<float>::rotation(deg(15.f)); Matrix3<float> b = Matrix3<float>::rotation(15.0_degf));
Matrix<2, float> rotationScaling = b.rotationScaling(); Matrix<2, float> rotationScaling = b.rotationScaling();
Vector2<float> up = b.up(); Vector2<float> up = b.up();
@endcode @endcode

2
doc/scenegraph.dox

@ -88,7 +88,7 @@ transformation. For convenience you can use method chaining:
Object3D* next = new Object3D; Object3D* next = new Object3D;
next->setParent(another) next->setParent(another)
->translate(Vector3::yAxis(3.0f)) ->translate(Vector3::yAxis(3.0f))
->rotateY(deg(35.0f)); ->rotateY(35.0_degf);
@endcode @endcode
@section scenegraph-features Object features @section scenegraph-features Object features

11
src/Math/Matrix3.h

@ -62,14 +62,13 @@ template<class T> class Matrix3: public Matrix<3, T> {
/** /**
* @brief 2D rotation matrix * @brief 2D rotation matrix
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise)
* *
* @see rotation() const, Matrix4::rotation(T, const Vector3&), deg(), * @see rotation() const, Matrix4::rotation(Rad, const Vector3&)
* rad()
*/ */
static Matrix3<T> rotation(T angle) { static Matrix3<T> rotation(Rad<T> angle) {
T sine = std::sin(angle); T sine = std::sin(T(angle));
T cosine = std::cos(angle); T cosine = std::cos(T(angle));
return {{ cosine, sine, T(0)}, return {{ cosine, sine, T(0)},
{ -sine, cosine, T(0)}, { -sine, cosine, T(0)},

51
src/Math/Matrix4.h

@ -70,21 +70,21 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** /**
* @brief 3D rotation around arbitrary axis * @brief 3D rotation around arbitrary axis
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise)
* @param normalizedAxis Normalized rotation axis * @param normalizedAxis Normalized rotation axis
* *
* Expects that the rotation axis is normalized. If possible, use * Expects that the rotation axis is normalized. If possible, use
* faster alternatives like rotationX(), rotationY() and rotationZ(). * faster alternatives like rotationX(), rotationY() and rotationZ().
* @see rotation() const, DualQuaternion::rotation(), * @see rotation() const, DualQuaternion::rotation(),
* Quaternion::rotation(), Matrix3::rotation(T), Vector3::xAxis(), * Quaternion::rotation(), Matrix3::rotation(Rad), Vector3::xAxis(),
* Vector3::yAxis(), Vector3::zAxis(), deg(), rad() * Vector3::yAxis(), Vector3::zAxis()
*/ */
static Matrix4<T> rotation(T angle, const Vector3<T>& normalizedAxis) { static Matrix4<T> rotation(Rad<T> angle, const Vector3<T>& normalizedAxis) {
CORRADE_ASSERT(MathTypeTraits<T>::equals(normalizedAxis.dot(), T(1)), CORRADE_ASSERT(MathTypeTraits<T>::equals(normalizedAxis.dot(), T(1)),
"Math::Matrix4::rotation(): axis must be normalized", {}); "Math::Matrix4::rotation(): axis must be normalized", {});
T sine = std::sin(angle); T sine = std::sin(T(angle));
T cosine = std::cos(angle); T cosine = std::cos(T(angle));
T oneMinusCosine = T(1) - cosine; T oneMinusCosine = T(1) - cosine;
T xx = normalizedAxis.x()*normalizedAxis.x(); T xx = normalizedAxis.x()*normalizedAxis.x();
@ -113,16 +113,15 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** /**
* @brief 3D rotation around X axis * @brief 3D rotation around X axis
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise)
* *
* Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`. * Faster than calling `Matrix4::rotation(angle, Vector3::xAxis())`.
* @see rotation(T, const Vector3&), rotationY(), rotationZ(), * @see rotation(Rad, const Vector3&), rotationY(), rotationZ(),
* rotation() const, Quaternion::rotation(), Matrix3::rotation(T), * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad)
* deg(), rad()
*/ */
static Matrix4<T> rotationX(T angle) { static Matrix4<T> rotationX(Rad<T> angle) {
T sine = std::sin(angle); T sine = std::sin(T(angle));
T cosine = std::cos(angle); T cosine = std::cos(T(angle));
return {{T(1), T(0), T(0), T(0)}, return {{T(1), T(0), T(0), T(0)},
{T(0), cosine, sine, T(0)}, {T(0), cosine, sine, T(0)},
@ -132,16 +131,15 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** /**
* @brief 3D rotation around Y axis * @brief 3D rotation around Y axis
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise)
* *
* Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`. * Faster than calling `Matrix4::rotation(angle, Vector3::yAxis())`.
* @see rotation(T, const Vector3&), rotationX(), rotationZ(), * @see rotation(Rad, const Vector3&), rotationX(), rotationZ(),
* rotation() const, Quaternion::rotation(), Matrix3::rotation(T), * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad)
* deg(), rad()
*/ */
static Matrix4<T> rotationY(T angle) { static Matrix4<T> rotationY(Rad<T> angle) {
T sine = std::sin(angle); T sine = std::sin(T(angle));
T cosine = std::cos(angle); T cosine = std::cos(T(angle));
return {{cosine, T(0), -sine, T(0)}, return {{cosine, T(0), -sine, T(0)},
{ T(0), T(1), T(0), T(0)}, { T(0), T(1), T(0), T(0)},
@ -151,16 +149,15 @@ template<class T> class Matrix4: public Matrix<4, T> {
/** /**
* @brief 3D rotation matrix around Z axis * @brief 3D rotation matrix around Z axis
* @param angle Rotation angle (counterclockwise, in radians) * @param angle Rotation angle (counterclockwise)
* *
* Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`. * Faster than calling `Matrix4::rotation(angle, Vector3::zAxis())`.
* @see rotation(T, const Vector3&), rotationX(), rotationY(), * @see rotation(Rad, const Vector3&), rotationX(), rotationY(),
* rotation() const, Quaternion::rotation(), Matrix3::rotation(T), * rotation() const, Quaternion::rotation(), Matrix3::rotation(Rad)
* deg(), rad()
*/ */
static Matrix4<T> rotationZ(T angle) { static Matrix4<T> rotationZ(Rad<T> angle) {
T sine = std::sin(angle); T sine = std::sin(T(angle));
T cosine = std::cos(angle); T cosine = std::cos(T(angle));
return {{cosine, sine, T(0), T(0)}, return {{cosine, sine, T(0), T(0)},
{ -sine, cosine, T(0), T(0)}, { -sine, cosine, T(0), T(0)},

11
src/Math/Test/Matrix3Test.cpp

@ -44,6 +44,7 @@ class Matrix3Test: public Corrade::TestSuite::Tester {
void configuration(); void configuration();
}; };
typedef Math::Deg<float> Deg;
typedef Math::Matrix3<float> Matrix3; typedef Math::Matrix3<float> Matrix3;
typedef Math::Matrix<2, float> Matrix2; typedef Math::Matrix<2, float> Matrix2;
typedef Math::Vector2<float> Vector2; typedef Math::Vector2<float> Vector2;
@ -107,7 +108,7 @@ void Matrix3Test::rotation() {
{-0.258819f, 0.965926f, 0.0f}, {-0.258819f, 0.965926f, 0.0f},
{ 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix3::rotation(deg(15.0f)), matrix); CORRADE_COMPARE(Matrix3::rotation(Deg(15.0f)), matrix);
} }
void Matrix3Test::reflection() { void Matrix3Test::reflection() {
@ -165,7 +166,7 @@ void Matrix3Test::rotationPart() {
Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f), Matrix2 expectedRotationPart(Vector2( 0.965926f, 0.258819f),
Vector2(-0.258819f, 0.965926f)); Vector2(-0.258819f, 0.965926f));
Matrix3 rotation = Matrix3::rotation(deg(15.0f)); Matrix3 rotation = Matrix3::rotation(Deg(15.0f));
CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart);
Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f)); Matrix3 rotationTransformed = Matrix3::translation({2.0f, 5.0f})*rotation*Matrix3::scaling(Vector2(9.0f));
@ -196,19 +197,19 @@ void Matrix3Test::invertedEuclidean() {
CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3()); CORRADE_COMPARE(Matrix3::scaling(Vector2(2.0f)).invertedEuclidean(), Matrix3());
CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); CORRADE_COMPARE(o.str(), "Math::Matrix3::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n");
Matrix3 actual = Matrix3::rotation(deg(-74.0f))* Matrix3 actual = Matrix3::rotation(Deg(-74.0f))*
Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())*
Matrix3::translation({2.0f, -3.0f}); Matrix3::translation({2.0f, -3.0f});
Matrix3 expected = Matrix3::translation({-2.0f, 3.0f})* Matrix3 expected = Matrix3::translation({-2.0f, 3.0f})*
Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())* Matrix3::reflection(Vector2(0.5f, -2.0f).normalized())*
Matrix3::rotation(deg(74.0f)); Matrix3::rotation(Deg(74.0f));
CORRADE_COMPARE(actual.invertedEuclidean(), expected); CORRADE_COMPARE(actual.invertedEuclidean(), expected);
CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted());
} }
void Matrix3Test::transform() { void Matrix3Test::transform() {
Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(deg(90.0f)); Matrix3 a = Matrix3::translation({1.0f, -5.0f})*Matrix3::rotation(Deg(90.0f));
Vector2 v(1.0f, -2.0f); Vector2 v(1.0f, -2.0f);
CORRADE_COMPARE(a.transformVector(v), Vector2(2.0f, 1.0f)); CORRADE_COMPARE(a.transformVector(v), Vector2(2.0f, 1.0f));

26
src/Math/Test/Matrix4Test.cpp

@ -49,6 +49,8 @@ class Matrix4Test: public Corrade::TestSuite::Tester {
void configuration(); void configuration();
}; };
typedef Math::Deg<float> Deg;
typedef Math::Rad<float> Rad;
typedef Math::Matrix4<float> Matrix4; typedef Math::Matrix4<float> Matrix4;
typedef Math::Matrix<3, float> Matrix3; typedef Math::Matrix<3, float> Matrix3;
typedef Math::Vector3<float> Vector3; typedef Math::Vector3<float> Vector3;
@ -120,14 +122,14 @@ void Matrix4Test::rotation() {
std::ostringstream o; std::ostringstream o;
Error::setOutput(&o); Error::setOutput(&o);
CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4()); CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), {-1.0f, 2.0f, 2.0f}), Matrix4());
CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n"); CORRADE_COMPARE(o.str(), "Math::Matrix4::rotation(): axis must be normalized\n");
Matrix4 matrix({ 0.35612214f, -0.80181062f, 0.47987163f, 0.0f}, Matrix4 matrix({ 0.35612214f, -0.80181062f, 0.47987163f, 0.0f},
{ 0.47987163f, 0.59757638f, 0.6423595f, 0.0f}, { 0.47987163f, 0.59757638f, 0.6423595f, 0.0f},
{-0.80181062f, 0.0015183985f, 0.59757638f, 0.0f}, {-0.80181062f, 0.0015183985f, 0.59757638f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix); CORRADE_COMPARE(Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()), matrix);
} }
void Matrix4Test::rotationX() { void Matrix4Test::rotationX() {
@ -135,8 +137,8 @@ void Matrix4Test::rotationX() {
{0.0f, 0.90096887f, 0.43388374f, 0.0f}, {0.0f, 0.90096887f, 0.43388374f, 0.0f},
{0.0f, -0.43388374f, 0.90096887f, 0.0f}, {0.0f, -0.43388374f, 0.90096887f, 0.0f},
{0.0f, 0.0f, 0.0f, 1.0f}); {0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants<float>::pi()/7), Vector3::xAxis()), matrix); CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<float>::pi()/7), Vector3::xAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationX(rad(Math::Constants<float>::pi()/7)), matrix); CORRADE_COMPARE(Matrix4::rotationX(Rad(Math::Constants<float>::pi()/7)), matrix);
} }
void Matrix4Test::rotationY() { void Matrix4Test::rotationY() {
@ -144,8 +146,8 @@ void Matrix4Test::rotationY() {
{ 0.0f, 1.0f, 0.0f, 0.0f}, { 0.0f, 1.0f, 0.0f, 0.0f},
{0.43388374f, 0.0f, 0.90096887f, 0.0f}, {0.43388374f, 0.0f, 0.90096887f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants<float>::pi()/7), Vector3::yAxis()), matrix); CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<float>::pi()/7), Vector3::yAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationY(rad(Math::Constants<float>::pi()/7)), matrix); CORRADE_COMPARE(Matrix4::rotationY(Rad(Math::Constants<float>::pi()/7)), matrix);
} }
void Matrix4Test::rotationZ() { void Matrix4Test::rotationZ() {
@ -153,8 +155,8 @@ void Matrix4Test::rotationZ() {
{-0.43388374f, 0.90096887f, 0.0f, 0.0f}, {-0.43388374f, 0.90096887f, 0.0f, 0.0f},
{ 0.0f, 0.0f, 1.0f, 0.0f}, { 0.0f, 0.0f, 1.0f, 0.0f},
{ 0.0f, 0.0f, 0.0f, 1.0f}); { 0.0f, 0.0f, 0.0f, 1.0f});
CORRADE_COMPARE(Matrix4::rotation(rad(Math::Constants<float>::pi()/7), Vector3::zAxis()), matrix); CORRADE_COMPARE(Matrix4::rotation(Rad(Math::Constants<float>::pi()/7), Vector3::zAxis()), matrix);
CORRADE_COMPARE(Matrix4::rotationZ(rad(Math::Constants<float>::pi()/7)), matrix); CORRADE_COMPARE(Matrix4::rotationZ(Rad(Math::Constants<float>::pi()/7)), matrix);
} }
void Matrix4Test::reflection() { void Matrix4Test::reflection() {
@ -232,7 +234,7 @@ void Matrix4Test::rotationPart() {
Vector3( 0.47987163f, 0.59757638f, 0.6423595f), Vector3( 0.47987163f, 0.59757638f, 0.6423595f),
Vector3(-0.80181062f, 0.0015183985f, 0.59757638f)); Vector3(-0.80181062f, 0.0015183985f, 0.59757638f));
Matrix4 rotation = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized()); Matrix4 rotation = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 2.0f, 2.0f).normalized());
CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f); CORRADE_COMPARE(rotation.rotation().determinant(), 1.0f);
CORRADE_COMPARE(rotation.rotation()*rotation.rotation().transposed(), Matrix3()); CORRADE_COMPARE(rotation.rotation()*rotation.rotation().transposed(), Matrix3());
CORRADE_COMPARE(rotation.rotation(), expectedRotationPart); CORRADE_COMPARE(rotation.rotation(), expectedRotationPart);
@ -270,19 +272,19 @@ void Matrix4Test::invertedEuclidean() {
CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4()); CORRADE_COMPARE(Matrix4::scaling(Vector3(2.0f)).invertedEuclidean(), Matrix4());
CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n"); CORRADE_COMPARE(o.str(), "Math::Matrix4::invertedEuclidean(): the matrix doesn't represent Euclidean transformation\n");
Matrix4 actual = Matrix4::rotation(deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())* Matrix4 actual = Matrix4::rotation(Deg(-74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized())*
Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())*
Matrix4::translation({1.0f, 2.0f, -3.0f}); Matrix4::translation({1.0f, 2.0f, -3.0f});
Matrix4 expected = Matrix4::translation({-1.0f, -2.0f, 3.0f})* Matrix4 expected = Matrix4::translation({-1.0f, -2.0f, 3.0f})*
Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())* Matrix4::reflection(Vector3(0.5f, -2.0f, 2.0f).normalized())*
Matrix4::rotation(deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized()); Matrix4::rotation(Deg(74.0f), Vector3(-1.0f, 0.5f, 2.0f).normalized());
CORRADE_COMPARE(actual.invertedEuclidean(), expected); CORRADE_COMPARE(actual.invertedEuclidean(), expected);
CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted()); CORRADE_COMPARE(actual.invertedEuclidean(), actual.inverted());
} }
void Matrix4Test::transform() { void Matrix4Test::transform() {
Matrix4 a = Matrix4::translation({1.0f, -5.0f, 3.5f})*Matrix4::rotation(deg(90.0f), Vector3::zAxis()); Matrix4 a = Matrix4::translation({1.0f, -5.0f, 3.5f})*Matrix4::rotation(Deg(90.0f), Vector3::zAxis());
Vector3 v(1.0f, -2.0f, 5.5f); Vector3 v(1.0f, -2.0f, 5.5f);
CORRADE_COMPARE(a.transformVector(v), Vector3(2.0f, 1.0f, 5.5f)); CORRADE_COMPARE(a.transformVector(v), Vector3(2.0f, 1.0f, 5.5f));

2
src/Math/Vector3.h

@ -41,7 +41,7 @@ template<class T> class Vector3: public Vector<3, T> {
* Usable for translation or rotation along given axis, for example: * Usable for translation or rotation along given axis, for example:
* @code * @code
* Matrix4::translation(Vector3::xAxis(5.0f)); // same as Matrix4::translation({5.0f, 0.0f, 0.0f}); * Matrix4::translation(Vector3::xAxis(5.0f)); // same as Matrix4::translation({5.0f, 0.0f, 0.0f});
* Matrix4::rotation(deg(30.0f), Vector3::xAxis()); // same as Matrix::rotation(deg(30.0f), {1.0f, 0.0f, 0.0f}); * Matrix4::rotation(30.0_degf, Vector3::xAxis()); // same as Matrix::rotation(30.0_degf, {1.0f, 0.0f, 0.0f});
* @endcode * @endcode
* @see yAxis(), zAxis(), xScale(), Matrix4::right() * @see yAxis(), zAxis(), xScale(), Matrix4::right()
*/ */

2
src/Physics/Test/CapsuleTest.cpp

@ -39,7 +39,7 @@ CapsuleTest::CapsuleTest() {
void CapsuleTest::applyTransformation() { void CapsuleTest::applyTransformation() {
Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f); Physics::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f);
capsule.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); capsule.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::zAxis()));
CORRADE_COMPARE(capsule.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(capsule.transformedA(), Vector3(-2.0f, 1.0f, 3.0f));
CORRADE_COMPARE(capsule.transformedB(), Vector3(2.0f, -1.0f, -3.0f)); CORRADE_COMPARE(capsule.transformedB(), Vector3(2.0f, -1.0f, -3.0f));
CORRADE_COMPARE(capsule.radius(), 7.0f); CORRADE_COMPARE(capsule.radius(), 7.0f);

2
src/Physics/Test/LineTest.cpp

@ -34,7 +34,7 @@ LineTest::LineTest() {
void LineTest::applyTransformation() { void LineTest::applyTransformation() {
Physics::Line3D line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}); Physics::Line3D line({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f});
line.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::zAxis())); line.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::zAxis()));
CORRADE_COMPARE(line.transformedA(), Vector3(-2.0f, 1.0f, 3.0f)); CORRADE_COMPARE(line.transformedA(), Vector3(-2.0f, 1.0f, 3.0f));
CORRADE_COMPARE(line.transformedB(), Vector3(2.0f, -1.0f, -3.0f)); CORRADE_COMPARE(line.transformedB(), Vector3(2.0f, -1.0f, -3.0f));
} }

2
src/Physics/Test/PlaneTest.cpp

@ -40,7 +40,7 @@ PlaneTest::PlaneTest() {
void PlaneTest::applyTransformation() { void PlaneTest::applyTransformation() {
Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0}); Physics::Plane plane({1.0f, 2.0f, 3.0f}, {Constants::sqrt2(), -Constants::sqrt2(), 0});
plane.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::xAxis())); plane.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::xAxis()));
CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.0f, -3.0f, 2.0f)); CORRADE_COMPARE(plane.transformedPosition(), Vector3(1.0f, -3.0f, 2.0f));
CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), 0, -Constants::sqrt2())); CORRADE_COMPARE(plane.transformedNormal(), Vector3(Constants::sqrt2(), 0, -Constants::sqrt2()));

2
src/Physics/Test/SphereTest.cpp

@ -44,7 +44,7 @@ SphereTest::SphereTest() {
void SphereTest::applyTransformation() { void SphereTest::applyTransformation() {
Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f); Physics::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f);
sphere.applyTransformationMatrix(Matrix4::rotation(deg(90.0f), Vector3::yAxis())); sphere.applyTransformationMatrix(Matrix4::rotation(Deg(90.0f), Vector3::yAxis()));
CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f)); CORRADE_COMPARE(sphere.transformedPosition(), Vector3(3.0f, 2.0f, -1.0f));
CORRADE_COMPARE(sphere.transformedRadius(), 7.0f); CORRADE_COMPARE(sphere.transformedRadius(), 7.0f);

6
src/SceneGraph/AbstractTranslationRotation2D.h

@ -49,13 +49,11 @@ class AbstractTranslationRotation2D: public AbstractTransformation<2, T> {
/** /**
* @brief Rotate object * @brief Rotate object
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
*
* @see deg(), rad()
*/ */
virtual AbstractTranslationRotation2D<T>* rotate(T angle, TransformationType type = TransformationType::Global) = 0; virtual AbstractTranslationRotation2D<T>* rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) = 0;
}; };
}} }}

22
src/SceneGraph/AbstractTranslationRotation3D.h

@ -50,54 +50,52 @@ class AbstractTranslationRotation3D: public AbstractTransformation<3, T> {
/** /**
* @brief Rotate object * @brief Rotate object
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param normalizedAxis Normalized rotation axis * @param normalizedAxis Normalized rotation axis
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis() * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(),
* Vector3::yAxis(), Vector3::zAxis()
*/ */
virtual AbstractTranslationRotation3D<T>* rotate(T angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) = 0; virtual AbstractTranslationRotation3D<T>* rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) = 0;
/** /**
* @brief Rotate object around X axis * @brief Rotate object around X axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* In some implementations faster than calling * In some implementations faster than calling
* `rotate(angle, Vector3::xAxis())`. * `rotate(angle, Vector3::xAxis())`.
* @see deg(), rad()
*/ */
virtual AbstractTranslationRotation3D<T>* rotateX(T angle, TransformationType type = TransformationType::Global) { virtual AbstractTranslationRotation3D<T>* rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
return rotate(angle, Math::Vector3<T>::xAxis(), type); return rotate(angle, Math::Vector3<T>::xAxis(), type);
} }
/** /**
* @brief Rotate object around Y axis * @brief Rotate object around Y axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* In some implementations faster than calling * In some implementations faster than calling
* `rotate(angle, Vector3::yAxis())`. * `rotate(angle, Vector3::yAxis())`.
* @see deg(), rad()
*/ */
virtual AbstractTranslationRotation3D<T>* rotateY(T angle, TransformationType type = TransformationType::Global) { virtual AbstractTranslationRotation3D<T>* rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
return rotate(angle, Math::Vector3<T>::yAxis(), type); return rotate(angle, Math::Vector3<T>::yAxis(), type);
} }
/** /**
* @brief Rotate object around Z axis * @brief Rotate object around Z axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* In some implementations faster than calling * In some implementations faster than calling
* `rotate(angle, Vector3::zAxis())`. * `rotate(angle, Vector3::zAxis())`.
* @see deg(), rad()
*/ */
virtual AbstractTranslationRotation3D<T>* rotateZ(T angle, TransformationType type = TransformationType::Global) { virtual AbstractTranslationRotation3D<T>* rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) {
return rotate(angle, Math::Vector3<T>::zAxis(), type); return rotate(angle, Math::Vector3<T>::zAxis(), type);
} }
}; };

2
src/SceneGraph/Animable.h

@ -75,7 +75,7 @@ class AnimableObject: public Object3D, SceneGraph::Animable3D<> {
} }
void animationStep(GLfloat time, GLfloat delta) override { void animationStep(GLfloat time, GLfloat delta) override {
rotateX(deg(15.0f)*delta); // rotate at 15 degrees per second rotateX(15.0_degf*delta); // rotate at 15 degrees per second
} }
} }
@endcode @endcode

2
src/SceneGraph/Drawable.h

@ -59,7 +59,7 @@ SceneGraph::DrawableGroup3D<> drawables;
(new DrawableObject(&scene, &drawables)) (new DrawableObject(&scene, &drawables))
->translate(Vector3::yAxis(-0.3f)) ->translate(Vector3::yAxis(-0.3f))
->rotateX(deg(30.0f)); ->rotateX(30.0_degf);
(new AnotherDrawableObject(&scene, &drawables)) (new AnotherDrawableObject(&scene, &drawables))
->translate(Vector3::zAxis(0.5f)); ->translate(Vector3::zAxis(0.5f));
// ... // ...

8
src/SceneGraph/EuclideanMatrixTransformation2D.h

@ -98,13 +98,13 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D<T> {
/** /**
* @brief Rotate object * @brief Rotate object
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), normalizeRotation() * @see normalizeRotation(), Matrix3::rotation()
*/ */
inline EuclideanMatrixTransformation2D<T>* rotate(T angle, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation2D<T>* rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix3<T>::rotation(angle), type); transform(Math::Matrix3<T>::rotation(angle), type);
return this; return this;
} }
@ -115,6 +115,8 @@ class EuclideanMatrixTransformation2D: public AbstractTranslationRotation2D<T> {
* (normalized) * (normalized)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
*
* @see Matrix3::reflection()
*/ */
inline EuclideanMatrixTransformation2D<T>* reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) { inline EuclideanMatrixTransformation2D<T>* reflect(const Math::Vector2<T>& normal, TransformationType type = TransformationType::Global) {
transform(Math::Matrix3<T>::reflection(normal), type); transform(Math::Matrix3<T>::reflection(normal), type);

39
src/SceneGraph/EuclideanMatrixTransformation3D.h

@ -90,7 +90,15 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D<T> {
return this; return this;
} }
/** @copydoc AbstractTranslationRotation3D::translate() */ /**
* @brief Translate object
* @param vector Translation vector
* @param type Transformation type
* @return Pointer to self (for method chaining)
*
* @see Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis(),
* Matrix4::translation()
*/
inline EuclideanMatrixTransformation3D<T>* translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation3D<T>* translate(const Math::Vector3<T>& vector, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::translation(vector), type); transform(Math::Matrix4<T>::translation(vector), type);
return this; return this;
@ -98,54 +106,55 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D<T> {
/** /**
* @brief Rotate object * @brief Rotate object
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param normalizedAxis Normalized rotation axis * @param normalizedAxis Normalized rotation axis
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), Vector3::xAxis(), Vector3::yAxis(), * @see rotateX(), rotateY(), rotateZ(), Vector3::xAxis(),
* Vector3::zAxis(), normalizeRotation() * Vector3::yAxis(), Vector3::zAxis(), normalizeRotation(),
* Matrix4::rotation()
*/ */
inline EuclideanMatrixTransformation3D<T>* rotate(T angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation3D<T>* rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type); transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
return this; return this;
} }
/** /**
* @brief Rotate object around X axis * @brief Rotate object around X axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), normalizeRotation() * @see normalizeRotation(), Matrix4::rotationX()
*/ */
inline EuclideanMatrixTransformation3D<T>* rotateX(T angle, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation3D<T>* rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationX(angle), type); transform(Math::Matrix4<T>::rotationX(angle), type);
return this; return this;
} }
/** /**
* @brief Rotate object around Y axis * @brief Rotate object around Y axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), normalizeRotation() * @see normalizeRotation(), Matrix4::rotationY()
*/ */
inline EuclideanMatrixTransformation3D<T>* rotateY(T angle, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation3D<T>* rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationY(angle), type); transform(Math::Matrix4<T>::rotationY(angle), type);
return this; return this;
} }
/** /**
* @brief Rotate object around Z axis * @brief Rotate object around Z axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* @see deg(), rad(), normalizeRotation() * @see normalizeRotation(), Matrix4::rotationZ()
*/ */
inline EuclideanMatrixTransformation3D<T>* rotateZ(T angle, TransformationType type = TransformationType::Global) override { inline EuclideanMatrixTransformation3D<T>* rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationZ(angle), type); transform(Math::Matrix4<T>::rotationZ(angle), type);
return this; return this;
} }
@ -157,7 +166,7 @@ class EuclideanMatrixTransformation3D: public AbstractTranslationRotation3D<T> {
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* Same as calling transform() with Matrix4::reflection(). * @see Matrix4::reflection()
*/ */
inline EuclideanMatrixTransformation3D<T>* reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) { inline EuclideanMatrixTransformation3D<T>* reflect(const Math::Vector3<T>& normal, TransformationType type = TransformationType::Global) {
transform(Math::Matrix4<T>::reflection(normal), type); transform(Math::Matrix4<T>::reflection(normal), type);

2
src/SceneGraph/MatrixTransformation2D.h

@ -104,7 +104,7 @@ class MatrixTransformation2D: public AbstractTranslationRotationScaling2D<T> {
* @copydoc AbstractTranslationRotationScaling2D::rotate() * @copydoc AbstractTranslationRotationScaling2D::rotate()
* Same as calling transform() with Matrix3::rotation(). * Same as calling transform() with Matrix3::rotation().
*/ */
inline MatrixTransformation2D<T>* rotate(T angle, TransformationType type = TransformationType::Global) override { inline MatrixTransformation2D<T>* rotate(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix3<T>::rotation(angle), type); transform(Math::Matrix3<T>::rotation(angle), type);
return this; return this;
} }

17
src/SceneGraph/MatrixTransformation3D.h

@ -104,49 +104,46 @@ class MatrixTransformation3D: public AbstractTranslationRotationScaling3D<T> {
* @copydoc AbstractTranslationRotationScaling3D::rotate() * @copydoc AbstractTranslationRotationScaling3D::rotate()
* Same as calling transform() with Matrix4::rotation(). * Same as calling transform() with Matrix4::rotation().
*/ */
inline MatrixTransformation3D<T>* rotate(T angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) override { inline MatrixTransformation3D<T>* rotate(Math::Rad<T> angle, const Math::Vector3<T>& normalizedAxis, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type); transform(Math::Matrix4<T>::rotation(angle, normalizedAxis), type);
return this; return this;
} }
/** /**
* @brief Rotate object around X axis * @brief Rotate object around X axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* Same as calling transform() with Matrix4::rotationX(). * Same as calling transform() with Matrix4::rotationX().
* @see deg(), rad()
*/ */
inline MatrixTransformation3D<T>* rotateX(T angle, TransformationType type = TransformationType::Global) override { inline MatrixTransformation3D<T>* rotateX(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationX(angle), type); transform(Math::Matrix4<T>::rotationX(angle), type);
return this; return this;
} }
/** /**
* @brief Rotate object around Y axis * @brief Rotate object around Y axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* Same as calling transform() with Matrix4::rotationY(). * Same as calling transform() with Matrix4::rotationY().
* @see deg(), rad()
*/ */
inline MatrixTransformation3D<T>* rotateY(T angle, TransformationType type = TransformationType::Global) override { inline MatrixTransformation3D<T>* rotateY(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationY(angle), type); transform(Math::Matrix4<T>::rotationY(angle), type);
return this; return this;
} }
/** /**
* @brief Rotate object around Z axis * @brief Rotate object around Z axis
* @param angle Angle in radians, counterclockwise * @param angle Angle (counterclockwise)
* @param type Transformation type * @param type Transformation type
* @return Pointer to self (for method chaining) * @return Pointer to self (for method chaining)
* *
* Same as calling transform() with Matrix4::rotationZ(). * Same as calling transform() with Matrix4::rotationZ().
* @see deg(), rad()
*/ */
inline MatrixTransformation3D<T>* rotateZ(T angle, TransformationType type = TransformationType::Global) override { inline MatrixTransformation3D<T>* rotateZ(Math::Rad<T> angle, TransformationType type = TransformationType::Global) override {
transform(Math::Matrix4<T>::rotationZ(angle), type); transform(Math::Matrix4<T>::rotationZ(angle), type);
return this; return this;
} }

2
src/SceneGraph/Test/CameraTest.cpp

@ -132,7 +132,7 @@ void CameraTest::projectionSizeOrthographic() {
void CameraTest::projectionSizePerspective() { void CameraTest::projectionSizePerspective() {
Object3D o; Object3D o;
Camera3D camera(&o); Camera3D camera(&o);
camera.setPerspective(deg(27.0f), 2.35f, 32.0f, 100); camera.setPerspective(Deg(27.0f), 2.35f, 32.0f, 100);
CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f, 0.204322f)); CORRADE_COMPARE(camera.projectionSize(), Vector2(0.48015756f, 0.204322f));
} }

40
src/SceneGraph/Test/EuclideanMatrixTransformation2DTest.cpp

@ -54,23 +54,23 @@ EuclideanMatrixTransformation2DTest::EuclideanMatrixTransformation2DTest() {
} }
void EuclideanMatrixTransformation2DTest::fromMatrix() { void EuclideanMatrixTransformation2DTest::fromMatrix() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::fromMatrix(m), m);
} }
void EuclideanMatrixTransformation2DTest::toMatrix() { void EuclideanMatrixTransformation2DTest::toMatrix() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::toMatrix(m), m);
} }
void EuclideanMatrixTransformation2DTest::compose() { void EuclideanMatrixTransformation2DTest::compose() {
Matrix3 parent = Matrix3::rotation(deg(17.0f)); Matrix3 parent = Matrix3::rotation(Deg(17.0f));
Matrix3 child = Matrix3::translation({1.0f, -0.3f}); Matrix3 child = Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::compose(parent, child), parent*child);
} }
void EuclideanMatrixTransformation2DTest::inverted() { void EuclideanMatrixTransformation2DTest::inverted() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3()); CORRADE_COMPARE(EuclideanMatrixTransformation2D<>::inverted(m)*m, Matrix3());
} }
@ -78,13 +78,13 @@ void EuclideanMatrixTransformation2DTest::setTransformation() {
/* Dirty after setting transformation */ /* Dirty after setting transformation */
Object2D o; Object2D o;
o.setClean(); o.setClean();
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
CORRADE_VERIFY(o.isDirty()); CORRADE_VERIFY(o.isDirty());
/* Scene cannot be transformed */ /* Scene cannot be transformed */
Scene2D s; Scene2D s;
s.setClean(); s.setClean();
s.rotate(deg(17.0f)); s.rotate(Deg(17.0f));
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3());
} }
@ -92,14 +92,14 @@ void EuclideanMatrixTransformation2DTest::setTransformation() {
void EuclideanMatrixTransformation2DTest::translate() { void EuclideanMatrixTransformation2DTest::translate() {
{ {
Object2D o; Object2D o;
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
o.translate({1.0f, -0.3f}); o.translate({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
o.translate({1.0f, -0.3f}, TransformationType::Local); o.translate({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} }
} }
@ -107,35 +107,35 @@ void EuclideanMatrixTransformation2DTest::rotate() {
{ {
Object2D o; Object2D o;
o.translate({1.0f, -0.3f}); o.translate({1.0f, -0.3f});
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} { } {
Object2D o; Object2D o;
o.translate({1.0f, -0.3f}); o.translate({1.0f, -0.3f});
o.rotate(deg(17.0f), TransformationType::Local); o.rotate(Deg(17.0f), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} }
} }
void EuclideanMatrixTransformation2DTest::reflect() { void EuclideanMatrixTransformation2DTest::reflect() {
{ {
Object2D o; Object2D o;
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
o.reflect(Vector2(-1.0f/Constants::sqrt2())); o.reflect(Vector2(-1.0f/Constants::sqrt2()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); 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_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2())));
} }
} }
void EuclideanMatrixTransformation2DTest::normalizeRotation() { void EuclideanMatrixTransformation2DTest::normalizeRotation() {
Object2D o; Object2D o;
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
o.normalizeRotation(); o.normalizeRotation();
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f)));
} }
}}} }}}

64
src/SceneGraph/Test/EuclideanMatrixTransformation3DTest.cpp

@ -54,23 +54,23 @@ EuclideanMatrixTransformation3DTest::EuclideanMatrixTransformation3DTest() {
} }
void EuclideanMatrixTransformation3DTest::fromMatrix() { void EuclideanMatrixTransformation3DTest::fromMatrix() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::fromMatrix(m), m);
} }
void EuclideanMatrixTransformation3DTest::toMatrix() { void EuclideanMatrixTransformation3DTest::toMatrix() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::toMatrix(m), m);
} }
void EuclideanMatrixTransformation3DTest::compose() { void EuclideanMatrixTransformation3DTest::compose() {
Matrix4 parent = Matrix4::rotationX(deg(17.0f)); Matrix4 parent = Matrix4::rotationX(Deg(17.0f));
Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::compose(parent, child), parent*child);
} }
void EuclideanMatrixTransformation3DTest::inverted() { void EuclideanMatrixTransformation3DTest::inverted() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4()); CORRADE_COMPARE(EuclideanMatrixTransformation3D<>::inverted(m)*m, Matrix4());
} }
@ -78,13 +78,13 @@ void EuclideanMatrixTransformation3DTest::setTransformation() {
/* Dirty after setting transformation */ /* Dirty after setting transformation */
Object3D o; Object3D o;
o.setClean(); o.setClean();
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
CORRADE_VERIFY(o.isDirty()); CORRADE_VERIFY(o.isDirty());
/* Scene cannot be transformed */ /* Scene cannot be transformed */
Scene3D s; Scene3D s;
s.setClean(); s.setClean();
s.rotateX(deg(17.0f)); s.rotateX(Deg(17.0f));
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4());
} }
@ -92,14 +92,14 @@ void EuclideanMatrixTransformation3DTest::setTransformation() {
void EuclideanMatrixTransformation3DTest::translate() { void EuclideanMatrixTransformation3DTest::translate() {
{ {
Object3D o; Object3D o;
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
o.translate({1.0f, -0.3f, 2.3f}); 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))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); 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})); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
} }
} }
@ -107,51 +107,51 @@ void EuclideanMatrixTransformation3DTest::rotate() {
{ {
Object3D o; Object3D o;
o.translate({1.0f, -0.3f, 2.3f}); o.translate({1.0f, -0.3f, 2.3f});
o.rotateX(deg(17.0f)) o.rotateX(Deg(17.0f))
->rotateY(deg(25.0f)) ->rotateY(Deg(25.0f))
->rotateZ(deg(-23.0f)) ->rotateZ(Deg(-23.0f))
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))*
Matrix4::rotationZ(deg(-23.0f))* Matrix4::rotationZ(Deg(-23.0f))*
Matrix4::rotationY(deg(25.0f))* Matrix4::rotationY(Deg(25.0f))*
Matrix4::rotationX(deg(17.0f))* Matrix4::rotationX(Deg(17.0f))*
Matrix4::translation({1.0f, -0.3f, 2.3f})); Matrix4::translation({1.0f, -0.3f, 2.3f}));
} { } {
Object3D o; Object3D o;
o.translate({1.0f, -0.3f, 2.3f}); o.translate({1.0f, -0.3f, 2.3f});
o.rotateX(deg(17.0f), TransformationType::Local) o.rotateX(Deg(17.0f), TransformationType::Local)
->rotateY(deg(25.0f), TransformationType::Local) ->rotateY(Deg(25.0f), TransformationType::Local)
->rotateZ(deg(-23.0f), TransformationType::Local) ->rotateZ(Deg(-23.0f), TransformationType::Local)
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::translation({1.0f, -0.3f, 2.3f})*
Matrix4::rotationX(deg(17.0f))* Matrix4::rotationX(Deg(17.0f))*
Matrix4::rotationY(deg(25.0f))* Matrix4::rotationY(Deg(25.0f))*
Matrix4::rotationZ(deg(-23.0f))* Matrix4::rotationZ(Deg(-23.0f))*
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())));
} }
} }
void EuclideanMatrixTransformation3DTest::reflect() { void EuclideanMatrixTransformation3DTest::reflect() {
{ {
Object3D o; Object3D o;
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
o.reflect(Vector3(-1.0f/Constants::sqrt3())); o.reflect(Vector3(-1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); 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_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3())));
} }
} }
void EuclideanMatrixTransformation3DTest::normalizeRotation() { void EuclideanMatrixTransformation3DTest::normalizeRotation() {
Object3D o; Object3D o;
o.rotateX(deg(17.0f)); o.rotateX(Deg(17.0f));
o.normalizeRotation(); o.normalizeRotation();
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f)));
} }
}}} }}}

54
src/SceneGraph/Test/MatrixTransformation2DTest.cpp

@ -56,23 +56,23 @@ MatrixTransformation2DTest::MatrixTransformation2DTest() {
} }
void MatrixTransformation2DTest::fromMatrix() { void MatrixTransformation2DTest::fromMatrix() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(MatrixTransformation2D<>::fromMatrix(m), m); CORRADE_COMPARE(MatrixTransformation2D<>::fromMatrix(m), m);
} }
void MatrixTransformation2DTest::toMatrix() { void MatrixTransformation2DTest::toMatrix() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(MatrixTransformation2D<>::toMatrix(m), m); CORRADE_COMPARE(MatrixTransformation2D<>::toMatrix(m), m);
} }
void MatrixTransformation2DTest::compose() { void MatrixTransformation2DTest::compose() {
Matrix3 parent = Matrix3::rotation(deg(17.0f)); Matrix3 parent = Matrix3::rotation(Deg(17.0f));
Matrix3 child = Matrix3::translation({1.0f, -0.3f}); Matrix3 child = Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(MatrixTransformation2D<>::compose(parent, child), parent*child); CORRADE_COMPARE(MatrixTransformation2D<>::compose(parent, child), parent*child);
} }
void MatrixTransformation2DTest::inverted() { void MatrixTransformation2DTest::inverted() {
Matrix3 m = Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f}); Matrix3 m = Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f});
CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3()); CORRADE_COMPARE(MatrixTransformation2D<>::inverted(m)*m, Matrix3());
} }
@ -81,15 +81,15 @@ void MatrixTransformation2DTest::setTransformation() {
Object2D o; Object2D o;
o.setClean(); o.setClean();
CORRADE_VERIFY(!o.isDirty()); CORRADE_VERIFY(!o.isDirty());
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
CORRADE_VERIFY(o.isDirty()); CORRADE_VERIFY(o.isDirty());
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f)));
/* Scene cannot be transformed */ /* Scene cannot be transformed */
Scene2D s; Scene2D s;
s.setClean(); s.setClean();
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
s.setTransformation(Matrix3::rotation(deg(17.0f))); s.setTransformation(Matrix3::rotation(Deg(17.0f)));
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix3()); CORRADE_COMPARE(s.transformationMatrix(), Matrix3());
} }
@ -97,28 +97,28 @@ void MatrixTransformation2DTest::setTransformation() {
void MatrixTransformation2DTest::transform() { void MatrixTransformation2DTest::transform() {
{ {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.transform(Matrix3::translation({1.0f, -0.3f})); o.transform(Matrix3::translation({1.0f, -0.3f}));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.transform(Matrix3::translation({1.0f, -0.3f}), TransformationType::Local); 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})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} }
} }
void MatrixTransformation2DTest::translate() { void MatrixTransformation2DTest::translate() {
{ {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.translate({1.0f, -0.3f}); o.translate({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.translate({1.0f, -0.3f}, TransformationType::Local); o.translate({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} }
} }
@ -126,41 +126,41 @@ void MatrixTransformation2DTest::rotate() {
{ {
Object2D o; Object2D o;
o.setTransformation(Matrix3::translation({1.0f, -0.3f})); o.setTransformation(Matrix3::translation({1.0f, -0.3f}));
o.rotate(deg(17.0f)); o.rotate(Deg(17.0f));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::translation({1.0f, -0.3f})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::translation({1.0f, -0.3f}));
} { } {
Object2D o; Object2D o;
o.setTransformation(Matrix3::translation({1.0f, -0.3f})); o.setTransformation(Matrix3::translation({1.0f, -0.3f}));
o.rotate(deg(17.0f), TransformationType::Local); o.rotate(Deg(17.0f), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::translation({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} }
} }
void MatrixTransformation2DTest::scale() { void MatrixTransformation2DTest::scale() {
{ {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.scale({1.0f, -0.3f}); o.scale({1.0f, -0.3f});
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::scaling({1.0f, -0.3f})*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.scale({1.0f, -0.3f}, TransformationType::Local); o.scale({1.0f, -0.3f}, TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(deg(17.0f))*Matrix3::scaling({1.0f, -0.3f})); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::scaling({1.0f, -0.3f}));
} }
} }
void MatrixTransformation2DTest::reflect() { void MatrixTransformation2DTest::reflect() {
{ {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.reflect(Vector2(-1.0f/Constants::sqrt2())); o.reflect(Vector2(-1.0f/Constants::sqrt2()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2()))*Matrix3::rotation(Deg(17.0f)));
} { } {
Object2D o; Object2D o;
o.setTransformation(Matrix3::rotation(deg(17.0f))); o.setTransformation(Matrix3::rotation(Deg(17.0f)));
o.reflect(Vector2(-1.0f/Constants::sqrt2()), TransformationType::Local); 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_COMPARE(o.transformationMatrix(), Matrix3::rotation(Deg(17.0f))*Matrix3::reflection(Vector2(-1.0f/Constants::sqrt2())));
} }
} }

78
src/SceneGraph/Test/MatrixTransformation3DTest.cpp

@ -56,23 +56,23 @@ MatrixTransformation3DTest::MatrixTransformation3DTest() {
} }
void MatrixTransformation3DTest::fromMatrix() { void MatrixTransformation3DTest::fromMatrix() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f});
CORRADE_COMPARE(MatrixTransformation3D<>::fromMatrix(m), m); CORRADE_COMPARE(MatrixTransformation3D<>::fromMatrix(m), m);
} }
void MatrixTransformation3DTest::toMatrix() { void MatrixTransformation3DTest::toMatrix() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f});
CORRADE_COMPARE(MatrixTransformation3D<>::toMatrix(m), m); CORRADE_COMPARE(MatrixTransformation3D<>::toMatrix(m), m);
} }
void MatrixTransformation3DTest::compose() { void MatrixTransformation3DTest::compose() {
Matrix4 parent = Matrix4::rotationX(deg(17.0f)); Matrix4 parent = Matrix4::rotationX(Deg(17.0f));
Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f}); Matrix4 child = Matrix4::translation({1.0f, -0.3f, 2.3f});
CORRADE_COMPARE(MatrixTransformation3D<>::compose(parent, child), parent*child); CORRADE_COMPARE(MatrixTransformation3D<>::compose(parent, child), parent*child);
} }
void MatrixTransformation3DTest::inverted() { void MatrixTransformation3DTest::inverted() {
Matrix4 m = Matrix4::rotationX(deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f}); Matrix4 m = Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::scaling({2.0f, 1.4f, -2.1f});
CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4()); CORRADE_COMPARE(MatrixTransformation3D<>::inverted(m)*m, Matrix4());
} }
@ -81,15 +81,15 @@ void MatrixTransformation3DTest::setTransformation() {
Object3D o; Object3D o;
o.setClean(); o.setClean();
CORRADE_VERIFY(!o.isDirty()); CORRADE_VERIFY(!o.isDirty());
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
CORRADE_VERIFY(o.isDirty()); CORRADE_VERIFY(o.isDirty());
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f)));
/* Scene cannot be transformed */ /* Scene cannot be transformed */
Scene3D s; Scene3D s;
s.setClean(); s.setClean();
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
s.setTransformation(Matrix4::rotationX(deg(17.0f))); s.setTransformation(Matrix4::rotationX(Deg(17.0f)));
CORRADE_VERIFY(!s.isDirty()); CORRADE_VERIFY(!s.isDirty());
CORRADE_COMPARE(s.transformationMatrix(), Matrix4()); CORRADE_COMPARE(s.transformationMatrix(), Matrix4());
} }
@ -97,28 +97,28 @@ void MatrixTransformation3DTest::setTransformation() {
void MatrixTransformation3DTest::transform() { void MatrixTransformation3DTest::transform() {
{ {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f})); 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))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.transform(Matrix4::translation({1.0f, -0.3f, 2.3f}), TransformationType::Local); 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})); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
} }
} }
void MatrixTransformation3DTest::translate() { void MatrixTransformation3DTest::translate() {
{ {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.translate({1.0f, -0.3f, 2.3f}); 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))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::translation({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.translate({1.0f, -0.3f, 2.3f}, TransformationType::Local); 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})); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::translation({1.0f, -0.3f, 2.3f}));
} }
} }
@ -126,57 +126,57 @@ void MatrixTransformation3DTest::rotate() {
{ {
Object3D o; Object3D o;
o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f}));
o.rotateX(deg(17.0f)) o.rotateX(Deg(17.0f))
->rotateY(deg(25.0f)) ->rotateY(Deg(25.0f))
->rotateZ(deg(-23.0f)) ->rotateZ(Deg(-23.0f))
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3())); ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))* Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()))*
Matrix4::rotationZ(deg(-23.0f))* Matrix4::rotationZ(Deg(-23.0f))*
Matrix4::rotationY(deg(25.0f))* Matrix4::rotationY(Deg(25.0f))*
Matrix4::rotationX(deg(17.0f))* Matrix4::rotationX(Deg(17.0f))*
Matrix4::translation({1.0f, -0.3f, 2.3f})); Matrix4::translation({1.0f, -0.3f, 2.3f}));
} { } {
Object3D o; Object3D o;
o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f})); o.setTransformation(Matrix4::translation({1.0f, -0.3f, 2.3f}));
o.rotateX(deg(17.0f), TransformationType::Local) o.rotateX(Deg(17.0f), TransformationType::Local)
->rotateY(deg(25.0f), TransformationType::Local) ->rotateY(Deg(25.0f), TransformationType::Local)
->rotateZ(deg(-23.0f), TransformationType::Local) ->rotateZ(Deg(-23.0f), TransformationType::Local)
->rotate(deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local); ->rotate(Deg(96.0f), Vector3(1.0f/Constants::sqrt3()), TransformationType::Local);
CORRADE_COMPARE(o.transformationMatrix(), CORRADE_COMPARE(o.transformationMatrix(),
Matrix4::translation({1.0f, -0.3f, 2.3f})* Matrix4::translation({1.0f, -0.3f, 2.3f})*
Matrix4::rotationX(deg(17.0f))* Matrix4::rotationX(Deg(17.0f))*
Matrix4::rotationY(deg(25.0f))* Matrix4::rotationY(Deg(25.0f))*
Matrix4::rotationZ(deg(-23.0f))* Matrix4::rotationZ(Deg(-23.0f))*
Matrix4::rotation(deg(96.0f), Vector3(1.0f/Constants::sqrt3()))); Matrix4::rotation(Deg(96.0f), Vector3(1.0f/Constants::sqrt3())));
} }
} }
void MatrixTransformation3DTest::scale() { void MatrixTransformation3DTest::scale() {
{ {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.scale({1.0f, -0.3f, 2.3f}); 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))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::scaling({1.0f, -0.3f, 2.3f})*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.scale({1.0f, -0.3f, 2.3f}, TransformationType::Local); 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})); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::scaling({1.0f, -0.3f, 2.3f}));
} }
} }
void MatrixTransformation3DTest::reflect() { void MatrixTransformation3DTest::reflect() {
{ {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.reflect(Vector3(-1.0f/Constants::sqrt3())); o.reflect(Vector3(-1.0f/Constants::sqrt3()));
CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(deg(17.0f))); CORRADE_COMPARE(o.transformationMatrix(), Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3()))*Matrix4::rotationX(Deg(17.0f)));
} { } {
Object3D o; Object3D o;
o.setTransformation(Matrix4::rotationX(deg(17.0f))); o.setTransformation(Matrix4::rotationX(Deg(17.0f)));
o.reflect(Vector3(-1.0f/Constants::sqrt3()), TransformationType::Local); 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_COMPARE(o.transformationMatrix(), Matrix4::rotationX(Deg(17.0f))*Matrix4::reflection(Vector3(-1.0f/Constants::sqrt3())));
} }
} }

36
src/SceneGraph/Test/ObjectTest.cpp

@ -119,9 +119,9 @@ void ObjectTest::absoluteTransformation() {
CORRADE_COMPARE(o.transformation(), Matrix4::translation(Vector3::xAxis(2.0f))); CORRADE_COMPARE(o.transformation(), Matrix4::translation(Vector3::xAxis(2.0f)));
CORRADE_COMPARE(o.transformation(), o.transformationMatrix()); CORRADE_COMPARE(o.transformation(), o.transformationMatrix());
Object3D o2(&o); Object3D o2(&o);
o2.rotateY(deg(90.0f)); o2.rotateY(Deg(90.0f));
CORRADE_COMPARE(o2.absoluteTransformation(), CORRADE_COMPARE(o2.absoluteTransformation(),
Matrix4::translation(Vector3::xAxis(2.0f))*Matrix4::rotationY(deg(90.0f))); Matrix4::translation(Vector3::xAxis(2.0f))*Matrix4::rotationY(Deg(90.0f)));
CORRADE_COMPARE(o2.absoluteTransformation(), o2.absoluteTransformationMatrix()); CORRADE_COMPARE(o2.absoluteTransformation(), o2.absoluteTransformationMatrix());
/* Transformation of root object */ /* Transformation of root object */
@ -133,7 +133,7 @@ void ObjectTest::absoluteTransformation() {
void ObjectTest::transformations() { void ObjectTest::transformations() {
Scene3D s; Scene3D s;
Matrix4 initial = Matrix4::rotationX(deg(90.0f)).inverted(); Matrix4 initial = Matrix4::rotationX(Deg(90.0f)).inverted();
/* Empty list */ /* Empty list */
CORRADE_COMPARE(s.transformations(std::vector<Object3D*>(), initial), std::vector<Matrix4>()); CORRADE_COMPARE(s.transformations(std::vector<Object3D*>(), initial), std::vector<Matrix4>());
@ -143,16 +143,16 @@ void ObjectTest::transformations() {
/* One object */ /* One object */
Object3D first(&s); Object3D first(&s);
first.rotateZ(deg(30.0f)); first.rotateZ(Deg(30.0f));
Object3D second(&first); Object3D second(&first);
second.scale(Vector3(0.5f)); second.scale(Vector3(0.5f));
CORRADE_COMPARE(s.transformations({&second}, initial), std::vector<Matrix4>{ CORRADE_COMPARE(s.transformations({&second}, initial), std::vector<Matrix4>{
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)) initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f))
}); });
/* One object and scene */ /* One object and scene */
CORRADE_COMPARE(s.transformations({&second, &s}, initial), (std::vector<Matrix4>{ CORRADE_COMPARE(s.transformations({&second, &s}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial initial
})); }));
@ -160,15 +160,15 @@ void ObjectTest::transformations() {
Object3D third(&first); Object3D third(&first);
third.translate(Vector3::xAxis(5.0f)); third.translate(Vector3::xAxis(5.0f));
CORRADE_COMPARE(s.transformations({&second, &third}, initial), (std::vector<Matrix4>{ CORRADE_COMPARE(s.transformations({&second, &third}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)),
})); }));
/* Three objects with joint as one of them */ /* Three objects with joint as one of them */
CORRADE_COMPARE(s.transformations({&second, &third, &first}, initial), (std::vector<Matrix4>{ CORRADE_COMPARE(s.transformations({&second, &third, &first}, initial), (std::vector<Matrix4>{
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)), initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f)),
initial*Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)), initial*Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)),
initial*Matrix4::rotationZ(deg(30.0f)), initial*Matrix4::rotationZ(Deg(30.0f)),
})); }));
} }
@ -177,7 +177,7 @@ void ObjectTest::transformationsRelative() {
Scene3D s; Scene3D s;
Object3D first(&s); Object3D first(&s);
first.rotateZ(deg(30.0f)); first.rotateZ(Deg(30.0f));
Object3D second(&first); Object3D second(&first);
second.scale(Vector3(0.5f)); second.scale(Vector3(0.5f));
Object3D third(&first); Object3D third(&first);
@ -190,7 +190,7 @@ void ObjectTest::transformationsRelative() {
/* Transformation relative to another object, not part of any scene (but should work) */ /* Transformation relative to another object, not part of any scene (but should work) */
Object3D orphanParent1; Object3D orphanParent1;
orphanParent1.rotate(deg(31.0f), Vector3(1.0f).normalized()); orphanParent1.rotate(Deg(31.0f), Vector3(1.0f).normalized());
Object3D orphanParent(&orphanParent1); Object3D orphanParent(&orphanParent1);
Object3D orphan1(&orphanParent); Object3D orphan1(&orphanParent);
orphan1.scale(Vector3::xScale(3.0f)); orphan1.scale(Vector3::xScale(3.0f));
@ -215,15 +215,15 @@ void ObjectTest::transformationsOrphan() {
void ObjectTest::transformationsDuplicate() { void ObjectTest::transformationsDuplicate() {
Scene3D s; Scene3D s;
Object3D first(&s); Object3D first(&s);
first.rotateZ(deg(30.0f)); first.rotateZ(Deg(30.0f));
Object3D second(&first); Object3D second(&first);
second.scale(Vector3(0.5f)); second.scale(Vector3(0.5f));
Object3D third(&first); Object3D third(&first);
third.translate(Vector3::xAxis(5.0f)); third.translate(Vector3::xAxis(5.0f));
Matrix4 firstExpected = Matrix4::rotationZ(deg(30.0f)); Matrix4 firstExpected = Matrix4::rotationZ(Deg(30.0f));
Matrix4 secondExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::scaling(Vector3(0.5f)); Matrix4 secondExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::scaling(Vector3(0.5f));
Matrix4 thirdExpected = Matrix4::rotationZ(deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f)); Matrix4 thirdExpected = Matrix4::rotationZ(Deg(30.0f))*Matrix4::translation(Vector3::xAxis(5.0f));
CORRADE_COMPARE(s.transformations({&second, &third, &second, &first, &third}), (std::vector<Matrix4>{ CORRADE_COMPARE(s.transformations({&second, &third, &second, &first, &third}), (std::vector<Matrix4>{
secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected secondExpected, thirdExpected, secondExpected, firstExpected, thirdExpected
})); }));
@ -267,7 +267,7 @@ void ObjectTest::setClean() {
CachingInvertedFeature* childTwoFeature2 = new CachingInvertedFeature(childTwo); CachingInvertedFeature* childTwoFeature2 = new CachingInvertedFeature(childTwo);
CachingObject* childThree = new CachingObject(childTwo); CachingObject* childThree = new CachingObject(childTwo);
childThree->rotate(deg(90.0f), Vector3::yAxis()); childThree->rotate(Deg(90.0f), Vector3::yAxis());
/* Object is dirty at the beginning */ /* Object is dirty at the beginning */
CORRADE_VERIFY(scene.isDirty()); CORRADE_VERIFY(scene.isDirty());

Loading…
Cancel
Save