Fix issues and add unit tests

This commit is contained in:
Daniel Chappuis 2016-04-02 01:51:41 +02:00
parent b7b8cad191
commit f22db4b4ed
2 changed files with 333 additions and 139 deletions

View File

@ -86,26 +86,10 @@ class TestDynamicAABBTree : public Test {
// ---------- Atributes ---------- //
// Dynamic AABB Tree
DynamicAABBTree mTree;
AABB mAABB1;
AABB mAABB2;
AABB mAABB3;
AABB mAABB4;
OverlapCallback mOverlapCallback;
DynamicTreeRaycastCallback mRaycastCallback;
int mObject1Id;
int mObject2Id;
int mObject3Id;
int mObject4Id;
int mObject1Data = 56;
int mObject2Data = 23;
int mObject3Data = 13;
int mObject4Data = 7;
public :
@ -114,21 +98,7 @@ class TestDynamicAABBTree : public Test {
/// Constructor
TestDynamicAABBTree(const std::string& name): Test(name) {
// First object
mAABB1 = AABB(Vector3(-6, 4, -3), Vector3(4, 8, 3));
mObject1Id = mTree.addObject(mAABB1, &mObject1Data);
// Second object
mAABB2 = AABB(Vector3(5, 2, -3), Vector3(10, 7, 3));
mObject2Id = mTree.addObject(mAABB2, &mObject2Data);
// Third object
mAABB3 = AABB(Vector3(-5, 1, -3), Vector3(-2, 3, 3));
mObject3Id = mTree.addObject(mAABB3, &mObject3Data);
// Fourth object
mAABB4 = AABB(Vector3(0, -4, -3), Vector3(3, -2, 3));
mObject4Id = mTree.addObject(mAABB4, &mObject4Data);
}
/// Run the tests
@ -142,187 +112,409 @@ class TestDynamicAABBTree : public Test {
void testBasicsMethods() {
// ------------ Create tree ---------- //
// Dynamic AABB Tree
DynamicAABBTree tree;
int object1Data = 56;
int object2Data = 23;
int object3Data = 13;
int object4Data = 7;
// First object
AABB aabb1 = AABB(Vector3(-6, 4, -3), Vector3(4, 8, 3));
int object1Id = tree.addObject(aabb1, &object1Data);
// Second object
AABB aabb2 = AABB(Vector3(5, 2, -3), Vector3(10, 7, 3));
int object2Id = tree.addObject(aabb2, &object2Data);
// Third object
AABB aabb3 = AABB(Vector3(-5, 1, -3), Vector3(-2, 3, 3));
int object3Id = tree.addObject(aabb3, &object3Data);
// Fourth object
AABB aabb4 = AABB(Vector3(0, -4, -3), Vector3(3, -2, 3));
int object4Id = tree.addObject(aabb4, &object4Data);
// ----------- Tests ----------- //
// Test root AABB
AABB rootAABB = tree.getRootAABB();
test(rootAABB.getMin().x == -6);
test(rootAABB.getMin().y == -4);
test(rootAABB.getMin().z == -3);
test(rootAABB.getMax().x == 10);
test(rootAABB.getMax().y == 8);
test(rootAABB.getMax().z == 3);
// Test data stored at the nodes of the tree
test(*(int*)(mTree.getNodeDataPointer(mObject1Id)) == mObject1Data);
test(*(int*)(mTree.getNodeDataPointer(mObject2Id)) == mObject2Data);
test(*(int*)(mTree.getNodeDataPointer(mObject3Id)) == mObject3Data);
test(*(int*)(mTree.getNodeDataPointer(mObject4Id)) == mObject4Data);
test(*(int*)(tree.getNodeDataPointer(object1Id)) == object1Data);
test(*(int*)(tree.getNodeDataPointer(object2Id)) == object2Data);
test(*(int*)(tree.getNodeDataPointer(object3Id)) == object3Data);
test(*(int*)(tree.getNodeDataPointer(object4Id)) == object4Data);
}
void testOverlapping() {
// ------------- Create tree ----------- //
// Dynamic AABB Tree
DynamicAABBTree tree;
int object1Data = 56;
int object2Data = 23;
int object3Data = 13;
int object4Data = 7;
// First object
AABB aabb1 = AABB(Vector3(-6, 4, -3), Vector3(4, 8, 3));
int object1Id = tree.addObject(aabb1, &object1Data);
// Second object
AABB aabb2 = AABB(Vector3(5, 2, -3), Vector3(10, 7, 3));
int object2Id = tree.addObject(aabb2, &object2Data);
// Third object
AABB aabb3 = AABB(Vector3(-5, 1, -3), Vector3(-2, 3, 3));
int object3Id = tree.addObject(aabb3, &object3Data);
// Fourth object
AABB aabb4 = AABB(Vector3(0, -4, -3), Vector3(3, -2, 3));
int object4Id = tree.addObject(aabb4, &object4Data);
// ---------- Tests ---------- //
// AABB overlapping nothing
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
mTree.updateObject(mObject1Id, mAABB1, Vector3::zero(), false);
mTree.updateObject(mObject2Id, mAABB2, Vector3::zero(), false);
mTree.updateObject(mObject3Id, mAABB3, Vector3::zero(), false);
mTree.updateObject(mObject4Id, mAABB4, Vector3::zero(), false);
tree.updateObject(object1Id, aabb1, Vector3::zero(), false);
tree.updateObject(object2Id, aabb2, Vector3::zero(), false);
tree.updateObject(object3Id, aabb3, Vector3::zero(), false);
tree.updateObject(object4Id, aabb4, Vector3::zero(), false);
// AABB overlapping nothing
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
mTree.updateObject(mObject1Id, mAABB1, Vector3::zero(), true);
mTree.updateObject(mObject2Id, mAABB2, Vector3::zero(), true);
mTree.updateObject(mObject3Id, mAABB3, Vector3::zero(), true);
mTree.updateObject(mObject4Id, mAABB4, Vector3::zero(), true);
tree.updateObject(object1Id, aabb1, Vector3::zero(), true);
tree.updateObject(object2Id, aabb2, Vector3::zero(), true);
tree.updateObject(object3Id, aabb3, Vector3::zero(), true);
tree.updateObject(object4Id, aabb4, Vector3::zero(), true);
// AABB overlapping nothing
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-10, 12, -4), Vector3(10, 50, 4)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping everything
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-15, -15, -4), Vector3(15, 15, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 1 and 3
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-4, 2, -4), Vector3(-1, 7, 4)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 3 and 4
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(!mOverlapCallback.isOverlapping(mObject2Id));
test(mOverlapCallback.isOverlapping(mObject3Id));
test(mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-6, -5, -2), Vector3(2, 2, 0)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping object 2
mOverlapCallback.reset();
mTree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(mObject1Id));
test(mOverlapCallback.isOverlapping(mObject2Id));
test(!mOverlapCallback.isOverlapping(mObject3Id));
test(!mOverlapCallback.isOverlapping(mObject4Id));
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(5, -10, -2), Vector3(7, 10, 9)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// ---- Move objects 2 and 3 ----- //
AABB newAABB2(Vector3(-7, 10, -3), Vector3(1, 13, 3));
tree.updateObject(object2Id, newAABB2, Vector3::zero());
AABB newAABB3(Vector3(7, -6, -3), Vector3(9, 1, 3));
tree.updateObject(object3Id, newAABB3, Vector3::zero());
// AABB overlapping object 3
mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(6, -10, -2), Vector3(8, 5, 3)), mOverlapCallback);
test(!mOverlapCallback.isOverlapping(object1Id));
test(!mOverlapCallback.isOverlapping(object2Id));
test(mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
// AABB overlapping objects 1, 2
mOverlapCallback.reset();
tree.reportAllShapesOverlappingWithAABB(AABB(Vector3(-8, 5, -3), Vector3(-2, 11, 3)), mOverlapCallback);
test(mOverlapCallback.isOverlapping(object1Id));
test(mOverlapCallback.isOverlapping(object2Id));
test(!mOverlapCallback.isOverlapping(object3Id));
test(!mOverlapCallback.isOverlapping(object4Id));
}
void testRaycast() {
// ------------- Create tree ----------- //
// Dynamic AABB Tree
DynamicAABBTree tree;
int object1Data = 56;
int object2Data = 23;
int object3Data = 13;
int object4Data = 7;
// First object
AABB aabb1 = AABB(Vector3(-6, 4, -3), Vector3(4, 8, 3));
int object1Id = tree.addObject(aabb1, &object1Data);
// Second object
AABB aabb2 = AABB(Vector3(5, 2, -3), Vector3(10, 7, 3));
int object2Id = tree.addObject(aabb2, &object2Data);
// Third object
AABB aabb3 = AABB(Vector3(-5, 1, -3), Vector3(-2, 3, 3));
int object3Id = tree.addObject(aabb3, &object3Data);
// Fourth object
AABB aabb4 = AABB(Vector3(0, -4, -3), Vector3(3, -2, 3));
int object4Id = tree.addObject(aabb4, &object4Data);
// ---------- Tests ---------- //
// Ray with no hits
mRaycastCallback.reset();
Ray ray1(Vector3(4.5, -10, -5), Vector3(4.5, 10, -5));
mTree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(mObject1Id));
test(!mRaycastCallback.isHit(mObject2Id));
test(!mRaycastCallback.isHit(mObject3Id));
test(!mRaycastCallback.isHit(mObject4Id));
tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1
mRaycastCallback.reset();
Ray ray2(Vector3(-1, -20, -2), Vector3(-1, 20, -2));
mTree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(mObject1Id));
test(!mRaycastCallback.isHit(mObject2Id));
test(!mRaycastCallback.isHit(mObject3Id));
test(!mRaycastCallback.isHit(mObject4Id));
tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2
mRaycastCallback.reset();
Ray ray3(Vector3(-7, 6, -2), Vector3(8, 6, -2));
mTree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(mObject1Id));
test(mRaycastCallback.isHit(mObject2Id));
test(!mRaycastCallback.isHit(mObject3Id));
test(!mRaycastCallback.isHit(mObject4Id));
tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3
mRaycastCallback.reset();
Ray ray4(Vector3(-7, 2, 0), Vector3(-1, 2, 0));
mTree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(mObject1Id));
test(!mRaycastCallback.isHit(mObject2Id));
test(mRaycastCallback.isHit(mObject3Id));
test(!mRaycastCallback.isHit(mObject4Id));
tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// ---- Update the object AABBs with the initial AABBs (no reinsertion) ----- //
tree.updateObject(object1Id, aabb1, Vector3::zero(), false);
tree.updateObject(object2Id, aabb2, Vector3::zero(), false);
tree.updateObject(object3Id, aabb3, Vector3::zero(), false);
tree.updateObject(object4Id, aabb4, Vector3::zero(), false);
// Ray with no hits
mRaycastCallback.reset();
tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1
mRaycastCallback.reset();
tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2
mRaycastCallback.reset();
tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3
mRaycastCallback.reset();
tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// ---- Update the object AABBs with the initial AABBs (with reinsertion) ----- //
tree.updateObject(object1Id, aabb1, Vector3::zero(), true);
tree.updateObject(object2Id, aabb2, Vector3::zero(), true);
tree.updateObject(object3Id, aabb3, Vector3::zero(), true);
tree.updateObject(object4Id, aabb4, Vector3::zero(), true);
// Ray with no hits
mRaycastCallback.reset();
tree.raycast(ray1, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1
mRaycastCallback.reset();
tree.raycast(ray2, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 1 and 2
mRaycastCallback.reset();
tree.raycast(ray3, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3
mRaycastCallback.reset();
tree.raycast(ray4, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// ---- Move objects 2 and 3 ----- //
AABB newAABB2(Vector3(-7, 10, -3), Vector3(1, 13, 3));
tree.updateObject(object2Id, newAABB2, Vector3::zero());
AABB newAABB3(Vector3(7, -6, -3), Vector3(9, 1, 3));
tree.updateObject(object3Id, newAABB3, Vector3::zero());
// Ray that hits object 1, 2
Ray ray5(Vector3(-4, -5, 0), Vector3(-4, 12, 0));
mRaycastCallback.reset();
tree.raycast(ray5, mRaycastCallback);
test(mRaycastCallback.isHit(object1Id));
test(mRaycastCallback.isHit(object2Id));
test(!mRaycastCallback.isHit(object3Id));
test(!mRaycastCallback.isHit(object4Id));
// Ray that hits object 3 and 4
Ray ray6(Vector3(11, -3, 1), Vector3(-2, -3, 1));
mRaycastCallback.reset();
tree.raycast(ray6, mRaycastCallback);
test(!mRaycastCallback.isHit(object1Id));
test(!mRaycastCallback.isHit(object2Id));
test(mRaycastCallback.isHit(object3Id));
test(mRaycastCallback.isHit(object4Id));
}
};

View File

@ -288,10 +288,12 @@ class TestRaycast : public Test {
mConcaveMeshIndices.push_back(1); mConcaveMeshIndices.push_back(4); mConcaveMeshIndices.push_back(5);
mConcaveMeshIndices.push_back(5); mConcaveMeshIndices.push_back(7); mConcaveMeshIndices.push_back(6);
mConcaveMeshIndices.push_back(4); mConcaveMeshIndices.push_back(7); mConcaveMeshIndices.push_back(5);
TriangleVertexArray::VertexDataType vertexType = sizeof(decimal) == 4 ? TriangleVertexArray::VERTEX_FLOAT_TYPE :
TriangleVertexArray::VERTEX_DOUBLE_TYPE;
mConcaveMeshVertexArray =
new TriangleVertexArray(8, &(mConcaveMeshVertices[0]), sizeof(Vector3),
12, &(mConcaveMeshIndices[0]), sizeof(int),
TriangleVertexArray::VERTEX_FLOAT_TYPE,
12, &(mConcaveMeshIndices[0]), sizeof(uint),
vertexType,
TriangleVertexArray::INDEX_INTEGER_TYPE);