I’m having trouble transforming the matrix for my camera (intended as a first person camera for a future First Person Shooter Project).

Previously, instead of CreateFromAxisAngle, I used CreateRotation to rotate the view around the axes. That didn’t work as intended, since as I understand that rotates around world axes. The further you got from the starting target direction, the worse the camera behaved.

I researched it and I understand I have to transform the Vectors/Matrices to a rotation around a local axis, but I’m having trouble actually doing that. The current code doesn’t seem to rotate the camera, since the models I have drawn (in the main game class) are never visible.

I’m hoping someone could point out where I went wrong!

using System;

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework.Input;

namespace MonoGame3D

{

public class Camera

{

// We need this to calculate the aspectRatio

// in the ProjectionMatrix property.

GraphicsDevice graphicsDevice;

float angleX;

float angleY;

Vector3 cameraUpVector = Vector3.UnitZ;

Vector3 lookAtVector = new Vector3(0, -1, -.5f);

MouseState currentMouseState, previousMouseState;

`Vector3 position = new Vector3(0, 20, 10);`

`public Matrix ViewMatrix { get { lookAtVector = Vector3.Transform(lookAtVector, Matrix.CreateFromAxisAngle(cameraUpVector, angleX)); lookAtVector = Vector3.Transform(lookAtVector, Matrix.CreateFromAxisAngle(Vector3.Cross(cameraUpVector, lookAtVector), angleY)); lookAtVector += position; cameraUpVector = Vector3.Transform(cameraUpVector, Matrix.CreateFromAxisAngle(Vector3.Cross(cameraUpVector, lookAtVector), angleY));`

`return Matrix.CreateLookAt( position, lookAtVector, cameraUpVector); } }`

`public Matrix ProjectionMatrix { get { float fieldOfView = Microsoft.Xna.Framework.MathHelper.PiOver4; float nearClipPlane = 1; float farClipPlane = 200; float aspectRatio = graphicsDevice.Viewport.Width / (float)graphicsDevice.Viewport.Height;`

`return Matrix.CreatePerspectiveFieldOfView( fieldOfView, aspectRatio, nearClipPlane, farClipPlane); } }`

`public Camera(GraphicsDevice graphicsDevice) { this.graphicsDevice = graphicsDevice; }`

`public void Update(GameTime gameTime) { previousMouseState = currentMouseState; currentMouseState = Mouse.GetState();`

`angleX -= (currentMouseState.Position.X - previousMouseState.Position.X) * (float)gameTime.ElapsedGameTime.TotalSeconds; angleY -= (currentMouseState.Position.Y - previousMouseState.Position.Y) * (float)gameTime.ElapsedGameTime.TotalSeconds; } }`

}