diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2021-06-30 18:28:45 +0200 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2021-06-30 18:28:45 +0200 |
commit | 79d2aec6e835c75962ae49462dab4bea2b122720 (patch) | |
tree | 9d809af851aaa3324f0b225ffa0f99d71d4c1c57 /src/main.zig | |
parent | d79befe12a8d6b32a41beb88d6e75b12a75615a7 (diff) |
fixed event issue, and made it look cooler
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); |