diff --git a/src/Physics/Box.cpp b/src/Physics/Box.cpp new file mode 100644 index 000000000..36c230870 --- /dev/null +++ b/src/Physics/Box.cpp @@ -0,0 +1,27 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "Box.h" + +#include "Math/Matrix4.h" +#include "Math/Point3D.h" + +namespace Magnum { namespace Physics { + +void Box::applyTransformation(const Matrix4& transformation) { + _transformedTransformation = (transformation*_transformation); +} + +}} diff --git a/src/Physics/Box.h b/src/Physics/Box.h index 34535e7a6..f1c3286ff 100644 --- a/src/Physics/Box.h +++ b/src/Physics/Box.h @@ -19,30 +19,29 @@ * @brief Class Magnum::Physics::Box */ +#include "Math/Matrix4.h" #include "AbstractShape.h" namespace Magnum { namespace Physics { /** @brief Unit size box with assigned transformation matrix */ -class Box: public AbstractShape { +class PHYSICS_EXPORT Box: public AbstractShape { public: /** @brief Constructor */ inline Box(const Matrix4& transformation): _transformation(transformation), _transformedTransformation(transformation) {} - inline void applyTransformation(const Matrix4& transformation) { - _transformedTransformation = transformation*_transformation; - } + void applyTransformation(const Matrix4& transformation); /** @brief Transformation */ - inline constexpr Matrix4 transformation() const { return _transformation; } + inline Matrix4 transformation() const { return _transformation; } /** @brief Set transformation */ - inline Vector3 setTransformation(const Matrix4& transformation) { + inline void setTransformation(const Matrix4& transformation) { _transformation = transformation; } /** @brief Transformed transformation */ - inline constexpr Vector3 transformedTransformation() const { + inline Matrix4 transformedTransformation() const { return _transformedTransformation; } @@ -50,7 +49,7 @@ class Box: public AbstractShape { inline Type type() const { return Type::Box; } private: - Vector3 _transformation, _transformedTransformation; + Matrix4 _transformation, _transformedTransformation; }; }} diff --git a/src/Physics/CMakeLists.txt b/src/Physics/CMakeLists.txt index a42842084..430587b7d 100644 --- a/src/Physics/CMakeLists.txt +++ b/src/Physics/CMakeLists.txt @@ -1,6 +1,7 @@ set(MagnumPhysics_SRCS AbstractShape.cpp AxisAlignedBox.cpp + Box.cpp Capsule.cpp Line.cpp Plane.cpp diff --git a/src/Physics/Test/BoxTest.cpp b/src/Physics/Test/BoxTest.cpp new file mode 100644 index 000000000..e844e4d2e --- /dev/null +++ b/src/Physics/Test/BoxTest.cpp @@ -0,0 +1,36 @@ +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include "BoxTest.h" + +#include "Math/Matrix4.h" +#include "Physics/Box.h" + +CORRADE_TEST_MAIN(Magnum::Physics::Test::BoxTest) + +namespace Magnum { namespace Physics { namespace Test { + +BoxTest::BoxTest() { + addTests(&BoxTest::applyTransformation); +} + +void BoxTest::applyTransformation() { + Physics::Box box(Matrix4::translation({1.0f, 2.0f, -3.0f})); + + box.applyTransformation(Matrix4::scaling({2.0f, -1.0f, 1.5f})); + CORRADE_COMPARE(box.transformedTransformation(), Matrix4::scaling({2.0f, -1.0f, 1.5f})*Matrix4::translation({1.0f, 2.0f, -3.0f})); +} + +}}} diff --git a/src/Physics/Test/BoxTest.h b/src/Physics/Test/BoxTest.h new file mode 100644 index 000000000..48781ad08 --- /dev/null +++ b/src/Physics/Test/BoxTest.h @@ -0,0 +1,31 @@ +#ifndef Magnum_Physics_Test_BoxTest_h +#define Magnum_Physics_Test_BoxTest_h +/* + Copyright © 2010, 2011, 2012 Vladimír Vondruš + + This file is part of Magnum. + + Magnum is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License version 3 + only, as published by the Free Software Foundation. + + Magnum is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License version 3 for more details. +*/ + +#include + +namespace Magnum { namespace Physics { namespace Test { + +class BoxTest: public Corrade::TestSuite::Tester { + public: + BoxTest(); + + void applyTransformation(); +}; + +}}} + +#endif diff --git a/src/Physics/Test/CMakeLists.txt b/src/Physics/Test/CMakeLists.txt index b182873a0..4f8130a83 100644 --- a/src/Physics/Test/CMakeLists.txt +++ b/src/Physics/Test/CMakeLists.txt @@ -1,4 +1,5 @@ corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) +corrade_add_test2(PhysicsBoxTest BoxTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics)