Quaternion rotation!

This commit is contained in:
duck
2025-05-15 00:08:01 +05:00
parent 12285321d2
commit 796d2bfb35
4 changed files with 165 additions and 45 deletions

View File

@@ -80,9 +80,20 @@ fn processEvents(graphics: *Graphics, run_info: *RunInfo) GameError!void {
run_info.running = false;
},
sdl.EVENT_WINDOW_RESIZED => {
if (event.window.windowID != sdl.GetWindowID(graphics.window)) return;
if (event.window.windowID != sdl.GetWindowID(graphics.window)) continue;
graphics.resize(@intCast(event.window.data1), @intCast(event.window.data2));
},
sdl.EVENT_MOUSE_MOTION => {
if (event.motion.windowID != sdl.GetWindowID(graphics.window)) continue;
if (@abs(event.motion.xrel) < 0.01 and @abs(event.motion.yrel) < 0.01) continue;
const Transform = @import("graphics/transform.zig");
const delta, const length = Transform.extractNormal(.{ -event.motion.yrel, -event.motion.xrel, 0.0 });
const rot = Transform.rotationByAxis(
delta,
length * std.math.pi / @as(f32, @floatFromInt(graphics.window_size[1])) * 2.0,
);
graphics.mesh_transform.rotate(rot);
},
else => {},
}
}