Skip to content

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

Return a blank vector

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

Return all one vector

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 all elements 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

create a Vec4 function passing x,y,z as parameteres. w is set to 1

fn zero_m4 #

fn zero_m4() Mat4

Return a zero matrix

fn zero_v4 #

fn zero_v4() Vec4

Return a zero vector

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) clean #

fn (a Vec4) clean() Vec4

Remove all the raw zeros

fn (Vec4) copy #

fn (mut x Vec4) copy(value f32)

Set all elements to value

fn (Vec4) mul_scalar #

fn (x Vec4) mul_scalar(value f32) Vec4

Scale the vector using a scalar

fn (Vec4) inv #

fn (x Vec4) inv() Vec4

Reciprocal of the vector

fn (Vec4) normalize #

fn (x Vec4) normalize() Vec4

Normalize the vector

fn (Vec4) normalize3 #

fn (x Vec4) normalize3() Vec4

Normalize only xyz, w set to 0

fn (Vec4) mod #

fn (x Vec4) mod() f32

Module of the vector xyzw

fn (Vec4) mod3 #

fn (x Vec4) mod3() f32

Module for 3d vector xyz, w ignored

fn (Vec4) sum #

fn (x Vec4) sum() f32

Sum of all the elements

fn (Vec4) + #

fn (a Vec4) + (b Vec4) Vec4


fn (Vec4) - #

fn (a Vec4) - (b Vec4) Vec4


fn (Vec4) * #

fn (a Vec4) * (b Vec4) f32

Dot product

fn (Vec4) % #

fn (a Vec4) % (b Vec4) Vec4

Cross product

fn (Vec4) mul_vec4 #

fn (x Vec4) mul_vec4(y Vec4) Vec4

Components multiplication