opengl/math
mat4-identity
(mat4-identity :int)
return a 4x4 identity matrix.
Opaque :int handle to a heap-allocated 16-float identity matrix.
(mat4-identity) ; => :int mat4 handle
Since: v0.1.0
mat4-perspective
(mat4-perspective [fovy :float aspect :float near :float far :float] :int)
build a perspective projection matrix.
| fovy | vertical field-of-view in radians (e.g. 0.785 = 45 degrees) | |
| aspect | viewport width / height ratio | |
| near | near clip plane distance (positive) | |
| far | far clip plane distance (positive, > near) |
Opaque :int mat4 handle.
(mat4-perspective 0.785 (/ 800.0 600.0) 0.1 100.0)
Since: v0.1.0
mat4-look-at
(mat4-look-at [ex :float ey :float ez :float cx :float cy :float cz :float ux :float uy :float uz :float] :int)
build a view matrix using eye/center/up vectors.
| ex ey ez -- eye position | ||
| cx cy cz -- look-at target position | ||
| ux uy uz -- world up vector (usually 0 1 0) |
Opaque :int mat4 handle.
(mat4-look-at 0.0 0.0 3.0 0.0 0.0 0.0 0.0 1.0 0.0)
Since: v0.1.0
mat4-translate
(mat4-translate [tx :float ty :float tz :float] :int)
build a translation matrix.
| tx ty tz -- translation vector |
Opaque :int mat4 handle.
(mat4-translate 0.0 0.0 -5.0)
Since: v0.1.0
mat4-rotate-x
(mat4-rotate-x [angle :float] :int)
build a rotation matrix around the X axis.
| angle | rotation angle in radians |
Opaque :int mat4 handle.
Since: v0.1.0
mat4-rotate-y
(mat4-rotate-y [angle :float] :int)
build a rotation matrix around the Y axis.
| angle | rotation angle in radians |
Opaque :int mat4 handle.
(mat4-rotate-y (ref-get angle))
Since: v0.1.0
mat4-rotate-z
(mat4-rotate-z [angle :float] :int)
build a rotation matrix around the Z axis.
| angle | rotation angle in radians |
Since: v0.1.0
mat4-mul
(mat4-mul [a :int b :int] :int)
multiply two mat4 matrices (result = a * b).
| a | left mat4 handle | |
| b | right mat4 handle |
New heap-allocated mat4 handle with the product.
(mat4-mul projection (mat4-mul view model))
Since: v0.1.0
mat4-ptr
(mat4-ptr [mat :int] :int)
return the raw float* pointer to a mat4 for uniform upload.
| mat | mat4 handle from any mat4-* function |
Opaque :int raw float pointer (pass directly to set-uniform-mat4).
(set-uniform-mat4 prog "model" (mat4-ptr model))
Since: v0.1.0
normal-mat4
(normal-mat4 [model :int] :int)
compute the normal matrix from a model matrix.
| model | model mat4 handle |
New heap-allocated mat4 handle for use as the normal matrix uniform.
(set-uniform-mat4 prog "normalMatrix" (mat4-ptr (normal-mat4 model)))
Since: v0.1.0