[orx-camera] Enable toggling user interaction in OrbitalControls (#276)
This commit is contained in:
@@ -8,7 +8,11 @@ import kotlin.math.PI
|
||||
import kotlin.math.abs
|
||||
import kotlin.math.tan
|
||||
|
||||
class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boolean = true, val keySpeed: Double = 1.0) : Extension {
|
||||
class OrbitalControls(
|
||||
val orbitalCamera: OrbitalCamera,
|
||||
var userInteraction: Boolean = true,
|
||||
val keySpeed: Double = 1.0
|
||||
) : Extension {
|
||||
enum class STATE {
|
||||
NONE,
|
||||
ROTATE,
|
||||
@@ -22,7 +26,7 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo
|
||||
private lateinit var lastMousePosition: Vector2
|
||||
|
||||
private fun mouseScrolled(event: MouseEvent) {
|
||||
if (!event.propagationCancelled) {
|
||||
if (userInteraction && !event.propagationCancelled) {
|
||||
|
||||
if (orbitalCamera.projectionType == ProjectionType.PERSPECTIVE) {
|
||||
if (abs(event.rotation.x) > 0.1) return
|
||||
@@ -42,7 +46,7 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo
|
||||
|
||||
private fun mouseMoved(event: MouseEvent) {
|
||||
|
||||
if (!event.propagationCancelled) {
|
||||
if (userInteraction && !event.propagationCancelled) {
|
||||
if (state == STATE.NONE) return
|
||||
val delta = lastMousePosition - event.position
|
||||
lastMousePosition = event.position
|
||||
@@ -67,7 +71,7 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo
|
||||
}
|
||||
|
||||
private fun mouseButtonDown(event: MouseEvent) {
|
||||
if (!event.propagationCancelled) {
|
||||
if (userInteraction && !event.propagationCancelled) {
|
||||
val previousState = state
|
||||
|
||||
when (event.button) {
|
||||
@@ -90,7 +94,7 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo
|
||||
}
|
||||
|
||||
fun keyPressed(keyEvent: KeyEvent) {
|
||||
if (!keyEvent.propagationCancelled) {
|
||||
if (userInteraction && !keyEvent.propagationCancelled) {
|
||||
if (keyEvent.key == KEY_ARROW_RIGHT) {
|
||||
orbitalCamera.pan(keySpeed, 0.0, 0.0)
|
||||
}
|
||||
@@ -138,13 +142,11 @@ class OrbitalControls(val orbitalCamera: OrbitalCamera, val userInteraction: Boo
|
||||
override fun setup(program: Program) {
|
||||
this.program = program
|
||||
|
||||
if (userInteraction) {
|
||||
program.mouse.moved.listen { mouseMoved(it) }
|
||||
program.mouse.buttonDown.listen { mouseButtonDown(it) }
|
||||
program.mouse.buttonUp.listen { state = STATE.NONE }
|
||||
program.mouse.scrolled.listen { mouseScrolled(it) }
|
||||
program.keyboard.keyDown.listen { keyPressed(it) }
|
||||
program.keyboard.keyRepeat.listen { keyPressed(it) }
|
||||
}
|
||||
program.mouse.moved.listen { mouseMoved(it) }
|
||||
program.mouse.buttonDown.listen { mouseButtonDown(it) }
|
||||
program.mouse.buttonUp.listen { state = STATE.NONE }
|
||||
program.mouse.scrolled.listen { mouseScrolled(it) }
|
||||
program.keyboard.keyDown.listen { keyPressed(it) }
|
||||
program.keyboard.keyRepeat.listen { keyPressed(it) }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user