|
|
|
|
@ -105,12 +105,29 @@ void SphereTest::collisionLineSegment() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void SphereTest::collisionSphere() { |
|
|
|
|
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); |
|
|
|
|
const Shapes::Sphere3D sphere({1.0f, 2.0f, 3.0f}, 2.0f); |
|
|
|
|
|
|
|
|
|
/* Collision */ |
|
|
|
|
const Shapes::Sphere3D sphere1({3.5f, 2.0f, 3.0f}, 1.0f); |
|
|
|
|
const Shapes::Collision3D collision = sphere/sphere1; |
|
|
|
|
CORRADE_VERIFY(sphere%sphere1 && sphere1%sphere); |
|
|
|
|
CORRADE_COMPARE(collision.position(), sphere1.position() - Vector3::xAxis(sphere1.radius())); |
|
|
|
|
CORRADE_COMPARE(collision.separationNormal(), -Vector3::xAxis()); |
|
|
|
|
CORRADE_COMPARE(collision.separationDistance(), 0.5f); |
|
|
|
|
|
|
|
|
|
VERIFY_COLLIDES(sphere, sphere1); |
|
|
|
|
VERIFY_NOT_COLLIDES(sphere, sphere2); |
|
|
|
|
/* Collision, flipped */ |
|
|
|
|
CORRADE_COMPARE(collision.separationNormal(), -(sphere1/sphere).separationNormal()); |
|
|
|
|
|
|
|
|
|
/* Collision with ambiguous separation vector */ |
|
|
|
|
const Shapes::Sphere3D sphere2(sphere.position(), 0.5f); |
|
|
|
|
const Shapes::Collision3D collision2 = sphere/sphere2; |
|
|
|
|
CORRADE_COMPARE(collision2.position(), sphere2.position() + Vector3::yAxis(sphere2.radius())); |
|
|
|
|
CORRADE_COMPARE(collision2.separationNormal(), Vector3::yAxis()); |
|
|
|
|
CORRADE_COMPARE(collision2.separationDistance(), 2.5f); |
|
|
|
|
|
|
|
|
|
/* No collision */ |
|
|
|
|
const Shapes::Sphere3D sphere3({-2.5f, 2.0f, 3.0f}, 1.0f); |
|
|
|
|
CORRADE_VERIFY(!(sphere%sphere3) && !(sphere/sphere3)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}}} |
|
|
|
|
|