diff options
| author | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-28 16:25:19 +0000 |
|---|---|---|
| committer | James Barnett <noreply@jamesbarnett.xyz> | 2020-12-28 16:25:19 +0000 |
| commit | 9e886b392fbc6f8dfac1ce8f6943a7a1679bce74 (patch) | |
| tree | 81ff992d818b5aa92090b6c02f5685e08bb6fdab /src/main/kotlin/Raycaster.kt | |
| parent | f28500d963d6546feda522d7748a0462a568ba28 (diff) | |
| download | kotlin-raycaster-9e886b392fbc6f8dfac1ce8f6943a7a1679bce74.tar.xz kotlin-raycaster-9e886b392fbc6f8dfac1ce8f6943a7a1679bce74.zip | |
Refactor input handling. General cleanup
Diffstat (limited to 'src/main/kotlin/Raycaster.kt')
| -rw-r--r-- | src/main/kotlin/Raycaster.kt | 6 |
1 files changed, 3 insertions, 3 deletions
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) |