Skip to content

Commit d34696a

Browse files
committed
More closely match Blender style arcball
1 parent c418f95 commit d34696a

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)