| 1 |
// |
| 2 |
// SPDX-License-Identifier: BSD-3-Clause |
| 3 |
// Copyright Contributors to the OpenEXR Project. |
| 4 |
// |
| 5 |
|
| 6 |
#ifdef NDEBUG |
| 7 |
# undef NDEBUG |
| 8 |
#endif |
| 9 |
|
| 10 |
#include <ImathBox.h> |
| 11 |
#include <ImathFrustum.h> |
| 12 |
#include <ImathFrustumTest.h> |
| 13 |
#include <ImathSphere.h> |
| 14 |
#include <assert.h> |
| 15 |
#include <iostream> |
| 16 |
#include "testFrustumTest.h" |
| 17 |
|
| 18 |
// Include ImathForward *after* other headers to validate forward declarations |
| 19 |
#include <ImathForward.h> |
| 20 |
|
| 21 |
using namespace std; |
| 22 |
|
| 23 |
void |
| 24 |
testFrustumTest() |
| 25 |
{ |
| 26 |
cout << "Testing functions in ImathFrustumTest.h"; |
| 27 |
|
| 28 |
cout << "\nisVisible(Vec3) "; |
| 29 |
|
| 30 |
float n = 1.7f; |
| 31 |
float f = 567.0f; |
| 32 |
float l = -3.5f; |
| 33 |
float r = 2.0f; |
| 34 |
float b = -1.3f; |
| 35 |
float t = 0.9f; |
| 36 |
|
| 37 |
IMATH_INTERNAL_NAMESPACE::Frustum<float> frustum (n, f, l, r, t, b, false); |
| 38 |
|
| 39 |
IMATH_INTERNAL_NAMESPACE::Matrix44<float> cameraMat; |
| 40 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> cameraPos (100.0f, 200.0f, 300.0f); |
| 41 |
cameraMat.makeIdentity(); |
| 42 |
cameraMat.translate (cameraPos); |
| 43 |
|
| 44 |
IMATH_INTERNAL_NAMESPACE::FrustumTest<float> frustumTest (frustum, cameraMat); |
| 45 |
|
| 46 |
///////////////////////////////////////////////////// |
| 47 |
// Test Vec3's |
| 48 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> insideVec (100.0f, 200.0f, 300 - 2.0f); |
| 49 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> outsideVec_near (100.0f, 200.0f, 300 - 1.5f); |
| 50 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> outsideVec_far (100.0f, 200.0f, 300 - 568.0f); |
| 51 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> outsideVec_side (100.0f, 200.0f + 100.0f, 300 - 2.0f); |
| 52 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> outsideVec_up (100.0f + 100.0f, 200.0f, 300 - 2.0f); |
| 53 |
|
| 54 |
assert (frustumTest.isVisible (insideVec)); |
| 55 |
assert (!frustumTest.isVisible (outsideVec_near)); |
| 56 |
assert (!frustumTest.isVisible (outsideVec_far)); |
| 57 |
assert (!frustumTest.isVisible (outsideVec_side)); |
| 58 |
assert (!frustumTest.isVisible (outsideVec_up)); |
| 59 |
|
| 60 |
cout << "passed Vec3\n"; |
| 61 |
|
| 62 |
///////////////////////////////////////////////////// |
| 63 |
// Test Boxes |
| 64 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> tinySize (0.0001f, 0.0001f, 0.0001f); |
| 65 |
IMATH_INTERNAL_NAMESPACE::Vec3<float> hugeSize (1000.0f, 1000.0f, 1000.0f); |
| 66 |
|
| 67 |
// Empty box should NOT be visible |
| 68 |
assert (!frustumTest.isVisible ( |
| 69 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>>())); |
| 70 |
|
| 71 |
// Tiny box inside the frust should be visible |
| 72 |
assert (frustumTest.isVisible ( |
| 73 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 74 |
insideVec + tinySize, |
| 75 |
insideVec + tinySize))); |
| 76 |
|
| 77 |
assert (frustumTest.completelyContains ( |
| 78 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 79 |
insideVec + tinySize, insideVec + tinySize))); |
| 80 |
|
| 81 |
// Huge boxes inside and outside should be visible |
| 82 |
assert (frustumTest.isVisible ( |
| 83 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 84 |
insideVec - hugeSize, |
| 85 |
insideVec + hugeSize))); |
| 86 |
assert (frustumTest.isVisible ( |
| 87 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 88 |
outsideVec_near - hugeSize, |
| 89 |
outsideVec_near + hugeSize))); |
| 90 |
assert (frustumTest.isVisible ( |
| 91 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 92 |
outsideVec_far - hugeSize, |
| 93 |
outsideVec_far + hugeSize))); |
| 94 |
assert (frustumTest.isVisible ( |
| 95 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 96 |
outsideVec_side - hugeSize, |
| 97 |
outsideVec_side + hugeSize))); |
| 98 |
assert (frustumTest.isVisible ( |
| 99 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 100 |
outsideVec_up - hugeSize, |
| 101 |
outsideVec_up + hugeSize))); |
| 102 |
|
| 103 |
// Tiny boxes outside should NOT be visible |
| 104 |
assert (!frustumTest.isVisible ( |
| 105 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 106 |
outsideVec_near - tinySize, |
| 107 |
outsideVec_near + tinySize))); |
| 108 |
assert (!frustumTest.isVisible ( |
| 109 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 110 |
outsideVec_far - tinySize, |
| 111 |
outsideVec_far + tinySize))); |
| 112 |
assert (!frustumTest.isVisible ( |
| 113 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 114 |
outsideVec_side - tinySize, |
| 115 |
outsideVec_side + tinySize))); |
| 116 |
assert (!frustumTest.isVisible ( |
| 117 |
IMATH_INTERNAL_NAMESPACE::Box<IMATH_INTERNAL_NAMESPACE::Vec3<float>> ( |
| 118 |
outsideVec_up - tinySize, |
| 119 |
outsideVec_up + tinySize))); |
| 120 |
cout << "passed Box\n"; |
| 121 |
|
| 122 |
///////////////////////////////////////////////////// |
| 123 |
// Test Spheres |
| 124 |
float tinyRadius = 0.0001f; |
| 125 |
float hugeRadius = 1000.0f; |
| 126 |
|
| 127 |
// Tiny sphere inside the frust should be visible |
| 128 |
assert ( |
| 129 |
frustumTest.isVisible (IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, tinyRadius))); |
| 130 |
|
| 131 |
assert (frustumTest.completelyContains( |
| 132 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, tinyRadius))); |
| 133 |
|
| 134 |
// Huge spheres inside and outside should be visible |
| 135 |
assert ( |
| 136 |
frustumTest.isVisible (IMATH_INTERNAL_NAMESPACE::Sphere3<float> (insideVec, hugeRadius))); |
| 137 |
assert (frustumTest.isVisible ( |
| 138 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_near, hugeRadius))); |
| 139 |
assert (frustumTest.isVisible ( |
| 140 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_far, hugeRadius))); |
| 141 |
assert (frustumTest.isVisible ( |
| 142 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_side, hugeRadius))); |
| 143 |
assert (frustumTest.isVisible ( |
| 144 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_up, hugeRadius))); |
| 145 |
|
| 146 |
// Tiny spheres outside should NOT be visible |
| 147 |
assert (!frustumTest.isVisible ( |
| 148 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_near, tinyRadius))); |
| 149 |
assert (!frustumTest.isVisible ( |
| 150 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_far, tinyRadius))); |
| 151 |
assert (!frustumTest.isVisible ( |
| 152 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_side, tinyRadius))); |
| 153 |
assert (!frustumTest.isVisible ( |
| 154 |
IMATH_INTERNAL_NAMESPACE::Sphere3<float> (outsideVec_up, tinyRadius))); |
| 155 |
cout << "passed Sphere\n"; |
| 156 |
|
| 157 |
cout << "\nok\n\n"; |
| 158 |
} |