From 9e886b392fbc6f8dfac1ce8f6943a7a1679bce74 Mon Sep 17 00:00:00 2001 From: James Barnett Date: Mon, 28 Dec 2020 16:25:19 +0000 Subject: Refactor input handling. General cleanup --- src/main/kotlin/Raycaster.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/main/kotlin/Raycaster.kt') diff --git a/src/main/kotlin/Raycaster.kt b/src/main/kotlin/Raycaster.kt index d3fa694..640ffef 100644 --- a/src/main/kotlin/Raycaster.kt +++ b/src/main/kotlin/Raycaster.kt @@ -9,7 +9,7 @@ class Raycaster(private val stepPrecision: Int = 32) { val viewportHeight = renderer.viewportHeight val viewportHeightHalf = viewportHeight / 2 - var raySweepAngle = camera.rotation - camera.halfFov + var raySweepAngle = camera.rotation - (camera.fov / 2) for (rayIndex in 0 until viewportWidth) { @@ -17,8 +17,8 @@ class Raycaster(private val stepPrecision: Int = 32) { var rayY = camera.yPos do { - rayX += kotlin.math.cos(toRadians(raySweepAngle)) / stepPrecision - rayY += kotlin.math.sin(toRadians(raySweepAngle)) / stepPrecision + rayX += raySweepAngle.cosine() / stepPrecision + rayY += raySweepAngle.sine() / stepPrecision // TODO bounds checking val wallHit = map.data[kotlin.math.floor(rayY).toInt()][kotlin.math.floor(rayX).toInt()] > 0 } while (!wallHit) -- cgit v1.2.3