diff options
| author | tslil clingman <> | 2021-10-08 21:38:41 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2021-10-08 21:38:41 -0400 |
| commit | 1aad9b2a1c5e86c8c6ea635772db5ddb20af39ed (patch) | |
| tree | 8c9d2c77bfdbe6c1d645cac9fed506e4c980bf17 /src | |
| parent | d4f2376bb0ea219b79dac3f4f37b77342ca6ef4a (diff) | |
Fixed some artefacts for walls with both lower and upper parts
I can't quite explain it, but something about the way floating point
numbers round meant that we weren't calculating consistent
distances (in pixels) for the length of the strip between the top of
the floor and the bottom of the ceiling in cells which had both.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.zig | 5 | ||||
| -rw-r--r-- | src/player.zig | 11 |
2 files changed, 9 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig index d76e424..3c425ba 100644 --- a/src/main.zig +++ b/src/main.zig @@ -62,14 +62,13 @@ pub fn main() !void { } } - map.cells.items[16 * 7 + 7] = level.Cell{ .floor_height = level.Cell.DEFAULT_HEIGHT, .lower_texture = 1 }; - map.cells.items[16 * 7 + 6] = level.Cell{ + map.cells.items[16 * 7 + 7] = level.Cell{ .floor_height = 0.5, .ceiling_height = 2, .lower_texture = 1, .upper_texture = 1, .floor_texture = 1, - .ceiling_texture = 1, + .ceiling_texture = 2, .draw_down = true, }; diff --git a/src/player.zig b/src/player.zig index c8fc4df..8fe0002 100644 --- a/src/player.zig +++ b/src/player.zig @@ -383,13 +383,16 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { if (draw_lower) { // which texture index? const t_lower_off = cell.lower_texture * td; - // now we have what we need to draw the face, and - // update the z-buffer - const constrained_top = std.math.min(top_of_floor, lowest_drawn); + // Note the bizarre rounding we have to do to avoid artifacts + const constrained_top = std.math.min(std.math.floor(top_of_floor), std.math.ceil(lowest_drawn)); + const stop = @floatToInt(i32, highest_drawn); var zb_y = @floatToInt(i32, constrained_top); var pix_y = @floatToInt(usize, std.math.ceil(std.math.max(PlaneHeight - constrained_top, 0))); var texel_y = (top_of_floor - constrained_top) / nominal_length; - while (zb_y > @floatToInt(i32, highest_drawn)) : ({ + + // now we have what we need to draw the face, + // and update the z-buffer + while (zb_y > stop) : ({ zb_y -= 1; pix_y += 1; texel_y += inv_nom_len; |
