Libprimis
Imprimis' 3D destroyable world engine
|
matrix3: 3x3 matrix comprised of three vec3 vectors arranged as follows: [ a1 b1 c1 a2 b2 c2 a3 b3 c3 ] More...
#include <geom.h>
Public Member Functions | |
matrix3 () | |
Creates an empty matrix. | |
matrix3 (const vec &a, const vec &b, const vec &c) | |
Creates a new matrix with the given vectors. | |
matrix3 (float angle, const vec &axis) | |
Creates a new matrix as a rotation matrix. | |
matrix3 (const quat &q) | |
Creates a 3d rotation matrix given a quaternion object. | |
matrix3 (const matrix4x3 &m) | |
Creates a 3d matrix given a 4x3 matrix. | |
matrix3 (const matrix4 &m) | |
Creates a 3x3 matrix given a 4x4 matrix. | |
void | mul (const matrix3 &m, const matrix3 &n) |
Calculates the product of three matrices. | |
void | mul (const matrix3 &n) |
Multiplies the matrix by another. | |
void | multranspose (const matrix3 &n) |
Calculates the multiplication-transpose with another matrix. | |
void | transposemul (const matrix3 &m, const matrix3 &n) |
Calculates the transpose-multiplication with another two matrices. | |
void | transposemul (const matrix3 &n) |
Calculates the transpose-multiplication with another matrix. | |
void | transpose () |
Transposes the matrix. | |
void | invert (const matrix3 &o) |
Inverts the matrix using another matrix for the scale factor. | |
void | invert () |
Inverts the matrix using itself for the scale factor. | |
void | normalize () |
Normalizes each of the three rows to a magnitude of 1. | |
void | scale (float k) |
Multiplies each element of the matrix by the scale factor given. | |
void | rotate (float angle, const vec &axis) |
Rotates the matrix around the given axis by the given angle. | |
void | rotate (float ck, float sk, const vec &axis) |
Rotates the matrix around the given axis by the given angle. | |
void | setyaw (float angle) |
Sets the matrix to a 2D rotation matrix. | |
float | trace () const |
Returns the trace of the matrix. | |
bool | calcangleaxis (float tr, float &angle, vec &axis, float threshold=1e-16f) const |
Calculates the axis and angle from a rotation matrix. | |
bool | calcangleaxis (float &angle, vec &axis, float threshold=1e-16f) const |
Calculates the axis and angle from a rotation matrix. | |
vec | transform (const vec &o) const |
Sets the matrix to the transform of the matrix. | |
vec | transposedtransform (const vec &o) const |
Sets the matrix to the transpose-transform. | |
vec | abstransform (const vec &o) const |
Sets the matrix to the absolute value of the transform. | |
vec | abstransposedtransform (const vec &o) const |
Sets the matrix to the absolute value of the transpose-transform. | |
void | identity () |
Sets the matrix to be the identity matrix. | |
void | rotate_around_x (float angle) |
Rotates the matrix values around the X axis. | |
void | rotate_around_x (const vec2 &sc) |
Rotates the matrix values around the X axis. | |
void | rotate_around_y (float angle) |
Rotates the matrix values around the Y axis. | |
void | rotate_around_y (const vec2 &sc) |
Rotates the matrix values around the Y axis. | |
void | rotate_around_z (float angle) |
Rotates the matrix values around the Z axis. | |
void | rotate_around_z (const vec2 &sc) |
Rotates the matrix values around the Z axis. | |
vec | transform (const vec2 &o) const |
Returns the transform of the matrix. | |
vec | transposedtransform (const vec2 &o) const |
Returns the transposed transform of the matrix. | |
vec | rowx () const |
Returns the first (top) row of the matrix. | |
vec | rowy () const |
Returns the second (middle) row of the matrix. | |
vec | rowz () const |
Returns the third (bottom) row of the matrix. | |
Public Attributes | |
vec | a |
the three vectors making up the rows of the matrix | |
vec | b |
vec | c |
matrix3: 3x3 matrix comprised of three vec3 vectors arranged as follows: [ a1 b1 c1 a2 b2 c2 a3 b3 c3 ]
used largely in models/anims/ragdolls but also in stuff like bih
Creates a new matrix with the given vectors.
a | the vector to assign to the top row |
b | the vector to assign to the middle row |
c | the vector to assign to the bottom row |
|
explicit |
Creates a new matrix as a rotation matrix.
If the axis passed is not normalized, the resulting rotation matrix will not encode a pure rotation.
angle | the rotation amount the rotation matrix encodes |
axis | the direction which is invariant under the rotation encoded by angle |
|
explicit |
Creates a 3d rotation matrix given a quaternion object.
Note that quaternions are an engine-specific construct and not part of the game API beyond the prototype defined in this header.
q | the quaternion to use |
|
inlineexplicit |
Creates a 3d matrix given a 4x3 matrix.
m | the matrix to use |
|
inlineexplicit |
Creates a 3x3 matrix given a 4x4 matrix.
This truncates the 4th member in both dimensions of the matrix.
m | the matrix to use |
Sets the matrix to the absolute value of the transform.
o | the 3d vector to transform by |
Sets the matrix to the absolute value of the transpose-transform.
o | the 3d vector to transform by |
bool matrix3::calcangleaxis | ( | float & | angle, |
vec & | axis, | ||
float | threshold = 1e-16f ) const |
Calculates the axis and angle from a rotation matrix.
Ony used in certain ragdoll calculations.
Same behavior as calcangleaxis(float, float &, vec &, float)
except the trace()
is automatically calculated.
angle | the angle to set |
axis | the axis to set |
threshold | the magnitude required not to reject the matrix |
bool matrix3::calcangleaxis | ( | float | tr, |
float & | angle, | ||
vec & | axis, | ||
float | threshold = 1e-16f ) const |
Calculates the axis and angle from a rotation matrix.
Only used in certain ragdoll calculations.
The axis vector represents the vector which is invariant under the rotation encoded in the rotation matrix.
The angle represents the rotation magnitude around the axis vector.
Both angle
and axis
are pure output parameters and their prior values are discarded.
If the values encoding the axis result in a magnitude smaller than threshhold
, returns false and does not set the angle nor the axis (except axis will be set if trace = 0..2); otherwise sets both angle and axis and returns true
tr | the trace of the matrix |
angle | the angle to set |
axis | the axis to set |
threshold | the magnitude required not to reject the matrix |
void matrix3::identity | ( | ) |
Sets the matrix to be the identity matrix.
void matrix3::invert | ( | ) |
Inverts the matrix using itself for the scale factor.
This operation can be undone by calling invert() again.
void matrix3::invert | ( | const matrix3 & | o | ) |
Inverts the matrix using another matrix for the scale factor.
This operation can be undone by calling invert() again using the same argument.
Calculates the product of three matrices.
m | the first matrix to multiply by |
n | the second matrix to multiply by |
void matrix3::mul | ( | const matrix3 & | n | ) |
Multiplies the matrix by another.
This operation changes the value of the matrix.
n |
void matrix3::multranspose | ( | const matrix3 & | n | ) |
Calculates the multiplication-transpose with another matrix.
n | the matrix to use |
void matrix3::normalize | ( | ) |
Normalizes each of the three rows to a magnitude of 1.
Calls normalize() for each of the three vec objects making up the matrix.
void matrix3::rotate | ( | float | angle, |
const vec & | axis ) |
Rotates the matrix around the given axis by the given angle.
angle | the angle to rotate by (radians) |
axis | the axis to rotate about |
void matrix3::rotate | ( | float | ck, |
float | sk, | ||
const vec & | axis ) |
Rotates the matrix around the given axis by the given angle.
ck | the cosine term |
sk | the sine term |
axis | the axis to rotate about |
void matrix3::rotate_around_x | ( | const vec2 & | sc | ) |
Rotates the matrix values around the X axis.
sc | a vector containing the cosine + sine terms |
void matrix3::rotate_around_x | ( | float | angle | ) |
Rotates the matrix values around the X axis.
angle | the angle by which to rotate about |
void matrix3::rotate_around_y | ( | const vec2 & | sc | ) |
Rotates the matrix values around the Y axis.
sc | a vector containing the cosine + sine terms |
void matrix3::rotate_around_y | ( | float | angle | ) |
Rotates the matrix values around the Y axis.
angle | the angle by which to rotate about |
void matrix3::rotate_around_z | ( | const vec2 & | sc | ) |
Rotates the matrix values around the Z axis.
sc | a vector containing the cosine + sine terms |
void matrix3::rotate_around_z | ( | float | angle | ) |
Rotates the matrix values around the Z axis.
angle | by which to rotate |
vec matrix3::rowx | ( | ) | const |
Returns the first (top) row of the matrix.
vec matrix3::rowy | ( | ) | const |
Returns the second (middle) row of the matrix.
vec matrix3::rowz | ( | ) | const |
Returns the third (bottom) row of the matrix.
void matrix3::scale | ( | float | k | ) |
Multiplies each element of the matrix by the scale factor given.
k | the scale factor to multiply by |
void matrix3::setyaw | ( | float | angle | ) |
Sets the matrix to a 2D rotation matrix.
The output matrix looks like this:
(This is a rotation matrix around the Z-axis.)
angle | the angle to rotate by (radians) |
float matrix3::trace | ( | ) | const |
Returns the trace of the matrix.
The trace is equal to the sum of the diagonal values of the matrix.
Sets the matrix to the transform of the matrix.
o | the 3d vector to transform by |
Returns the transform of the matrix.
o | the 2d vector to transform by |
void matrix3::transpose | ( | ) |
Transposes the matrix.
Sets the matrix to the transpose-transform.
o | the 3d vector to transform by |
Returns the transposed transform of the matrix.
o | the vector to transform with |
Calculates the transpose-multiplication with another two matrices.
m | the first matrix to use |
n | the second matrix to use |
void matrix3::transposemul | ( | const matrix3 & | n | ) |
Calculates the transpose-multiplication with another matrix.
n | the matrix to multiply by |
vec matrix3::a |
the three vectors making up the rows of the matrix
a is the top vector b is the middle vector c is the bottom vector