btAxisSweep3 question

Post Reply
User avatar
teravus
Posts: 12
Joined: Sat Sep 19, 2009 12:44 pm

btAxisSweep3 question

Post by teravus »

in btAxisSweep3Internal::sortMinDown, pEdge and pPrev are defined like;

Edge* pEdge = m_pEdges[axis] + edge;
Edge* pPrev = pEdge - 1;

where m_pEdges[axis] + edge actually means m_pEdges[axis][edge], and
Edge* pPrev = pEdge - 1; is a short way of saying, pPrev = m_pEdges[axis][edge - 1]

This gets two pointers to elements in the edge array(allocation), the pointer to the edge specified by the index passed in and the previous edge.

Then, some operations are done on the edge values.

Then the edge pointers are swapped

Code: Select all

// swap the edges
Edge swap = *pEdge;
*pEdge = *pPrev;
*pPrev = swap;
Then the position the pointers refer to in the allocation is decremented

Code: Select all

// decrement
pEdge--;
pPrev--;
So, my question here.. is.. when it's swapped, is the address it's pointing to also swapped so that when the decrement occurs, pEdge-- is referring to the element in the edge allocation that is one less then pPrev? Or, is it just the value internals that's swapped and the 'cursor' in the aligned allocation is not swapped?

To put it another way,
lets say I have Item0, Item1, Item2 and Item3.
pEdge = Item3;
pPrev = Item2;

if I swap them and decrement using the above code,
is pEdge-- == Item1 or Item0?
is pPrev-- == Item2 or Item1?

Thanks :D

Teravus
User avatar
teravus
Posts: 12
Joined: Sat Sep 19, 2009 12:44 pm

Re: btAxisSweep3 question

Post by teravus »

nevermind, I think I figured it out.
Post Reply