PDA

View Full Version : Creating a 2D Animation With Movable Objects



meinkamfyschweter
10-25-2010, 02:09 PM
I'm a little bit stuck on trying to figure this out. From some of the sources I've seen so far, a lot of people have described how to create an object, and move/translate the camera around it.

I would like to create object(s), and move it a around my window with the keyboard keys up, down, left, right... I've setup the the program to listen properly for the keys, but stuck on creating/moving the object.

Does anyone have any good tips on this, or tutorials? I don't have the code with me right now, sitting in a lab at school. I can try and post it later, really isn't much to it though. I've basically created the window and setup the event listener for the keyboard input.

david_f_knight
10-25-2010, 09:24 PM
Not hard to do. You typically use the ModelView matrix for translating geometry. You will need to update it each frame that there is any change desired in the location of your geometry. You can define the ModelView matrix as you wish, but (assuming it is a 4x4 matrix), the fourth column is where you store, from top to bottom, the X translation, then Y translation, then Z translation, then 1. For your 2D animation, you would typically start with the X, Y, and Z translations each set to zero, and as the user presses the appropriate keys, you would add or subtract a suitable constant to the X and/or Y translation values stored in your ModelView matrix.