namechange TouchesKeyhole to IntersectsKeyhole

This commit is contained in:
Andrew Meadows 2016-02-23 11:52:09 -08:00
parent 918880b058
commit 5d1e283508
7 changed files with 125 additions and 125 deletions

View file

@ -3423,7 +3423,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node
rootDetails.y * TREE_SCALE,
rootDetails.z * TREE_SCALE) - glm::vec3(HALF_TREE_SCALE),
rootDetails.s * TREE_SCALE);
if (_viewFrustum.cubeTouchesKeyhole(serverBounds)) {
if (_viewFrustum.cubeIntersectsKeyhole(serverBounds)) {
inViewServers++;
}
}
@ -3489,7 +3489,7 @@ void Application::queryOctree(NodeType_t serverType, PacketType packetType, Node
rootDetails.s * TREE_SCALE);
inView = _viewFrustum.cubeTouchesKeyhole(serverBounds);
inView = _viewFrustum.cubeIntersectsKeyhole(serverBounds);
} else {
if (wantExtraDebugging) {
qCDebug(interfaceapp) << "Jurisdiction without RootCode for node " << *node << ". That's unusual!";

View file

@ -304,7 +304,7 @@ OctreeElement::AppendState EntityTreeElement::appendElementData(OctreePacketData
// frustum culling on rendering.
bool success;
AACube entityCube = entity->getQueryAACube(success);
if (!success || params.viewFrustum->cubeTouchesKeyhole(entityCube)) {
if (!success || params.viewFrustum->cubeIntersectsKeyhole(entityCube)) {
includeThisEntity = false; // out of view, don't include it
} else {
// Check the size of the entity, it's possible that a "too small to see" entity is included in a

View file

@ -459,7 +459,7 @@ float OctreeElement::getEnclosingRadius() const {
}
ViewFrustum::location OctreeElement::computeViewLocation(const ViewFrustum& viewFrustum) const {
return viewFrustum.cubeInKeyhole(_cube);
return viewFrustum.calculateCubeKeyholeIntersection(_cube);
}
// There are two types of nodes for which we want to "render"

View file

@ -91,7 +91,7 @@ void OctreeHeadlessViewer::queryOctree() {
if (foundRootDetails) {
AACube serverBounds(glm::vec3(rootDetails.x, rootDetails.y, rootDetails.z), rootDetails.s);
if (_viewFrustum.cubeTouchesKeyhole(serverBounds)) {
if (_viewFrustum.cubeIntersectsKeyhole(serverBounds)) {
inViewServers++;
}
}

View file

@ -196,7 +196,7 @@ ViewFrustum::location ViewFrustum::boxInFrustum(const AABox& box) const {
const float HALF_SQRT_THREE = 0.8660254f;
ViewFrustum::location ViewFrustum::cubeInKeyhole(const AACube& cube) const {
ViewFrustum::location ViewFrustum::calculateCubeKeyholeIntersection(const AACube& cube) const {
// check against centeral sphere
ViewFrustum::location sphereResult = INTERSECT;
glm::vec3 cubeOffset = cube.calcCenter() - _position;
@ -221,7 +221,7 @@ ViewFrustum::location ViewFrustum::cubeInKeyhole(const AACube& cube) const {
return (frustumResult == OUTSIDE) ? sphereResult : frustumResult;
}
bool ViewFrustum::sphereTouchesKeyhole(const glm::vec3& center, float radius) const {
bool ViewFrustum::sphereIntersectsKeyhole(const glm::vec3& center, float radius) const {
// check positive touch against central sphere
if (glm::length(center - _position) <= (radius + _centerSphereRadius)) {
return true;
@ -235,7 +235,7 @@ bool ViewFrustum::sphereTouchesKeyhole(const glm::vec3& center, float radius) co
return true;
}
bool ViewFrustum::cubeTouchesKeyhole(const AACube& cube) const {
bool ViewFrustum::cubeIntersectsKeyhole(const AACube& cube) const {
// check positive touch against central sphere
if (cube.touchesSphere(_position, _centerSphereRadius)) {
return true;
@ -250,7 +250,7 @@ bool ViewFrustum::cubeTouchesKeyhole(const AACube& cube) const {
return true;
}
bool ViewFrustum::boxTouchesKeyhole(const AABox& box) const {
bool ViewFrustum::boxIntersectsKeyhole(const AABox& box) const {
// check positive touch against central sphere
if (box.touchesSphere(_position, _centerSphereRadius)) {
return true;

View file

@ -100,12 +100,12 @@ public:
ViewFrustum::location boxInFrustum(const AABox& box) const;
/// @return INSIDE, INTERSECT, or OUTSIDE depending on how cube intersects the keyhole shape
ViewFrustum::location cubeInKeyhole(const AACube& cube) const;
ViewFrustum::location calculateCubeKeyholeIntersection(const AACube& cube) const;
// more efficient methods when only need boolean result
bool sphereTouchesKeyhole(const glm::vec3& center, float radius) const;
bool cubeTouchesKeyhole(const AACube& cube) const;
bool boxTouchesKeyhole(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;
// some frustum comparisons
bool matches(const ViewFrustum& compareTo, bool debug = false) const;

View file

@ -629,28 +629,28 @@ void ViewFrustumTests::testCubeInKeyhole() {
localOffset = (cubeDistance - cubeBoundingRadius - delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
localOffset = cubeDistance * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT);
localOffset = (cubeDistance + cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// nearPlane
localOffset = (nearClip + 2.0f * cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
localOffset = (nearClip + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
// topPlane
angle = 0.5f * fovY;
@ -658,19 +658,19 @@ void ViewFrustumTests::testCubeInKeyhole() {
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(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.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// bottom plane
angle = -0.5f * fovY;
@ -678,19 +678,19 @@ void ViewFrustumTests::testCubeInKeyhole() {
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(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.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// right plane
angle = 0.5f * fovX;
@ -698,19 +698,19 @@ void ViewFrustumTests::testCubeInKeyhole() {
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(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.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// left plane
angle = -0.5f * fovX;
@ -718,79 +718,79 @@ void ViewFrustumTests::testCubeInKeyhole() {
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(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.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// central sphere right
localOffset = (holeRadius - cubeBoundingRadius - delta) * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
localOffset = holeRadius * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT);
localOffset = (holeRadius + cubeBoundingRadius + delta) * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// central sphere up
localOffset = (holeRadius - cubeBoundingRadius - delta) * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
localOffset = holeRadius * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT);
localOffset = (holeRadius + cubeBoundingRadius + delta) * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// central sphere back
localOffset = (-holeRadius + cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE);
localOffset = - holeRadius * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT);
localOffset = (-holeRadius - cubeBoundingRadius - delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::OUTSIDE);
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::OUTSIDE);
// central sphere center
float bigCubeScale = 2.0f * holeRadius / sqrtf(3.0f) - delta;
cube.setBox(center - glm::vec3(0.5f * bigCubeScale), bigCubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INSIDE); // smaller than sphere
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INSIDE); // smaller than sphere
bigCubeScale = 2.0f * holeRadius / sqrtf(3.0f) + delta;
cube.setBox(center - glm::vec3(0.5f * bigCubeScale), bigCubeScale);
QCOMPARE(view.cubeInKeyhole(cube), ViewFrustum::INTERSECT); // larger than sphere
QCOMPARE(view.calculateCubeKeyholeIntersection(cube), ViewFrustum::INTERSECT); // larger than sphere
}
void ViewFrustumTests::testSphereTouchesKeyhole() {
void ViewFrustumTests::testSphereIntersectsKeyhole() {
float aspect = 1.0f;
float fovX = PI / 2.0f;
float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect);
@ -823,142 +823,142 @@ void ViewFrustumTests::testSphereTouchesKeyhole() {
// farPlane
localOffset = (sphereDistance - sphereRadius - delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // inside
localOffset = sphereDistance * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
localOffset = (sphereDistance + sphereRadius + delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), false); // outside
// nearPlane
localOffset = (nearClip + 2.0f * sphereRadius + delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // inside
localOffset = (nearClip - sphereRadius + delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
localOffset = (nearClip - sphereRadius - delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // touches central sphere
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // touches central sphere
// topPlane
angle = 0.5f * fovY - sphereAngle;
elevation = glm::angleAxis(angle - deltaAngle, localRight);
localOffset = elevation * (sphereDistance * localForward);
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
elevation = glm::angleAxis(angle + deltaAngle, localRight);
localOffset = elevation * (sphereDistance * localForward);
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
elevation = glm::angleAxis(angle - deltaAngle, localRight);
localOffset = elevation * (sphereDistance * localForward);
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
swing = glm::angleAxis(angle + deltaAngle, localUp);
localOffset = swing * (sphereDistance * localForward);
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside
QCOMPARE(view.sphereIntersectsKeyhole(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.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect
swing = glm::angleAxis(angle - sphereAngle - deltaAngle, localUp);
localOffset = swing * (sphereDistance * localForward);
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), false); // outside
// central sphere right
localOffset = (holeRadius - sphereRadius - delta) * localRight;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside right
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // inside right
localOffset = holeRadius * localRight;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect right
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect right
localOffset = (holeRadius + sphereRadius + delta) * localRight;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside right
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), false); // outside right
// central sphere up
localOffset = (holeRadius - sphereRadius - delta) * localUp;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside up
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // inside up
localOffset = holeRadius * localUp;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect up
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect up
localOffset = (holeRadius + sphereRadius + delta) * localUp;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside up
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), false); // outside up
// central sphere back
localOffset = (-holeRadius + sphereRadius + delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // inside back
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // inside back
localOffset = - holeRadius * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), true); // intersect back
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), true); // intersect back
localOffset = (-holeRadius - sphereRadius - delta) * localForward;
sphereCenter = center + rotation * localOffset;
QCOMPARE(view.sphereTouchesKeyhole(sphereCenter, sphereRadius), false); // outside back
QCOMPARE(view.sphereIntersectsKeyhole(sphereCenter, sphereRadius), false); // outside back
}
void ViewFrustumTests::testCubeTouchesKeyhole() {
void ViewFrustumTests::testCubeIntersectsKeyhole() {
float aspect = 1.0f;
float fovX = PI / 2.0f;
float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect);
@ -995,33 +995,33 @@ void ViewFrustumTests::testCubeTouchesKeyhole() {
localOffset = (cubeDistance - cubeBoundingRadius - delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true);
QCOMPARE(view.cubeIntersectsKeyhole(cube), true);
localOffset = cubeDistance * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true);
QCOMPARE(view.cubeIntersectsKeyhole(cube), true);
localOffset = (cubeDistance + cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false);
QCOMPARE(view.cubeIntersectsKeyhole(cube), false);
// nearPlane
localOffset = (nearClip + 2.0f * cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside
localOffset = (nearClip + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect
localOffset = (nearClip - cubeBoundingRadius - delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // touches centeral sphere
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // touches centeral sphere
// topPlane
angle = 0.5f * fovY;
@ -1029,19 +1029,19 @@ void ViewFrustumTests::testCubeTouchesKeyhole() {
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect
elevation = glm::angleAxis(angle + cubeAngle + deltaAngle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside
// bottom plane
angle = -0.5f * fovY;
@ -1049,19 +1049,19 @@ void ViewFrustumTests::testCubeTouchesKeyhole() {
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect
elevation = glm::angleAxis(angle - cubeAngle - deltaAngle, localRight);
localOffset = elevation * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside
// right plane
angle = 0.5f * fovX;
@ -1069,19 +1069,19 @@ void ViewFrustumTests::testCubeTouchesKeyhole() {
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect
swing = glm::angleAxis(angle + cubeAngle + deltaAngle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside
// left plane
angle = -0.5f * fovX;
@ -1089,70 +1089,70 @@ void ViewFrustumTests::testCubeTouchesKeyhole() {
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect
swing = glm::angleAxis(angle - cubeAngle - deltaAngle, localUp);
localOffset = swing * (cubeDistance * localForward);
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside
// central sphere right
localOffset = (holeRadius - cubeBoundingRadius - delta) * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside right
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside right
localOffset = holeRadius * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect right
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect right
localOffset = (holeRadius + cubeBoundingRadius + delta) * localRight;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside right
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside right
// central sphere up
localOffset = (holeRadius - cubeBoundingRadius - delta) * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside up
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside up
localOffset = holeRadius * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect up
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect up
localOffset = (holeRadius + cubeBoundingRadius + delta) * localUp;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside up
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside up
// central sphere back
localOffset = (-holeRadius + cubeBoundingRadius + delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // inside back
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // inside back
localOffset = - holeRadius * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), true); // intersect back
QCOMPARE(view.cubeIntersectsKeyhole(cube), true); // intersect back
localOffset = (-holeRadius - cubeBoundingRadius - delta) * localForward;
cubeCenter = center + rotation * localOffset;
cube.setBox(cubeCenter - halfScaleOffset, cubeScale);
QCOMPARE(view.cubeTouchesKeyhole(cube), false); // outside back
QCOMPARE(view.cubeIntersectsKeyhole(cube), false); // outside back
}
void ViewFrustumTests::testBoxTouchesKeyhole() {
void ViewFrustumTests::testBoxIntersectsKeyhole() {
float aspect = 1.0f;
float fovX = PI / 2.0f;
float fovY = 2.0f * asinf(sinf(0.5f * fovX) / aspect);
@ -1189,33 +1189,33 @@ void ViewFrustumTests::testBoxTouchesKeyhole() {
localOffset = (boxDistance - boxBoundingRadius - delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true);
QCOMPARE(view.boxIntersectsKeyhole(box), true);
localOffset = boxDistance * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true);
QCOMPARE(view.boxIntersectsKeyhole(box), true);
localOffset = (boxDistance + boxBoundingRadius + delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false);
QCOMPARE(view.boxIntersectsKeyhole(box), false);
// nearPlane
localOffset = (nearClip + 2.0f * boxBoundingRadius + delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside
localOffset = (nearClip + delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect
localOffset = (nearClip - boxBoundingRadius - delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // touches centeral sphere
QCOMPARE(view.boxIntersectsKeyhole(box), true); // touches centeral sphere
// topPlane
angle = 0.5f * fovY;
@ -1223,19 +1223,19 @@ void ViewFrustumTests::testBoxTouchesKeyhole() {
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect
elevation = glm::angleAxis(angle + boxAngle + deltaAngle, localRight);
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside
// bottom plane
angle = -0.5f * fovY;
@ -1243,19 +1243,19 @@ void ViewFrustumTests::testBoxTouchesKeyhole() {
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside
elevation = glm::angleAxis(angle, localRight);
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect
elevation = glm::angleAxis(angle - boxAngle - deltaAngle, localRight);
localOffset = elevation * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside
// right plane
angle = 0.5f * fovX;
@ -1263,19 +1263,19 @@ void ViewFrustumTests::testBoxTouchesKeyhole() {
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect
swing = glm::angleAxis(angle + boxAngle + deltaAngle, localUp);
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside
// left plane
angle = -0.5f * fovX;
@ -1283,65 +1283,65 @@ void ViewFrustumTests::testBoxTouchesKeyhole() {
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside
swing = glm::angleAxis(angle, localUp);
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect
swing = glm::angleAxis(angle - boxAngle - deltaAngle, localUp);
localOffset = swing * (boxDistance * localForward);
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside
// central sphere right
localOffset = (holeRadius - boxBoundingRadius - delta) * localRight;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside right
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside right
localOffset = holeRadius * localRight;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect right
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect right
localOffset = (holeRadius + boxBoundingRadius + delta) * localRight;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside right
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside right
// central sphere up
localOffset = (holeRadius - boxBoundingRadius - delta) * localUp;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside up
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside up
localOffset = holeRadius * localUp;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect up
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect up
localOffset = (holeRadius + boxBoundingRadius + delta) * localUp;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside up
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside up
// central sphere back
localOffset = (-holeRadius + boxBoundingRadius + delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // inside back
QCOMPARE(view.boxIntersectsKeyhole(box), true); // inside back
localOffset = - holeRadius * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), true); // intersect back
QCOMPARE(view.boxIntersectsKeyhole(box), true); // intersect back
localOffset = (-holeRadius - boxBoundingRadius - delta) * localForward;
boxCenter = center + rotation * localOffset;
box.setBox(boxCenter - halfScaleOffset, boxScale);
QCOMPARE(view.boxTouchesKeyhole(box), false); // outside back
QCOMPARE(view.boxIntersectsKeyhole(box), false); // outside back
}