linalg/small
fixed-size concrete helpers: vec2/vec3/vec4, mat2/mat3/mat4
vec2
(defstruct vec2 :copy [x : float y : float])
2D vector
vec3
(defstruct vec3 :copy [x : float y : float z : float])
3D vector
vec4
(defstruct vec4 :copy [x : float y : float z : float w : float])
4D vector
mat2
(defstruct mat2 [])
2x2 matrix (column-major)
mat3
(defstruct mat3 [])
3x3 matrix (column-major)
mat4
(defstruct mat4 [])
4x4 matrix (column-major to match OpenGL)
vec2-of
(vec2-of [x : float y : float] :)
Returns: vec2
vec3-of
(vec3-of [x : float y : float z : float] :)
Returns: vec3
vec4-of
(vec4-of [x : float y : float z : float w : float] :)
Returns: vec4
mat2-identity
(mat2-identity :)
2x2 identity matrix -- Returns: mat2
mat3-identity
(mat3-identity :)
3x3 identity matrix -- Returns: mat3
mat4-identity
(mat4-identity :)
4x4 identity matrix -- Returns: mat4
vec2-dot
(vec2-dot [a : vec2 b : vec2] :)
dot product of two vec2 -- Returns: :float
vec3-dot
(vec3-dot [a : vec3 b : vec3] :)
dot product of two vec3 -- Returns: :float
vec3-cross
(vec3-cross [a : vec3 b : vec3] :)
cross product of two vec3 -- Returns: vec3
vec3-length
(vec3-length [v : vec3] :)
length (L2 norm) of a vec3 -- Returns: :float
vec3-normalize
(vec3-normalize [v : vec3] :)
normalize a vec3 to unit length -- Returns: vec3
vec3-sub
(vec3-sub [a : vec3 b : vec3] :)
subtract two vec3 -- Returns: vec3
vec4-dot
(vec4-dot [a : vec4 b : vec4] :)
dot product of two vec4 -- Returns: :float
mat4-mul
(mat4-mul [a : mat4 b : mat4] :)
multiply two mat4 (column-major) -- Returns: mat4
mat4-mul-vec4
(mat4-mul-vec4 [m : mat4 v : vec4] :)
multiply mat4 by vec4 -- Returns: vec4
mat4-transpose
(mat4-transpose [m : mat4] :)
transpose a mat4 -- Returns: mat4
mat4-inv
(mat4-inv [m : mat4] :)
inverse of a mat4. Panics if the matrix is singular.
vec3->vec4
(vec3->vec4 [v : vec3] :)
promote a vec3 to vec4 with w=1.0 -- Returns: vec4
mat4-translate
(mat4-translate [v : vec3] :)
translation matrix -- Returns: mat4
mat4-scale
(mat4-scale [v : vec3] :)
scaling matrix -- Returns: mat4
mat4-rotate-x
(mat4-rotate-x [angle : float] :)
rotation about x-axis (radians) -- Returns: mat4
mat4-rotate-y
(mat4-rotate-y [angle : float] :)
rotation about y-axis (radians) -- Returns: mat4
mat4-rotate-z
(mat4-rotate-z [angle : float] :)
rotation about z-axis (radians) -- Returns: mat4
mat4-rotate
(mat4-rotate [axis : vec3 angle : float] :)
rotation about an arbitrary (normalized) axis -- Returns: mat4
mat4-perspective
(mat4-perspective [fovy : float aspect : float near : float far : float] :)
perspective projection -- Returns: mat4
mat4-ortho
(mat4-ortho [l : float r : float b : float t : float near : float far : float] :)
orthographic projection -- Returns: mat4
mat4-look-at
(mat4-look-at [eye : vec3 center : vec3 up : vec3] :)
view (camera) matrix -- Returns: mat4
mat4-ptr
(mat4-ptr [^borrow m : mat4] :)
address of a mat4's 16 column-major float64 fields, as an int.
vec3-ptr
(vec3-ptr [^borrow v : vec3] :)
address of a vec3's 3 float64 fields, as an int.