I you are going the low level approach ,you do not have to use the rigid bodies they are only goo for system when you will use physics to advance the world.
Instead you can save the pointer to the collision shape and the tow vector to represent the entity aabb in global space with your entity.
these function functions are useful
void NewtonCollisionCalculateAABB (const NewtonCollision* const collision, const dFloat* const matrix, dFloat* const p0, dFloat* const p1);
int NewtonCollisionCollide (const NewtonWorld* const newtonWorld, int maxSize, const NewtonCollision* const collisionA, const dFloat* const matrixA, const NewtonCollision* const collisionB, const dFloat* const matrixB,dFloat* const contacts, dFloat* const normals, dFloat* const penetration, int threadIndex);
When you are ready to implement the AABB test you the it is a very simple, you can use this functions
basically you will do something like this:
-after you move a body you calculate the AABB and same it with the body, that way the AABB calculation only happens the entity changes its matrix.
// Called each frame to maintain the position up-to-date.
- Code: Select all
void E3D::entityPos(const s32& id, const f32 *pos) const
{
dgVector front(0, 0, -1, 0), up(0, 1, 0, 0), right(1, 0, 0, 0);
dgMatrix matrix(front, up, right, pos);
//NewtonBodySetMatrix(__g_E3D_aEntities[id]->body, &matrix[0][0]);
entMatrix = matrix;
NewtonCollisionCalculateAABB (entCollision, &matrix[0], &entAABB_p0[0], &entAABB_p1[0]);
}
-if your world is very small then a brute force will be fine. do not worry about aabb test for now.
- Code: Select all
int OverlapTest (const dgVector& p0, const dgVector& p1, const dgVector& q0, const dgVector& q1)
{
return ((p0.m_x < q1.m_x) && (p1.m_x > q0.m_x) && (p0.m_z < q1.m_z) && (p1.m_z > q0.m_z) && (p0.m_y < q1.m_y) && (p1.m_y > q0.m_y));
}
void MyWorld::BruteForceCollisionSystem ()
{
for (i = 0; i <bodyCount; i ++) {
E3D* ent0 = GetEnt(i);
for (j = i + 1; j < bodyCount; j ++) {
E3D* ent2 = GetEnt(j);
if (OverlapTest (ent0->&entAABB_p0[0], ent0->&entAABB_p1[0], ent1->&entAABB_p0[0], ent1->&entAABB_p1[0]) {
if (E3D::collide(const s32& id1, const s32& id2) {
// do stuff whne body collide
}
}
}
}
then when you have that working if you want to move to a move advance system, you can use a hirarchy or a mutigrid like Newton and 200 and 300
but liek a say if you work is small (less than 100 objects then you do not have to worry about that.