diff options
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/src/main.zig b/src/main.zig index 909e4ae..9a26a6c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -7,9 +7,6 @@ const Cube = struct { }; pub fn draw_cube(instance: sdl.instance, cube: Cube) void { - sdl.draw_color(instance, 0, 0, 0, 0); - sdl.clear(instance); - var c = cube.points; sdl.draw_color(instance, 255, 255, 255, 0); sdl.draw_line(instance, &c[0], &c[1]); @@ -27,8 +24,17 @@ pub fn draw_cube(instance: sdl.instance, cube: Cube) void { sdl.draw_line(instance, &c[6], &c[2]); sdl.draw_line(instance, &c[3], &c[1]); sdl.draw_line(instance, &c[4], &c[6]); +} + +pub fn get_shifted_cube(cube: Cube, x: f32, y: f32, z: f32) Cube { + var shifted_cube = Cube{ .points = undefined }; + for (cube.points) |point, i| { + shifted_cube.points[i][0] = point[0] + x; + shifted_cube.points[i][1] = point[1] + y; + shifted_cube.points[i][2] = point[2] + z; + } - sdl.present(instance); + return shifted_cube; } pub fn get_centered_cube(cube: Cube, offset: f32) Cube { @@ -101,9 +107,8 @@ pub fn main() anyerror!void { }, }; - var counter: u32 = 0; var beta: f32 = 0; - var alpha: f32 = 35.264; + var alpha: f32 = 0; while (true) { var event = sdl.get_event(); if (event.mode == sdl.modes.quit) { @@ -115,18 +120,36 @@ pub fn main() anyerror!void { } } + sdl.draw_color(instance, 0, 0, 0, 0); + sdl.clear(instance); + var cube = get_projected_cube(unit_cube, alpha, beta); - cube = get_scaled_cube(cube, 100); + cube = get_scaled_cube(cube, 50); + cube = get_centered_cube(cube, 250); + draw_cube(instance, cube); + + cube = get_projected_cube(unit_cube, alpha + 90, beta + 90); + cube = get_scaled_cube(cube, 25); cube = get_centered_cube(cube, 250); draw_cube(instance, cube); + + cube = get_shifted_cube(unit_cube, 5, 0, 0); + cube = get_projected_cube(cube, alpha, beta); + cube = get_scaled_cube(cube, 25); + cube = get_centered_cube(cube, 250); + draw_cube(instance, cube); + + cube = get_shifted_cube(unit_cube, -5, 0, 0); + cube = get_projected_cube(cube, alpha, beta); + cube = get_scaled_cube(cube, 25); + cube = get_centered_cube(cube, 250); + draw_cube(instance, cube); + beta += 0.01; alpha += 0.01; + sdl.present(instance); sdl.delay(10); - counter += 10; - if (counter > 10000) { - break; - } } sdl.quit(instance); |