zm is a Zig math library. It is fast, easy to use and cross-platform.
Note
This library is tracking Zig's master branch. Last tested with 0.14.0-dev.3219+bffbc918e
.
It may not compile with newer or older versions.
Run zig fetch --save git+https://github.com/griush/zm
on the directory of your build.zig
and build.zig.zon
.
Then in the build.zig
add:
const zm = b.dependency("zm", .{});
exe_mod.addImport("zm", zm.module("zm"));
Now, in your code, you can use:
const zm = @import("zm");
For an example using Zig's build system see: example. There is a working example using OpenGL and GLFW here.
Simple example for game development.
const zm = @import("zm");
const std = @import("std");
pub fn main() !void {
// Initialize window (with GLFW for example)
// Create OpenGL/Vulkan... context
const projection = zm.Mat4.perspective(zm.toRadians(60.0), 16.0 / 9.0, 0.05, 100.0);
const view = zm.Mat4.translation(0.0, 0.75, 5.0);
const view_proj = projection.multiply(view);
// Upload data
gl.NamedBufferSubData(ubo, 0, @sizeOf(zm.Mat4), &view_proj);
// Render loop
// Cleanup
}
See benchmarks.