{"id":26491986,"url":"https://github.com/zig-gamedev/zmath","last_synced_at":"2025-08-18T09:33:26.425Z","repository":{"id":270771518,"uuid":"882806658","full_name":"zig-gamedev/zmath","owner":"zig-gamedev","description":"SIMD math library for Zig game developers","archived":false,"fork":false,"pushed_at":"2025-03-10T07:57:39.000Z","size":69,"stargazers_count":23,"open_issues_count":6,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-10T08:32:44.562Z","etag":null,"topics":["3d-graphics","gamedev","linear-algebra","math","simd","zig"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zig-gamedev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-03T20:05:17.000Z","updated_at":"2025-03-10T07:57:44.000Z","dependencies_parsed_at":"2025-03-10T08:37:53.556Z","dependency_job_id":null,"html_url":"https://github.com/zig-gamedev/zmath","commit_stats":null,"previous_names":["zig-gamedev/zmath"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zig-gamedev%2Fzmath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zig-gamedev","download_url":"https://codeload.github.com/zig-gamedev/zmath/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244583172,"owners_count":20476233,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d-graphics","gamedev","linear-algebra","math","simd","zig"],"created_at":"2025-03-20T08:51:36.131Z","updated_at":"2025-08-18T09:33:26.418Z","avatar_url":"https://github.com/zig-gamedev.png","language":"Zig","funding_links":[],"categories":["Game Development \u0026 Graphics"],"sub_categories":[],"readme":"# [zmath](https://github.com/zig-gamedev/zmath)\n\nSIMD math library for game developers\n\nTested on x86_64 and AArch64.\n\nProvides ~140 optimized routines and ~70 extensive tests.\n\nCan be used with any graphics API.\n\nDocumentation can be found [here](https://github.com/zig-gamedev/zmath/blob/main/src/zmath.zig).\n\nBenchamrks can be found [here](https://github.com/zig-gamedev/zmath/blob/main/src/benchmark.zig).\n\nAn intro article can be found [here](https://zig.news/michalz/fast-multi-platform-simd-math-library-in-zig-2adn).\n\n## Getting started\n\nHow to get dependencies\n\n1. specific version: `zig fetch --save https://github.com/zig-gamedev/zmath/archive/refs/tags/\u003cREPLACE ME\u003e.tar.gz`\n2. main branch version: `zig fetch --save git+https://github.com/zig-gamedev/zmath.git`\n\nExample `build.zig`\n\n```zig\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{ ... });\n\n    const zmath = b.dependency(\"zmath\", .{});\n    exe.root_module.addImport(\"zmath\", zmath.module(\"root\"));\n}\n```\n\nNow in your code you may import and use zmath:\n\n```zig\nconst zm = @import(\"zmath\");\n\npub fn main() !void {\n    //\n    // OpenGL/Vulkan example\n    //\n    const object_to_world = zm.rotationY(..);\n    const world_to_view = zm.lookAtRh(\n        zm.f32x4(3.0, 3.0, 3.0, 1.0), // eye position\n        zm.f32x4(0.0, 0.0, 0.0, 1.0), // focus point\n        zm.f32x4(0.0, 1.0, 0.0, 0.0), // up direction ('w' coord is zero because this is a vector not a point)\n    );\n    // `perspectiveFovRhGl` produces Z values in [-1.0, 1.0] range (Vulkan app should use `perspectiveFovRh`)\n    const view_to_clip = zm.perspectiveFovRhGl(0.25 * math.pi, aspect_ratio, 0.1, 20.0);\n\n    const object_to_view = zm.mul(object_to_world, world_to_view);\n    const object_to_clip = zm.mul(object_to_view, view_to_clip);\n\n    // Transposition is needed because GLSL uses column-major matrices by default\n    gl.uniformMatrix4fv(0, 1, gl.TRUE, zm.arrNPtr(\u0026object_to_clip));\n    \n    // In GLSL: gl_Position = vec4(in_position, 1.0) * object_to_clip;\n    \n    //\n    // DirectX example\n    //\n    const object_to_world = zm.rotationY(..);\n    const world_to_view = zm.lookAtLh(\n        zm.f32x4(3.0, 3.0, -3.0, 1.0), // eye position\n        zm.f32x4(0.0, 0.0, 0.0, 1.0), // focus point\n        zm.f32x4(0.0, 1.0, 0.0, 0.0), // up direction ('w' coord is zero because this is a vector not a point)\n    );\n    const view_to_clip = zm.perspectiveFovLh(0.25 * math.pi, aspect_ratio, 0.1, 20.0);\n\n    const object_to_view = zm.mul(object_to_world, world_to_view);\n    const object_to_clip = zm.mul(object_to_view, view_to_clip);\n    \n    // Transposition is needed because HLSL uses column-major matrices by default\n    const mem = allocateUploadMemory(...);\n    zm.storeMat(mem, zm.transpose(object_to_clip));\n    \n    // In HLSL: out_position_sv = mul(float4(in_position, 1.0), object_to_clip);\n    \n    //\n    // 'WASD' camera movement example\n    //\n    {\n        const speed = zm.f32x4s(10.0);\n        const delta_time = zm.f32x4s(demo.frame_stats.delta_time);\n        const transform = zm.mul(zm.rotationX(demo.camera.pitch), zm.rotationY(demo.camera.yaw));\n        var forward = zm.normalize3(zm.mul(zm.f32x4(0.0, 0.0, 1.0, 0.0), transform));\n\n        zm.storeArr3(\u0026demo.camera.forward, forward);\n\n        const right = speed * delta_time * zm.normalize3(zm.cross3(zm.f32x4(0.0, 1.0, 0.0, 0.0), forward));\n        forward = speed * delta_time * forward;\n\n        var cam_pos = zm.loadArr3(demo.camera.position);\n\n        if (keyDown('W')) {\n            cam_pos += forward;\n        } else if (keyDown('S')) {\n            cam_pos -= forward;\n        }\n        if (keyDown('D')) {\n            cam_pos += right;\n        } else if (keyDown('A')) {\n            cam_pos -= right;\n        }\n\n        zm.storeArr3(\u0026demo.camera.position, cam_pos);\n    }\n   \n    //\n    // SIMD wave equation solver example (works with vector width 4, 8 and 16)\n    // 'T' can be F32x4, F32x8 or F32x16\n    //\n    var z_index: i32 = 0;\n    while (z_index \u003c grid_size) : (z_index += 1) {\n        const z = scale * @intToFloat(f32, z_index - grid_size / 2);\n        const vz = zm.splat(T, z);\n\n        var x_index: i32 = 0;\n        while (x_index \u003c grid_size) : (x_index += zm.veclen(T)) {\n            const x = scale * @intToFloat(f32, x_index - grid_size / 2);\n            const vx = zm.splat(T, x) + voffset * zm.splat(T, scale);\n\n            const d = zm.sqrt(vx * vx + vz * vz);\n            const vy = zm.sin(d - vtime);\n\n            const index = @intCast(usize, x_index + z_index * grid_size);\n            zm.store(xslice[index..], vx, 0);\n            zm.store(yslice[index..], vy, 0);\n            zm.store(zslice[index..], vz, 0);\n        }\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzmath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzig-gamedev%2Fzmath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzig-gamedev%2Fzmath/lists"}