@@ -72,21 +72,22 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v
7272 lastX = x
7373 lastY = y
7474
75- val frameYaw = ( xoffset) / 180.0f * Math .PI .toFloat()
75+ val frameYaw = xoffset / 180.0f * Math .PI .toFloat()
7676 val framePitch = yoffset / 180.0f * Math .PI .toFloat() * - 1f
7777
78- // first calculate the total rotation quaternion to be applied to the camera
79- val yawQ = Quaternionf ().rotateXYZ( 0.0f , frameYaw, 0.0f ).normalize()
80- val pitchQ = Quaternionf ().rotateXYZ (framePitch, 0.0f , 0.0f ).normalize()
78+ // First calculate the total rotation quaternion to be applied to the camera
79+ val yawQ = Quaternionf ().rotateY( frameYaw).normalize()
80+ val pitchQ = Quaternionf ().rotateX (framePitch).normalize()
8181
8282 node.ifSpatial {
8383 distance = (target.invoke() - position).length()
84- node.target = target.invoke()
8584 val currentRotation = rotation
8685
87- // Rotate pitch first, then yaw to ensure proper axis alignment
88- rotation = pitchQ.mul(currentRotation).normalize()
89- rotation = yawQ.mul(rotation).normalize()
86+ // Combine the rotations in a way that pitch is applied first, then yaw
87+ val newRotation = yawQ.mul(pitchQ.mul(currentRotation, Quaternionf ()), Quaternionf ()).normalize()
88+
89+ // Update the camera rotation
90+ rotation = newRotation
9091
9192 // Update position based on new rotation
9293 position = target.invoke() + node.forward * distance * (- 1.0f )
@@ -96,6 +97,7 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v
9697 }
9798 }
9899
100+
99101 override fun scroll (wheelRotation : Double , isHorizontal : Boolean , x : Int , y : Int ) {
100102 scrollAction.invoke(wheelRotation, isHorizontal, x, y)
101103
0 commit comments