Browse Source

Physics: Fixed Box shape compilation, added missing unit test.

vectorfields
Vladimír Vondruš 14 years ago
parent
commit
f4bc8b6174
  1. 27
      src/Physics/Box.cpp
  2. 15
      src/Physics/Box.h
  3. 1
      src/Physics/CMakeLists.txt
  4. 36
      src/Physics/Test/BoxTest.cpp
  5. 31
      src/Physics/Test/BoxTest.h
  6. 1
      src/Physics/Test/CMakeLists.txt

27
src/Physics/Box.cpp

@ -0,0 +1,27 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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);
}
}}

15
src/Physics/Box.h

@ -19,30 +19,29 @@
* @brief Class Magnum::Physics::Box * @brief Class Magnum::Physics::Box
*/ */
#include "Math/Matrix4.h"
#include "AbstractShape.h" #include "AbstractShape.h"
namespace Magnum { namespace Physics { namespace Magnum { namespace Physics {
/** @brief Unit size box with assigned transformation matrix */ /** @brief Unit size box with assigned transformation matrix */
class Box: public AbstractShape { class PHYSICS_EXPORT Box: public AbstractShape {
public: public:
/** @brief Constructor */ /** @brief Constructor */
inline Box(const Matrix4& transformation): _transformation(transformation), _transformedTransformation(transformation) {} inline Box(const Matrix4& transformation): _transformation(transformation), _transformedTransformation(transformation) {}
inline void applyTransformation(const Matrix4& transformation) { void applyTransformation(const Matrix4& transformation);
_transformedTransformation = transformation*_transformation;
}
/** @brief Transformation */ /** @brief Transformation */
inline constexpr Matrix4 transformation() const { return _transformation; } inline Matrix4 transformation() const { return _transformation; }
/** @brief Set transformation */ /** @brief Set transformation */
inline Vector3 setTransformation(const Matrix4& transformation) { inline void setTransformation(const Matrix4& transformation) {
_transformation = transformation; _transformation = transformation;
} }
/** @brief Transformed transformation */ /** @brief Transformed transformation */
inline constexpr Vector3 transformedTransformation() const { inline Matrix4 transformedTransformation() const {
return _transformedTransformation; return _transformedTransformation;
} }
@ -50,7 +49,7 @@ class Box: public AbstractShape {
inline Type type() const { return Type::Box; } inline Type type() const { return Type::Box; }
private: private:
Vector3 _transformation, _transformedTransformation; Matrix4 _transformation, _transformedTransformation;
}; };
}} }}

1
src/Physics/CMakeLists.txt

@ -1,6 +1,7 @@
set(MagnumPhysics_SRCS set(MagnumPhysics_SRCS
AbstractShape.cpp AbstractShape.cpp
AxisAlignedBox.cpp AxisAlignedBox.cpp
Box.cpp
Capsule.cpp Capsule.cpp
Line.cpp Line.cpp
Plane.cpp Plane.cpp

36
src/Physics/Test/BoxTest.cpp

@ -0,0 +1,36 @@
/*
Copyright © 2010, 2011, 2012 Vladimír Vondruš <mosra@centrum.cz>
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}));
}
}}}

31
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š <mosra@centrum.cz>
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 <TestSuite/Tester.h>
namespace Magnum { namespace Physics { namespace Test {
class BoxTest: public Corrade::TestSuite::Tester<BoxTest> {
public:
BoxTest();
void applyTransformation();
};
}}}
#endif

1
src/Physics/Test/CMakeLists.txt

@ -1,4 +1,5 @@
corrade_add_test2(PhysicsAxisAlignedBoxTest AxisAlignedBoxTest.cpp LIBRARIES MagnumPhysics) 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(PhysicsCapsuleTest CapsuleTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsLineTest LineTest.cpp LIBRARIES MagnumPhysics)
corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics) corrade_add_test2(PhysicsPlaneTest PlaneTest.cpp LIBRARIES MagnumPhysics)

Loading…
Cancel
Save