mat2
2x2 matrix of floats.
Fields and methods
Members of the struct matrix_stack<float,2,2>. Most of what you do with a CGP type goes through the free functions listed below.
Fields
numarray_stack<numarray_stack<float,2>,2> data | Coefficients stored row by row as 2 rows of 2 floats, contiguous in memory. |
Methods
matrix_stack() | Builds a matrix with all elements set to zero.10 overloads src |
matrix_stack(numarray_stack<vec2,2> const& elements) | Builds a mat2 from an array of two vec2 rows. src |
matrix_stack(vec2 const& row_1, vec2 const& row_2) | Builds a mat2 from its two rows. src |
matrix_stack(numarray_stack<float,4> const& elements) | Builds a mat2 from 4 values in row-major order. src |
matrix_stack(float xx, float xy, float yx, float yy) | Builds a mat2 from its 4 elements given row by row (xx, xy, yx, yy). src |
matrix_stack(matrix_stack<float,N1_arg,N2_arg> const& M) | Builds a mat2, mat3 or mat4 from a float matrix of another size (explicit), copying the common top-left block and setting the other elements to zero (a mat4 built from a mat3 uses the dedicated constructor instead, which puts 1 at (3,3)). src |
matrix_stack(float value) | Builds the mat2, mat3 or mat4 with the given value on the whole diagonal and zeros elsewhere (explicit, as in glm). src |
matrix_stack(float xx, float yy) | Builds the diagonal mat2 diag(xx, yy) (explicit). src |
matrix_stack(std::initializer_list<float> const& arg) | Builds a mat2, mat3 or mat4 from a brace list of floats; N*N or more values fill it in row-major order (extra ones ignored), 1 value or N values build a diagonal matrix (mat4 also accepts 3 values, with 1 as last diagonal element), and any other count raises an error. src |
matrix_stack(std::initializer_list<vec2> const& arg) | Builds a mat2 from a brace list of at least two vec2 rows (asserted); extra rows are ignored. src |
| Returns the total number of elements N1*N2 (4, 9 and 16 for mat2, mat3 and mat4). src | |
| Returns the dimensions {N1, N2} (number of rows, number of columns) as an int2. src | |
| Sets every element to the given value and returns a reference to the matrix. src | |
| Returns the identity matrix (ones on the main diagonal, zeros elsewhere; for a non-square generic matrix the diagonal has min(N1,N2) ones). src | |
| Returns a mat2, mat3 or mat4 with all elements equal to zero. src | |
| Returns a mat2, mat3 or mat4 with all elements equal to the given value. src | |
static mat2 build_diagonal(float value) | Returns the mat2, mat3 or mat4 with the given value on the whole diagonal (including element (3,3) of a mat4) and zeros elsewhere.3 overloads src |
static mat2 build_diagonal(vec2 const& arg) | Returns the diagonal mat2 whose diagonal is the given vec2. src |
static mat2 build_diagonal(float x, float y) | Returns the diagonal mat2 diag(x, y). src |
static mat2 build_scaling(float value) | Returns the uniform scaling matrix of the given factor; same as build_diagonal for mat2 and mat3, while a mat4 keeps 1 as element (3,3).3 overloads src |
static mat2 build_scaling(vec2 const& arg) | Returns the mat2 scaling diag(arg.x, arg.y), same as build_diagonal. src |
static mat2 build_scaling(float x, float y) | Returns the mat2 scaling diag(x, y), same as build_diagonal. src |
| Returns the mat2 of the counterclockwise rotation of angle theta in radians, rows (cos, -sin) and (sin, cos). src | |
| Returns a const reference to row k (a vec2, vec3 or vec4 for mat2, mat3 or mat4), with bound checking unless CGP_NO_DEBUG is defined. src | |
vec2 const& operator()(int k2) constvec2& operator()(int k2) | Returns a const reference to row k1 (a vector of N2 elements), with bound checking unless CGP_NO_DEBUG is defined.2 overloads src |
float const& operator()(int k1, int k2) constfloat& operator()(int k1, int k2) | Returns a const reference to the element at row k1 and column k2, with bound checking unless CGP_NO_DEBUG is defined. src |
vec2 const& at(int k2) constvec2& at(int k2) | For mat2 and mat3, returns a const reference to row k, bound-checked through the row array unless CGP_NO_DEBUG is defined.2 overloads src |
float const& at(int k1, int k2) constfloat& at(int k1, int k2) | Returns a const reference to the element at row k1 and column k2; bound-checked for mat2, mat3 and mat4 (unless CGP_NO_DEBUG is defined) but not for the generic matrix_stack. src |
float const& coeff(int k1, int k2) constfloat& coeff(int k1, int k2) | Returns a const reference to the element at row k1 and column k2, without bound checking.2 overloads src |
vec2 const& coeff(int k1) constvec2& coeff(int k1) | Returns a const reference to row k1, without bound checking. src |
| Returns a const reference to the element at the row-major offset k1*N2+k2; bound-checked for the generic matrix and mat4 (unless CGP_NO_DEBUG is defined) but not for mat2 and mat3. src | |
| Returns a const reference to the element at the given row-major offset, without bound checking. src | |
| Returns the (N1-1)x(N2-1) matrix obtained by removing row k1 and column k2 (asserts k1<N1 and k2<N2), e.g. a mat2 for a mat3. src | |
| Copies a smaller matrix into this one with its top-left corner at (offset_1, offset_2), default (0,0), and returns a reference to this matrix; the block must fit (static_assert on its size, assert on the offsets). src | |
| Returns a const pointer to the first element (0,0) of the contiguous row-major storage. src | |
| Returns a const pointer one past the last element (N1-1,N2-1) of the contiguous row-major storage. src | |
| Returns a const pointer to the first element (0,0) of the contiguous row-major storage. src | |
| Returns a const pointer one past the last element (N1-1,N2-1) of the contiguous row-major storage. src |
Functions taking a mat2
Transform 1
Compute 1
Convert 1
Other 1
Documented on another page
opengl_uniformSend a mat2 uniform (row-major, transposed on upload) to the shader; warns if the uniform is not found and expected is true.onopengl_shader_structure
Functions returning a mat2
Construct 1
mat2 tensor_product(vec2 const& a, vec2 const& b)Outer product a * transpose(b), as a 2x2 matrix.
Operators
None besides the shared functions above.