Hey all,
Am trying to implement simple collision detection in OpenGl (using C++) in my graphics, any suggestions???
Need to keep it as simple as possible.
Thanks.
Hey all,
Am trying to implement simple collision detection in OpenGl (using C++) in my graphics, any suggestions???
Need to keep it as simple as possible.
Thanks.
Try either bounding spheres or axis aligned bounding boxes.
ahhh can you explain in more detail please??
Here’s what I would do in your position:
Learning where to go for stuff like this will get you far.
You can take the distance between the two object A & B with the following:
dx = Ax - Bx
dy = Ay - By
dz = Az - Bz
distance = sqrt(dxdx + dydy + dz*dz)
if( distance <= (A_radius + B_radius) // radius is the radus of our bounding sphere for each object
// If the distance is less or equal to the sum of the two radius of the spheres, then they are touching.
Originally posted by mike55:
ahhh can you explain in more detail please??
Originally posted by nexusone:
[b]You can take the distance between the two object A & B with the following:
dx = Ax - Bx
dy = Ay - By
dz = Az - Bz
distance = sqrt(dxdx + dydy + dz*dz)
if( distance <= (A_radius + B_radius) // radius is the radus of our bounding sphere for each object
// If the distance is less or equal to the sum of the two radius of the spheres, then they are touching.
[/b]
Sounds interesting to me …
Ok … if I’m using glutSolidSphere to draw to spheres from where I get each centre point for the two sphere to get the destance between them, let me set an example here …
if my first sphere is :
glTranslatef(x1,y1,0.0f);
glutSolidSphere( 5.0,50,50);
The second one is:
if my first sphere is :
glTranslatef(x2,y2,0.0f);
glutSolidSphere( 10.0,50,50);
Then according to your calculation :
dx = x2 - x1 or x1 - x2 !
dy = y2 - y1 or y1 - y2!
dz = 0 ;
distance = sqrt(dxdx + dydy + dz*dz)
if( distance <= (15.0) then contact= true ;
Am I right … ?
Thanks in Advance nexusone …
Yes
IT Works …
Thanks alot nexusone
Hi again nexusone …
I tried this time to implement the collision between two shperes and a rectangle like the following ( the two spheres bounced when hitting each other and when each of them hit the rectangle) … but it didn’t work with the rectangle I dont know why … Maybe because I didn’t determine the sum correctly here :…
if( distance <= (A_radius + ??? ) // radius is the radus of our bounding sphere for each object
… Any suggestion … ?
Thanks in advance