|
|
|
@ -42,6 +42,7 @@ struct IntersectionTest: Corrade::TestSuite::Tester { |
|
|
|
|
|
|
|
|
|
|
|
void pointFrustum(); |
|
|
|
void pointFrustum(); |
|
|
|
void rangeFrustum(); |
|
|
|
void rangeFrustum(); |
|
|
|
|
|
|
|
void rayRange(); |
|
|
|
void aabbFrustum(); |
|
|
|
void aabbFrustum(); |
|
|
|
void sphereFrustum(); |
|
|
|
void sphereFrustum(); |
|
|
|
|
|
|
|
|
|
|
|
@ -51,7 +52,6 @@ struct IntersectionTest: Corrade::TestSuite::Tester { |
|
|
|
void sphereConeView(); |
|
|
|
void sphereConeView(); |
|
|
|
void sphereConeViewNotRigid(); |
|
|
|
void sphereConeViewNotRigid(); |
|
|
|
void rangeCone(); |
|
|
|
void rangeCone(); |
|
|
|
void rayRange(); |
|
|
|
|
|
|
|
void aabbCone(); |
|
|
|
void aabbCone(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
@ -73,6 +73,7 @@ IntersectionTest::IntersectionTest() { |
|
|
|
|
|
|
|
|
|
|
|
&IntersectionTest::pointFrustum, |
|
|
|
&IntersectionTest::pointFrustum, |
|
|
|
&IntersectionTest::rangeFrustum, |
|
|
|
&IntersectionTest::rangeFrustum, |
|
|
|
|
|
|
|
&IntersectionTest::rayRange, |
|
|
|
&IntersectionTest::aabbFrustum, |
|
|
|
&IntersectionTest::aabbFrustum, |
|
|
|
&IntersectionTest::sphereFrustum, |
|
|
|
&IntersectionTest::sphereFrustum, |
|
|
|
|
|
|
|
|
|
|
|
@ -82,7 +83,6 @@ IntersectionTest::IntersectionTest() { |
|
|
|
&IntersectionTest::sphereConeView, |
|
|
|
&IntersectionTest::sphereConeView, |
|
|
|
&IntersectionTest::sphereConeViewNotRigid, |
|
|
|
&IntersectionTest::sphereConeViewNotRigid, |
|
|
|
&IntersectionTest::rangeCone, |
|
|
|
&IntersectionTest::rangeCone, |
|
|
|
&IntersectionTest::rayRange, |
|
|
|
|
|
|
|
&IntersectionTest::aabbCone}); |
|
|
|
&IntersectionTest::aabbCone}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -181,6 +181,52 @@ void IntersectionTest::rangeFrustum() { |
|
|
|
CORRADE_VERIFY(!Intersection::rangeFrustum(Range3D{Vector3{-10.0f}, Vector3{-5.0f}}, frustum)); |
|
|
|
CORRADE_VERIFY(!Intersection::rangeFrustum(Range3D{Vector3{-10.0f}, Vector3{-5.0f}}, frustum)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IntersectionTest::rayRange() { |
|
|
|
|
|
|
|
const Vector3 origin{2.0f, 2.0f, 2.0f}; |
|
|
|
|
|
|
|
const Range3D range{{-1.0f, -1.0f, -1.0f}, |
|
|
|
|
|
|
|
{ 1.0f, 1.0f, 1.0f}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Vector3 center{0.0f, 0.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 edge{0.0f, -1.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 corner{-1.0f, -1.0f, 1.0f}; |
|
|
|
|
|
|
|
const Float eps = 1e-6f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection at face center */ |
|
|
|
|
|
|
|
const Vector3 direction1 = center - origin; |
|
|
|
|
|
|
|
const Vector3 invDir1 = 1.0f/direction1; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir1, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection close to edge */ |
|
|
|
|
|
|
|
const Vector3 direction2 = edge + Vector3{0.0f, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir2 = 1.0f/direction2; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir2, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no intersection close to edge */ |
|
|
|
|
|
|
|
const Vector3 direction3 = edge - Vector3{0.0f, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir3 = 1.0f/direction3; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir3, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection close to corner */ |
|
|
|
|
|
|
|
const Vector3 direction4 = corner + Vector3{eps, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir4 = 1.0f/direction4; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir4, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no intersection close to corner */ |
|
|
|
|
|
|
|
const Vector3 direction5 = corner - Vector3{eps, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir5 = 1.0f/direction5; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir5, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* divide by zero test with intersection */ |
|
|
|
|
|
|
|
const Vector3 direction6{0.0f, 0.0f, -1.0f}; |
|
|
|
|
|
|
|
const Vector3 invDir6 = 1.0f/direction6; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange({0.0f, 0.0f, 2.0f}, invDir6, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* divide by zero test without intersection */ |
|
|
|
|
|
|
|
const Vector3 direction7{0.0f, 0.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 invDir7 = 1.0f/direction7; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir7, range)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IntersectionTest::aabbFrustum() { |
|
|
|
void IntersectionTest::aabbFrustum() { |
|
|
|
const Frustum frustum{ |
|
|
|
const Frustum frustum{ |
|
|
|
{1.0f, 0.0f, 0.0f, 0.0f}, |
|
|
|
{1.0f, 0.0f, 0.0f, 0.0f}, |
|
|
|
@ -436,52 +482,6 @@ void IntersectionTest::rangeCone() { |
|
|
|
center, normal, angle)); |
|
|
|
center, normal, angle)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void IntersectionTest::rayRange() { |
|
|
|
|
|
|
|
const Vector3 origin{2.0f, 2.0f, 2.0f}; |
|
|
|
|
|
|
|
const Range3D range{{-1.0f, -1.0f, -1.0f}, |
|
|
|
|
|
|
|
{ 1.0f, 1.0f, 1.0f}}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Vector3 center{0.0f, 0.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 edge{0.0f, -1.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 corner{-1.0f, -1.0f, 1.0f}; |
|
|
|
|
|
|
|
const Float eps = 1e-6f; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection at face center */ |
|
|
|
|
|
|
|
const Vector3 direction1 = center - origin; |
|
|
|
|
|
|
|
const Vector3 invDir1 = 1.0f/direction1; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir1, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection close to edge */ |
|
|
|
|
|
|
|
const Vector3 direction2 = edge + Vector3{0.0f, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir2 = 1.0f/direction2; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir2, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no intersection close to edge */ |
|
|
|
|
|
|
|
const Vector3 direction3 = edge - Vector3{0.0f, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir3 = 1.0f/direction3; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir3, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* intersection close to corner */ |
|
|
|
|
|
|
|
const Vector3 direction4 = corner + Vector3{eps, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir4 = 1.0f/direction4; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange(origin, invDir4, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* no intersection close to corner */ |
|
|
|
|
|
|
|
const Vector3 direction5 = corner - Vector3{eps, eps, 0.0f} - origin; |
|
|
|
|
|
|
|
const Vector3 invDir5 = 1.0f/direction5; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir5, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* divide by zero test with intersection */ |
|
|
|
|
|
|
|
const Vector3 direction6{0.0f, 0.0f, -1.0f}; |
|
|
|
|
|
|
|
const Vector3 invDir6 = 1.0f/direction6; |
|
|
|
|
|
|
|
CORRADE_VERIFY(Intersection::rayRange({0.0f, 0.0f, 2.0f}, invDir6, range)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* divide by zero test without intersection */ |
|
|
|
|
|
|
|
const Vector3 direction7{0.0f, 0.0f, 1.0f}; |
|
|
|
|
|
|
|
const Vector3 invDir7 = 1.0f/direction7; |
|
|
|
|
|
|
|
CORRADE_VERIFY(!Intersection::rayRange(origin, invDir7, range)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void IntersectionTest::aabbCone() { |
|
|
|
void IntersectionTest::aabbCone() { |
|
|
|
const Vector3 center{1.0f, -2.0f, 1.3f}; |
|
|
|
const Vector3 center{1.0f, -2.0f, 1.3f}; |
|
|
|
const Vector3 normal{0.453154f, 0.422618f, 0.784886f}; |
|
|
|
const Vector3 normal{0.453154f, 0.422618f, 0.784886f}; |
|
|
|
|