Skip to content

Commit

Permalink
Merge pull request #554 from scenerygraphics/arcballreset-movement
Browse files Browse the repository at this point in the history
Move arcball target as user translates camera
  • Loading branch information
kephale authored Feb 20, 2024
2 parents a41f0b8 + 8cc6a25 commit 514a33e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 34 deletions.
62 changes: 31 additions & 31 deletions src/main/kotlin/sc/iview/Controls.kt
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,19 @@ open class Controls(val sciview: SciView) {
//unused until some reasonable action (to the selection) would be provided
//behaviourMap.put("select_command", SelectCommand("select_command", renderer, scene, { scene.findObserver() }))

sciview.sceneryInputHandler?.addBehaviour("move_forward", MovementCommand("forward", { sciview.currentScene.findObserver() }, slowMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_back", MovementCommand("back", { sciview.currentScene.findObserver() }, slowMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_left", MovementCommand("left", { sciview.currentScene.findObserver() }, slowMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_right", MovementCommand("right", { sciview.currentScene.findObserver() }, slowMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_up", MovementCommand("up", { sciview.currentScene.findObserver() }, slowMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_down", MovementCommand("down", { sciview.currentScene.findObserver() }, slowMovementSpeed))

sciview.sceneryInputHandler?.addBehaviour("move_forward_fast", MovementCommand("forward", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_back_fast", MovementCommand("back", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_left_fast", MovementCommand("left", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_right_fast", MovementCommand("right", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_up_fast", MovementCommand("up", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_down_fast", MovementCommand("down", { sciview.currentScene.findObserver() }, fastMovementSpeed))
sciview.sceneryInputHandler?.addBehaviour("move_forward", ArcballResetMovementCommand("forward", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_back", ArcballResetMovementCommand("back", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_left", ArcballResetMovementCommand("left", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_right", ArcballResetMovementCommand("right", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_up", ArcballResetMovementCommand("up", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_down", ArcballResetMovementCommand("down", { sciview.currentScene.findObserver() }, slowMovementSpeed, sciview))

sciview.sceneryInputHandler?.addBehaviour("move_forward_fast", ArcballResetMovementCommand("forward", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_back_fast", ArcballResetMovementCommand("back", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_left_fast", ArcballResetMovementCommand("left", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_right_fast", ArcballResetMovementCommand("right", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_up_fast", ArcballResetMovementCommand("up", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))
sciview.sceneryInputHandler?.addBehaviour("move_down_fast", ArcballResetMovementCommand("down", { sciview.currentScene.findObserver() }, fastMovementSpeed, sciview))

sciview.sceneryInputHandler?.addBehaviour("toggle_debug", ToggleCommand(sciview.getSceneryRenderer()!!, "toggleDebug"))
sciview.sceneryInputHandler?.addBehaviour("toggle_fullscreen", ToggleCommand(sciview.getSceneryRenderer()!!, "toggleFullscreen"))
Expand Down Expand Up @@ -414,10 +414,10 @@ open class Controls(val sciview: SciView) {
var mcA: MovementCommand
var mcS: MovementCommand
var mcD: MovementCommand
mcW = MovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcS = MovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcA = MovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcD = MovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcW = ArcballResetMovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
mcS = ArcballResetMovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
mcA = ArcballResetMovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
mcD = ArcballResetMovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
parameters.registerSlowStepMover(mcW)
parameters.registerSlowStepMover(mcS)
parameters.registerSlowStepMover(mcA)
Expand All @@ -429,10 +429,10 @@ open class Controls(val sciview: SciView) {
// 'WASD' keys are registered already in scenery

//override shift+'WASD' from Scenery
mcW = MovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcS = MovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcA = MovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcD = MovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcW = ArcballResetMovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
mcS = ArcballResetMovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
mcA = ArcballResetMovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
mcD = ArcballResetMovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
parameters.registerFastStepMover(mcW)
parameters.registerFastStepMover(mcS)
parameters.registerFastStepMover(mcA)
Expand All @@ -444,10 +444,10 @@ open class Controls(val sciview: SciView) {
// shift+'WASD' keys are registered already in scenery

//define additionally shift+ctrl+'WASD'
mcW = MovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcS = MovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcA = MovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcD = MovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcW = ArcballResetMovementCommand("forward", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
mcS = ArcballResetMovementCommand("back", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
mcA = ArcballResetMovementCommand("left", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
mcD = ArcballResetMovementCommand("right", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
parameters.registerVeryFastStepMover(mcW)
parameters.registerVeryFastStepMover(mcS)
parameters.registerVeryFastStepMover(mcA)
Expand All @@ -464,24 +464,24 @@ open class Controls(val sciview: SciView) {
// Keyboard only move up/down (XC keys)
//
//[[ctrl]+shift]+'XC'
mcW = MovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcS = MovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow)
mcW = ArcballResetMovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
mcS = ArcballResetMovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedSlow, sciview)
parameters.registerSlowStepMover(mcW)
parameters.registerSlowStepMover(mcS)
h.addBehaviour("move_up", mcW)
h.addBehaviour("move_down", mcS)
h.addKeyBinding("move_up", "C")
h.addKeyBinding("move_down", "X")
mcW = MovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcS = MovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast)
mcW = ArcballResetMovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
mcS = ArcballResetMovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedFast, sciview)
parameters.registerFastStepMover(mcW)
parameters.registerFastStepMover(mcS)
h.addBehaviour("move_up_fast", mcW)
h.addBehaviour("move_down_fast", mcS)
h.addKeyBinding("move_up_fast", "shift C")
h.addKeyBinding("move_down_fast", "shift X")
mcW = MovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcS = MovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast)
mcW = ArcballResetMovementCommand("up", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
mcS = ArcballResetMovementCommand("down", { sciview.currentScene.findObserver() }, parameters.fpsSpeedVeryFast, sciview)
parameters.registerVeryFastStepMover(mcW)
parameters.registerVeryFastStepMover(mcS)
h.addBehaviour("move_up_veryfast", mcW)
Expand Down
1 change: 0 additions & 1 deletion src/main/kotlin/sc/iview/SciView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,6 @@ class SciView : SceneryBase, CalibratedRealInterval<CalibratedAxis> {
* @return the currently active node
*/
fun setActiveNode(n: Node?): Node? {
if (activeNode === n) return activeNode
activeNode = n
targetArcball.target = { n?.getMaximumBoundingBox()?.getBoundingSphere()?.origin ?: Vector3f(0.0f, 0.0f, 0.0f) }
mainWindow.selectNode(activeNode)
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/sc/iview/commands/edit/Properties.kt
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ class Properties : InteractiveCommand() {
}

// update property fields according to scene node properties
sciView.setActiveNode(currentSceneNode)
updateCommandFields()
if (sceneNodeChoices.size != sciView.getSceneNodes { _: Node? -> true }.size) {
rebuildSceneObjectChoiceList()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package sc.iview.controls.behaviours
import graphics.scenery.Camera
import graphics.scenery.Node
import graphics.scenery.controls.behaviours.MovementCommand
import graphics.scenery.utils.extensions.minus
import graphics.scenery.utils.extensions.plus
import graphics.scenery.utils.extensions.times
import org.joml.Vector3f
import sc.iview.SciView

class ArcballResetMovementCommand(
direction: String,
n: () -> Node?,
speed: Float,
private val sciview: SciView
) : MovementCommand(direction, n, speed) {

@Synchronized override fun click(x: Int, y: Int) {
// First, call the superclass method to handle the movement
super.click(x, y)

// Now, handle the arcball reset
// Since you can't directly access the 'node', use 'n()' to get the current Node, which should be the Camera
val cameraNode = sciview.camera

// Assuming SciView has a method to get the camera and its position
// And assuming 'targetArcball' is a feature of SciView you want to update
val currentDistance = sciview.targetArcball.distance // Example to access current distance
val newTargetPosition = cameraNode!!.spatial().position + cameraNode.forward.mul(currentDistance, Vector3f())

// Update the targetArcball's target to the new position
// This assumes that 'targetArcball.target' is a setter method or lambda you can update
sciview.targetArcball.target = { newTargetPosition }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ class CameraTranslateControl(protected val sciView: SciView, var dragSpeed: Floa
lastX = x
lastY = y



//set up (the current) shortcuts to the FPS movement routines
val inputHandler = sciView.sceneryInputHandler!!
move_left_slow = inputHandler.getBehaviour("move_left") as ClickBehaviour
Expand Down

0 comments on commit 514a33e

Please sign in to comment.