Skip to content

Commit 4b4bd8c

Browse files
kephaleskalarproduktraum
authored andcommitted
Fix for handling gimbal lock on rotation axes
1 parent 5ceadb8 commit 4b4bd8c

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/main/kotlin/sc/iview/AnimatedCenteringBeforeArcBallControl.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,13 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v
8282
node.ifSpatial {
8383
distance = (target.invoke() - position).length()
8484
node.target = target.invoke()
85-
rotation = pitchQ.mul(rotation).mul(yawQ).normalize()
85+
val currentRotation = rotation
86+
87+
// Rotate pitch first, then yaw to ensure proper axis alignment
88+
rotation = pitchQ.mul(currentRotation).normalize()
89+
rotation = yawQ.mul(rotation).normalize()
90+
91+
// Update position based on new rotation
8692
position = target.invoke() + node.forward * distance * (-1.0f)
8793
}
8894

0 commit comments

Comments
 (0)