diff options
Diffstat (limited to 'src/raycast.zig')
| -rw-r--r-- | src/raycast.zig | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/raycast.zig b/src/raycast.zig index 1f1fd7f..41458c7 100644 --- a/src/raycast.zig +++ b/src/raycast.zig @@ -47,7 +47,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { acc_x: f32 = 0, acc_y: f32 = 0, fov: f32 = std.math.pi / 3.0, - height: f32 = 1.8, // TODO + height: f32 = 1.8 / 2.5, // TODO z_buffer: std.BoundedArray(f32, PlanePixels), const FOV: f32 = std.math.pi / 3.0; @@ -107,16 +107,15 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { self.renderObjects(window, objects_sprite, renderSlice, map); } - fn playerDistComp(self: @This(), lhs: Object, rhs: Object) bool { - const lx = lhs.pos_x - self.pos_x; - const ly = lhs.pos_y - self.pos_y; - const rx = rhs.pos_x - self.pos_x; - const ry = rhs.pos_y - self.pos_y; + fn playerDistComp(pos : [2]f32, lhs: Object, rhs: Object) bool { + const lx = lhs.pos_x - pos[0]; + const ly = lhs.pos_y - pos[1]; + const rx = rhs.pos_x - pos[0]; + const ry = rhs.pos_y - pos[1]; - return (lx * lx + ly * ly < rx * rx + ry * ry); + return (lx * lx + ly * ly > rx * rx + ry * ry); } - // Assumes objects are sorted by proximity! fn renderObjects( self: @This(), window: RenderWindow, @@ -124,7 +123,11 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { renderSlice: RenderSliceFunction, map: Map, ) void { - //std.sort.sort(Object, map.objects.items, {}, self.playerDistComp); + std.sort.sort(Object, map.objects.items, + // Wow, context with an arbitrary type! No macros, just + // Zig all the way down! + [2]f32{self.pos_x, self.pos_y}, + playerDistComp); const self_cos = std.math.cos(self.ang); const self_sin = std.math.sin(self.ang); @@ -349,7 +352,7 @@ pub fn Player(PlaneWidth: f32, PlaneHeight: f32) type { if (map.inBounds(ix, iy)) { const tex = @as(c_uint, map.lookup(ix, iy).floor_texture); - const toff = tex * @floatToInt(c_uint, 1 + TextureDim); + const toff = tex * @floatToInt(c_uint, TextureDim); const px = @floatToInt(c_uint, TextureDim * std.math.fabs(sx.fpart)); const py = @floatToInt(c_uint, TextureDim * std.math.fabs(sy.fpart)); |
