aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/CameraController.kt
diff options
context:
space:
mode:
authorJames Barnett <noreply@jamesbarnett.xyz>2020-12-30 23:13:40 +0000
committerJames Barnett <noreply@jamesbarnett.xyz>2020-12-30 23:13:40 +0000
commit3c3322ef1a7aca3517ff94f723004fb809dec6cd (patch)
treefd195eeedbb03cea8b25795b5e3c8fcf1a10c05c /src/main/kotlin/CameraController.kt
parentc05b68f786715b20d0a9aef6538141c4227642ae (diff)
downloadkotlin-raycaster-3c3322ef1a7aca3517ff94f723004fb809dec6cd.tar.xz
kotlin-raycaster-3c3322ef1a7aca3517ff94f723004fb809dec6cd.zip
Add adjustable render options. Update UI
Diffstat (limited to 'src/main/kotlin/CameraController.kt')
-rw-r--r--src/main/kotlin/CameraController.kt15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/main/kotlin/CameraController.kt b/src/main/kotlin/CameraController.kt
index 436b34b..510f1a0 100644
--- a/src/main/kotlin/CameraController.kt
+++ b/src/main/kotlin/CameraController.kt
@@ -1,4 +1,5 @@
import kotlinx.browser.document
+import org.w3c.dom.HTMLButtonElement
class CameraController(
private val camera: Camera,
@@ -8,18 +9,20 @@ class CameraController(
) {
init {
- document.onkeydown = { inputHandler(it.code) }
+ document.onkeydown = { keyHandler(it.code) }
+ (document.getElementById("up") as HTMLButtonElement).onclick = { moveForward() }
+ (document.getElementById("down") as HTMLButtonElement).onclick = { moveBack() }
+ (document.getElementById("left") as HTMLButtonElement).onclick = { rotateAntiClockwise() }
+ (document.getElementById("right") as HTMLButtonElement).onclick = { rotateClockwise() }
}
- private fun inputHandler(code: String) {
+ private fun keyHandler(code: String) {
when (code) {
"KeyW" -> moveForward()
"KeyS" -> moveBack()
"KeyA" -> rotateAntiClockwise()
"KeyD" -> rotateClockwise()
}
- afterInput()
- console.log("x: ${camera.xPos} y: ${camera.yPos} r: ${camera.rotation}")
}
private fun moveForward() {
@@ -27,6 +30,7 @@ class CameraController(
val cameraSin = camera.rotation.sine() * moveSpeed
camera.xPos += cameraCos
camera.yPos += cameraSin
+ afterInput()
}
private fun moveBack() {
@@ -34,14 +38,17 @@ class CameraController(
val cameraSin = camera.rotation.sine() * moveSpeed
camera.xPos -= cameraCos
camera.yPos -= cameraSin
+ afterInput()
}
private fun rotateClockwise() {
camera.rotation += rotateSpeed
+ afterInput()
}
private fun rotateAntiClockwise() {
camera.rotation -= rotateSpeed
+ afterInput()
}
} \ No newline at end of file