Beginning Animation

Started by
0 comments, last by c_olin 12 years, 7 months ago
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.
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.

This topic is closed to new replies.

Advertisement