Skip to content

Commit 1ee5a3f

Browse files
Updated tracking camera based on
MonoGame/MonoGame.Samples#80 (comment)
1 parent e5c267c commit 1ee5a3f

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

articles/getting_to_know/howto/graphics/camera/HowTo_Understand_Different_Camera_Modes.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ This is the simplest way of rendering a camera, you just create a `View Matrix`
109109

110110
### The Tracking Camera
111111

112-
Giving the camera something to look at requires a little more thought, the target, while positioned in a 3D world using a `Vector3`, needs transforming by the world `Matrix` in order to determine its position relative to the same world the camera is located in.
113-
114-
Once transformed, a simple `Vector3` addition is used to give the final world position before generating the view, as follows:
112+
Giving the camera something to look at is also quite simple, instead of looking at the center of the world (assuming the world is `Matrix.Identity`), we instead "Look at" the model itself, dymanically updated each frame, as follows:
115113

116114
```csharp
117115
// Set the position of the camera in world space, for the fixed camera view matrix.
@@ -121,14 +119,8 @@ Once transformed, a simple `Vector3` addition is used to give the final world po
121119
{
122120
// Tracking view, the camera is always in the same position but changes the view matrix to "look" towards a target.
123121
124-
// Create a vector pointing the direction the camera is facing.
125-
Vector3 transformedReference = Vector3.Transform(modelPosition, Matrix.Identity);
126-
127-
// Calculate the position the camera is looking at.
128-
Vector3 cameraLookat = transformedReference + modelPosition;
129-
130122
// Set up our world matrix, view matrix and projection matrix.
131-
UpdateCameraView(cameraFixedPosition, cameraLookat);
123+
UpdateCameraView(cameraFixedPosition, modelPosition);
132124
}
133125
```
134126

0 commit comments

Comments
 (0)