|
|
|
|
@ -3,6 +3,7 @@
|
|
|
|
|
|
|
|
|
|
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016 |
|
|
|
|
Vladimír Vondruš <mosra@centrum.cz> |
|
|
|
|
Copyright © 2016 Jonathan Hale <squareys@googlemail.com> |
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a |
|
|
|
|
copy of this software and associated documentation files (the "Software"), |
|
|
|
|
@ -34,15 +35,22 @@ struct IntersectionTest: Corrade::TestSuite::Tester {
|
|
|
|
|
|
|
|
|
|
void planeLine(); |
|
|
|
|
void lineLine(); |
|
|
|
|
void pointFrustum(); |
|
|
|
|
void boxFrustum(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
typedef Math::Vector2<Float> Vector2; |
|
|
|
|
typedef Math::Vector3<Float> Vector3; |
|
|
|
|
typedef Math::Vector4<Float> Vector4; |
|
|
|
|
typedef Math::Frustum<Float> Frustum; |
|
|
|
|
typedef Math::Constants<Float> Constants; |
|
|
|
|
typedef Math::Range3D<Float> Range3D; |
|
|
|
|
|
|
|
|
|
IntersectionTest::IntersectionTest() { |
|
|
|
|
addTests({&IntersectionTest::planeLine, |
|
|
|
|
&IntersectionTest::lineLine}); |
|
|
|
|
&IntersectionTest::lineLine, |
|
|
|
|
&IntersectionTest::pointFrustum, |
|
|
|
|
&IntersectionTest::boxFrustum}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void IntersectionTest::planeLine() { |
|
|
|
|
@ -97,6 +105,39 @@ void IntersectionTest::lineLine() {
|
|
|
|
|
{0.0f, 0.0f}, {1.0f, 2.0f}), Constants::inf()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void IntersectionTest::pointFrustum() { |
|
|
|
|
const Frustum frustum{ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 0.0f}, |
|
|
|
|
{-1.0f, 0.0f, 0.0f, 10.0f}, |
|
|
|
|
{0.0f, 1.0f, 0.0f, 0.0f}, |
|
|
|
|
{0.0f, -1.0f, 0.0f, 10.0f}, |
|
|
|
|
{0.0f, 0.0f, 1.0f, 0.0f}, |
|
|
|
|
{0.0f, 0.0f, -1.0f, 10.0f}}; |
|
|
|
|
|
|
|
|
|
/* Point on edge */ |
|
|
|
|
CORRADE_VERIFY(Intersection::pointFrustum<Float>(Vector3{}, frustum)); |
|
|
|
|
/* Point inside */ |
|
|
|
|
CORRADE_VERIFY(Intersection::pointFrustum<Float>(Vector3{5.0f, 5.0f, 5.0f}, frustum)); |
|
|
|
|
/* Point outside */ |
|
|
|
|
CORRADE_VERIFY(!Intersection::pointFrustum<Float>(Vector3{0.0f, 0.0f, 100.0f}, frustum)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void IntersectionTest::boxFrustum() { |
|
|
|
|
const Frustum frustum{ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 0.0f}, |
|
|
|
|
{-1.0f, 0.0f, 0.0f, 10.0f}, |
|
|
|
|
{0.0f, 1.0f, 0.0f, 0.0f}, |
|
|
|
|
{0.0f, -1.0f, 0.0f, 10.0f}, |
|
|
|
|
{0.0f, 0.0f, 1.0f, 0.0f}, |
|
|
|
|
{0.0f, 0.0f, -1.0f, 10.0f}}; |
|
|
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::boxFrustum<Float>(Range3D{Vector3{1.0f}, Vector3{2.0f}}, frustum)); |
|
|
|
|
/* Bigger than frustum, but still intersects */ |
|
|
|
|
CORRADE_VERIFY(Intersection::boxFrustum<Float>(Range3D{Vector3{-100.0f}, Vector3{100.0f}}, frustum)); |
|
|
|
|
/* Outside of frustum */ |
|
|
|
|
CORRADE_VERIFY(!Intersection::boxFrustum<Float>(Range3D{Vector3{-10.0f}, Vector3{-5.0f}}, frustum)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}}}} |
|
|
|
|
|
|
|
|
|
CORRADE_TEST_MAIN(Magnum::Math::Geometry::Test::IntersectionTest) |
|
|
|
|
|