What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

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

What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

Post by teravus »

In btOverlappingPairCache.cpp in btHashedOverlappingPairCache::removeOverlappingPair(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1,btDispatcher* dispatcher)

Can someone explain,

int pairIndex = int(pair - &m_overlappingPairArray[0]);

It seems to do a subtraction of the btBroadPhasePair, but I didn't see any info that included a description of what ends up in pairIndex. There doesn't seem to be a subtraction operator for btBroadPhasePair and m_overlappingPairArray[0] would seem to be the address of the first element in the btAlignedObjectArray<btBroadPhasePair>.

Are we subtracting addresses now? 0.o

Is this another way of saying, 'Find this object in m_overlappingPairArray'?

Thanks

T
rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

Post by rrck »

You can apply some arithmetic operation with pointers, but results is not like with numbers.

pair - overlappingPairArray[0] returns how many objects(holded by pair array) is stored between first pair and given pair. That is equal to pair index.

You can try to search on pointers arithmetics topic.
User avatar
teravus
Posts: 12
Joined: Sat Sep 19, 2009 12:44 pm

Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

Post by teravus »

Much appreciated, sir. Helps me understand what's going on there.

An aligned object array.. so the memory address of the pair - the memory address of the first element is the total number of elements between pair and the first element.

:)

So a compatible but slower algorithm would be ;

int pairIndex = m_overlappingPairArray.findLinearSearch(pair) + 1;

the array index of pair - 0 is always pair, then add 1 because the array is zero based == the number of elements between the specific element and the 0 element.
rrck
Posts: 26
Joined: Mon Sep 21, 2009 7:30 am

Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

Post by rrck »

+1 is wrong.
linearSearch must return actual index of pair.
User avatar
teravus
Posts: 12
Joined: Sat Sep 19, 2009 12:44 pm

Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);

Post by teravus »

Ok, that makes sense.

:) Thanks.
Post Reply