![Build Status] ![Coverage Status] ![Latest Version] ![docs] ![Minimum Supported Rust Version]
A simple and fast 3D math library for games and graphics.
glam is in beta stage. Base functionality has been implemented and the look
and feel of the API has solidified.
f32 types
Vec2, Vec3, Vec3A and Vec4Mat2, Mat3, Mat3A and Mat4QuatAffine2 and Affine3Af64 types
DVec2, DVec3 and DVec4DMat2, DMat3 and DMat4DQuatDAffine2 and DAffine3i32 types
IVec2, IVec3 and IVec4u32 types
UVec2, UVec3 and UVec4bool types
BVec2, BVec3 and BVec4The Vec3A, Vec4, Quat, Mat2, Mat3A, Mat4, Affine2 and Affine3A
types use 128-bit wide SIMD vector types for storage on x86/x86_64
architectures. As a result, these types are all 16 byte aligned and depending
on the size of the type or the type's members, they may contain internal
padding. This results in some wasted space in the cases of Vec3A, Mat3A,
Affine2 and Affine3A. However the use of SIMD generally results in better
performance than scalar math.
glam outperforms similar Rust libraries for common operations as tested by the
mathbench project.
no_std supportno_std support can be enabled by compiling with --no-default-features to
disable std support and --features libm for math functions that are only
defined in std. For example:
toml
[dependencies]
glam = { version = "0.15.2", default-features = false, features = ["libm"] }
To support both std and no_std builds in project, you can use the following
in your Cargo.toml:
```toml [features] default = ["std"]
std = ["glam/std"] libm = ["glam/libm"]
[dependencies] glam = { version = "0.15.2", default-features = false } ```
approx] - traits and macros for approximate float comparisonsbytemuck] - for casting into slices of byteslibm] - required to compile with no_stdmint] - for interoperating with other 3D math librariesnum-traits] - required to compile no_std, will be included when enabling
the libm featurerand] - implementations of Distribution trait for all glam types.serde] - implementations of Serialize and Deserialize for all glam
types. Note that serialization should work between builds of glam with and
without SIMD enabledscalar-math - compiles with SIMD support disableddebug-glam-assert - adds assertions in debug builds which check the validity
of parameters passed to glam to help catch runtime errorsglam-assert - adds validation assertions to all buildsThe minimum supported version of Rust for glam is 1.45.0.
glam interprets vectors as column matrices (also known as "column vectors")
meaning when transforming a vector with a matrix the matrix goes on the left,
e.g. v' = Mv. DirectX uses row vectors, OpenGL uses column vectors. There
are pros and cons to both.
Matrices are stored in column major format. Each column vector is stored in contiguous memory.
glam is co-ordinate system agnostic and intends to support both right handed
and left handed conventions.
The design of this library is guided by a desire for simplicity and good performance.
mint, rand and serde)Mat4 for certain operations like inverse and multiplieswasm supportThere were many inspirations for the interface and internals of glam from the Rust and C++ worlds. In particular:
Vec3A
implementationglam is a play on the name of the popular C++ library [GLM]Licensed under either of
at your option.
Contributions in any form (issues, pull requests, etc.) to this project must adhere to Rust's [Code of Conduct].
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Thank you to all of the glam [contributors]!
If you are interested in contributing or have a request or suggestion [start a discussion] on github. See [CONTRIBUTING.md] for more information for contributors.
The [Game Development in Rust Discord] and [Bevy Engine Discord] servers can are
also good places to ask for help with glam.
glam contains code ported from the following C++ libraries:
See [ATTRIBUTION.md] for details.