Libprimis
Imprimis' 3D destroyable world engine
Loading...
Searching...
No Matches
matrix3 Class Reference

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
 

Detailed Description

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

Constructor & Destructor Documentation

◆ matrix3() [1/5]

matrix3::matrix3 ( const vec & a,
const vec & b,
const vec & c )

Creates a new matrix with the given vectors.

Parameters
athe vector to assign to the top row
bthe vector to assign to the middle row
cthe vector to assign to the bottom row

◆ matrix3() [2/5]

matrix3::matrix3 ( float angle,
const vec & axis )
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.

Parameters
anglethe rotation amount the rotation matrix encodes
axisthe direction which is invariant under the rotation encoded by angle

◆ matrix3() [3/5]

matrix3::matrix3 ( const quat & q)
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.

Parameters
qthe quaternion to use

◆ matrix3() [4/5]

matrix3::matrix3 ( const matrix4x3 & m)
inlineexplicit

Creates a 3d matrix given a 4x3 matrix.

Parameters
mthe matrix to use

◆ matrix3() [5/5]

matrix3::matrix3 ( const matrix4 & m)
inlineexplicit

Creates a 3x3 matrix given a 4x4 matrix.

This truncates the 4th member in both dimensions of the matrix.

Parameters
mthe matrix to use

Member Function Documentation

◆ abstransform()

vec matrix3::abstransform ( const vec & o) const

Sets the matrix to the absolute value of the transform.

Parameters
othe 3d vector to transform by
Returns
the dot products of the resulting matrix

◆ abstransposedtransform()

vec matrix3::abstransposedtransform ( const vec & o) const

Sets the matrix to the absolute value of the transpose-transform.

Parameters
othe 3d vector to transform by
Returns
the result of the transform

◆ calcangleaxis() [1/2]

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.

Parameters
anglethe angle to set
axisthe axis to set
thresholdthe magnitude required not to reject the matrix
Returns
whether the axis and angle were both set

◆ calcangleaxis() [2/2]

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

Parameters
trthe trace of the matrix
anglethe angle to set
axisthe axis to set
thresholdthe magnitude required not to reject the matrix
Returns
whether the axis and angle were both set

◆ identity()

void matrix3::identity ( )

Sets the matrix to be the identity matrix.

1 0 0
0 1 0
0 0 1

◆ invert() [1/2]

void matrix3::invert ( )

Inverts the matrix using itself for the scale factor.

This operation can be undone by calling invert() again.

◆ invert() [2/2]

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.

◆ mul() [1/2]

void matrix3::mul ( const matrix3 & m,
const matrix3 & n )

Calculates the product of three matrices.

Parameters
mthe first matrix to multiply by
nthe second matrix to multiply by

◆ mul() [2/2]

void matrix3::mul ( const matrix3 & n)

Multiplies the matrix by another.

This operation changes the value of the matrix.

Parameters
n

◆ multranspose()

void matrix3::multranspose ( const matrix3 & n)

Calculates the multiplication-transpose with another matrix.

Parameters
nthe matrix to use

◆ normalize()

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.

◆ rotate() [1/2]

void matrix3::rotate ( float angle,
const vec & axis )

Rotates the matrix around the given axis by the given angle.

Parameters
anglethe angle to rotate by (radians)
axisthe axis to rotate about

◆ rotate() [2/2]

void matrix3::rotate ( float ck,
float sk,
const vec & axis )

Rotates the matrix around the given axis by the given angle.

Parameters
ckthe cosine term
skthe sine term
axisthe axis to rotate about

◆ rotate_around_x() [1/2]

void matrix3::rotate_around_x ( const vec2 & sc)

Rotates the matrix values around the X axis.

Parameters
sca vector containing the cosine + sine terms

◆ rotate_around_x() [2/2]

void matrix3::rotate_around_x ( float angle)

Rotates the matrix values around the X axis.

Parameters
anglethe angle by which to rotate about

◆ rotate_around_y() [1/2]

void matrix3::rotate_around_y ( const vec2 & sc)

Rotates the matrix values around the Y axis.

Parameters
sca vector containing the cosine + sine terms

◆ rotate_around_y() [2/2]

void matrix3::rotate_around_y ( float angle)

Rotates the matrix values around the Y axis.

Parameters
anglethe angle by which to rotate about

◆ rotate_around_z() [1/2]

void matrix3::rotate_around_z ( const vec2 & sc)

Rotates the matrix values around the Z axis.

Parameters
sca vector containing the cosine + sine terms

◆ rotate_around_z() [2/2]

void matrix3::rotate_around_z ( float angle)

Rotates the matrix values around the Z axis.

Parameters
angleby which to rotate

◆ rowx()

vec matrix3::rowx ( ) const

Returns the first (top) row of the matrix.

Returns
a 3d vector containing the first row of the matrix

◆ rowy()

vec matrix3::rowy ( ) const

Returns the second (middle) row of the matrix.

Returns
a 3d vector containing the second row of the matrix

◆ rowz()

vec matrix3::rowz ( ) const

Returns the third (bottom) row of the matrix.

Returns
a 3d fector containing the thrid row of the matrix

◆ scale()

void matrix3::scale ( float k)

Multiplies each element of the matrix by the scale factor given.

Parameters
kthe scale factor to multiply by

◆ setyaw()

void matrix3::setyaw ( float angle)

Sets the matrix to a 2D rotation matrix.

The output matrix looks like this:

cosf(angle) sinf(angle) 0
-sinf(angle) cosf(angle) 0
0 0 1

(This is a rotation matrix around the Z-axis.)

Parameters
anglethe angle to rotate by (radians)

◆ trace()

float matrix3::trace ( ) const

Returns the trace of the matrix.

The trace is equal to the sum of the diagonal values of the matrix.

Returns
a float representing the trace of the matrix

◆ transform() [1/2]

vec matrix3::transform ( const vec & o) const

Sets the matrix to the transform of the matrix.

Parameters
othe 3d vector to transform by
Returns
whether the angle is within the allowable range

◆ transform() [2/2]

vec matrix3::transform ( const vec2 & o) const

Returns the transform of the matrix.

Parameters
othe 2d vector to transform by
Returns
the transform of the matrix

◆ transpose()

void matrix3::transpose ( )

Transposes the matrix.

a b c a d g
d e f -> b e h
g h i c f i
vec a
the three vectors making up the rows of the matrix
Definition geom.h:1397

◆ transposedtransform() [1/2]

vec matrix3::transposedtransform ( const vec & o) const

Sets the matrix to the transpose-transform.

Parameters
othe 3d vector to transform by
Returns
the result of the transform

◆ transposedtransform() [2/2]

vec matrix3::transposedtransform ( const vec2 & o) const

Returns the transposed transform of the matrix.

Parameters
othe vector to transform with
Returns
the transposed transform of the matrix

◆ transposemul() [1/2]

void matrix3::transposemul ( const matrix3 & m,
const matrix3 & n )

Calculates the transpose-multiplication with another two matrices.

Parameters
mthe first matrix to use
nthe second matrix to use

◆ transposemul() [2/2]

void matrix3::transposemul ( const matrix3 & n)

Calculates the transpose-multiplication with another matrix.

Parameters
nthe matrix to multiply by

Member Data Documentation

◆ a

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


The documentation for this class was generated from the following file: