Skip to content

GuYeying/pyglam

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🧑‍🎤 pyglam

High-performance Python bindings for the glam Rust linear algebra library. A simple, fast, SIMD-optimized 3D math library for games, graphics, and simulations.


About

pyglam is a thin, zero-cost Python interface for bitshifter/glam-rs — the industry-leading Rust math library used in Bevy, macroquad, and many Rust game engines.

It brings native Rust performance directly into Python with:

  • Clean Pythonic API

  • Full f32 / f64 support

  • SIMD acceleration on x86 / x86_64 / aarch64

  • Column-major matrices & column vectors

  • Zero-overhead function calls


Features

Single‑precision (f32)

  • Vectors: Vec2, Vec3, Vec4

  • Matrices: Mat3, Mat4

  • Quaternion: Quat

Double‑precision (f64)

  • Vectors: DVec2, DVec3, DVec4

  • Matrices: DMat3, DMat4

  • Quaternion: DQuat

All types exactly match the glam API behavior and memory layout.


Supported Operations

Vectors

  • Addition, subtraction, scalar multiply/divide

  • Dot product

  • Length & normalization

  • Component access (x, y, z, w)

Matrices

  • Construction & identity

  • Matrix multiplication (@)

  • Scalar multiplication

  • Transpose

  • Inverse

Quaternions

  • From axis-angle

  • Quaternion multiplication

  • Vector rotation

  • Inversion & normalization


Example

from pyglam.mat4 import Mat4
from pyglam.vec4 import Vec4

mat = Mat4.identity()

mat2 = Mat4.identity()
mat_mul = mat @ mat2

vec = Vec4(1.0, 2.0, 3.0, 1.0)
result = mat @ vec
print("mat × vec:", result.x, result.y, result.z, result.w)

inv_mat = mat.inverse()
tp_mat = mat.transpose()

Conventions (Same as glam)

  • Column-major memory order

  • Coordinate system agnostic

  • No generic hacks — clean, static types

  • 1:1 API compatibility with glam


Performance

  • SIMD optimized where available

  • Zero Python overhead for basic math

  • Same performance characteristics as Rust glam


License

This project is licensed under either of:

  • Apache License, Version 2.0

  • MIT license


Contribution

Contributions are welcome! Unless you explicitly state otherwise, any contribution you submit will be dual-licensed as above.


Attribution

All math internals are ported from:


About

This is a Python binding of glam completed based on pyo3

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors