From 1562232871cd16000aa3556335ba3b2b38a9db05 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Sat, 14 May 2022 16:23:15 -0700 Subject: [PATCH] examples/gkurve: use orthographic projection + pixel units Signed-off-by: Stephen Gutekanst --- examples/gkurve/main.zig | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/gkurve/main.zig b/examples/gkurve/main.zig index c8523bee..d77a08c9 100644 --- a/examples/gkurve/main.zig +++ b/examples/gkurve/main.zig @@ -16,9 +16,9 @@ pub const Vertex = struct { }; // Simple triangle pub const vertices = [_]Vertex{ - .{ .pos = .{ 0, 0.5, 0, 1 }, .uv = .{ 0.5, 1 }, .bary = .{ 0, 0, 1 } }, - .{ .pos = .{ -0.5, -0.5, 0, 1 }, .uv = .{ 0, 0 }, .bary = .{ 1, 0, 0 } }, - .{ .pos = .{ 0.5, -0.5, 0, 1 }, .uv = .{ 1, 0 }, .bary = .{ 0, 1, 0 } }, + .{ .pos = .{ 0, 250, 0, 1 }, .uv = .{ 0.5, 1 }, .bary = .{ 0, 0, 1 } }, + .{ .pos = .{ -250, -250, 0, 1 }, .uv = .{ 0, 0 }, .bary = .{ 1, 0, 0 } }, + .{ .pos = .{ 250, -250, 0, 1 }, .uv = .{ 1, 0 }, .bary = .{ 0, 1, 0 } }, }; // TODO: Need to ask Ayush about this, ideally we have a square window in this example because it @@ -214,12 +214,19 @@ pub fn update(app: *App, engine: *mach.Engine) !bool { }; { + const proj = zm.orthographicRh( + @intToFloat(f32, engine.gpu_driver.current_desc.width), + @intToFloat(f32, engine.gpu_driver.current_desc.height), + -100, + 100, + ); + // TODO: // Use better positioning system const ubos = [_]VertexUniform{ - .{ .mat = zm.translation(0.5, 0.5, 0) }, - .{ .mat = zm.translation(-0.5, 0, 0) }, - .{ .mat = zm.translation(0.5, -0.5, 0) }, + .{ .mat = zm.mul(zm.translation(250, 250, 0), proj) }, + .{ .mat = zm.mul(zm.translation(-250, 0, 0), proj) }, + .{ .mat = zm.mul(zm.translation(250, -250, 0), proj) }, }; encoder.writeBuffer(app.vertex_uniform_buffer, 0, VertexUniform, &ubos); }