scenerygraphics / sciview

sciview is a tool for visualization and interaction with ND image and mesh data
BSD 2-Clause "Simplified" License
67 stars 17 forks source link

smooth cam centering (on node center) is sometimes not smooth #355

Open xulman opened 3 years ago

xulman commented 3 years ago

suppose I select/activate a node that is displayed in the corner of the scene, if I:

why is this not the same anymore?

kephale commented 1 year ago

Related to https://github.com/scenerygraphics/sciview/issues/319

kephale commented 1 year ago

I'll bump @skalarproduktraum on this one as well, since he wrote the smooth camera motion code.

kephale commented 1 year ago

Yeah, I checked this again, and it is kind of confusing for me to track what is going on with AnimatedCenteringBeforeArcBallControl

xulman commented 1 year ago

I'm confirming: the shift+drag (centering-then-rotate-around) centers much faster than the centering from dbl-clicking in the inspector

xulman commented 1 year ago

the patch is the following:

--- a/src/main/kotlin/sc/iview/Controls.kt
+++ b/src/main/kotlin/sc/iview/Controls.kt
@@ -240,13 +240,15 @@ open class Controls(val sciview: SciView) {
     private fun enableArcBallControl() {
         val h = inputHandler

-        val target: Vector3f = sciview.activeNode?.position ?: Vector3f(0.0f, 0.0f, 0.0f)
+        // please REVIEW (I'm no good at Kotlin):
+        // the original `position` is deprecated, was underlined in IDE
+        val target: Vector3f = sciview.activeNode?.spatialOrNull()?.position ?: Vector3f(0.0f, 0.0f, 0.0f)

         //setup ArcballCameraControl from scenery, register it with SciView's parameters
         val cameraSupplier = { sciview.currentScene.findObserver() }
-        val initAction = { _: Int, _: Int -> }
+        val initAction = { _: Int, _: Int -> sciview.centerOnActiveNode() } //DA FIX
         val scrollAction = { _: Double, _: Boolean, _: Int, _:Int -> }

         targetArcball = AnimatedCenteringBeforeArcBallControl(
                 initAction,
                 scrollAction,

this does the reasonably fast move to first make the active/selected obj in view centre and then runs the usual arcball on it; the issue was that the first part was skipped (scene jumped)

the initial movement itself may be cumbersome to some users, may be an optional tick in some future ControlsPref

xulman commented 1 year ago

I would have submitted PR right away, but I need

kephale commented 1 year ago

@skalarproduktraum @moreApi see the above request for Kotlin feedback

moreApi commented 1 year ago

The kotlin part looks good. I can't say anytging about the other question.

xulman commented 1 year ago

The kotlin part looks good. I can't say anytging about the other question.

Thank you @moreApi for the review

.... I was apparently lucky in my Kotlin syntax guessing ;-)

xulman commented 1 year ago

as for the second part, the current implementation of AnimatedCenteringBeforeArcBallControl is basically only wrapping around ArcballCameraControl and, if the former is plain-initiated, does nothing more than the later, brings no extra functionality....; my modification upgrades from the plain-initiation to one where one-time init-phase does call centerOnActiveNode() before it passes control to the ArcballCameraControl; apart from that it leaves the implementation of AnimatedCenteringBeforeArcBallControl untouched

kephale commented 1 year ago

@xulman I'm familiar with what you're talking about and support the extra centerOnActiveNode() call. I'm very used to "just click on the scene and wiggle your mouse around until the Node shows up" but it shouldn't be like that.