diff options
| author | salmonik <raisersoft@proton.me> | 2026-07-09 23:30:38 +0200 |
|---|---|---|
| committer | salmonik <raisersoft@proton.me> | 2026-07-09 23:30:38 +0200 |
| commit | 26bec7cc6aa9a67b918bd35a33772baecacb1dc3 (patch) | |
| tree | 1c6cac89a97900f213b868477006d44266d2b8d3 | |
| parent | no crosshair (diff) | |
| download | dungeon-26bec7cc6aa9a67b918bd35a33772baecacb1dc3.tar.gz dungeon-26bec7cc6aa9a67b918bd35a33772baecacb1dc3.zip | |
fix floor warping
| -rw-r--r-- | src/renderer.rs | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/src/renderer.rs b/src/renderer.rs index 3ab67d6..bce3391 100644 --- a/src/renderer.rs +++ b/src/renderer.rs | |||
| @@ -46,6 +46,14 @@ impl Renderer { | |||
| 46 | let rdx = ray_angle.cos(); | 46 | let rdx = ray_angle.cos(); |
| 47 | let rdy = ray_angle.sin(); | 47 | let rdy = ray_angle.sin(); |
| 48 | 48 | ||
| 49 | // Floor uses perpendicular distance from the LUT, but needs | ||
| 50 | // Euclidean distance for correct world-position projection. | ||
| 51 | // Scale by 1/cos(angle_diff) so that rdx_floor / rdy_floor | ||
| 52 | // map floor_dist → Euclidean travel along the ray. | ||
| 53 | let cos_diff = (ray_angle - game.player.angle).cos().abs().max(0.001); | ||
| 54 | let rdx_floor = rdx / cos_diff; | ||
| 55 | let rdy_floor = rdy / cos_diff; | ||
| 56 | |||
| 49 | // ---- DDA setup ------------------------------------------------- | 57 | // ---- DDA setup ------------------------------------------------- |
| 50 | let mut map_x = game.player.x as isize; | 58 | let mut map_x = game.player.x as isize; |
| 51 | let mut map_y = game.player.y as isize; | 59 | let mut map_y = game.player.y as isize; |
| @@ -151,8 +159,8 @@ impl Renderer { | |||
| 151 | let gray = darken_fx(0xFF80_8080, self.floor_bright_lut[py]); | 159 | let gray = darken_fx(0xFF80_8080, self.floor_bright_lut[py]); |
| 152 | buffer[py * self.screen_w + sx] = gray; | 160 | buffer[py * self.screen_w + sx] = gray; |
| 153 | } else { | 161 | } else { |
| 154 | let fx = game.player.x + floor_dist * rdx; | 162 | let fx = game.player.x + floor_dist * rdx_floor; |
| 155 | let fy = game.player.y + floor_dist * rdy; | 163 | let fy = game.player.y + floor_dist * rdy_floor; |
| 156 | 164 | ||
| 157 | let ftx = ((fx.fract().abs() * TEX_SIZE as f64) as usize).min(TEX_SIZE - 1); | 165 | let ftx = ((fx.fract().abs() * TEX_SIZE as f64) as usize).min(TEX_SIZE - 1); |
| 158 | let fty = ((fy.fract().abs() * TEX_SIZE as f64) as usize).min(TEX_SIZE - 1); | 166 | let fty = ((fy.fract().abs() * TEX_SIZE as f64) as usize).min(TEX_SIZE - 1); |
