diff --git a/libraries/octree/src/AABox.cpp b/libraries/octree/src/AABox.cpp index 409b362b24..60f26a5533 100644 --- a/libraries/octree/src/AABox.cpp +++ b/libraries/octree/src/AABox.cpp @@ -225,21 +225,21 @@ bool AABox::findRayIntersection(const glm::vec3& origin, const glm::vec3& direct isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale.y) && isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale.z))) { distance = axisDistance; - face = direction.x > 0 ? MIN_X_FACE : MAX_X_FACE; + face = direction.x > 0 ? MAX_X_FACE : MIN_X_FACE; return true; } if ((findInsideOutIntersection(origin.y, direction.y, _corner.y, _scale.y, axisDistance) && axisDistance >= 0 && isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale.x) && isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale.z))) { distance = axisDistance; - face = direction.y > 0 ? MIN_Y_FACE : MAX_Y_FACE; + face = direction.y > 0 ? MAX_Y_FACE : MIN_Y_FACE; return true; } if ((findInsideOutIntersection(origin.z, direction.z, _corner.z, _scale.z, axisDistance) && axisDistance >= 0 && isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale.y) && isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale.x))) { distance = axisDistance; - face = direction.z > 0 ? MIN_Z_FACE : MAX_Z_FACE; + face = direction.z > 0 ? MAX_Z_FACE : MIN_Z_FACE; return true; } // This case is unexpected, but mimics the previous behavior for inside out intersections diff --git a/libraries/octree/src/AACube.cpp b/libraries/octree/src/AACube.cpp index 5a8839db4e..e359eac9e9 100644 --- a/libraries/octree/src/AACube.cpp +++ b/libraries/octree/src/AACube.cpp @@ -215,21 +215,21 @@ bool AACube::findRayIntersection(const glm::vec3& origin, const glm::vec3& direc isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale) && isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale))) { distance = axisDistance; - face = direction.x > 0 ? MIN_X_FACE : MAX_X_FACE; + face = direction.x > 0 ? MAX_X_FACE : MIN_X_FACE; return true; } if ((findInsideOutIntersection(origin.y, direction.y, _corner.y, _scale, axisDistance) && axisDistance >= 0 && isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale) && isWithin(origin.z + axisDistance*direction.z, _corner.z, _scale))) { distance = axisDistance; - face = direction.y > 0 ? MIN_Y_FACE : MAX_Y_FACE; + face = direction.y > 0 ? MAX_Y_FACE : MIN_Y_FACE; return true; } if ((findInsideOutIntersection(origin.z, direction.z, _corner.z, _scale, axisDistance) && axisDistance >= 0 && isWithin(origin.y + axisDistance*direction.y, _corner.y, _scale) && isWithin(origin.x + axisDistance*direction.x, _corner.x, _scale))) { distance = axisDistance; - face = direction.z > 0 ? MIN_Z_FACE : MAX_Z_FACE; + face = direction.z > 0 ? MAX_Z_FACE : MIN_Z_FACE; return true; } // This case is unexpected, but mimics the previous behavior for inside out intersections diff --git a/tests/octree/src/AABoxCubeTests.cpp b/tests/octree/src/AABoxCubeTests.cpp new file mode 100644 index 0000000000..85787e279b --- /dev/null +++ b/tests/octree/src/AABoxCubeTests.cpp @@ -0,0 +1,100 @@ +// +// AABoxCubeTests.h +// tests/octree/src +// +// Created by Brad Hefta-Gaub on 06/04/2014. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include + +#include +#include + +#include "AABoxCubeTests.h" + +void AABoxCubeTests::AABoxCubeTests() { + qDebug() << "******************************************************************************************"; + qDebug() << "AABoxCubeTests::AABoxCubeTests()"; + + { + qDebug() << "Test 1: AABox.findRayIntersection() inside out MIN_X_FACE"; + + glm::vec3 corner(0.0f, 0.0f, 0.0f); + float size = 1.0f; + + AABox box(corner, size); + glm::vec3 origin(0.5f, 0.5f, 0.5f); + glm::vec3 direction(-1.0f, 0.0f, 0.0f); + float distance; + BoxFace face; + + bool intersects = box.findRayIntersection(origin, direction, distance, face); + + if (intersects && distance == 0.5f && face == MIN_X_FACE) { + qDebug() << "Test 1: PASSED"; + } else { + qDebug() << "intersects=" << intersects << "expected=" << true; + qDebug() << "distance=" << distance << "expected=" << 0.5f; + qDebug() << "face=" << face << "expected=" << MIN_X_FACE; + + } + } + + { + qDebug() << "Test 2: AABox.findRayIntersection() inside out MAX_X_FACE"; + + glm::vec3 corner(0.0f, 0.0f, 0.0f); + float size = 1.0f; + + AABox box(corner, size); + glm::vec3 origin(0.5f, 0.5f, 0.5f); + glm::vec3 direction(1.0f, 0.0f, 0.0f); + float distance; + BoxFace face; + + bool intersects = box.findRayIntersection(origin, direction, distance, face); + + if (intersects && distance == 0.5f && face == MAX_X_FACE) { + qDebug() << "Test 2: PASSED"; + } else { + qDebug() << "intersects=" << intersects << "expected=" << true; + qDebug() << "distance=" << distance << "expected=" << 0.5f; + qDebug() << "face=" << face << "expected=" << MAX_X_FACE; + + } + } + + { + qDebug() << "Test 3: AABox.findRayIntersection() outside in"; + + glm::vec3 corner(0.5f, 0.0f, 0.0f); + float size = 0.5f; + + AABox box(corner, size); + glm::vec3 origin(0.25f, 0.25f, 0.25f); + glm::vec3 direction(1.0f, 0.0f, 0.0f); + float distance; + BoxFace face; + + bool intersects = box.findRayIntersection(origin, direction, distance, face); + + if (intersects && distance == 0.25f && face == MIN_X_FACE) { + qDebug() << "Test 3: PASSED"; + } else { + qDebug() << "intersects=" << intersects << "expected=" << true; + qDebug() << "distance=" << distance << "expected=" << 0.5f; + qDebug() << "face=" << face << "expected=" << MIN_X_FACE; + + } + } + + qDebug() << "******************************************************************************************"; +} + +void AABoxCubeTests::runAllTests() { + AABoxCubeTests(); +} diff --git a/tests/octree/src/AABoxCubeTests.h b/tests/octree/src/AABoxCubeTests.h new file mode 100644 index 0000000000..8d1ece51f8 --- /dev/null +++ b/tests/octree/src/AABoxCubeTests.h @@ -0,0 +1,20 @@ +// +// AABoxCubeTests.h +// tests/octree/src +// +// Created by Brad Hefta-Gaub on 06/04/2014. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_AABoxCubeTests_h +#define hifi_AABoxCubeTests_h + +namespace AABoxCubeTests { + void AABoxCubeTests(); + void runAllTests(); +} + +#endif // hifi_AABoxCubeTests_h diff --git a/tests/octree/src/OctreeTests.cpp b/tests/octree/src/OctreeTests.cpp index ddc3f2c74d..70ef97f225 100644 --- a/tests/octree/src/OctreeTests.cpp +++ b/tests/octree/src/OctreeTests.cpp @@ -1,6 +1,6 @@ // // OctreeTests.h -// tests/physics/src +// tests/octree/src // // Created by Brad Hefta-Gaub on 06/04/2014. // Copyright 2014 High Fidelity, Inc. diff --git a/tests/octree/src/OctreeTests.h b/tests/octree/src/OctreeTests.h index 53b0d9fb83..5eae6c6158 100644 --- a/tests/octree/src/OctreeTests.h +++ b/tests/octree/src/OctreeTests.h @@ -1,6 +1,6 @@ // // OctreeTests.h -// tests/physics/src +// tests/octree/src // // Created by Brad Hefta-Gaub on 06/04/2014. // Copyright 2014 High Fidelity, Inc. diff --git a/tests/octree/src/main.cpp b/tests/octree/src/main.cpp index ec3dc19e01..de7b3926ae 100644 --- a/tests/octree/src/main.cpp +++ b/tests/octree/src/main.cpp @@ -9,8 +9,10 @@ // #include "OctreeTests.h" +#include "AABoxCubeTests.h" int main(int argc, char** argv) { OctreeTests::runAllTests(); + AABoxCubeTests::runAllTests(); return 0; }