Game Development Reference

In-Depth Information

Figure 3.8.
Remove operation.

positioned. We can calculate variance of rigid bodies by checking how far away

each rigid body's position is from the average position (see Listing 3.1). The axis

with the largest distance can be selected. Then, an AABB array along only the

selected axis is used to find overlapping pairs.

// Calculate average

Vector average (0.0f ,0.0f ,0.0 f );

for( int i=0;i

<

numRigidBodies ; i ++)

{

average .x += position[i ].x;

average .y += position[i ].y;

average .z += position[i ].z;

}
average .x /= ( float )numRigidBodies ;

average .y /= ( float )numRigidBodies ;

average .z /= ( float )numRigidBodies ;

// Calculate variance

Vector

total distance (0.0f ,0.0f ,0.0f );

Figure 3.9.
Parallel sort algorithm.