Skip to content

Commit a3cbf35

Browse files
authored
Merge pull request #544 from Zi5han/vertical-camera-flipping-patch
Fix for vertical camera flipping in 3D viewer
2 parents ff2eac3 + 298f459 commit a3cbf35

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

FModel/Views/Snooper/Camera.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,21 @@ public void Modify(Vector2 mouseDelta)
6262
mouseDelta *= lookSensitivity;
6363

6464
var rotationX = Matrix4x4.CreateFromAxisAngle(-Up, mouseDelta.X);
65+
var tolerance = 0.001f;
6566
switch (Mode)
6667
{
6768
case WorldMode.FlyCam:
6869
{
6970
Direction = Vector3.Transform(DirectionArc, rotationX) + Position;
7071

7172
var right = Vector3.Normalize(Vector3.Cross(Up, DirectionArc));
72-
var rotationY = Matrix4x4.CreateFromAxisAngle(right, mouseDelta.Y);
73+
74+
var currentPitch = MathF.Acos(Vector3.Dot(DirectionArc, Up) / (DirectionArc.Length() * Up.Length()));
75+
var newPitch = currentPitch + mouseDelta.Y;
76+
var clampedPitch = Math.Clamp(newPitch, tolerance, MathF.PI - tolerance);
77+
var pitchDelta = clampedPitch - currentPitch;
78+
79+
var rotationY = Matrix4x4.CreateFromAxisAngle(right, pitchDelta);
7380
Direction = Vector3.Transform(DirectionArc, rotationY) + Position;
7481
break;
7582
}
@@ -78,7 +85,13 @@ public void Modify(Vector2 mouseDelta)
7885
Position = Vector3.Transform(PositionArc, rotationX) + Direction;
7986

8087
var right = Vector3.Normalize(Vector3.Cross(-Up, PositionArc));
81-
var rotationY = Matrix4x4.CreateFromAxisAngle(right, mouseDelta.Y);
88+
89+
var currentPitch = MathF.Acos(Vector3.Dot(PositionArc, -Up) / (PositionArc.Length() * Up.Length()));
90+
var newPitch = currentPitch + mouseDelta.Y;
91+
var clampedPitch = Math.Clamp(newPitch, tolerance, MathF.PI - tolerance);
92+
var pitchDelta = clampedPitch - currentPitch;
93+
94+
var rotationY = Matrix4x4.CreateFromAxisAngle(right, pitchDelta);
8295
Position = Vector3.Transform(PositionArc, rotationY) + Direction;
8396
break;
8497
}

0 commit comments

Comments
 (0)