gg.m4 #
Constants #
const precision = f32(10e-7)
fn add #
fn add(a Mat4, b Mat4) Mat4
Sum of matrix function
fn blank_v4 #
fn blank_v4() Vec4
blank_v4 returns a vector, where all elements are set to 0, except w
, which is set to 1
fn calc_tr_matrices #
fn calc_tr_matrices(w f32, h f32, rx f32, ry f32, in_scale f32) Mat4
Get the complete transformation matrix for GLSL demos
fn deg #
fn deg(grad f32) f32
Translate radians to degrees
fn det #
fn det(x Mat4) f32
Calculate the determinant of the Matrix
fn look_at #
fn look_at(eye Vec4, center Vec4, up Vec4) Mat4
Calculate the look-at matrix
fn mul #
fn mul(a Mat4, b Mat4) Mat4
Multiplication of matrix function
fn mul_vec #
fn mul_vec(a Mat4, v Vec4) Vec4
Multiply a Matrix by a vector
fn one_v4 #
fn one_v4() Vec4
one_v4 returns a vector, where all elements are set to 1
fn ortho #
fn ortho(left f32, right f32, bottom f32, top f32, z_near f32, z_far f32) Mat4
calculate the Orthographic projection matrix
fn perspective #
fn perspective(fov f32, ar f32, n f32, f f32) Mat4
Calculate the perspective matrix using (fov:fov, ar:aspect_ratio ,n:near_pane, f:far_plane) as parameters
fn rad #
fn rad(deg f32) f32
Translate degrees to radians
fn rotate #
fn rotate(angle f32, w Vec4) Mat4
Get a rotation matrix using w as rotation axis vector, the angle is in radians
fn scale #
fn scale(w Vec4) Mat4
Get a scale matrix, the scale vector is w, only xyz are evaluated.
fn set_m4 #
fn set_m4(value f32) Mat4
Return a matrix initialized with value
fn set_v4 #
fn set_v4(value f32) Vec4
set_v4 returns a vector, where all elements are set to value
fn sub #
fn sub(a Mat4, b Mat4) Mat4
Subtraction of matrix function
fn unit_m4 #
fn unit_m4() Mat4
Return a unity matrix
fn vec3 #
fn vec3(x f32, y f32, z f32) Vec4
vec3 creates a Vec4 value, passing x,y,z as parameters. The w element is set to 1
fn vec4 #
fn vec4(x f32, y f32, z f32, w f32) Vec4
vec4 creates a Vec4 value, based on the x,y,z,w parameters
fn zero_m4 #
fn zero_m4() Mat4
Return a zero matrix
fn zero_v4 #
fn zero_v4() Vec4
zero_v4 returns a zero vector (all elements set to 0)
struct Mat4 #
union Mat4 {
pub mut:
e [16]f32
f [4][4]f32
}
fn (Mat4) str #
fn (x Mat4) str() string
String representation of the matrix
fn (Mat4) clean #
fn (a Mat4) clean() Mat4
Remove all the raw zeros
fn (Mat4) sum_all #
fn (x Mat4) sum_all() f32
Sum all the elements of the matrix
fn (Mat4) is_equal #
fn (x Mat4) is_equal(y Mat4) bool
Check if two matrix are equal using module precision
fn (Mat4) get_e #
fn (x Mat4) get_e(elem_index int) f32
Set/Get values
Get an element of the matrix using [0..15] indexes, one dimension
fn (Mat4) get_f #
fn (x Mat4) get_f(index_col int, index_row int) f32
Get an element of the matrix using [0..3][0..3] indexes, two dimension
fn (Mat4) set_e #
fn (mut x Mat4) set_e(index int, value f32)
Set an element of the matrix using [0..15] indexes, one dimension
fn (Mat4) set_f #
fn (mut x Mat4) set_f(index_col int, index_row int, value f32)
Set an element of the matrix using [0..3][0..3] indexes, two dimension
fn (Mat4) copy #
fn (mut x Mat4) copy(y Mat4)
Copy a matrix elements from another matrix
fn (Mat4) set_trace #
fn (mut x Mat4) set_trace(v3 Vec4)
Set the trace of the matrix using a vec4
fn (Mat4) get_trace #
fn (x Mat4) get_trace() Vec4
Get the trace of the matrix
fn (Mat4) set_f32 #
fn (mut x Mat4) set_f32(value f32)
Set all the matrix elements to value
fn (Mat4) set_row #
fn (mut x Mat4) set_row(row int, v3 Vec4)
Rows/Column access
Set the row as the input vec4
fn (Mat4) get_row #
fn (x Mat4) get_row(row int) Vec4
Get a row from a matrix
fn (Mat4) set_col #
fn (mut x Mat4) set_col(col int, v3 Vec4)
Set the column as the input vec4
fn (Mat4) get_col #
fn (x Mat4) get_col(col int) Vec4
Get a column from a matrix
fn (Mat4) swap_col #
fn (mut x Mat4) swap_col(col1 int, col2 int)
Swap two columns in the matrix
fn (Mat4) swap_row #
fn (mut x Mat4) swap_row(row1 int, row2 int)
Swap two rows in the matrix
fn (Mat4) transpose #
fn (x Mat4) transpose() Mat4
Modify data
Transpose the matrix
fn (Mat4) mul_scalar #
fn (x Mat4) mul_scalar(s f32) Mat4
Multiply the all the elements of the matrix by a scalar
fn (Mat4) + #
fn (a Mat4) + (b Mat4) Mat4
Sum of matrix, operator +
fn (Mat4) - #
fn (a Mat4) - (b Mat4) Mat4
Subtraction of matrix, operator -
fn (Mat4) * #
fn (a Mat4) * (b Mat4) Mat4
Multiplication of matrix, operator *
fn (Mat4) inverse #
fn (x Mat4) inverse() Mat4
Calculate the inverse of the Matrix
fn (Mat4) translate #
fn (x Mat4) translate(w Vec4) Mat4
Get a matrix translated by a vector w
struct Vec4 #
struct Vec4 {
pub mut:
e [4]f32
}
fn (Vec4) str #
fn (x Vec4) str() string
str returns a string
representation of Vec4
.
fn (Vec4) is_equal #
fn (x Vec4) is_equal(y Vec4) bool
is_equal checks if two vector are equal using the module precision (10e-7)
fn (Vec4) clean #
fn (x Vec4) clean() Vec4
clean returns a new vector, based on x
, but with all the values < precision, set to 0
fn (Vec4) copy #
fn (mut x Vec4) copy(value f32)
copy sets all elements of x
to value
fn (Vec4) mul_scalar #
fn (x Vec4) mul_scalar(value f32) Vec4
mul_scalar returns the result of multiplying the vector x
, by the scalar value
fn (Vec4) inv #
fn (x Vec4) inv() Vec4
inv returns the reciprocal of the vector x
fn (Vec4) normalize #
fn (x Vec4) normalize() Vec4
normalize returns a normalized form of the vector x
fn (Vec4) normalize3 #
fn (x Vec4) normalize3() Vec4
normalize3 returns a normalized form of the vector x
, where the w element is set to 0
fn (Vec4) mod #
fn (x Vec4) mod() f32
mod returns a module of the vector x
fn (Vec4) mod3 #
fn (x Vec4) mod3() f32
mod3 returns a module of the 3d vector x
, ignoring the value of its w element
fn (Vec4) sum #
fn (x Vec4) sum() f32
sum returns a sum of all the elements
fn (Vec4) + #
fn (a Vec4) + (b Vec4) Vec4
- returns
a
+b
(corresponding elements are added)
fn (Vec4) - #
fn (a Vec4) - (b Vec4) Vec4
- returns
a
+b
(corresponding elements are subtracted)
fn (Vec4) * #
fn (a Vec4) * (b Vec4) f32
- returns
a
*b
(corresponding elements are multiplied, then summed), i.e. a dot product
fn (Vec4) % #
fn (a Vec4) % (b Vec4) Vec4
% returns a cross product of the vectors a
and b
fn (Vec4) mul_vec4 #
fn (x Vec4) mul_vec4(y Vec4) Vec4
mul_vec4 returns a vector, where the corresponding x
and y
elements are multiplied