mirror of https://github.com/mosra/magnum.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
4.3 KiB
111 lines
4.3 KiB
|
13 years ago
|
/*
|
||
|
|
This file is part of Magnum.
|
||
|
|
|
||
|
13 years ago
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz>
|
||
|
|
|
||
|
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
|
copy of this software and associated documentation files (the "Software"),
|
||
|
|
to deal in the Software without restriction, including without limitation
|
||
|
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
|
||
|
|
The above copyright notice and this permission notice shall be included
|
||
|
|
in all copies or substantial portions of the Software.
|
||
|
|
|
||
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
|
DEALINGS IN THE SOFTWARE.
|
||
|
13 years ago
|
*/
|
||
|
|
|
||
|
|
#include <TestSuite/Tester.h>
|
||
|
|
|
||
|
|
#include "DebugTools/Implementation/ForceRendererTransformation.h"
|
||
|
|
|
||
|
|
namespace Magnum { namespace DebugTools { namespace Implementation { namespace Test {
|
||
|
|
|
||
|
13 years ago
|
class ForceRendererTest: public TestSuite::Tester {
|
||
|
13 years ago
|
public:
|
||
|
|
explicit ForceRendererTest();
|
||
|
|
|
||
|
|
void zero2D();
|
||
|
13 years ago
|
void common2D();
|
||
|
13 years ago
|
|
||
|
|
void zero3D();
|
||
|
|
void parallel3D();
|
||
|
|
void antiParallel3D();
|
||
|
|
void arbitrary3D();
|
||
|
|
};
|
||
|
|
|
||
|
|
ForceRendererTest::ForceRendererTest() {
|
||
|
|
addTests({&ForceRendererTest::zero2D,
|
||
|
13 years ago
|
&ForceRendererTest::common2D,
|
||
|
13 years ago
|
|
||
|
|
&ForceRendererTest::zero3D,
|
||
|
|
&ForceRendererTest::parallel3D,
|
||
|
|
&ForceRendererTest::antiParallel3D,
|
||
|
|
&ForceRendererTest::arbitrary3D});
|
||
|
|
}
|
||
|
|
|
||
|
|
void ForceRendererTest::zero2D() {
|
||
|
|
CORRADE_COMPARE(Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, Vector2()),
|
||
|
|
Matrix3::translation({0.5f, -3.0f})*Matrix3::scaling(Vector2(0.0f)));
|
||
|
|
}
|
||
|
|
|
||
|
13 years ago
|
void ForceRendererTest::common2D() {
|
||
|
13 years ago
|
Vector2 force(2.7f, -11.5f);
|
||
|
|
Matrix3 m = Implementation::forceRendererTransformation<2>({0.5f, -3.0f}, force);
|
||
|
|
|
||
|
|
/* Translation, right-pointing base vector is the same as force */
|
||
|
|
CORRADE_COMPARE(m.translation(), Vector2(0.5f, -3.0f));
|
||
|
|
CORRADE_COMPARE(m.right(), force);
|
||
|
|
|
||
|
|
/* All vectors have the same length */
|
||
|
|
CORRADE_COMPARE(m.up().length(), force.length());
|
||
|
|
|
||
|
13 years ago
|
/* All vectors are orthogonal */
|
||
|
13 years ago
|
CORRADE_COMPARE(Vector2::dot(m.right(), m.up()), 0.0f);
|
||
|
|
}
|
||
|
|
|
||
|
|
void ForceRendererTest::zero3D() {
|
||
|
|
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3()),
|
||
|
|
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(0.0f)));
|
||
|
|
}
|
||
|
|
|
||
|
|
void ForceRendererTest::parallel3D() {
|
||
|
|
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(2.5f)),
|
||
|
|
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling(Vector3(2.5f)));
|
||
|
|
}
|
||
|
|
|
||
|
|
void ForceRendererTest::antiParallel3D() {
|
||
|
|
CORRADE_COMPARE(Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, Vector3::xAxis(-2.5f)),
|
||
|
|
Matrix4::translation({0.5f, -3.0f, 1.0f})*Matrix4::scaling({-2.5f, 2.5f, 2.5f}));
|
||
|
|
}
|
||
|
|
|
||
|
|
void ForceRendererTest::arbitrary3D() {
|
||
|
|
Vector3 force(3.7f, -5.7f, -11.5f);
|
||
|
|
Matrix4 m = Implementation::forceRendererTransformation<3>({0.5f, -3.0f, 1.0f}, force);
|
||
|
|
|
||
|
|
/* Translation, right-pointing base vector is the same as force */
|
||
|
|
CORRADE_COMPARE(m.translation(), Vector3(0.5f, -3.0f, 1.0f));
|
||
|
|
CORRADE_COMPARE(m.right(), force);
|
||
|
|
|
||
|
|
/* All vectors have the same length */
|
||
|
|
CORRADE_COMPARE(m.up().length(), force.length());
|
||
|
|
CORRADE_COMPARE(m.backward().length(), force.length());
|
||
|
|
|
||
|
13 years ago
|
/* All vectors are orthogonal */
|
||
|
13 years ago
|
CORRADE_COMPARE(Vector3::dot(m.right(), m.up()), 0.0f);
|
||
|
|
CORRADE_COMPARE(Vector3::dot(m.right(), m.backward()), 0.0f);
|
||
|
13 years ago
|
/** @todo This shouldn't be too different */
|
||
|
|
CORRADE_COMPARE(Vector3::dot(m.up(), m.backward()), -Math::TypeTraits<Float>::epsilon());
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
}}}}
|
||
|
|
|
||
|
|
CORRADE_TEST_MAIN(Magnum::DebugTools::Implementation::Test::ForceRendererTest)
|