From 1634f96817f32d095edf36c5995c0df6e92d08c0 Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Wed, 30 Oct 2024 10:51:13 +0100 Subject: [PATCH] split up user / testing definitions --- definitions.zig | 15 +++++++++++++++ main.zig | 14 ++++++++------ primitives.zig | 11 ----------- 3 files changed, 23 insertions(+), 17 deletions(-) create mode 100644 definitions.zig diff --git a/definitions.zig b/definitions.zig new file mode 100644 index 0000000..6fb59ed --- /dev/null +++ b/definitions.zig @@ -0,0 +1,15 @@ +const primitive = @import("primitives.zig"); +const Vec3 = primitive.Vec3; +const Point = primitive.Point; + +pub var vec = Vec3{ + .a = Point{ .x = 20, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, + .b = Point{ .x = 50, .y = 40, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, + .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, +}; +pub var vec2 = Vec3{ + .a = Point{ .x = 20, .y = 20, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, + .b = Point{ .x = 50, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, + .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, +}; +pub var obj: [10]Vec3 = undefined; diff --git a/main.zig b/main.zig index 7d7f397..316998d 100644 --- a/main.zig +++ b/main.zig @@ -19,6 +19,8 @@ const getTermDimension = term.getTermDimension; const movement = @import("movement.zig"); const mv_axis_border_bounce = movement.mv_axis_border_bounce; +const definitions = @import("definitions.zig"); + pub fn main() !void { var win = Winsize{}; @@ -48,10 +50,10 @@ fn draw() !void { var buffer = try allocator.alloc(u8, buffer_size); //utf-8 can be 4 bytes long defer allocator.free(buffer); - primitive.obj[0].a.x = 10; - print("primitive.obj[0].a.x:{}\n", .{primitive.obj[0].a.x}); - print("primitive.obj[0].b.x:{}\n", .{primitive.obj[0].b.x}); - print("primitive.obj[9].b.x:{}\n", .{primitive.obj[9].b.x}); + definitions.obj[0].a.x = 10; + print("definitions.obj[0].a.x:{}\n", .{definitions.obj[0].a.x}); + print("definitions.obj[0].b.x:{}\n", .{definitions.obj[0].b.x}); + print("definitions.obj[9].b.x:{}\n", .{definitions.obj[9].b.x}); _ = try stdin.readUntilDelimiterOrEof(&buf, '\n'); //video loop while (true) { @@ -66,7 +68,7 @@ fn draw() !void { slice[bytes_written + ii] = 0; } } - try triangle(buffer, w, primitive.vec); + try triangle(buffer, w, definitions.vec); //_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 }); try out.print("\x1B[2J", .{}); @@ -87,7 +89,7 @@ fn draw() !void { // mv_axis_border_bounce(w, &primitive.vec2.b, 'Y'); // mv_axis_border_bounce(w, &primitive.vec2.c, 'x'); // mv_axis_border_bounce(w, &primitive.vec2.c, 'y'); - //try triangle(buffer, w, primitive.obj.vec); + //try triangle(buffer, w, definitions.obj.vec); try fill_draw(w, buffer); try out.print("{s}", .{buffer}); diff --git a/primitives.zig b/primitives.zig index 08a46ff..8af3136 100644 --- a/primitives.zig +++ b/primitives.zig @@ -23,17 +23,6 @@ pub const Triangle = struct { bufb: *i32, bufc: *i32, }; -pub var vec = Vec3{ - .a = Point{ .x = 20, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, - .b = Point{ .x = 50, .y = 40, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, - .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, -}; -pub var vec2 = Vec3{ - .a = Point{ .x = 20, .y = 20, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, - .b = Point{ .x = 50, .y = 30, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, - .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, -}; -pub var obj: [10]Vec3 = undefined; pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void { const i: usize = @intCast(4 * (x + y * w.ws_col));