Question

Hi everybody …

I’m trying to let two sheres bounced when they hit each other and when they hit a rectangle … It works correctly when the hit each other but with the rectangle it didn’t work … I don’t know why ? …

Here is the code I used :

//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);

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;

This is for the bouncing of the two spheres …

For the bouncing between the two shperes and the rectangle :

dx1 = dragx - Ball1x;
dx2 = Ball2x - dragx;
dy1 = dragy - Ball1y;
dy2 = Ball2y - dragy;

distance1 = sqrt(dx1dx1 +dy1dy1);
distance2 = sqrt(dx2dx2 +dy2dy2);

if (distance1<= 10.0f) { vx=-vx; angle=-angle;vy=-vy;}
if (distance2<= 10.0f) { vx2=-vx2; angle2=-angle;vy2=-vy2;}

Where the parameters of the rectangle :

// Rectangle para.s
int x1=10.00f ,yy=-40.00f,x2=-60.00,y2=-50.00, D=0.0;

glPushMatrix();

  glTranslatef(dragx,dragy,0.0f);    
	glColor3f(1.0, 1.0, 1.0);

glRectf(x1,yy,x2,y2);
glPopMatrix();

Any help …?

Thanks in advance …

[This message has been edited by glcrazy (edited 11-28-2003).]

http://www.gamasutra.com/features/19991018/Gomez_4.htm

gamasutra is a good site, you have to register, but it is free.

just realized that the size talks about AABB…these are axis aligned bounding boxes…there is alink on the right side of the above page that talks about an AABB sweep test or something …that page describes AABB’s.

[This message has been edited by bumby (edited 11-28-2003).]

Now is a good time for your two break out a math book and maybe look at some vector math tutors on the web.
Option one, use sphere’s bounding for all object and just aproximate the location on the box.

Option two, use vector math to find out where on the box the sphere hits. sometime like vector plane intersection would work.

I dont know that math for it by heart, but for just moving on the x/y. Simple if statement’s to create a bounding area.
The compaire it against the sphere x/y position.

[This message has been edited by nexusone (edited 11-28-2003).]

Hello

I got the idea and it works with me perfctly now …

Thanks alot