Sign in to follow this  

qrawing a shape in a new position

This topic is 3534 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi, i want to draw two balls. but the problem is i want to dwaw them according to the output of another program. that is i am estimating new 2d position every time and i like to draw the sphare everytime in newly estimated positions. for examle : i wnat to draw a ball in the position- x=1200.5 y=100.6 after that i want to draw the same ball at position x=125.5 y=102.6 how can i do that pls give me some example. thaking you all

Share this post


Link to post
Share on other sites
glTranslatef translates the OpenGL coordinate system to a new position (flaot x, float y, float z).

glTranslatef(1200.5, 100.6, 0);
drawBall();
glTranslatef(125.5, 102.6, 0);
drawBall();
glTranslatef(0, 0, 0); //reset back to the default position

Share this post


Link to post
Share on other sites
no no, that'll draw the ball once at (1200.5,100.6), and then at (1326,203.2), and then the final glTranslatef(0, 0, 0) will do nothing. The translates add onto eachother.

you want:

glPushMatrix();
glTranslatef(1200.5, 100.6, 0);
drawBall();
glPopMatrix();

glPushMatrix();
glTranslatef(125.5, 102.6, 0);
drawBall();
glPopMatrix();

Share this post


Link to post
Share on other sites
Sign in to follow this