Jump to content
  • Advertisement
Sign in to follow this  
JeremyStrawn

Beginning Animation

This topic is 2643 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

I've just completed my second c++ class at college and have decided that I know enough to start trying to make a game. Ive used opengl and glut and let myself draw boxes with my mouse and drag them around, but I don't know how to make them move independently of my mouse. Like have the box move slowly to my mouse when I click. Or having a box randomly wander around. I'm sure its a topic that can't be explained in one post, but I don't even know where to start. I've never dealt with timing, so having a box move over time is beyond me. If anyone could direct me to a tutorial on how to deal with moving over time, that would be great.

Thanks.

Share this post


Link to post
Share on other sites
Advertisement
There really isn't much a difference between the two. When you move a box based on the mouse, you are just changing the state of the box based on the mouse input. For moving an object independently of the mouse you are just changing the state of the box based on the boxe's last state in your main loop.

I haven't used GLUT for awhile but I believe it is set up with some sort of update function which is called every frame. In which case moving a box would be something like this:

void update() {
box.x = box.x + 1; // Moves the boxes x coordinate by 1.
box.y = box.y + 1; // Moves the boxes y coordinate by 1.
}


This would move the box diagonally across the screen at a rate of 1 unit per frame.

The speed of the movement of the box in this case will be determined by how many frames per second the application is running at. There is a good article called Fix Your Timestep! which explores how to update objects at a constant rate regardless of frames per second.

However there are probably plenty of specific examples using OpenGL and GLUT which demonstrate a moving object of some sort.

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!