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.
89 lines
3.2 KiB
89 lines
3.2 KiB
|
14 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.
|
||
|
14 years ago
|
|
||
|
13 years ago
|
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.
|
||
|
14 years ago
|
*/
|
||
|
|
|
||
|
13 years ago
|
#include "Math/Matrix4.h"
|
||
|
|
#include "Magnum.h"
|
||
|
13 years ago
|
#include "Shapes/Capsule.h"
|
||
|
|
#include "Shapes/Point.h"
|
||
|
|
#include "Shapes/Sphere.h"
|
||
|
14 years ago
|
|
||
|
14 years ago
|
#include "ShapeTestBase.h"
|
||
|
14 years ago
|
|
||
|
13 years ago
|
namespace Magnum { namespace Shapes { namespace Test {
|
||
|
14 years ago
|
|
||
|
13 years ago
|
class CapsuleTest: public Corrade::TestSuite::Tester {
|
||
|
14 years ago
|
public:
|
||
|
|
CapsuleTest();
|
||
|
|
|
||
|
13 years ago
|
void transformed();
|
||
|
|
void transformedAverageScaling();
|
||
|
14 years ago
|
void collisionPoint();
|
||
|
|
void collisionSphere();
|
||
|
|
};
|
||
|
|
|
||
|
14 years ago
|
CapsuleTest::CapsuleTest() {
|
||
|
13 years ago
|
addTests({&CapsuleTest::transformed,
|
||
|
13 years ago
|
&CapsuleTest::collisionPoint,
|
||
|
|
&CapsuleTest::collisionSphere});
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void CapsuleTest::transformed() {
|
||
|
13 years ago
|
const Shapes::Capsule3D capsule({1.0f, 2.0f, 3.0f}, {-1.0f, -2.0f, -3.0f}, 7.0f);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
const auto transformed = capsule.transformed(Matrix4::rotation(Deg(90.0f), Vector3::zAxis()));
|
||
|
|
CORRADE_COMPARE(transformed.a(), Vector3(-2.0f, 1.0f, 3.0f));
|
||
|
|
CORRADE_COMPARE(transformed.b(), Vector3(2.0f, -1.0f, -3.0f));
|
||
|
|
CORRADE_COMPARE(transformed.radius(), 7.0f);
|
||
|
14 years ago
|
|
||
|
|
/* Apply average scaling to radius */
|
||
|
13 years ago
|
const auto scaled = capsule.transformed(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f}));
|
||
|
|
CORRADE_COMPARE(scaled.radius(), Constants::sqrt3()*7.0f);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void CapsuleTest::collisionPoint() {
|
||
|
13 years ago
|
Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
|
||
|
|
Shapes::Point3D point({2.0f, 0.0f, 0.0f});
|
||
|
|
Shapes::Point3D point1({2.9f, 1.0f, 0.0f});
|
||
|
|
Shapes::Point3D point2({1.0f, 3.1f, 0.0f});
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(capsule, point);
|
||
|
|
VERIFY_COLLIDES(capsule, point1);
|
||
|
|
VERIFY_NOT_COLLIDES(capsule, point2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void CapsuleTest::collisionSphere() {
|
||
|
13 years ago
|
Shapes::Capsule3D capsule({-1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}, 2.0f);
|
||
|
|
Shapes::Sphere3D sphere({3.0f, 0.0f, 0.0f}, 0.9f);
|
||
|
|
Shapes::Sphere3D sphere1({3.5f, 1.0f, 0.0f}, 0.6f);
|
||
|
|
Shapes::Sphere3D sphere2({1.0f, 4.1f, 0.0f}, 1.0f);
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(capsule, sphere);
|
||
|
|
VERIFY_COLLIDES(capsule, sphere1);
|
||
|
|
VERIFY_NOT_COLLIDES(capsule, sphere2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
}}}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
CORRADE_TEST_MAIN(Magnum::Shapes::Test::CapsuleTest)
|