I have made my own camera class in Xna (well, FNA, but same underlying framework). It contains a projection & view matrix. I calculate those matrices like this:
// Position: The camera's position (X, Y) // WindowSize: The size of the actual window (e.g. 1920x1080). // WorldSize: The world size the camera is emulating (e.g. 16x9). // Zoom: The camera's zoom (2 => twice as zoomed in, 0.5 => twice as zoomed out) // Projection var translation = Matrix.CreateTranslation(new Vector3(-Position, 0)); var scale = Matrix.CreateScale(new Vector3(WindowSize / WorldSize * Zoom, 1)); var projection = translation * scale; // View var position = new Vector3(Position, 0); var view = Matrix.CreateLookAt(position, position + Vector3.Forward, Vector3.Up); // straight ahead // Combined (used when drawing) return projection * view;
This works, except that whenever I move my camera it laggs behind very slightly. I’ve deduced that this is because of the view matrix, as changing it to
Matrix.Identity removes the issue. Changing the position used to
Vector3.Zero fixes the issue as well.