Sign in to follow this  
SiRobertson

Moving a camera forwards (3D)

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 this post


Link to post
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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this