hi, i am having troubles on detecting an AABB collision.
my bounding box is a cube with mins and max.
here is the code where i draw the cube:
void CPaint::DrawCube(BBox bbox, float size)
{
bbox.Min.x = bbox.Max.x - size;
bbox.Min.y = bbox.Max.y - size;
bbox.Max.z = bbox.Min.z - size;
// clear the code a bit
CVector bmax = bbox.Max;
CVector bmin = bbox.Min;
//glColor3ub ( 255,128, 98);
//front
glBegin( GL_QUADS );
glVertex3f ( bmin.x , bmin.y, bmin.z );
glVertex3f ( bmax.x , bmin.y, bmin.z );
glVertex3f ( bmax.x , bmax.y, bmin.z );
glVertex3f ( bmin.x , bmax.y, bmin.z );
glEnd ();
// back
glBegin( GL_QUADS );
glVertex3f ( bmin.x , bmin.y, bmax.z );
glVertex3f ( bmax.x , bmin.y, bmax.z );
glVertex3f ( bmax.x , bmax.y, bmax.z );
glVertex3f ( bmin.x , bmax.y, bmax.z );
glEnd ();
// up
glBegin( GL_QUADS );
glVertex3f ( bmin.x , bmax.y, bmax.z );
glVertex3f ( bmax.x , bmax.y, bmax.z );
glVertex3f ( bmax.x , bmax.y, bmin.z );
glVertex3f ( bmin.x , bmax.y, bmin.z );
glEnd ();
// down
glBegin( GL_QUADS );
glVertex3f ( bmin.x , bmin.y, bmax.z );
glVertex3f ( bmax.x , bmin.y, bmax.z );
glVertex3f ( bmax.x , bmin.y, bmin.z );
glVertex3f ( bmin.x , bmin.y, bmin.z );
glEnd ();
// left side
glBegin( GL_QUADS );
glVertex3f ( bmin.x , bmin.y, bmax.z );
glVertex3f ( bmin.x , bmax.y, bmax.z );
glVertex3f ( bmin.x , bmax.y, bmin.z );
glVertex3f ( bmin.x , bmin.y, bmin.z );
glEnd ();
// rigth side
glBegin( GL_QUADS );
glVertex3f ( bmax.x , bmin.y, bmax.z );
glVertex3f ( bmax.x , bmax.y, bmax.z );
glVertex3f ( bmax.x , bmax.y, bmin.z );
glVertex3f ( bmax.x , bmin.y, bmin.z );
glEnd ();
}
here is how i init the cube and what does the BBox is
void CPaint::InitCube(BBox bbox[])
{
bbox[0].Max.x = 1;
bbox[0].Max.y = 1;
bbox[0].Min.z = 1;
bbox[1].Max.x = 5;
bbox[1].Max.y = 2;
bbox[1].Min.z = 5;
}
struct BBox
{
CVector Min;
CVector Max;
};
with all that code i have no problem, i can move the cube only changing the Max.x , Max.y and Min.z
and can draw as many cubes as i want. (static or dinamic).
the real problem is where i try to check if 2 AABB collide.
this is the code:
bool CPaint::BboxCollision( BBox box1, BBox box2 )
{
if( box1.Min.x > box2.Max.x ) return false;
if( box1.Max.x < box2.Min.x ) return false;
if( box1.Max.z > box2.Min.z ) return false;
if( box1.Min.z < box2.Max.z ) return false;
else
return true;
}
since i only move them in Z or X, i didnt put the Y.
but that doesnt works.....
it says that it is colliding when it doesnt....
what am i doing wrong?