Advertisement

forward and backwards

Started by February 27, 2002 03:06 PM
8 comments, last by ryan_carter87 22 years, 11 months ago
Ok i have made a 3d room, i can make the camera look up and down and left and right, but i can not figure out how to make it move forward and backward. Could someone please explain it to me. I tried looking at tutorial 10 but i couldn''t understand it.
To set the camera :
1- translate the world to the camera position
2- rotate the camera

to move forward/backward you have to change the camera position according to its orientation.
With the camera orientation, you can compute the camera direction (ie the vector). And with this vector you can compute the new position of the camera.

So, to compute the position of a camera which moves forward/backward, you need :
1- the vector of the camera direction,
2- the speed of the camera (eg the speed of the vehicle/player)
3- the elapsed time since, say, last frame
Advertisement
You know that you can just take the z axis and move the camera through that axis!

you just take the z-axis and change that and the camera will move forward(add if directx or subtract in opengl)and backward(subtract if directx or add in opengl).

I hope this helps!

------DirectxDave------
Programming Rules!
-----------------------
------Skatetronics------Programming Rules!-----------------------
I have tried moving it through the z axis, all it does is make the world spin around. Also i dont really understand vincoof''s reply, could you please rephrase it? Thanx
I think what vincoof is trying to say is that you have to move the camera based on its current rotation. If you just increase the Z value then you wont be heading in the direction that you are looking at unless if you are looking right down the Z axis. To move forward or backward you have to use trig functions: sin() and cos()

Didn''t tut #10 talk about those a little bit? I thought it did .. hmm
blueEbola''s right.

I think you have a camera object (probably a class) which contain camera''s position and camera''s orientation.
If not, then you should !
With camera''s orientation, you can determine which is the camera direction. And with this direction vector you can move forward/backward by computing the new camera _position_ (the camera orientation remains unchanged).

and DirectxDave''s solution does work only for very particular cases which I bet does not fit your case.
Advertisement
Ok thanx. I tried using the sin and cos functions from lesson 10, but it shows syntax errors about it. Is there something more i need to add to use those functions?
What kind of syntax errors? You have to make sure that before the sin() or cos() you put a (float) or else you''ll get some warnings (but not errors) Otherwise it should work
include either "math.h" (for C) or "cmath" (for C++)
Ya i figured out that i have to add the math.h header. Im just gonna find a better tutorial on the issue somewhere. Thanx for your replies

This topic is closed to new replies.

Advertisement