This is the vector math and geometry library I've been slowly accreting for more than 30 years. It's not that pretty, and it's not that clean, but it does a lot of what I need whenever I whip up a little graphics test. I'm putting it in this repository to have a central copy.
Some functions and classes in this implementation and notes of interest:
vec2
,vec3
,vec4
- These expose the member array asfloat*
so something likev[0]
will work.dot
,min
,max
,length
,normalize
,reflect
,refract
, and the normal math operators are all templated on the vector class (or any other class you'd like that definesvector_size
)rot4f
- Angle-axis rotation. Notablymult
andoperator*
concatenate rotations.mat4f
- 4x4 matrix, including convenience functionsscale
,translation
,rotation
,inverse
,transpose
,frustum
andmult
inverse
contains some very old code that invertsmat4f
using Gaussian elimination.
vec4 operator*(const vec4& in, const mat4f& m)
multiplies a vector by a matrix.make_plane
turns a vector and two vectors normal to the first vector into a "vector-distance" representation (useful for ray-plane intersection)ray
can be transformed by amat4f
- convenience functions
transform_ray
also transform a pair of origin and directionvec3
by a matrix aabox
can be constructed empty or from min and maxvec3
s, then extended withvec3
s or moreaabox
s or spheres made of avec3
center andfloat
radius.add_sphere
extends a center and radius to enclose another center and radius.range
encapsulates an interval that can beintersect
ed with anotherrange
ray_intersect_box
yields arange
from aray
andaabox
; the range may beempty
indicating theray
didn't intersect theaabox
.