https://github.com/griush/zm
zm - Fast, Zig math library, fully cross-platform
https://github.com/griush/zm
game-development gamedev math zig zig-package
Last synced: about 1 month ago
JSON representation
zm - Fast, Zig math library, fully cross-platform
- Host: GitHub
- URL: https://github.com/griush/zm
- Owner: griush
- License: mit
- Created: 2024-06-01T15:15:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-03-22T08:51:41.000Z (8 months ago)
- Last Synced: 2025-03-31T04:41:12.411Z (7 months ago)
- Topics: game-development, gamedev, math, zig, zig-package
- Language: Zig
- Homepage: https://griush.github.io/zm/
- Size: 118 KB
- Stars: 62
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README


# 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.16.0-dev.43+99b2b6151`.
> 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:
```zig
const zm = b.dependency("zm", .{
.target = target,
.optimize = optimize,
});
module.addImport("zm", zm.module("zm"));
```
Now, in your code, you can use:
```zig
const zm = @import("zm");
```
### Getting Started
For an example using Zig's build system see: [example](/example/).
Simple example:
```zig
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](/test/benchmark.zig).