GithubHelp home page GithubHelp logo

msvbg / glam-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitshifter/glam-rs

0.0 1.0 0.0 774 KB

A simple and fast linear algebra library for games and graphics

License: Apache License 2.0

Rust 100.00%

glam-rs's Introduction

glam

Build Status Coverage Status Latest Version docs

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.

Features

  • Only single precision floating point (f32) arithmetic is supported
  • vectors: Vec2, Vec3, Vec3A Vec4
  • square matrices: Mat2, Mat3, Mat4
  • a quaternion type: Quat

SIMD

The Vec3A, Vec4 and Quat types use SSE2 on x86/x86_64 architectures. Mat2, Mat3 and Mat4 also use SSE2 for some functionality. Not everything has a SIMD implementation yet.

Note that this does result in some wasted space in the case of Vec3A as the SIMD vector type is 16 bytes large and 16 byte aligned.

glam outperforms similar Rust libraries for common operations as tested by the mathbench project.

Due to the use of SIMD, vector elements may only be get and set via accessor methods, e.g. Vec4::x() and Vec4::x_mut() or Vec4::set_x(). If getting or setting more than one element it is more efficient to convert from tuples or arrays:

let (x, y, z, w) = v.into();
let [x, y, z, w]: [f32; 4] = v.into();

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:

[dependencies]
glam = { version = "0.10.0", default-features = false, features = ["libm"] }

Optional features

  • 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. This is primarily used for unit testing
  • 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 Version of Rust (MSVR)

The minimum supported version of Rust for glam is 1.36.0.

Conventions

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 traits or generics for simplicity of implementation and usage
  • Only single precision floating point f32 arithmetic is supported for now
  • 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
  • no-std support
  • wasm support

Inspirations

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

License

Licensed under either of

at your option.

Contribution

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!

Support

If you are interested in contributing or have a request or suggestion create an issue on github.

The Game Development in Rust Discord and Bevy Engine Discord servers can are also good places to ask for help with glam.

Attribution

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.

glam-rs's People

Contributors

alexene avatar aloucks avatar benfrankel avatar bitshifter avatar bvrner avatar cessen avatar deprilula28 avatar fu5ha avatar hrydgard avatar icefoxen avatar iwikal avatar matthias-fauconneau avatar michal-z avatar neo-zhixing avatar repi avatar xavientois avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.