Jump to content
  • Advertisement
Sign in to follow this  
SiRobertson

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
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. :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!