PDA

View Full Version : How to move a object in Parabolic shape in OpenGL



Girishentc
02-07-2014, 06:03 PM
Hi Everyone,

I have started learning OpenGL since 2 months. I am making one Basketball game where my aim is once user drag the ball and leave then it need to reach in basket or miss, depending upon parabolic equestion. So I am trying to move the object in Parabolic shape,I could draw the parabola but could not move the object so can anybody suggest how to move the object in parabolic shape.


Thanks
Girish

tonyo_au
02-08-2014, 05:13 PM
have a look at glTranslate - this is the basic function you need to move an object

Girishentc
02-08-2014, 06:11 PM
Thanks For the reply..I am already glTranslate to move an object in x and y direction. But once I put the for loop to move an object in paraolic shape then sometimes window goes blank or geting unpridictable behaviour. Here is my function which draws sphares in parabolic Sphere but it does not move in prabolic shape. Can you please help me in this....

void DrawParabola()
// The Drawing Routine
{
double x,y;
glColor3f(1.0, 1.0, 1.0);
for (tranx = -2; tranx <= 8; tranx += .002)
{
glPushMatrix();
trany = 18* tranx -9* tranx * tranx;
glLoadIdentity();
tranx +=0.1*Speedfact;
trany +=0.1*Speedfact;
glTranslatef(tranx*3,trany,tranz);
glutWireSphere(0.6, 20, 16);
glPopMatrix();
Sleep(50);
glutPostRedisplay();
}

}

Girishentc
02-08-2014, 06:13 PM
Thanks For the reply..I am already using glTranslate to move an object in x and y direction. But once I put the for loop to move an object in parabolic shape then sometimes window goes blank or geting unpridictable behaviour. Here is my function which draws sphares in parabolic shape but it does not move in prabolic shape. Can you please help me in this....

void DrawParabola()
// The Drawing Routine
{
double x,y;
glColor3f(1.0, 1.0, 1.0);
for (tranx = -2; tranx <= 8; tranx += .002)
{
glPushMatrix();
trany = 18* tranx -9* tranx * tranx;
glLoadIdentity();
tranx +=0.1*Speedfact;
trany +=0.1*Speedfact;
glTranslatef(tranx*3,trany,tranz);
glutWireSphere(0.6, 20, 16);
glPopMatrix();
Sleep(50);
glutPostRedisplay();
}

}

tonyo_au
02-08-2014, 10:39 PM
The code you have included looks ok but why do you change your loop control with

tranx +=0.1*Speedfact;

You may simply be calculating an x,y that is outside the view frustrum