# Moving a camera forwards (3D)

This topic is 3471 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi guys, I'm currently working on a little 3D engine and everything is working as expected but I seem to be stuck with something that sounds as though it should be pretty simple. The "camera" I am moving around the 3D world is working fine but the XYZ movements are relative to the orientation of the coordinate system the camera is in, I can't work out how to make the camera move forwards/backwards left/right relative to the direction it is facing. The camera has a 3x4 matrix that is updated whenever the position or rotation values are changed and I ideally I would like to use that somehow, I could calculate the forwards/backwards movement with cos and sin etc but I would prefer to avoid those if possible. Any help or pointers would be great. Thanks. :)

##### Share on other sites
3d rotation is represented by a 3x3 matrix.

The 3x3 matrix is made up of 3 vectors wich represent unit vectors representing a xyz axis system.

Thus, if you want your camera to move in the new z axis(after rotation) you just use the z vector from the matrix and add that to the camera postion.

I'll illustrate

[xx, xy, xz]
[yx, yy, yz]
[zx, zy, zz]

4x4 matrix is no different

[xx, xy, xz, xw]
[yx, yy, yz, yw]
[zx, zy, zz, zw]
[wx, wy, wz, ww]

delta=speed*time;

camera.x += zx * delta;
camera.y += zy * delta;
camera.z += zz * delta;

Stefan

##### Share on other sites
Thank-you Veslefrikk. It occurred to me after I posted the question that I could just add two vectors together, I wasn't sure which values to pull from the matrix though. Thanks again. :)

• 35
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631358
• Total Posts
2999531
×