@@ -72,21 +72,22 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v
72
72
lastX = x
73
73
lastY = y
74
74
75
- val frameYaw = ( xoffset) / 180.0f * Math .PI .toFloat()
75
+ val frameYaw = xoffset / 180.0f * Math .PI .toFloat()
76
76
val framePitch = yoffset / 180.0f * Math .PI .toFloat() * - 1f
77
77
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()
81
81
82
82
node.ifSpatial {
83
83
distance = (target.invoke() - position).length()
84
- node.target = target.invoke()
85
84
val currentRotation = rotation
86
85
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
90
91
91
92
// Update position based on new rotation
92
93
position = target.invoke() + node.forward * distance * (- 1.0f )
@@ -96,6 +97,7 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v
96
97
}
97
98
}
98
99
100
+
99
101
override fun scroll (wheelRotation : Double , isHorizontal : Boolean , x : Int , y : Int ) {
100
102
scrollAction.invoke(wheelRotation, isHorizontal, x, y)
101
103
0 commit comments