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).]