Skip to content

Commit

Permalink
Variable zoom speed without modifier keys
Browse files Browse the repository at this point in the history
  • Loading branch information
kephale committed Jul 21, 2023
1 parent f43b0e0 commit fe55b3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ package sc.iview

import graphics.scenery.Camera
import graphics.scenery.controls.behaviours.ArcballCameraControl
import graphics.scenery.utils.extensions.minus
import graphics.scenery.utils.extensions.plus
import graphics.scenery.utils.extensions.times
import org.joml.Vector3f
import java.util.function.Supplier

Expand All @@ -51,6 +54,20 @@ class AnimatedCenteringBeforeArcBallControl(val initAction: (Int, Int) -> Any, v

override fun scroll(wheelRotation: Double, isHorizontal: Boolean, x: Int, y: Int) {
scrollAction.invoke(wheelRotation, isHorizontal, x, y)
super.scroll(wheelRotation, isHorizontal, x, y)

if (isHorizontal || cam == null) {
return
}

val sign = if (wheelRotation.toFloat() > 0) 1 else -1

distance = (target.invoke() - cam!!.spatial().position).length()
// This is the difference from scenery's scroll: we use a quadratic speed
distance += sign * wheelRotation.toFloat() * wheelRotation.toFloat() * scrollSpeedMultiplier

if (distance >= maximumDistance) distance = maximumDistance
if (distance <= minimumDistance) distance = minimumDistance

cam?.let { node -> node.spatialOrNull()?.position = target.invoke() + node.forward * distance * (-1.0f) }
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/sc/iview/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ open class Controls(val sciview: SciView) {
val wrappedFpsControl = selectCommand?.let {
ClickAndDragWrapper(it, fpsControl!!)
} ?: fpsControl!!
h.addBehaviour("view: freely look around", wrappedFpsControl)
h.addKeyBinding("view: freely look around", "shift button3")
// h.addBehaviour("view: freely look around", wrappedFpsControl)
// h.addKeyBinding("view: freely look around", "shift button3")

//slow and fast camera motion
h.addBehaviour("move_withMouse_back/forward/left/right", CameraTranslateControl(sciview, 1f))
Expand Down

0 comments on commit fe55b3c

Please sign in to comment.