Jump to content
  • Advertisement
Sign in to follow this  
beginnerfurqan

OpenGL moving objects in opengl

This topic is 4903 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,im trying to get an object to move from one side of the window to the other side but its not moving. as a basic model i have created the object using sphere and i have tried the solar system example in the red book but i dont want rotation round an origin just movement on x, y co-ordinates. i have a clue that its something in idle function but dont know how to code it. can someone help?

Share this post


Link to post
Share on other sites
Advertisement
did you try:

float x,y,z;

//x = 0.0f,y = 0.0f; z = -1.0f; thats the way I do it ;)

void Draw()
{
glTranslatef(x,y,z);
//draw the object
x += 0.02;
}







that will cause the object to move right. x -= 0.02 would cause it to move left.
y += 0.02 up, y -= 0.02 down etc. Hope this helps.

~Jay

ps. to make it stop at one side of the screen and return to the other...

static float dir = 0.02; //go right
x += dir;

if(x >= 1.0f)
dir = -0.02; //go left
else if(x <= -1.0f)
dir = 0.02;//go right again

good luck.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!