The code that I am using is:
std::vector <PhysicsBody*> physicsChildren; //containing all objects
...
std::sort(physicsChildren.begin(), physicsChildren.end(), sortByLeft);
std::vector <PhysicsBody*> activeList;
unsigned int one;
unsigned int two;
for(one = 0; one < physicsChildren.size(); ++one)
{
activeList.push_back(physicsChildren[one]);
for(two = 0; two < activeList.size(); ++two)
{
if (physicsChildren[one]->m_position.x + physicsChildren[one]->m_radius > activeList[two]->m_position.x - activeList[two]->m_radius)
{
CheckIntersectionBetween(physicsChildren[one], activeList[two]);
} else {
activeList.pop_back();
}
}
}
I think something is wrong because for 800 objects 309169 calls to CheckIntersectionBetween. A bruteforce would use 640000 calls, I didn't think this was much improvement (considering only objects close in the x-axis should test).
I wrote the code from reading Jitter-Physics article about SAP:
Create a new temporary list called “activeList”. You begin on the left of your axisList, adding the first item to the activeList. Now you have a look at the next item in the axisList and compare it with all items currently in the activeList (at the moment just one): - If the new item’s left is greater then the current activeList-item right, then remove the activeList-item from the activeList - otherwise report a possible collision between the new axisList-item and the current activeList-item. Add the new item itself to the activeList and continue with the next item in the axisList.
What have I done wrong?