diff --git a/interface/src/avatar/Avatar.cpp b/interface/src/avatar/Avatar.cpp index 4c9fe7f476..83351d5188 100644 --- a/interface/src/avatar/Avatar.cpp +++ b/interface/src/avatar/Avatar.cpp @@ -188,14 +188,14 @@ void Avatar::simulate(float deltaTime) { // simple frustum check float boundingRadius = getBoundingRadius(); - bool inViewFrustum = (bool)(qApp->getViewFrustum()->sphereInFrustum(getPosition(), boundingRadius)); + bool inView = qApp->getViewFrustum()->sphereIntersectsFrustum(getPosition(), boundingRadius); { PerformanceTimer perfTimer("hand"); getHand()->simulate(deltaTime, false); } - if (_shouldAnimate && !_shouldSkipRender && inViewFrustum) { + if (_shouldAnimate && !_shouldSkipRender && inView) { { PerformanceTimer perfTimer("skeleton"); _skeletonModel.getRig()->copyJointsFromJointData(_jointData); @@ -400,7 +400,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { frustum = qApp->getDisplayViewFrustum(); } - if ((bool)(frustum->sphereInFrustum(getPosition(), boundingRadius))) { + if (frustum->sphereIntersectsFrustum(getPosition(), boundingRadius)) { endRender(); return; } @@ -516,7 +516,7 @@ void Avatar::render(RenderArgs* renderArgs, const glm::vec3& cameraPosition) { auto& frustum = *renderArgs->_viewFrustum; auto textPosition = getDisplayNamePosition(); - if ((bool)frustum.pointInFrustum(textPosition)) { + if (frustum.pointIntersectsFrustum(textPosition)) { renderDisplayName(batch, frustum, textPosition); } } @@ -669,10 +669,10 @@ glm::vec3 Avatar::getDisplayNamePosition() const { return namePosition; } -Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, const glm::vec3& textPosition) const { - Q_ASSERT_X((bool)(frustum.pointInFrustum(textPosition)), +Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& view, const glm::vec3& textPosition) const { + Q_ASSERT_X(view.pointIntersectsFrustum(textPosition), "Avatar::calculateDisplayNameTransform", "Text not in viewfrustum."); - glm::vec3 toFrustum = frustum.getPosition() - textPosition; + glm::vec3 toFrustum = view.getPosition() - textPosition; // Compute orientation // If x and z are 0, atan(x, z) adais undefined, so default to 0 degrees @@ -694,7 +694,7 @@ Transform Avatar::calculateDisplayNameTransform(const ViewFrustum& frustum, cons return result; } -void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, const glm::vec3& textPosition) const { +void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& view, const glm::vec3& textPosition) const { PROFILE_RANGE_BATCH(batch, __FUNCTION__); bool shouldShowReceiveStats = DependencyManager::get()->shouldShowReceiveStats() && !isMyAvatar(); @@ -702,7 +702,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, co // If we have nothing to draw, or it's totally transparent, or it's too close or behind the camera, return static const float CLIP_DISTANCE = 0.2f; if ((_displayName.isEmpty() && !shouldShowReceiveStats) || _displayNameAlpha == 0.0f - || (glm::dot(frustum.getDirection(), getDisplayNamePosition() - frustum.getPosition()) <= CLIP_DISTANCE)) { + || (glm::dot(view.getDirection(), getDisplayNamePosition() - view.getPosition()) <= CLIP_DISTANCE)) { return; } auto renderer = textRenderer(DISPLAYNAME); @@ -743,7 +743,7 @@ void Avatar::renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, co (_displayNameAlpha / DISPLAYNAME_ALPHA) * DISPLAYNAME_BACKGROUND_ALPHA); // Compute display name transform - auto textTransform = calculateDisplayNameTransform(frustum, textPosition); + auto textTransform = calculateDisplayNameTransform(view, textPosition); // Test on extent above insures abs(height) > 0.0f textTransform.postScale(1.0f / height); batch.setModelTransform(textTransform); diff --git a/interface/src/avatar/Avatar.h b/interface/src/avatar/Avatar.h index 766a4734eb..cd9fc86e1e 100644 --- a/interface/src/avatar/Avatar.h +++ b/interface/src/avatar/Avatar.h @@ -231,8 +231,8 @@ protected: float getPelvisFloatingHeight() const; glm::vec3 getDisplayNamePosition() const; - Transform calculateDisplayNameTransform(const ViewFrustum& frustum, const glm::vec3& textPosition) const; - void renderDisplayName(gpu::Batch& batch, const ViewFrustum& frustum, const glm::vec3& textPosition) const; + Transform calculateDisplayNameTransform(const ViewFrustum& view, const glm::vec3& textPosition) const; + void renderDisplayName(gpu::Batch& batch, const ViewFrustum& view, const glm::vec3& textPosition) const; virtual void renderBody(RenderArgs* renderArgs, ViewFrustum* renderFrustum, float glowLevel = 0.0f); virtual bool shouldRenderHead(const RenderArgs* renderArgs) const; virtual void fixupModelsInScene(); diff --git a/libraries/octree/src/OctreeHeadlessViewer.cpp b/libraries/octree/src/OctreeHeadlessViewer.cpp index b20bfcd725..33c12b1fe5 100644 --- a/libraries/octree/src/OctreeHeadlessViewer.cpp +++ b/libraries/octree/src/OctreeHeadlessViewer.cpp @@ -91,7 +91,7 @@ void OctreeHeadlessViewer::queryOctree() { if (foundRootDetails) { AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); - if (_viewFrustum.cubeIntersectsKeyhole(serverBounds)) { + if ((bool)(_viewFrustum.calculateCubeKeyholeIntersection(serverBounds))) { inViewServers++; } } @@ -162,7 +162,7 @@ void OctreeHeadlessViewer::queryOctree() { if (foundRootDetails) { AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s); - inView = _viewFrustum.cubeInFrustum(serverBounds); + inView = (bool)(_viewFrustum.calculateCubeKeyholeIntersection(serverBounds)); } if (inView) { diff --git a/libraries/octree/src/ViewFrustum.cpp b/libraries/octree/src/ViewFrustum.cpp index c571addd82..4fe9faccbe 100644 --- a/libraries/octree/src/ViewFrustum.cpp +++ b/libraries/octree/src/ViewFrustum.cpp @@ -130,33 +130,7 @@ const char* ViewFrustum::debugPlaneName (int plane) const { return "Unknown"; } -ViewFrustum::location ViewFrustum::pointInFrustum(const glm::vec3& point) const { - // only check against frustum - for(int i = 0; i < 6; ++i) { - float distance = _planes[i].distance(point); - if (distance < 0.0f) { - return OUTSIDE; - } - } - return INSIDE; -} - -ViewFrustum::location ViewFrustum::sphereInFrustum(const glm::vec3& center, float radius) const { - // only check against frustum - ViewFrustum::location result = INSIDE; - for(int i=0; i < 6; i++) { - float distance = _planes[i].distance(center); - if (distance < -radius) { - // This is outside the regular frustum, so just return the value from checking the keyhole - return OUTSIDE; - } else if (distance < radius) { - result = INTERSECT; - } - } - return result; -} - -ViewFrustum::location ViewFrustum::cubeInFrustum(const AACube& cube) const { +ViewFrustum::location ViewFrustum::calculateCubeFrustumIntersection(const AACube& cube) const { // only check against frustum ViewFrustum::location result = INSIDE; for(int i=0; i < 6; i++) { @@ -175,25 +149,6 @@ ViewFrustum::location ViewFrustum::cubeInFrustum(const AACube& cube) const { return result; } -ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const { - // only check against frustum - ViewFrustum::location result = INSIDE; - for(int i=0; i < 6; i++) { - const glm::vec3& normal = _planes[i].getNormal(); - // check distance to farthest box point - if ( _planes[i].distance(box.getFarthestVertex(normal)) < 0.0f) { - return OUTSIDE; - } else { - // check distance to nearest box point - if (_planes[i].distance(box.getNearestVertex(normal)) < 0.0f) { - // box straddles the plane - result = INTERSECT; - } - } - } - return result; -} - const float HALF_SQRT_THREE = 0.8660254f; ViewFrustum::location ViewFrustum::calculateCubeKeyholeIntersection(const AACube& cube) const { @@ -216,11 +171,47 @@ ViewFrustum::location ViewFrustum::calculateCubeKeyholeIntersection(const AACube } // check against frustum - ViewFrustum::location frustumResult = cubeInFrustum(cube); + ViewFrustum::location frustumResult = calculateCubeFrustumIntersection(cube); return (frustumResult == OUTSIDE) ? sphereResult : frustumResult; } +bool ViewFrustum::pointIntersectsFrustum(const glm::vec3& point) const { + // only check against frustum + for(int i = 0; i < 6; ++i) { + float distance = _planes[i].distance(point); + if (distance < 0.0f) { + return false; + } + } + return true; +} + +bool ViewFrustum::sphereIntersectsFrustum(const glm::vec3& center, float radius) const { + // only check against frustum + for(int i=0; i < 6; i++) { + float distance = _planes[i].distance(center); + if (distance < -radius) { + // This is outside the regular frustum, so just return the value from checking the keyhole + return false; + } + } + return true; +} + +bool ViewFrustum::boxIntersectsFrustum(const AABox& box) const { + // only check against frustum + ViewFrustum::location result = INSIDE; + for(int i=0; i < 6; i++) { + const glm::vec3& normal = _planes[i].getNormal(); + // check distance to farthest box point + if ( _planes[i].distance(box.getFarthestVertex(normal)) < 0.0f) { + return false; + } + } + return true; +} + bool ViewFrustum::sphereIntersectsKeyhole(const glm::vec3& center, float radius) const { // check positive touch against central sphere if (glm::length(center - _position) <= (radius + _centerSphereRadius)) { diff --git a/libraries/octree/src/ViewFrustum.h b/libraries/octree/src/ViewFrustum.h index 72d6f0749a..f0ec412e34 100644 --- a/libraries/octree/src/ViewFrustum.h +++ b/libraries/octree/src/ViewFrustum.h @@ -94,15 +94,15 @@ public: typedef enum { OUTSIDE = 0, INTERSECT, INSIDE } location; - ViewFrustum::location pointInFrustum(const glm::vec3& point) const; - ViewFrustum::location sphereInFrustum(const glm::vec3& center, float radius) const; - ViewFrustum::location cubeInFrustum(const AACube& cube) const; - ViewFrustum::location boxInFrustum(const AABox& box) const; - /// @return INSIDE, INTERSECT, or OUTSIDE depending on how cube intersects the keyhole shape + ViewFrustum::location calculateCubeFrustumIntersection(const AACube& cube) const; ViewFrustum::location calculateCubeKeyholeIntersection(const AACube& cube) const; - // more efficient methods when only need boolean result + bool pointIntersectsFrustum(const glm::vec3& point) const; + bool sphereIntersectsFrustum(const glm::vec3& center, float radius) const; + bool cubeIntersectsFrustum(const AACube& box) const; + bool boxIntersectsFrustum(const AABox& box) const; + bool sphereIntersectsKeyhole(const glm::vec3& center, float radius) const; bool cubeIntersectsKeyhole(const AACube& cube) const; bool boxIntersectsKeyhole(const AABox& box) const; diff --git a/libraries/render-utils/src/MeshPartPayload.cpp b/libraries/render-utils/src/MeshPartPayload.cpp index bbcc877c07..e5a313e3b1 100644 --- a/libraries/render-utils/src/MeshPartPayload.cpp +++ b/libraries/render-utils/src/MeshPartPayload.cpp @@ -478,7 +478,7 @@ void ModelMeshPartPayload::render(RenderArgs* args) const { glm::vec4 cubeColor(1.0f, 1.0f, 0.0f, 1.0f); if (isSkinned) { cubeColor = glm::vec4(0.0f, 1.0f, 1.0f, 1.0f); - } else if ((bool)(args->_viewFrustum->boxInFrustum(partBounds))) { + } else if (args->_viewFrustum->boxIntersectsFrustum(partBounds)) { cubeColor = glm::vec4(1.0f, 0.0f, 1.0f, 1.0f); } diff --git a/libraries/render/src/render/CullTask.cpp b/libraries/render/src/render/CullTask.cpp index c2b9b99bef..7824514649 100644 --- a/libraries/render/src/render/CullTask.cpp +++ b/libraries/render/src/render/CullTask.cpp @@ -39,12 +39,12 @@ void render::cullItems(const RenderContextPointer& renderContext, const CullFunc // TODO: some entity types (like lights) might want to be rendered even // when they are outside of the view frustum... - bool outOfView; + bool inView; { - PerformanceTimer perfTimer("boxInFrustum"); - outOfView = frustum->boxInFrustum(item.bound) == ViewFrustum::OUTSIDE; + PerformanceTimer perfTimer("boxIntersectsFrustum"); + inView = frustum->boxIntersectsFrustum(item.bound); } - if (!outOfView) { + if (inView) { bool bigEnoughToRender; { PerformanceTimer perfTimer("shouldRender"); @@ -238,7 +238,7 @@ void CullSpatialSelection::run(const SceneContextPointer& sceneContext, const Re } bool frustumTest(const AABox& bound) { - if (_args->_viewFrustum->boxInFrustum(bound) == ViewFrustum::OUTSIDE) { + if (!_args->_viewFrustum->boxIntersectsFrustum(bound)) { _renderDetails._outOfView++; return false; } diff --git a/tests/octree/src/ViewFrustumTests.cpp b/tests/octree/src/ViewFrustumTests.cpp index 77041c8b44..2e9df54d83 100644 --- a/tests/octree/src/ViewFrustumTests.cpp +++ b/tests/octree/src/ViewFrustumTests.cpp @@ -78,521 +78,7 @@ void ViewFrustumTests::testInit() { QCOMPARE_WITH_ABS_ERROR(upDot, 1.0f, ACCEPTABLE_DOT_ERROR); } -void ViewFrustumTests::testPointInFrustum() { - float aspect = 1.0f; - float fovX = PI / 2.0f; - float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); - float nearClip = 1.0f; - float farClip = 100.0f; - float holeRadius = 10.0f; - - glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); - - float angle = PI / 7.0f; - glm::vec3 axis = Vectors::UNIT_Y; - glm::quat rotation = glm::angleAxis(angle, axis); - - ViewFrustum view; - view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); - view.setPosition(center); - view.setOrientation(rotation); - view.setCenterRadius(holeRadius); - view.calculate(); - - float delta = 0.1f; - float deltaAngle = 0.01f; - glm::quat elevation, swing; - glm::vec3 point, localOffset; - float pointDistance = farClip; - - // farPlane - localOffset = (pointDistance - delta) * localForward; - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - localOffset = (pointDistance + delta) * localForward; - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); - - // nearPlane - localOffset = (nearClip + delta) * localForward; - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - localOffset = (nearClip - delta) * localForward; - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); - - // topPlane - angle = 0.5f * fovY; - elevation = glm::angleAxis(angle - deltaAngle, localRight); - localOffset = elevation * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle + deltaAngle, localRight); - localOffset = elevation * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); - - // bottom plane - angle = -0.5f * fovY; - elevation = glm::angleAxis(angle + deltaAngle, localRight); - localOffset = elevation * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle - deltaAngle, localRight); - localOffset = elevation * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); - - // right plane - angle = 0.5f * fovX; - swing = glm::angleAxis(angle - deltaAngle, localUp); - localOffset = swing * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle + deltaAngle, localUp); - localOffset = swing * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); - - // left plane - angle = -0.5f * fovX; - swing = glm::angleAxis(angle + deltaAngle, localUp); - localOffset = swing * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle - deltaAngle, localUp); - localOffset = swing * (pointDistance * localForward); - point = center + rotation * localOffset; - QCOMPARE(view.pointInFrustum(point), ViewFrustum::OUTSIDE); -} - -void ViewFrustumTests::testSphereInFrustum() { - float aspect = 1.0f; - float fovX = PI / 2.0f; - float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); - float nearClip = 1.0f; - float farClip = 100.0f; - float holeRadius = 10.0f; - - glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); - - float angle = PI / 7.0f; - glm::vec3 axis = Vectors::UNIT_Y; - glm::quat rotation = glm::angleAxis(angle, axis); - - ViewFrustum view; - view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); - view.setPosition(center); - view.setOrientation(rotation); - view.setCenterRadius(holeRadius); - view.calculate(); - - float delta = 0.1f; - float deltaAngle = 0.01f; - glm::quat elevation, swing; - glm::vec3 sphereCenter, localOffset; - - float sphereRadius = 2.68f; // must be much smaller than sphereDistance for small angle approx below - float sphereDistance = farClip; - float sphereAngle = sphereRadius / sphereDistance; // sine of small angles approximation - - // farPlane - localOffset = (sphereDistance - sphereRadius - delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - localOffset = (sphereDistance + sphereRadius - delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - localOffset = (sphereDistance + sphereRadius + delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); - - // nearPlane - localOffset = (nearClip + 2.0f * sphereRadius + delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - localOffset = (nearClip - sphereRadius + delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - localOffset = (nearClip - sphereRadius - delta) * localForward; - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); - - // topPlane - angle = 0.5f * fovY - sphereAngle; - elevation = glm::angleAxis(angle - deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - angle = 0.5f * fovY + sphereAngle; - elevation = glm::angleAxis(angle - deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle + deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); - - // bottom plane - angle = -0.5f * fovY + sphereAngle; - elevation = glm::angleAxis(angle + deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - angle = -0.5f * fovY - sphereAngle; - elevation = glm::angleAxis(angle + deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle - deltaAngle, localRight); - localOffset = elevation * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); - - // right plane - angle = 0.5f * fovX - sphereAngle; - swing = glm::angleAxis(angle - deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - angle = 0.5f * fovX + sphereAngle; - swing = glm::angleAxis(angle - deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle + deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); - - // left plane - angle = -0.5f * fovX + sphereAngle; - swing = glm::angleAxis(angle + deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INSIDE); - - angle = -0.5f * fovX - sphereAngle; - swing = glm::angleAxis(angle + deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle - sphereAngle - deltaAngle, localUp); - localOffset = swing * (sphereDistance * localForward); - sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereInFrustum(sphereCenter, sphereRadius), ViewFrustum::OUTSIDE); -} - -void ViewFrustumTests::testCubeInFrustum() { - float aspect = 1.0f; - float fovX = PI / 2.0f; - float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); - float nearClip = 1.0f; - float farClip = 100.0f; - float holeRadius = 10.0f; - - glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); - - float angle = PI / 7.0f; - glm::vec3 axis = Vectors::UNIT_Y; - glm::quat rotation = glm::angleAxis(angle, axis); - - ViewFrustum view; - view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); - view.setPosition(center); - view.setOrientation(rotation); - view.setCenterRadius(holeRadius); - view.calculate(); - - float delta = 0.1f; - float deltaAngle = 0.01f; - glm::quat elevation, swing; - glm::vec3 cubeCenter, localOffset; - - float cubeScale = 2.68f; // must be much smaller than cubeDistance for small angle approx below - glm::vec3 halfScaleOffset = 0.5f * glm::vec3(cubeScale); - float cubeDistance = farClip; - float cubeBoundingRadius = 0.5f * sqrtf(3.0f) * cubeScale; - float cubeAngle = cubeBoundingRadius / cubeDistance; // sine of small angles approximation - AACube cube(center, cubeScale); - - // farPlane - localOffset = (cubeDistance - cubeBoundingRadius - delta) * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - localOffset = cubeDistance * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - localOffset = (cubeDistance + cubeBoundingRadius + delta) * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); - - // nearPlane - localOffset = (nearClip + 2.0f * cubeBoundingRadius + delta) * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - localOffset = (nearClip + delta) * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - localOffset = (nearClip - cubeBoundingRadius - delta) * localForward; - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); - - // topPlane - angle = 0.5f * fovY; - elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); - - // bottom plane - angle = -0.5f * fovY; - elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight); - localOffset = elevation * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); - - // right plane - angle = 0.5f * fovX; - swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); - - // left plane - angle = -0.5f * fovX; - swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp); - localOffset = swing * (cubeDistance * localForward); - cubeCenter = center + rotation * localOffset; - cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeInFrustum(cube), ViewFrustum::OUTSIDE); -} - -void ViewFrustumTests::testBoxInFrustum() { - float aspect = 1.0f; - float fovX = PI / 2.0f; - float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); - float nearClip = 1.0f; - float farClip = 100.0f; - float holeRadius = 10.0f; - - glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); - - float angle = PI / 7.0f; - glm::vec3 axis = Vectors::UNIT_Y; - glm::quat rotation = glm::angleAxis(angle, axis); - - ViewFrustum view; - view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); - view.setPosition(center); - view.setOrientation(rotation); - view.setCenterRadius(holeRadius); - view.calculate(); - - float delta = 0.1f; - float deltaAngle = 0.01f; - glm::quat elevation, swing; - glm::vec3 boxCenter, localOffset; - - glm::vec3 boxScale = glm::vec3(2.68f, 1.78f, 0.431f); - float boxDistance = farClip; - float boxBoundingRadius = 0.5f * glm::length(boxScale); - float boxAngle = boxBoundingRadius / boxDistance; // sine of small angles approximation - AABox box(center, boxScale); - - // farPlane - localOffset = (boxDistance - boxBoundingRadius - delta) * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - localOffset = boxDistance * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - localOffset = (boxDistance + boxBoundingRadius + delta) * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); - - // nearPlane - localOffset = (nearClip + 2.0f * boxBoundingRadius + delta) * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - localOffset = nearClip * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - localOffset = (nearClip - boxBoundingRadius - delta) * localForward; - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); - - // topPlane - angle = 0.5f * fovY; - elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); - - // bottom plane - angle = -0.5f * fovY; - elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - elevation = glm::angleAxis(angle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight); - localOffset = elevation * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); - - // right plane - angle = 0.5f * fovX; - swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); - - // left plane - angle = -0.5f * fovX; - swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INSIDE); - - swing = glm::angleAxis(angle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::INTERSECT); - - swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp); - localOffset = swing * (boxDistance * localForward); - boxCenter = center + rotation * localOffset; - box.setBox(boxCenter - 0.5f * boxScale, boxScale); - QCOMPARE(view.boxInFrustum(box), ViewFrustum::OUTSIDE); -} - -void ViewFrustumTests::testCubeInKeyhole() { +void ViewFrustumTests::testCubeKeyholeIntersection() { float aspect = 1.0f; float fovX = PI / 2.0f; float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); @@ -790,6 +276,520 @@ void ViewFrustumTests::testCubeInKeyhole() { QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT); // larger than sphere } +void ViewFrustumTests::testCubeFrustumIntersection() { + float aspect = 1.0f; + float fovX = PI / 2.0f; + float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); + float nearClip = 1.0f; + float farClip = 100.0f; + float holeRadius = 10.0f; + + glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); + + float angle = PI / 7.0f; + glm::vec3 axis = Vectors::UNIT_Y; + glm::quat rotation = glm::angleAxis(angle, axis); + + ViewFrustum view; + view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); + view.setPosition(center); + view.setOrientation(rotation); + view.setCenterRadius(holeRadius); + view.calculate(); + + float delta = 0.1f; + float deltaAngle = 0.01f; + glm::quat elevation, swing; + glm::vec3 cubeCenter, localOffset; + + float cubeScale = 2.68f; // must be much smaller than cubeDistance for small angle approx below + glm::vec3 halfScaleOffset = 0.5f * glm::vec3(cubeScale); + float cubeDistance = farClip; + float cubeBoundingRadius = 0.5f * sqrtf(3.0f) * cubeScale; + float cubeAngle = cubeBoundingRadius / cubeDistance; // sine of small angles approximation + AACube cube(center, cubeScale); + + // farPlane + localOffset = (cubeDistance - cubeBoundingRadius - delta) * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + localOffset = cubeDistance * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + localOffset = (cubeDistance + cubeBoundingRadius + delta) * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); + + // nearPlane + localOffset = (nearClip + 2.0f * cubeBoundingRadius + delta) * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + localOffset = (nearClip + delta) * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + localOffset = (nearClip - cubeBoundingRadius - delta) * localForward; + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); + + // topPlane + angle = 0.5f * fovY; + elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + elevation = glm::angleAxis(angle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); + + // bottom plane + angle = -0.5f * fovY; + elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + elevation = glm::angleAxis(angle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight); + localOffset = elevation * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); + + // right plane + angle = 0.5f * fovX; + swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + swing = glm::angleAxis(angle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); + + // left plane + angle = -0.5f * fovX; + swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INSIDE); + + swing = glm::angleAxis(angle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::INTERSECT); + + swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp); + localOffset = swing * (cubeDistance * localForward); + cubeCenter = center + rotation * localOffset; + cube.setBox(cubeCenter - halfScaleOffset, cubeScale); + QCOMPARE(view.calculateCubeFrustumIntersection(cube), ViewFrustum::OUTSIDE); +} + +void ViewFrustumTests::testPointIntersectsFrustum() { + float aspect = 1.0f; + float fovX = PI / 2.0f; + float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); + float nearClip = 1.0f; + float farClip = 100.0f; + float holeRadius = 10.0f; + + glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); + + float angle = PI / 7.0f; + glm::vec3 axis = Vectors::UNIT_Y; + glm::quat rotation = glm::angleAxis(angle, axis); + + ViewFrustum view; + view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); + view.setPosition(center); + view.setOrientation(rotation); + view.setCenterRadius(holeRadius); + view.calculate(); + + float delta = 0.1f; + float deltaAngle = 0.01f; + glm::quat elevation, swing; + glm::vec3 point, localOffset; + float pointDistance = farClip; + + // farPlane + localOffset = (pointDistance - delta) * localForward; + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + localOffset = (pointDistance + delta) * localForward; + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside + + // nearPlane + localOffset = (nearClip + delta) * localForward; + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + localOffset = (nearClip - delta) * localForward; + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside + + // topPlane + angle = 0.5f * fovY; + elevation = glm::angleAxis(angle - deltaAngle, localRight); + localOffset = elevation * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + elevation = glm::angleAxis(angle + deltaAngle, localRight); + localOffset = elevation * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside + + // bottom plane + angle = -0.5f * fovY; + elevation = glm::angleAxis(angle + deltaAngle, localRight); + localOffset = elevation * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + elevation = glm::angleAxis(angle - deltaAngle, localRight); + localOffset = elevation * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside + + // right plane + angle = 0.5f * fovX; + swing = glm::angleAxis(angle - deltaAngle, localUp); + localOffset = swing * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + swing = glm::angleAxis(angle + deltaAngle, localUp); + localOffset = swing * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside + + // left plane + angle = -0.5f * fovX; + swing = glm::angleAxis(angle + deltaAngle, localUp); + localOffset = swing * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), true); // inside + + swing = glm::angleAxis(angle - deltaAngle, localUp); + localOffset = swing * (pointDistance * localForward); + point = center + rotation * localOffset; + QCOMPARE(view.pointIntersectsFrustum(point), false); // outside +} + +void ViewFrustumTests::testSphereIntersectsFrustum() { + float aspect = 1.0f; + float fovX = PI / 2.0f; + float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); + float nearClip = 1.0f; + float farClip = 100.0f; + float holeRadius = 10.0f; + + glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); + + float angle = PI / 7.0f; + glm::vec3 axis = Vectors::UNIT_Y; + glm::quat rotation = glm::angleAxis(angle, axis); + + ViewFrustum view; + view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); + view.setPosition(center); + view.setOrientation(rotation); + view.setCenterRadius(holeRadius); + view.calculate(); + + float delta = 0.1f; + float deltaAngle = 0.01f; + glm::quat elevation, swing; + glm::vec3 sphereCenter, localOffset; + + float sphereRadius = 2.68f; // must be much smaller than sphereDistance for small angle approx below + float sphereDistance = farClip; + float sphereAngle = sphereRadius / sphereDistance; // sine of small angles approximation + + // farPlane + localOffset = (sphereDistance - sphereRadius - delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + localOffset = (sphereDistance + sphereRadius - delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + localOffset = (sphereDistance + sphereRadius + delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside + + // nearPlane + localOffset = (nearClip + 2.0f * sphereRadius + delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + localOffset = (nearClip - sphereRadius + delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + localOffset = (nearClip - sphereRadius - delta) * localForward; + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside + + // topPlane + angle = 0.5f * fovY - sphereAngle; + elevation = glm::angleAxis(angle - deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + angle = 0.5f * fovY + sphereAngle; + elevation = glm::angleAxis(angle - deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + elevation = glm::angleAxis(angle + deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside + + // bottom plane + angle = -0.5f * fovY + sphereAngle; + elevation = glm::angleAxis(angle + deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + angle = -0.5f * fovY - sphereAngle; + elevation = glm::angleAxis(angle + deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + elevation = glm::angleAxis(angle - deltaAngle, localRight); + localOffset = elevation * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside + + // right plane + angle = 0.5f * fovX - sphereAngle; + swing = glm::angleAxis(angle - deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + angle = 0.5f * fovX + sphereAngle; + swing = glm::angleAxis(angle - deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + swing = glm::angleAxis(angle + deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside + + // left plane + angle = -0.5f * fovX + sphereAngle; + swing = glm::angleAxis(angle + deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // inside + + angle = -0.5f * fovX - sphereAngle; + swing = glm::angleAxis(angle + deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), true); // straddle + + swing = glm::angleAxis(angle - sphereAngle - deltaAngle, localUp); + localOffset = swing * (sphereDistance * localForward); + sphereCenter = center + rotation * localOffset; + QCOMPARE(view.sphereIntersectsFrustum(sphereCenter, sphereRadius), false); // outside +} + +void ViewFrustumTests::testBoxIntersectsFrustum() { + float aspect = 1.0f; + float fovX = PI / 2.0f; + float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect); + float nearClip = 1.0f; + float farClip = 100.0f; + float holeRadius = 10.0f; + + glm::vec3 center = glm::vec3(12.3f, 4.56f, 89.7f); + + float angle = PI / 7.0f; + glm::vec3 axis = Vectors::UNIT_Y; + glm::quat rotation = glm::angleAxis(angle, axis); + + ViewFrustum view; + view.setProjection(glm::perspective(fovX, aspect, nearClip, farClip)); + view.setPosition(center); + view.setOrientation(rotation); + view.setCenterRadius(holeRadius); + view.calculate(); + + float delta = 0.1f; + float deltaAngle = 0.01f; + glm::quat elevation, swing; + glm::vec3 boxCenter, localOffset; + + glm::vec3 boxScale = glm::vec3(2.68f, 1.78f, 0.431f); + float boxDistance = farClip; + float boxBoundingRadius = 0.5f * glm::length(boxScale); + float boxAngle = boxBoundingRadius / boxDistance; // sine of small angles approximation + AABox box(center, boxScale); + + // farPlane + localOffset = (boxDistance - boxBoundingRadius - delta) * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + localOffset = boxDistance * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + localOffset = (boxDistance + boxBoundingRadius + delta) * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside + + // nearPlane + localOffset = (nearClip + 2.0f * boxBoundingRadius + delta) * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + localOffset = nearClip * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + localOffset = (nearClip - boxBoundingRadius - delta) * localForward; + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside + + // topPlane + angle = 0.5f * fovY; + elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + elevation = glm::angleAxis(angle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside + + // bottom plane + angle = -0.5f * fovY; + elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + elevation = glm::angleAxis(angle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight); + localOffset = elevation * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside + + // right plane + angle = 0.5f * fovX; + swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + swing = glm::angleAxis(angle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside + + // left plane + angle = -0.5f * fovX; + swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // inside + + swing = glm::angleAxis(angle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), true); // straddle + + swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp); + localOffset = swing * (boxDistance * localForward); + boxCenter = center + rotation * localOffset; + box.setBox(boxCenter - 0.5f * boxScale, boxScale); + QCOMPARE(view.boxIntersectsFrustum(box), false); // outside +} + void ViewFrustumTests::testSphereIntersectsKeyhole() { float aspect = 1.0f; float fovX = PI / 2.0f; @@ -827,7 +827,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { localOffset = sphereDistance * localForward; sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle localOffset = (sphereDistance + sphereRadius + delta) * localForward; sphereCenter = center + rotation * localOffset; @@ -840,7 +840,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { localOffset = (nearClip - sphereRadius + delta) * localForward; sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle localOffset = (nearClip - sphereRadius - delta) * localForward; sphereCenter = center + rotation * localOffset; @@ -857,7 +857,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { elevation = glm::angleAxis(angle - deltaAngle, localRight); localOffset = elevation * (sphereDistance * localForward); sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle elevation = glm::angleAxis(angle + deltaAngle, localRight); localOffset = elevation * (sphereDistance * localForward); @@ -875,7 +875,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { elevation = glm::angleAxis(angle + deltaAngle, localRight); localOffset = elevation * (sphereDistance * localForward); sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle elevation = glm::angleAxis(angle - deltaAngle, localRight); localOffset = elevation * (sphereDistance * localForward); @@ -893,7 +893,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { swing = glm::angleAxis(angle - deltaAngle, localUp); localOffset = swing * (sphereDistance * localForward); sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle swing = glm::angleAxis(angle + deltaAngle, localUp); localOffset = swing * (sphereDistance * localForward); @@ -911,7 +911,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { swing = glm::angleAxis(angle + deltaAngle, localUp); localOffset = swing * (sphereDistance * localForward); sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle swing = glm::angleAxis(angle - sphereAngle - deltaAngle, localUp); localOffset = swing * (sphereDistance * localForward); @@ -925,7 +925,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { localOffset = holeRadius * localRight; sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect right + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle right localOffset = (holeRadius + sphereRadius + delta) * localRight; sphereCenter = center + rotation * localOffset; @@ -938,7 +938,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { localOffset = holeRadius * localUp; sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect up + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle up localOffset = (holeRadius + sphereRadius + delta) * localUp; sphereCenter = center + rotation * localOffset; @@ -951,7 +951,7 @@ void ViewFrustumTests::testSphereIntersectsKeyhole() { localOffset = - holeRadius * localForward; sphereCenter = center + rotation * localOffset; - QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect back + QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // straddle back localOffset = (-holeRadius - sphereRadius - delta) * localForward; sphereCenter = center + rotation * localOffset; @@ -1016,7 +1016,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = (nearClip + delta) * localForward; cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle localOffset = (nearClip - cubeBoundingRadius - delta) * localForward; cubeCenter = center + rotation * localOffset; @@ -1035,7 +1035,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = elevation * (cubeDistance * localForward); cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight); localOffset = elevation * (cubeDistance * localForward); @@ -1055,7 +1055,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = elevation * (cubeDistance * localForward); cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight); localOffset = elevation * (cubeDistance * localForward); @@ -1075,7 +1075,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = swing * (cubeDistance * localForward); cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp); localOffset = swing * (cubeDistance * localForward); @@ -1095,7 +1095,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = swing * (cubeDistance * localForward); cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp); localOffset = swing * (cubeDistance * localForward); @@ -1112,7 +1112,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = holeRadius * localRight; cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect right + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle right localOffset = (holeRadius + cubeBoundingRadius + delta) * localRight; cubeCenter = center + rotation * localOffset; @@ -1128,7 +1128,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = holeRadius * localUp; cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect up + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle up localOffset = (holeRadius + cubeBoundingRadius + delta) * localUp; cubeCenter = center + rotation * localOffset; @@ -1144,7 +1144,7 @@ void ViewFrustumTests::testCubeIntersectsKeyhole() { localOffset = - holeRadius * localForward; cubeCenter = center + rotation * localOffset; cube.setBox(cubeCenter - halfScaleOffset, cubeScale); - QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect back + QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // straddle back localOffset = (-holeRadius - cubeBoundingRadius - delta) * localForward; cubeCenter = center + rotation * localOffset; @@ -1210,7 +1210,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = (nearClip + delta) * localForward; boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle localOffset = (nearClip - boxBoundingRadius - delta) * localForward; boxCenter = center + rotation * localOffset; @@ -1229,7 +1229,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = elevation * (boxDistance * localForward); boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight); localOffset = elevation * (boxDistance * localForward); @@ -1249,7 +1249,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = elevation * (boxDistance * localForward); boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight); localOffset = elevation * (boxDistance * localForward); @@ -1269,7 +1269,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = swing * (boxDistance * localForward); boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp); localOffset = swing * (boxDistance * localForward); @@ -1289,7 +1289,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = swing * (boxDistance * localForward); boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp); localOffset = swing * (boxDistance * localForward); @@ -1306,7 +1306,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = holeRadius * localRight; boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect right + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle right localOffset = (holeRadius + boxBoundingRadius + delta) * localRight; boxCenter = center + rotation * localOffset; @@ -1322,7 +1322,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = holeRadius * localUp; boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect up + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle up localOffset = (holeRadius + boxBoundingRadius + delta) * localUp; boxCenter = center + rotation * localOffset; @@ -1338,7 +1338,7 @@ void ViewFrustumTests::testBoxIntersectsKeyhole() { localOffset = - holeRadius * localForward; boxCenter = center + rotation * localOffset; box.setBox(boxCenter - halfScaleOffset, boxScale); - QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect back + QCOMPARE(view.boxIntersectsKeyhole(box), true); // straddle back localOffset = (-holeRadius - boxBoundingRadius - delta) * localForward; boxCenter = center + rotation * localOffset; diff --git a/tests/octree/src/ViewFrustumTests.h b/tests/octree/src/ViewFrustumTests.h index 6d47348a04..a64a72e669 100644 --- a/tests/octree/src/ViewFrustumTests.h +++ b/tests/octree/src/ViewFrustumTests.h @@ -19,14 +19,14 @@ class ViewFrustumTests : public QObject { private slots: void testInit(); - void testPointInFrustum(); - void testSphereInFrustum(); - void testCubeInFrustum(); - void testBoxInFrustum(); - void testCubeInKeyhole(); - void testSphereTouchesKeyhole(); - void testCubeTouchesKeyhole(); - void testBoxTouchesKeyhole(); + void testCubeFrustumIntersection(); + void testCubeKeyholeIntersection(); + void testPointIntersectsFrustum(); + void testSphereIntersectsFrustum(); + void testBoxIntersectsFrustum(); + void testSphereIntersectsKeyhole(); + void testCubeIntersectsKeyhole(); + void testBoxIntersectsKeyhole(); }; #endif // hifi_ViewFruxtumTests_h