Hi Guys,
I read up on spatial partition, created a grid structure with std::vector<Cell> cells where each cell size is 100 x 100 (dealing with 2D here) and at each update, i check when an entity has switched cells. I think so far so good.
The problem I believe lies below:
void updateGrid(Grid *grid, std::vector<MovingEntity*> entities,std::vector<Manifold> &manifolds){
for(int y=0;y<grid->num_y_cells;y++){
for(int x=0;x<grid->num_x_cells;x++){
for(int _y=y-1;_y<=y+1;_y++){
for(int _x=x-1;_x<=x+1;_x++){
if(_x<0 || _y<0 || _x>=grid->num_x_cells || _y>=grid->num_y_cells)
continue;
for(int out=0;out<grid->cells[_y].entities.size();out++){
for(int in=0;in<grid->cells[_x].entities.size();in++){
MovingEntity *e1=grid->cells[_y].entities[out];
MovingEntity *e2=grid->cells[_x].entities[in];
if(e1==e2)continue;
e1->aabb.init(e1->pos,e1->half_extents);
e2->aabb.init(e2->pos,e2->half_extents);
Contact contact;
if(myAABBvsAABB(e1->aabb,e2->aabb,contact)){
manifolds.push_back(Manifold(e1,e2,contact));
}
}
}
}
}
}
}
}
I iteratate over a 1D vector (using the 2d trick) check all neighbouring cells for collision, and attempt to create a contact if one exists.
My algo above unfortunatelly is not doing anything. No collisions are detected, even when I fill the screen with AABBs.
Could someone tell me please where the error is?
Thanks,
Mike