Camera Help.

To add to what nkast and others have said.

Everything that you think of as a actual game object is positioned with a orientation matrix which is technically a world matrix. That includes a object you might define as a camera or a player that will act as the camera.

The above is a important concept to keep in mind that is nearly always skipped over.

That world matrix defines any object in your world by its total orientation including its position which is the Translational component of the matrix. The .Forward vector of a world matrix is the direction it is facing in relation to the coordinate system the monogame framework uses.

The view matrix is created from a world matrix specifically the one you choose to be the camera. It is a special matrix which creates a eye translation vector it is primarily needed to transform everything in the scene around it’s position. This only needs to be recreated if the camera’s (world) matrix changes position or orientation in any way.

The projection matrix creates a vanishing point at the end for a perspective projection or defines the viewing box area for a orthographic type of projection. This never needs to change unless you alter it which is typically not need to be done once created.

The multiplication of these matrices wvp = world * view * projection creates a final matrix that can be multiplyed by local model space vertices (that never change) on a shader to draw objects in the world this part lies in the realm of shaders or you can just use basic effect to pass all 3 matrices.
Such that you can draw the same model with different world matrices and the same view and projection matrices to draw the same model in many different positions or orientations in your scene.

To set up these matrices the Matrix class provides functions.

The world matrix is typically created with Matrix.CreateWorld( … ); this is for all objects including a object you deem to be a camera be it a player or a specifically created camera object that wont be drawn at all.

The view matrix is created with Matrix.CreateLookAt( … ); using values from the world matrix that belongs to a object you created or a existing game object with a world matrix you select to act as the camera in your world.

The projection matrix is typically created one time using Matrix.CreatePerspective or Orthagonal with values mostly derived from the graphics device viewport for width and heights and field of views ect.

Additional notes
CreateWorld takes a Forward directional vector as a parameter (this implys TargetPosition - PlayerPosition is to be passed) were CreateLookAt takes a target vector this is actually just a position in space to look at (implying pass targetPosition only).
If you want to use a direction instead of a position for the look at parameter, then take the camera.Forward vector of that world matrix which is the object you have selected to be the camera multiply it by say 10 and add it to that same world matrices position which is the camera.Translation then pass it as the target.
Both Forward and Target are basically were the world object or view looks at.
CreateLookAt also can be passed Vector3.Up for the Up value parameter if you want your camera to be fixed which is what most fps games do to keep the horizon stable.
Be aware with fixed cameras looking straight up or down will be the gimble lock directions.

There are quite a few example cameras if you search the monogame forums itself in code.

Just ask if you have more questions or get stuck.

2 Likes