Skip to content

Commit

Permalink
Rename VR controller bindings using TrackerRole and OpenVRButton
Browse files Browse the repository at this point in the history
  • Loading branch information
smlpt committed Dec 9, 2024
1 parent 148ceb5 commit 09d3e9e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
35 changes: 19 additions & 16 deletions src/main/kotlin/sc/iview/commands/demo/advanced/CellTrackingBase.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package sc.iview.commands.demo.advanced

import com.intellij.ui.tabs.impl.ShapeTransform.Right
import graphics.scenery.*
import graphics.scenery.controls.OpenVRHMD
import graphics.scenery.controls.TrackerRole
Expand All @@ -11,6 +12,7 @@ import graphics.scenery.utils.extensions.minus
import graphics.scenery.utils.lazyLogger
import graphics.scenery.volumes.RAIVolume
import graphics.scenery.volumes.Volume
import org.apache.commons.math3.geometry.partitioning.Side
import org.joml.Math
import org.joml.Matrix4f
import org.joml.Vector3f
Expand Down Expand Up @@ -103,13 +105,14 @@ open class CellTrackingBase(

sciview.sceneryInputHandler?.let { handler ->
hashMapOf(
"move_forward_fast" to "K",
"move_back_fast" to "J",
"move_left_fast" to "H",
"move_right_fast" to "L").forEach { (name, key) ->
"move_forward_fast" to (TrackerRole.LeftHand to OpenVRHMD.OpenVRButton.Up),
"move_back_fast" to (TrackerRole.LeftHand to OpenVRHMD.OpenVRButton.Down),
"move_left_fast" to (TrackerRole.LeftHand to OpenVRHMD.OpenVRButton.Left),
"move_right_fast" to (TrackerRole.LeftHand to OpenVRHMD.OpenVRButton.Right)).forEach { (name, key) ->
handler.getBehaviour(name)?.let { b ->
hmd.addBehaviour(name, b)
hmd.addKeyBinding(name, key)
hmd.addKeyBinding(name, key.first, key.second)

}
}
}
Expand Down Expand Up @@ -227,22 +230,22 @@ open class CellTrackingBase(
hmd.addBehaviour("slower_or_scale", slowerOrScale)
hmd.addBehaviour("play_pause", playPause)
hmd.addBehaviour("toggle_hedgehog", toggleHedgehog)
hmd.addBehaviour("trigger_move", move)
hmd.addBehaviour("delete_hedgehog", deleteLastHedgehog)
hmd.addBehaviour("trigger_move", move)
hmd.addBehaviour("cell_division", cellDivision)

hmd.addKeyBinding("toggle_hedgehog", "X")
hmd.addKeyBinding("delete_hedgehog", "Y")
hmd.addKeyBinding("skip_to_next", "D")
hmd.addKeyBinding("skip_to_prev", "A")
hmd.addKeyBinding("faster_or_scale", "W")
hmd.addKeyBinding("slower_or_scale", "S")
hmd.addKeyBinding("play_pause", "M")
hmd.addKeyBinding("playback_direction", "N")
hmd.addKeyBinding("cell_division", "T")
hmd.addKeyBinding("skip_to_next", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Right)
hmd.addKeyBinding("skip_to_prev", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Left)
hmd.addKeyBinding("faster_or_scale", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Up)
hmd.addKeyBinding("slower_or_scale", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Down)
hmd.addKeyBinding("play_pause", TrackerRole.LeftHand, OpenVRHMD.OpenVRButton.Menu)
hmd.addKeyBinding("toggle_hedgehog", TrackerRole.LeftHand, OpenVRHMD.OpenVRButton.Side)
hmd.addKeyBinding("delete_hedgehog", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Side)
hmd.addKeyBinding("playback_direction", TrackerRole.RightHand, OpenVRHMD.OpenVRButton.Menu)
hmd.addKeyBinding("cell_division", TrackerRole.LeftHand, OpenVRHMD.OpenVRButton.Trigger)

hmd.allowRepeats += OpenVRHMD.OpenVRButton.Trigger to TrackerRole.LeftHand
logger.info("calibration should start now")
logger.info("Registered VR controller bindings.")

}

Expand Down
11 changes: 8 additions & 3 deletions src/main/kotlin/sc/iview/commands/demo/advanced/EyeTracking.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package sc.iview.commands.demo.advanced
import graphics.scenery.*
import graphics.scenery.attribute.material.Material
import graphics.scenery.controls.OpenVRHMD
import graphics.scenery.controls.OpenVRHMD.OpenVRButton
import graphics.scenery.controls.TrackedDeviceType
import graphics.scenery.controls.TrackerRole
import graphics.scenery.controls.eyetracking.PupilEyeTracker
import graphics.scenery.primitives.Cylinder
import graphics.scenery.primitives.TextBoard
Expand Down Expand Up @@ -182,7 +184,10 @@ class EyeTracking(
}


private fun setupCalibration(keybindingCalibration: String = "N", keybindingTracking: String = "U") {
private fun setupCalibration(
keybindingCalibration: Pair<TrackerRole, OpenVRButton> = (TrackerRole.RightHand to OpenVRButton.Menu),
keybindingTracking: Pair<TrackerRole, OpenVRButton> = (TrackerRole.RightHand to OpenVRButton.Trigger)
) {
val startCalibration = ClickBehaviour { _, _ ->
thread {
val cam = sciview.camera as? DetachedHeadCamera ?: return@thread
Expand Down Expand Up @@ -225,7 +230,7 @@ class EyeTracking(
tracking = !tracking
}
hmd.addBehaviour("toggle_tracking", toggleTracking)
hmd.addKeyBinding("toggle_tracking", keybindingTracking)
hmd.addKeyBinding("toggle_tracking", keybindingTracking.first, keybindingTracking.second)

volume.visible = true
playing = true
Expand Down Expand Up @@ -265,7 +270,7 @@ class EyeTracking(
}
}
hmd.addBehaviour("start_calibration", startCalibration)
hmd.addKeyBinding("start_calibration", keybindingCalibration)
hmd.addKeyBinding("start_calibration", keybindingCalibration.first, keybindingCalibration.second)
}

/** Toggles the VR rendering off, cleans up eyetracking-related scene objects and removes the light tetrahedron
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package sc.iview.commands.demo.advanced
import graphics.scenery.*
import graphics.scenery.attribute.material.Material
import graphics.scenery.controls.OpenVRHMD
import graphics.scenery.controls.OpenVRHMD.OpenVRButton
import graphics.scenery.controls.TrackedDevice
import graphics.scenery.controls.TrackedDeviceType
import graphics.scenery.controls.TrackerRole
import graphics.scenery.primitives.Cylinder
import graphics.scenery.primitives.TextBoard
import graphics.scenery.utils.SystemHelpers
Expand Down Expand Up @@ -119,7 +121,9 @@ class VRControllerTracking(
launchUpdaterThread()
}

private fun setupControllerforTracking( keybindingTracking: String = "U") {
private fun setupControllerforTracking(
keybindingTracking: Pair<TrackerRole, OpenVRButton> = (TrackerRole.RightHand to OpenVRButton.Trigger)
) {

thread {
val cam = sciview.camera as? DetachedHeadCamera ?: return@thread
Expand All @@ -140,7 +144,7 @@ class VRControllerTracking(
}
}
hmd.addBehaviour("toggle_tracking", toggleTracking)
hmd.addKeyBinding("toggle_tracking", keybindingTracking)
hmd.addKeyBinding("toggle_tracking", keybindingTracking.first, keybindingTracking.second)

volume.visible = true
volume.runRecursive { it.visible = true }
Expand Down

0 comments on commit 09d3e9e

Please sign in to comment.