Graphics Reference
In-Depth Information
pAABB->max.pLeft[i] = pElem->pLeft[i];
pAABB->max.pRight[i] = pElem;
pElem->pLeft[i]->pRight[i] = &pAABB->max;
pElem->pLeft[i] = &pAABB->max;
}
// Now scan through list and add overlap pairs for all objects that
// this AABB intersects. This pair tracking could be incorporated into
// the loops above, but is not done here to simplify the code
for (Elem *pElem = gListHead[0];;){
if (pElem- > minmax == MIN_ELEM) {
if (pElem- > value[0] > pAABB- > max.value[0])
break;
if (AABBOverlap(pAABB, GetAABB(pElem)))
AddCollisionPair(pAABB, GetAABB(pElem));
} else if (pElem- > value[0] < pAABB- > min.value[0])
break;
}
}
After the position of an AABB has changed, the lists must be updated:
// This updating code assumes all other elements of list are sorted
void UpdateAABBPosition(AABB *pAABB)
{
// For all three axes
for(inti=0;i<3;i++) {
Elem *pMin = &pAABB- > min, *pMax = &pAABB- > max, *t;
// Try to move min element to the left. Move the roaming pointer t left
// for as long as it points to elem with value larger than pMin's. While
// doing so, keep track of the update status of any AABBs passed over
for (t = pMin- > pLeft[i]; pMin- > value[i] < t- > value[i];t=t- > pLeft[i])
if (t- > minmax == MAX_ELEM)
if (AABBOverlap(pAABB, GetAABB(t)))
if (!HasCollisionPair(pAABB, GetAABB(t)))
AddCollisionPair(pAABB, GetAABB(t));
// If t moves from its original position, move pMin into new place
if (t != pMin->pLeft[i])
MoveElement(i, pMin, t);
 
Search WWH ::




Custom Search