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.
110 lines
3.8 KiB
110 lines
3.8 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/LineSegment.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 SphereTest: public Corrade::TestSuite::Tester {
|
||
|
14 years ago
|
public:
|
||
|
|
SphereTest();
|
||
|
|
|
||
|
13 years ago
|
void transformed();
|
||
|
14 years ago
|
void collisionPoint();
|
||
|
|
void collisionLine();
|
||
|
|
void collisionLineSegment();
|
||
|
|
void collisionSphere();
|
||
|
|
};
|
||
|
|
|
||
|
14 years ago
|
SphereTest::SphereTest() {
|
||
|
13 years ago
|
addTests({&SphereTest::transformed,
|
||
|
13 years ago
|
&SphereTest::collisionPoint,
|
||
|
|
&SphereTest::collisionLine,
|
||
|
|
&SphereTest::collisionLineSegment,
|
||
|
|
&SphereTest::collisionSphere});
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
13 years ago
|
void SphereTest::transformed() {
|
||
|
13 years ago
|
const Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 7.0f);
|
||
|
14 years ago
|
|
||
|
13 years ago
|
const auto transformed = sphere.transformed(Matrix4::rotation(Deg(90.0f), Vector3::yAxis()));
|
||
|
|
CORRADE_COMPARE(transformed.position(), Vector3(3.0f, 2.0f, -1.0f));
|
||
|
|
CORRADE_COMPARE(transformed.radius(), 7.0f);
|
||
|
14 years ago
|
|
||
|
|
/* Symmetric scaling */
|
||
|
13 years ago
|
const auto scaled = sphere.transformed(Matrix4::scaling(Vector3(2.0f)));
|
||
|
|
CORRADE_COMPARE(scaled.position(), Vector3(2.0f, 4.0f, 6.0f));
|
||
|
|
CORRADE_COMPARE(scaled.radius(), 14.0f);
|
||
|
14 years ago
|
|
||
|
|
/* Apply average scaling to radius */
|
||
|
13 years ago
|
const auto nonEven = sphere.transformed(Matrix4::scaling({Constants::sqrt3(), -Constants::sqrt2(), 2.0f}));
|
||
|
|
CORRADE_COMPARE(nonEven.radius(), Constants::sqrt3()*7.0f);
|
||
|
14 years ago
|
}
|
||
|
|
|
||
|
14 years ago
|
void SphereTest::collisionPoint() {
|
||
|
13 years ago
|
Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
|
||
|
|
Shapes::Point3D point({1.0f, 3.0f, 3.0f});
|
||
|
|
Shapes::Point3D point2({1.0f, 3.0f, 1.0f});
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(sphere, point);
|
||
|
|
VERIFY_NOT_COLLIDES(sphere, point2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void SphereTest::collisionLine() {
|
||
|
13 years ago
|
Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
|
||
|
|
Shapes::Line3D line({1.0f, 1.5f, 3.5f}, {1.0f, 2.5f, 2.5f});
|
||
|
|
Shapes::Line3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 3.0f, 5.1f});
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(sphere, line);
|
||
|
|
VERIFY_NOT_COLLIDES(sphere, line2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void SphereTest::collisionLineSegment() {
|
||
|
13 years ago
|
Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
|
||
|
|
Shapes::LineSegment3D line({1.0f, 2.0f, 4.9f}, {1.0f, 2.0f, 7.0f});
|
||
|
|
Shapes::LineSegment3D line2({1.0f, 2.0f, 5.1f}, {1.0f, 2.0f, 7.0f});
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(sphere, line);
|
||
|
|
VERIFY_NOT_COLLIDES(sphere, line2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
void SphereTest::collisionSphere() {
|
||
|
13 years ago
|
Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f);
|
||
|
|
Shapes::Sphere3D sphere1({1.0f, 3.0f, 5.0f}, 1.0f);
|
||
|
|
Shapes::Sphere3D sphere2({1.0f, 3.0f, 0.0f}, 1.0f);
|
||
|
14 years ago
|
|
||
|
|
VERIFY_COLLIDES(sphere, sphere1);
|
||
|
|
VERIFY_NOT_COLLIDES(sphere, sphere2);
|
||
|
|
}
|
||
|
|
|
||
|
14 years ago
|
}}}
|
||
|
14 years ago
|
|
||
|
13 years ago
|
CORRADE_TEST_MAIN(Magnum::Shapes::Test::SphereTest)
|