Skip to content

Commit

Permalink
Refactor camera
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Dec 1, 2023
1 parent c728eab commit 3a9c543
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions osu.Framework/Graphics/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ public Matrix4 CreateMatrix(RectangleF viewport)
return Matrix4.Identity;

float focalLength = 2 * MathF.Tan(0.5f * MathUtils.DegreesToRadians(FovY));
float rangeInv = 1.0f / (ZNear - ZFar);
float aspect = viewport.Height / viewport.Width;

Matrix4 mat = new Matrix4(
focalLength * viewport.Height / viewport.Width, 0, 0, 0,
focalLength * aspect, 0, 0, 0,
0, -focalLength, 0, 0,
0, 0, (ZFar + ZNear) / (ZNear - ZFar), 1.0f,
0, 0, 2 * ZFar * ZNear / (ZNear - ZFar), 0);
0, 0, (ZNear + ZFar) * rangeInv, 1.0f,
0, 0, 2 * ZFar * ZNear * rangeInv, 0);

return Matrix4.CreateTranslation(-Position.X * viewport.Width, -Position.Y * viewport.Height, viewport.Height * focalLength / 2) * mat;
}
Expand Down

0 comments on commit 3a9c543

Please sign in to comment.