diff options
| author | tslil clingman <> | 2021-10-10 12:58:17 -0400 |
|---|---|---|
| committer | tslil clingman <> | 2021-10-10 12:58:17 -0400 |
| commit | 442f7210ea40f7f74b752575ee81b5f9394d6ea9 (patch) | |
| tree | d574ea52911950036760d0112f74c723718d77a3 | |
| parent | 1aad9b2a1c5e86c8c6ea635772db5ddb20af39ed (diff) | |
Off by ones!
| -rw-r--r-- | src/player.zig | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/player.zig b/src/player.zig index 8fe0002..7a94b7b 100644 --- a/src/player.zig +++ b/src/player.zig @@ -255,9 +255,9 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { }) { const index = col * @floatToInt(usize, PlaneHeight) + @floatToInt(usize, bottom); if (self.z_buffer[index] > scaled_perp_distance) { - const tx = @floatToInt(c_uint, tex_frac * constants.TextureDim); + const tx = @floatToInt(c_uint, tex_frac * (constants.TextureDim - 1)); const toff = obj.texture * @floatToInt(c_uint, constants.TextureDim); - const ty = @floatToInt(c_uint, texel_y * constants.TextureDim); + const ty = @floatToInt(c_uint, texel_y * (constants.TextureDim - 1)); const texel = objects_image.getPixel(.{ .x = toff + tx, .y = ty }); const pix_index = @floatToInt(usize, PlaneWidth) * pix_y + col; // TODO: Decide whether being accurate is as important as being fast @@ -371,8 +371,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { // we also want to be sure that we're consistently orienting // textures, in this case clockwise if ((horizontal_hit and sinra < 0) or (!horizontal_hit and cosra > 0)) texfrac = 1 - texfrac; - if (texfrac == 1) texfrac = 0.9999; // i think this caused a crash at one point - const texstrip = @floatToInt(c_uint, constants.TextureDim * texfrac); + const texstrip = @floatToInt(c_uint, (constants.TextureDim - 1) * texfrac); // height of a unit-height wall at this distance const nominal_length = PlaneDist / distance; @@ -397,7 +396,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { pix_y += 1; texel_y += inv_nom_len; }) { - const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * (constants.TextureDim - 1)); + const ty = @floatToInt(c_uint, std.math.modf(texel_y).fpart * constants.TextureDim); const texel = walls_image.getPixel(.{ .x = t_lower_off + texstrip, .y = ty }); const pix_index = pix_y * @floatToInt(usize, PlaneWidth) + col; @@ -484,7 +483,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { if (cell.draw_down and next_bottom < lowest_drawn) { bottom_of_ceiling = std.math.ceil(lowest_drawn); const thresh = std.math.max(std.math.max(next_bottom, highest_drawn), PlaneHeight / 2) - 1; - while (bottom_of_ceiling >= thresh) : (bottom_of_ceiling -= 1) { + while (bottom_of_ceiling > thresh) : (bottom_of_ceiling -= 1) { const row_dist = (cell.ceiling_height - self.height) * PlaneDist / (bottom_of_ceiling - PlaneHeight / 2); const ptop = @floatToInt(usize, bottom_of_ceiling); const itop = @floatToInt(usize, PlaneHeight) - ptop; |
