#gamedev #math #matrix #vector #quaternion

no-std glam

A simple and fast 3D math library for games and graphics

40 releases (12 breaking)

0.16.0 Jun 6, 2021
0.14.0 Apr 9, 2021
0.13.1 Mar 24, 2021
0.11.3 Dec 29, 2020
0.7.1 Jul 8, 2019

#1 in Game dev

Download history 7541/week @ 2021-02-24 10217/week @ 2021-03-03 9219/week @ 2021-03-10 7837/week @ 2021-03-17 9437/week @ 2021-03-24 7932/week @ 2021-03-31 11414/week @ 2021-04-07 9258/week @ 2021-04-14 7827/week @ 2021-04-21 10112/week @ 2021-04-28 9724/week @ 2021-05-05 11249/week @ 2021-05-12 11470/week @ 2021-05-19 11177/week @ 2021-05-26 12183/week @ 2021-06-02 9365/week @ 2021-06-09

41,566 downloads per month
Used in 223 crates (48 directly)


22K SLoC


Build Status Coverage Status Latest Version docs Minimum Supported Rust Version

A simple and fast 3D math library for games and graphics.

Development status

glam is in beta stage. Base functionality has been implemented and the look and feel of the API has solidified.


  • f32 types
    • vectors: Vec2, Vec3, Vec3A and Vec4
    • square matrices: Mat2, Mat3, Mat3A and Mat4
    • a quaternion type: Quat
    • affine transformation types: Affine2 and Affine3A
  • f64 types
    • vectors: DVec2, DVec3 and DVec4
    • square matrices: DMat2, DMat3 and DMat4
    • a quaternion type: DQuat
    • affine transformation types: DAffine2 and DAffine3
  • i32 types
    • vectors: IVec2, IVec3 and IVec4
  • u32 types
    • vectors: UVec2, UVec3 and UVec4
  • bool types
    • vectors: BVec2, BVec3 and BVec4


The 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 support

no_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:

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:

default = ["std"]

std = ["glam/std"]
libm = ["glam/libm"]

glam = { version = "0.15.2", default-features = false }

Optional features

  • [approx] - traits and macros for approximate float comparisons
  • bytemuck - for casting into slices of bytes
  • libm - required to compile with no_std
  • mint - for interoperating with other 3D math libraries
  • num-traits - required to compile no_std, will be included when enabling the libm feature
  • rand - 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 enabled

Feature gates

  • scalar-math - compiles with SIMD support disabled
  • debug-glam-assert - adds assertions in debug builds which check the validity of parameters passed to glam to help catch runtime errors
  • glam-assert - adds validation assertions to all builds

Minimum Supported Rust Version (MSRV)

The minimum supported version of Rust for glam is 1.45.0.


Column vectors

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.

Column-major order

Matrices are stored in column major format. Each column vector is stored in contiguous memory.

Co-ordinate system

glam is co-ordinate system agnostic and intends to support both right handed and left handed conventions.

Design Philosophy

The design of this library is guided by a desire for simplicity and good performance.

  • No generics and minimal traits in the public API for simplicity of usage
  • All dependencies are optional (e.g. mint, rand and serde)
  • Follows the Rust API Guidelines where possible
  • Aiming for 100% test coverage
  • Common functionality is benchmarked using Criterion.rs

Future work

  • Experiment with a using a 4x3 matrix as a 3D transform type that can be more efficient than Mat4 for certain operations like inverse and multiplies
  • wasm support


There were many inspirations for the interface and internals of glam from the Rust and C++ worlds. In particular:


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:

  • DirectXMath - MIT License - Copyright (c) 2011-2020 Microsoft Corp
  • Realtime Math - MIT License - Copyright (c) 2018 Nicholas Frechette
  • GLM - MIT License - Copyright (c) 2005 - G-Truc Creation

See ATTRIBUTION.md for details.