From 9ec8553cf868ad062b767d1eb7105d548bf404b4 Mon Sep 17 00:00:00 2001 From: Stephen Gutekanst Date: Thu, 21 Apr 2022 04:23:09 -0700 Subject: [PATCH] examples: texture-light: more instances, rotate camera by default, make movement independent of frame-rate Signed-off-by: Stephen Gutekanst --- examples/texture-light/main.zig | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/texture-light/main.zig b/examples/texture-light/main.zig index 7c35e026..04d216a1 100755 --- a/examples/texture-light/main.zig +++ b/examples/texture-light/main.zig @@ -86,7 +86,7 @@ fn frame(app: *App, params: *FrameParams) !void { } // move camera - const speed = zm.f32x4s(0.2); + const speed = zm.f32x4s(@floatCast(f32, app.delta_time * 5)); const fwd = zm.normalize3(params.camera.target - params.camera.eye); const right = zm.normalize3(zm.cross3(fwd, params.camera.up)); @@ -96,16 +96,15 @@ fn frame(app: *App, params: *FrameParams) !void { if (params.keys & FrameParams.down != 0) params.camera.eye -= fwd * speed; - if (params.keys & FrameParams.right != 0) - params.camera.eye += right * speed; - - if (params.keys & FrameParams.left != 0) - params.camera.eye -= right * speed; + if (params.keys & FrameParams.right != 0) params.camera.eye += right * speed + else if (params.keys & FrameParams.left != 0) params.camera.eye -= right * speed + else params.camera.eye += right * (speed * @Vector(4, f32){0.5, 0.5, 0.5, 0.5}); params.camera.update(params.queue); // move light - params.light.update(params.queue); + const light_speed = @floatCast(f32, app.delta_time * 2.5); + params.light.update(params.queue, light_speed); const back_buffer_view = app.swap_chain.?.getCurrentTextureView(); defer back_buffer_view.release(); @@ -268,7 +267,7 @@ const Cube = struct { instance: Buffer, texture: Texture, - const IPR = 10; // instances per row + const IPR = 20; // instances per row const SPACING = 2; // spacing between cubes const DISPLACEMENT = vec3u(IPR * SPACING / 2, 0, IPR * SPACING / 2); @@ -745,10 +744,10 @@ const Light = struct { }; } - fn update(self: *Self, queue: gpu.Queue) void { + fn update(self: *Self, queue: gpu.Queue, delta: f32) void { const old = self.uniform; const new = Light.Uniform { - .position = zm.qmul(zm.quatFromAxisAngle(vec3u(0, 1, 0), 0.05), old.position), + .position = zm.qmul(zm.quatFromAxisAngle(vec3u(0, 1, 0), delta), old.position), .color = old.color, }; queue.writeBuffer(self.buffer.buffer, 0, Light.Uniform, &.{new});