Another 3D camera question.

Hi folks.

While working on the camera in the latest thing sand box whatever it is, I cam across this which was really helpful and got my camera working on it’s axis.

So with that working I now need the side to side or strafe, and the forward and back. As well as the up and down.

What I can’t work out is how to move the camera according to it’s own world axis, or LookForward. Or At. Whichever it actually is. Can you tell I’m a bit confused?!

I can move the position according to the world x,y,z fine, but then when the camera is rotated 25’ to the left it’s no longer aligned to the world x,y. Of course.

I’m guessing I’ll need matrices but I have no idea which, or how to move an object according to a matrix.

Could someone please point me in the right direction?

Many thanks.

Use the cameras world matrix up down right or left vectors and add them to the cameras position then pass that back into your CreateWorld function to move the camera properly on the cameras local axis.
Opposed to the system coordinate axis.

cameraWorld.Translation = cameraWorld.Translation + cameraWorld.Left;


// So here we initially defined position and point a camera object in the world for the first time..
Matrix cameraWorld = Matrix.CreateWorld(new Vector3(0,1f,0), new Vector3(.707f, 0, .707f), Vector3.Up);


// When updating we want to move the camera on its own local axis, for example here to the left.
cameraWorld = Matrix.CreateWorld(cameraWorld.Translation + cameraWorld.Left * distance , cameraWorld.Forward, Vector3.Up);
// distance here is how much the camera is moved as the matrix left right up or down is unit length.


// If you allow the ability to roll your camera then instead of the above use the cameras up.
cameraWorld = Matrix.CreateWorld(cameraWorld.Translation + cameraWorld.Left * distance, cameraWorld.Forward, cameraWorld.Up);

Create the view matrix with CreateLookAt from that camera matrix.

view = Matrix.CreateLookAt(cameraWorld.Translation, cameraWorld.Translation + cameraWorld.Forward, cameraWorld.Up);

Similar to what was previously stated in the reply in the last post.

There are some things to know about the CreateWorld up parameter passed as well as how to prevent gimble lock but i don’t think you are quite there yet.