gl3n.linalg
Special thanks to:
Base template for all vector-types.
type | all values get stored as this type |
dimension | specifies the dimension of the vector, can be 1, 2, 3 or 4 |
alias Vector!(int, 3) vec3i; alias Vector!(float, 4) vec4; alias Vector!(real, 2) vec2r;
Holds the internal type of the vector.
Holds the dimension of the vector.
Holds all coordinates, length conforms dimension.
Returns a pointer to the coordinates.
Returns the current vector formatted as string, useful for printing the vector.
static properties to access the values.
canonical basis for Euclidian space
Constructs the vector. If a single value is passed the vector, the vector will be cleared with this value. If a vector with a higher dimension is passed the vector will hold the first values up to its dimension. If mixed types are passed they will be joined together (allowed types: vector, static array, vt).
vec4 v4 = vec4(1.0f, vec2(2.0f, 3.0f), 4.0f); vec3 v3 = vec3(v4); // v3 = vec3(1.0f, 2.0f, 3.0f); vec2 v2 = v3.xy; // swizzling returns a static array. vec3 v3_2 = vec3(1.0f); // vec3 v3_2 = vec3(1.0f, 1.0f, 1.0f);
Returns true if all values are not nan and finite, otherwise false.
Sets all values of the vector to value.
Updates the vector with the values from other.
Implements dynamic swizzling.
Returns the squared magnitude of the vector.
Returns the magnitude of the vector.
Normalizes the vector.
Returns a normalized copy of the current vector.
Calculates the product between two vectors.
Calculates the cross product of two 3-dimensional vectors.
Calculates the distance between two vectors.
Pre-defined vector types, the number represents the dimension and the last letter the type (none = float, d = double, i = int).
Base template for all matrix-types.
type | all values get stored as this type |
rows_ | rows of the matrix |
cols_ | columns of the matrix |
alias Matrix!(float, 4, 4) mat4; alias Matrix!(double, 3, 4) mat34d; alias Matrix!(real, 2, 2) mat2r;
Holds the internal type of the matrix;
Holds the number of rows;
Holds the number of columns;
Holds the matrix row-major in memory.
Returns the pointer to the stored values as OpenGL requires it. Note this will return a pointer to a row-major matrix, this means you've to set the transpose argument to GL_TRUE when passing it to OpenGL.
// 3rd argument = GL_TRUE
glUniformMatrix4fv(programs.main.model, 1, GL_TRUE, mat4.translation(-0.5f, -0.5f, 1.0f).value_ptr);
Returns the current matrix formatted as flat string.
Returns the current matrix as pretty formatted string.
Constructs the matrix: If a single value is passed, the matrix will be cleared with this value (each column in each row will contain this value). If a matrix with more rows and columns is passed, the matrix will be the upper left nxm matrix. If a matrix with less rows and columns is passed, the passed matrix will be stored in the upper left of an identity matrix. It's also allowed to pass vectors and scalars at a time, but the vectors dimension must match the number of columns and align correctly.
mat2 m2 = mat2(0.0f); // mat2 m2 = mat2(0.0f, 0.0f, 0.0f, 0.0f); mat3 m3 = mat3(m2); // mat3 m3 = mat3(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f); mat3 m3_2 = mat3(vec3(1.0f, 2.0f, 3.0f), 4.0f, 5.0f, 6.0f, vec3(7.0f, 8.0f, 9.0f)); mat4 m4 = mat4.identity; // just an identity matrix mat3 m3_3 = mat3(m4); // mat3 m3_3 = mat3.identity
Returns true if all values are not nan and finite, otherwise false.
Sets all values of the matrix to value (each column in each row will contain this value).
Makes the current matrix an identity matrix.
Returns a identity matrix.
Transposes the current matrix;
Returns a transposed copy of the matrix.
Returns an identity matrix with an applied rotate_axis around an arbitrary axis (nxn matrices, n >= 3).
Returns an identity matrix with an applied rotation around the x-axis (nxn matrices, n >= 3).
Returns an identity matrix with an applied rotation around the y-axis (nxn matrices, n >= 3).
Returns an identity matrix with an applied rotation around the z-axis (nxn matrices, n >= 3).
Rotates the current matrix around the x-axis and returns this (nxn matrices, n >= 3).
Rotates the current matrix around the y-axis and returns this (nxn matrices, n >= 3).
Rotates the current matrix around the z-axis and returns this (nxn matrices, n >= 3).
Sets the translation of the matrix (nxn matrices, n >= 3).
Copyies the translation from mat to the current matrix (nxn matrices, n >= 3).
Returns an identity matrix with the current translation applied (nxn matrices, n >= 3)..
Sets the scale of the matrix (nxn matrices, n >= 3).
Copyies the scale from mat to the current matrix (nxn matrices, n >= 3).
Returns an identity matrix with the current scale applied (nxn matrices, n >= 3).
Copies rot into the upper left corner, the translation (nxn matrices, n >= 3).
Returns an identity matrix with the current rotation applied (nxn matrices, n >= 3).
Returns an inverted copy of the current matrix (nxn matrices, n <= 4).
Inverts the current matrix (nxn matrices, n <= 4).
Pre-defined matrix types, the first number represents the number of rows and the second the number of columns, if there's just one it's a nxn matrix. All of these matrices are floating-point matrices.
Base template for all quaternion-types.
type | all values get stored as this type |
Holds the internal type of the quaternion.
Holds the w, x, y and z coordinates.
Returns a pointer to the quaternion in memory, it starts with the w coordinate.
Returns the current vector formatted as string, useful for printing the quaternion.
static properties to access the values.
Constructs the quaternion. Takes a 4-dimensional vector, where vector.x = the quaternions w coordinate, or a w coordinate of type qt and a 3-dimensional vector representing the imaginary part, or 4 values of type qt.
Returns true if all values are not nan and finite, otherwise false.
Returns the squared magnitude of the quaternion.
Returns the magnitude of the quaternion.
Returns an identity quaternion (w=1, x=0, y=0, z=0).
Makes the current quaternion an identity quaternion.
Inverts the quaternion.
Returns an inverted copy of the current quaternion.
Creates a quaternion from a 3x3 matrix.
Matrix!(qt, 3, 3) matrix | 3x3 matrix (rotation) |
Returns the quaternion as matrix.
rows | number of rows of the resulting matrix (min 3) |
cols | number of columns of the resulting matrix (min 3) |
Normalizes the current quaternion.
Returns a normalized copy of the current quaternion.
Returns the yaw.
Returns the pitch.
Returns the roll.
Returns a quaternion with applied rotation around the x-axis.
Returns a quaternion with applied rotation around the y-axis.
Returns a quaternion with applied rotation around the z-axis.
Returns a quaternion with applied rotation around an axis.
Creates a quaternion from an euler rotation.
Rotates the current quaternion around the x-axis and returns this.
Rotates the current quaternion around the y-axis and returns this.
Rotates the current quaternion around the z-axis and returns this.
Rotates the current quaternion around an axis and returns this.
Applies an euler rotation to the current quaternion and returns this.
Pre-defined quaternion of type float.