diff --git a/resources/images/tiles.png b/resources/images/tiles.png index 2198033..1d9be0b 100644 Binary files a/resources/images/tiles.png and b/resources/images/tiles.png differ diff --git a/resources/images/tiles.png.kra b/resources/images/tiles.png.kra index 2a1c535..d842b23 100644 Binary files a/resources/images/tiles.png.kra and b/resources/images/tiles.png.kra differ diff --git a/resources/images/tiles.png.kra~ b/resources/images/tiles.png.kra~ new file mode 100644 index 0000000..2a1c535 Binary files /dev/null and b/resources/images/tiles.png.kra~ differ diff --git a/resources/images/tiles.png~ b/resources/images/tiles.png~ index 6711326..e2f924e 100644 Binary files a/resources/images/tiles.png~ and b/resources/images/tiles.png~ differ diff --git a/src/main.zig b/src/main.zig index 4c1f3d1..7cfc3e1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -74,7 +74,7 @@ pub fn main() !void { const xt: i32 = @as(i32, @intCast(x)) - 16; const yt: i32 = @as(i32, @intCast(y)) - 16; const zt: i32 = @as(i32, @intCast(z)) - 16; - if (xt * xt + yt * yt + zt * zt < 15 * 15) chunk.setTile(x, y, z, 1); + if (xt * xt + yt * yt + zt * zt < 15 * 15) chunk.setTile(x, y, z, if (2 * xt > yt - 30) 1 else 2); }; if (benchmark_chunk_meshing) { diff --git a/src/world/chunk.zig b/src/world/chunk.zig index aa3c9f5..1b6d3d8 100644 --- a/src/world/chunk.zig +++ b/src/world/chunk.zig @@ -95,16 +95,48 @@ pub const Chunk = struct { const zmax: f32 = @as(f32, @floatFromInt(z2)) + 0.5; const yleft: f32 = if (sign == 1) ymin else ymax; const yright: f32 = if (sign == 1) ymax else ymin; - const raw_quad: RawQuad = .{ - .tile = surface, - .top_left = v3.newShifted(xf + 0.5 * sign, yleft, zmin, d), - .top_right = v3.newShifted(xf + 0.5 * sign, yright, zmin, d), - .bottom_left = v3.newShifted(xf + 0.5 * sign, yleft, zmax, d), - .bottom_right = v3.newShifted(xf + 0.5 * sign, yright, zmax, d), - .normal = v3.newShifted(sign, 0, 0, d), - .width = ymax - ymin, - .height = zmax - zmin, - }; + const zleft: f32 = if (sign == 1) zmin else zmax; + const zright: f32 = if (sign == 1) zmax else zmin; + var raw_quad: RawQuad = undefined; + switch (d) { + 0 => { + raw_quad = .{ + .tile = surface, + .top_left = v3.new(xf + 0.5 * sign, ymax, zright), + .top_right = v3.new(xf + 0.5 * sign, ymax, zleft), + .bottom_left = v3.new(xf + 0.5 * sign, ymin, zright), + .bottom_right = v3.new(xf + 0.5 * sign, ymin, zleft), + .normal = v3.new(sign, 0, 0), + .width = zmax - zmin, + .height = ymax - ymin, + }; + }, + 1 => { + raw_quad = .{ + .tile = surface, + .bottom_left = v3.new(yleft, zmin, xf + 0.5 * sign), + .top_left = v3.new(yleft, zmax, xf + 0.5 * sign), + .bottom_right = v3.new(yright, zmin, xf + 0.5 * sign), + .top_right = v3.new(yright, zmax, xf + 0.5 * sign), + .normal = v3.new(0, 0, sign), + .height = zmax - zmin, + .width = ymax - ymin, + }; + }, + 2 => { + raw_quad = .{ + .tile = surface, + .top_left = v3.new(zleft, xf + 0.5 * sign, ymin), + .top_right = v3.new(zright, xf + 0.5 * sign, ymin), + .bottom_left = v3.new(zleft, xf + 0.5 * sign, ymax), + .bottom_right = v3.new(zright, xf + 0.5 * sign, ymax), + .normal = v3.new(0, sign, 0), + .width = zmax - zmin, + .height = ymax - ymin, + }; + }, + else => unreachable, + } try raw_quads.append(raw_quad); }; } @@ -143,21 +175,21 @@ pub const Chunk = struct { texcoords2[12 * i + 0] = 0.0; texcoords2[12 * i + 1] = 0.0; - vertices[18 * i + 3] = raw_quad.top_right.x; - vertices[18 * i + 4] = raw_quad.top_right.y; - vertices[18 * i + 5] = raw_quad.top_right.z; - texcoords[12 * i + 2] = right_uv; - texcoords[12 * i + 3] = top_uv; - texcoords2[12 * i + 2] = raw_quad.width; - texcoords2[12 * i + 3] = 0.0; + vertices[18 * i + 3] = raw_quad.bottom_left.x; + vertices[18 * i + 4] = raw_quad.bottom_left.y; + vertices[18 * i + 5] = raw_quad.bottom_left.z; + texcoords[12 * i + 2] = left_uv; + texcoords[12 * i + 3] = bottom_uv; + texcoords2[12 * i + 2] = 0.0; + texcoords2[12 * i + 3] = raw_quad.height; - vertices[18 * i + 6] = raw_quad.bottom_left.x; - vertices[18 * i + 7] = raw_quad.bottom_left.y; - vertices[18 * i + 8] = raw_quad.bottom_left.z; - texcoords[12 * i + 4] = left_uv; - texcoords[12 * i + 5] = bottom_uv; - texcoords2[12 * i + 4] = 0.0; - texcoords2[12 * i + 5] = raw_quad.height; + vertices[18 * i + 6] = raw_quad.top_right.x; + vertices[18 * i + 7] = raw_quad.top_right.y; + vertices[18 * i + 8] = raw_quad.top_right.z; + texcoords[12 * i + 4] = right_uv; + texcoords[12 * i + 5] = top_uv; + texcoords2[12 * i + 4] = raw_quad.width; + texcoords2[12 * i + 5] = 0.0; vertices[18 * i + 9] = raw_quad.bottom_right.x; vertices[18 * i + 10] = raw_quad.bottom_right.y; @@ -167,21 +199,21 @@ pub const Chunk = struct { texcoords2[12 * i + 6] = raw_quad.width; texcoords2[12 * i + 7] = raw_quad.height; - vertices[18 * i + 12] = raw_quad.bottom_left.x; - vertices[18 * i + 13] = raw_quad.bottom_left.y; - vertices[18 * i + 14] = raw_quad.bottom_left.z; - texcoords[12 * i + 8] = left_uv; - texcoords[12 * i + 9] = bottom_uv; - texcoords2[12 * i + 8] = 0.0; - texcoords2[12 * i + 9] = raw_quad.height; + vertices[18 * i + 12] = raw_quad.top_right.x; + vertices[18 * i + 13] = raw_quad.top_right.y; + vertices[18 * i + 14] = raw_quad.top_right.z; + texcoords[12 * i + 8] = right_uv; + texcoords[12 * i + 9] = top_uv; + texcoords2[12 * i + 8] = raw_quad.width; + texcoords2[12 * i + 9] = 0.0; - vertices[18 * i + 15] = raw_quad.top_right.x; - vertices[18 * i + 16] = raw_quad.top_right.y; - vertices[18 * i + 17] = raw_quad.top_right.z; - texcoords[12 * i + 10] = right_uv; - texcoords[12 * i + 11] = top_uv; - texcoords2[12 * i + 10] = raw_quad.width; - texcoords2[12 * i + 11] = 0.0; + vertices[18 * i + 15] = raw_quad.bottom_left.x; + vertices[18 * i + 16] = raw_quad.bottom_left.y; + vertices[18 * i + 17] = raw_quad.bottom_left.z; + texcoords[12 * i + 10] = left_uv; + texcoords[12 * i + 11] = bottom_uv; + texcoords2[12 * i + 10] = 0.0; + texcoords2[12 * i + 11] = raw_quad.height; } var mesh = raylib.Mesh{