namespace esd::math
OR namespace esdm
This library aims to provide fast, flexible, and modern vector, matrix, and quaternion functions. constexpr
is used everywhere possible, including constructors and operators, to maximize compile-time optimizations. As this is intended to be a modern library, and will likely be under active development for some time, C++20 has been chosen as the language standard as its concepts allow for much cleaner template code. There is no intention to support obscure or old compilers, however, all code should be standard compliant.
This project began as part of a game engine, and is designed primarily with game programming in mind.
This is a header only library. Simply include the include
folder in your project.
Alternatively, link eseed_math
in CMake:
add_subdirectory("path/to/eseed_math/")
target_link_libraries(target eseed_math)
#include <iostream>
#include <eseed/math/vecops.hpp>
#include <eseed/math/matops.hpp>
int main() {
esdm::Vec3<float> a(1, 2, 3);
esdm::Vec3<float> b(4, 5, 6);
std::cout << "a: " << a << std::endl;
std::cout << "b: " << b << std::endl;
esdm::Vec4<float> point(5, 0, 0, 1);
esdm::Mat4<float> rotation = esdm::matrot(esdm::Vec3<float>(0, 1, 0), esdm::pi<float>() * 0.5f);
std::cout << "point: " << point << std::endl;
std::cout << "rotation: " << rotation << std::endl;
point *= rotation;
std::cout << "rotated point: " << point << std::endl;
}
- Special floating point values
- Infinity
- Constant
- Check
- NaN
- Quiet constant
- Signaling constant
- Check
- Constants
- Pi
- Infinity
- General functions
- Absolute value
- Square
- Square root
- Power
- Rounding
- Truncate
- Floor
- Ceil
- Round
- Direct-to-integer rounding
- Truncate to int
- Floor to int
- Ceil to int
- Round to int
- Templated with length and type
esdm::Vec<std::size_t L, typename T>
- Common-sized aliases
esdm::Vec1<typename T>
esdm::Vec2<typename T>
esdm::Vec3<typename T>
esdm::Vec4<typename T>
- Constructors
- Default
esdm::Vec3<float>()
=[0, 0, 0]
- Component-wise
esdm::Vec3<float>(x, y)
=[x, y, 0]
esdm::Vec3<float>(x, y, z)
=[x, y, z]
- Copy constructor
esdm::Vec3<float>(otherFloatVec3 /* [1.f, 2.f, 3.f] */)
=[1.f, 2.f, 3.f]
esdm::Vec3<float>(otherIntVec3 /* [1, 2, 3] */)
=[1.f, 2.f, 3.f]
esdm::Vec3<float>(otherDoubleVec2 /* [0.5, 1.0] */)
=[0.5f, 1.f]
- Default
- Operators (where applicable)
- Subscript
[]
vec[i]
- Value and reference
- Comparison
==
vec == vec
- Component-wise post and pre increment and decrement
++ --
vec++
++vec
- Component-wise unary
+ - ! ~
-vec
- Component-wise binary
+ - * / % & | ^ << >> && ||
vec + vec
vec + number
number + vec
- Component-wise assignment
+= -= *= /= %= &= |= ^= <<= >>=
vec += vec
vec += number
- ostream
<<
std::cout << aVec3 << std::endl;
prints in format "[x, y, z]
"
- Subscript
- Named component accessors
- Spatial components
- x, y, z, w
- Color components
- r, g, b, a
- Texture coord components
- u, v
get_()
- retrieve component, constexpr compatiblevec.getX()
set_(n)
- set a componentvec.setX(5)
_()
- retrieve reference to componentvec.x() = 5
- Spatial components
- Special floating point values
- Infinity
- Check all components
- Check any component
- NaN
- Check all components
- Check any component
- Infinity
- General component-wise functions
- Absolute value
- Square
- Square root
- Power
- General vector functions
- Dot product
- Cross product
- Component-wise rounding
- Truncate
- Floor
- Ceil
- Round
- Component-wise direct-to-integer rounding
- Truncate to int
- Floor to int
- Ceil to int
- Round to int
- Templated with column size, row size, and type
esdm::Mat<std::size_t M, std::size_t N, typename T>
- Stored column-major
- Important! When assigning components to a matrix, make sure the components are in a column-major format
- Shorthands for common sizes
- Any column and row size up to 4 as
esdm::Mat[M]x[N]<T>
- e.g.
esdm::Mat2x4<T>
,esdm::Mat3x3<T>
- e.g.
- Shorter-hand for square matrix as
esdm::Mat[L]<T>
- e.g.
esdm::Mat4<T>
- e.g.
- Any column and row size up to 4 as
- Constructors
- Default
esdm::Mat2<float>()
=[[0, 0], [0, 0]]
- Component-wise
esdm::Mat2<float>(1, 2, 3, 4)
=[[1, 2], [3, 4]]
- Default
- Column and row getters
- Operators
- Subscript
[]
mat[i]
- Value and reference
- Returns a column vector
- Comparison
==
mat == mat
- Component-wise post and pre increment and decrement
++ --
mat++
++mat
- Component-wise unary
+ - ! ~
-mat
- Component-wise binary
+ - * / % & | ^ << >> && ||
mat + mat
(+ -
only)mat + number
number + mat
- Component-wise assignment
+= -= *= /= %= &= |= ^= <<= >>=
mat += mat
(+= -=
only)mat += number
- Matrix multiplication
*
mat * mat
mat * vec
vec * mat
- ostream
<<
std::cout << aMat2 << std::endl;
prints in format "[[0, 1], [2, 3]]
"
- Subscript
- Builders
- Identity
- General functions
- Inverse
- Matrix multiplication
- Matrix * matrix
- Matrix * row vector
- Column vector * matrix
- Matrix generation
- Translation
- Rotation