View Full Version : Collision Detection + easy implementation

mike55

11-24-2003, 12:05 PM

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.

gumby

11-24-2003, 03:16 PM

Try either bounding spheres or axis aligned bounding boxes.

mike55

11-24-2003, 11:45 PM

ahhh can you explain in more detail please??

Deiussum

11-25-2003, 04:23 AM

Here's what I would do in your position:

Open a browser window Type http://www.google.com in the address bar. Type in things in the search such as, "collision detection", "bounding spheres", "axis aligned bounding boxes" Follow the pages and pages of results

Learning where to go for stuff like this will get you far.

nexusone

11-25-2003, 04:38 AM

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(dx*dx + dy*dy + 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??

glcrazy

11-25-2003, 05:46 PM

Originally posted by nexusone:

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(dx*dx + dy*dy + 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.

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(dx*dx + dy*dy + dz*dz)

if( distance <= (15.0) then contact= true ;

Am I right .. ?

Thanks in Advance nexusone ..

nexusone

11-26-2003, 03:59 AM

Yes

glcrazy

11-26-2003, 04:13 AM

IT Works ........ http://www.opengl.org/discussion_boards/ubb/smile.gif http://www.opengl.org/discussion_boards/ubb/smile.gif

Thanks alot nexusone http://www.opengl.org/discussion_boards/ubb/smile.gif

glcrazy

11-27-2003, 07:11 AM

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

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.