mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 13:12:40 +02:00
fixed a bug in inside out ray casting returning the wrong face
This commit is contained in:
parent
c5bd3df046
commit
4413049302
7 changed files with 130 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
100
tests/octree/src/AABoxCubeTests.cpp
Normal file
100
tests/octree/src/AABoxCubeTests.cpp
Normal file
|
@ -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 <QDebug>
|
||||
|
||||
#include <AABox.h>
|
||||
#include <AACube.h>
|
||||
|
||||
#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();
|
||||
}
|
20
tests/octree/src/AABoxCubeTests.h
Normal file
20
tests/octree/src/AABoxCubeTests.h
Normal file
|
@ -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
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -9,8 +9,10 @@
|
|||
//
|
||||
|
||||
#include "OctreeTests.h"
|
||||
#include "AABoxCubeTests.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
OctreeTests::runAllTests();
|
||||
AABoxCubeTests::runAllTests();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue