0
\$\begingroup\$

I'm making a game in C++ using Direct3D 9. How do I move the camera at constant rate?

I'm making a Flappy Bird type game and I'd like to move the camera forward through the level.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

If you have a camera eye position, move that in the forward direction (add to its xyz values the constant vector xyz values which you want to move it by). The camera up vector (which defines the up direction) should stay intact (unless you want to rotate the camera), the lookat vector (or forward vector in which your camera faces from the eye position) should be lookAt.xyz=lookAt.xyz+eye.xyz . Then recreate your view matrix with those values. The projection should not be changed.

\$\endgroup\$
5
  • \$\begingroup\$ It´s a 2D game .. \$\endgroup\$ Commented Mar 1, 2014 at 16:57
  • \$\begingroup\$ So basicly I create a camera and make a for int inside a while that keeps adding certain ammount of y values to the position?.. Sorry for the first comment looking kind of sarcastic, its because I didnt knew that ENTER posted the comment.. And thanks for the answer! :D \$\endgroup\$ Commented Mar 1, 2014 at 16:58
  • \$\begingroup\$ Well, if it is a 2D game and you only want to move the camera then keep a camera poosition variable and draw your images on the images position - camera position and the effect will be the same. (this is also what a camera matrix would do, but you can also store rotations, scalars in those) For example you've got a stone on position (10,20) and your camera is on (30,15), then when drawing the stone draw it on the position of (10-30,20-15) = (-20,5) ;) \$\endgroup\$ Commented Mar 1, 2014 at 17:56
  • \$\begingroup\$ Turánskzi How to I assign a camera to my game? thats my major doubt :\ .. \$\endgroup\$ Commented Mar 1, 2014 at 18:01
  • \$\begingroup\$ A camera is just a position and orientaton and a projection. You transform your scene with the inverse of that orientation and position and project them to the screen. Position and orientation is usually stored in the view matrix, and projection which is a bit more complex in another matrix. You should create an orthographic projection matrix for a 2D game. The view matrix should contain an xy translation and rotation and z rotation for a 2D game. Implementing that you should check out some matrix math. \$\endgroup\$ Commented Mar 1, 2014 at 18:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .