/zm

zm - Fast, Zig math library, fully cross-platform

Primary LanguageZigMIT LicenseMIT

zm Logo

zm Logo

GitHub Actions Workflow Status

zm - Fast math library

zm is a Zig math library. It is fast, easy to use and cross-platform.

Usage

Note

This library is tracking Zig's master branch. Last tested with 0.15.0-dev.828+3ce8d19f7. 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", .{
    .target = target,
    .optimize = optimize,
});
module.addImport("zm", zm.module("zm"));

Now, in your code, you can use:

const zm = @import("zm");

Getting Started

For an example using Zig's build system see: example.

Simple example:

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. Matrix should be transposed in OpenGL as they use column-major matrices.
    gl.NamedBufferSubData(ubo, 0, @sizeOf(zm.Mat4), &view_proj);

    // Render loop

    // Cleanup
}

Benchmarks

See benchmarks.