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
What?int pairIndex = int(pair - &m_overlappingPairArray[0]);
-
- Posts: 12
- Joined: Sat Sep 19, 2009 12:44 pm
-
- Posts: 26
- Joined: Mon Sep 21, 2009 7:30 am
Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);
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.
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.
-
- Posts: 12
- Joined: Sat Sep 19, 2009 12:44 pm
Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);
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.
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.
-
- Posts: 26
- Joined: Mon Sep 21, 2009 7:30 am
Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);
+1 is wrong.
linearSearch must return actual index of pair.
linearSearch must return actual index of pair.
-
- Posts: 12
- Joined: Sat Sep 19, 2009 12:44 pm
Re: What?int pairIndex = int(pair - &m_overlappingPairArray[0]);
Ok, that makes sense.
Thanks.
Thanks.