Fix orbit camera mirroring by matching gameplay handedness
This commit is contained in:
1 parent
1b679c641a
commit
d8f1b51c86
10 files changed
+125
-4
No files matched your search
@@ -0,0 +1,22 @@
|
||||
using System.Numerics;
|
||||
|
||||
namespace GamePort.Application;
|
||||
|
||||
/// <summary>Inspection camera in the same positive-Z view space as gameplay.
|
||||
/// Caller applies the Vulkan viewport Y flip to Projection exactly once.</summary>
|
||||
public readonly record struct OrbitCamera(Vector3 Eye, Matrix4x4 View, Matrix4x4 Projection)
|
||||
{
|
||||
public static OrbitCamera Create(Vector3 target, float radius, float angle, float elevation, float aspect)
|
||||
{
|
||||
if (!float.IsFinite(target.X) || !float.IsFinite(target.Y) || !float.IsFinite(target.Z)
|
||||
|| !float.IsFinite(radius) || radius < .01f || !float.IsFinite(angle)
|
||||
|| !float.IsFinite(elevation) || MathF.Abs(elevation) >= MathF.PI / 2
|
||||
|| !float.IsFinite(aspect) || aspect <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(radius), "A finite orbit outside the poles and positive viewport are required");
|
||||
var eye = target + radius * new Vector3(MathF.Cos(elevation) * MathF.Sin(angle),
|
||||
MathF.Sin(elevation), MathF.Cos(elevation) * MathF.Cos(angle));
|
||||
return new(eye, Matrix4x4.CreateLookAtLeftHanded(eye, target, Vector3.UnitY),
|
||||
Matrix4x4.CreatePerspectiveFieldOfViewLeftHanded(MathF.PI / 3, aspect,
|
||||
Math.Max(radius / 10000, .01f), radius * 20));
|
||||
}
|
||||
}
|
||||
@@ -1231,11 +1231,11 @@ internal static class Program
|
||||
if (keys.Contains(45) || keys.Contains(86)) radius *= MathF.Exp(dt);
|
||||
}
|
||||
radius = Math.Max(radius, 0.01f);
|
||||
var eye = target + radius * new Vector3(MathF.Cos(elevation) * MathF.Sin(angle),
|
||||
MathF.Sin(elevation), MathF.Cos(elevation) * MathF.Cos(angle));
|
||||
var orbit = OrbitCamera.Create(target,radius,angle,elevation,(float)renderer.Width / renderer.Height);
|
||||
var eye = orbit.Eye;
|
||||
var view = originalCamera
|
||||
? Matrix4x4.CreateLookAtLeftHanded(originalStart!.CameraPosition, originalStart.Position + new Vector3(0, 80, 0), Vector3.UnitY)
|
||||
: Matrix4x4.CreateLookAt(eye, target, Vector3.UnitY);
|
||||
: orbit.View;
|
||||
var renderEye = originalCamera ? originalStart!.CameraPosition : eye;
|
||||
var renderTarget = originalCamera ? originalStart!.Position + new Vector3(0,80,0) : target;
|
||||
if (simulation != null && !inspecting)
|
||||
@@ -1318,7 +1318,7 @@ internal static class Program
|
||||
viewportWidth: renderer.Width, viewportHeight: renderer.Height);
|
||||
var projection = gameplayProjection
|
||||
? SceneProjection.CreateGameplay(level?.Code, (float)renderer.Width / renderer.Height)
|
||||
: Matrix4x4.CreatePerspectiveFieldOfView(MathF.PI / 3, (float)renderer.Width / renderer.Height, Math.Max(radius / 10000, 0.01f), radius * 20);
|
||||
: orbit.Projection;
|
||||
projection.M22 *= -1;
|
||||
if (animations != null)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user