Advertisement Jump to content
Sign in to follow this  
beginnerfurqan

OpenGL moving objects in opengl

This topic is 5060 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!