LMatrix4f

class LMatrix4f

Bases: MemoryBase

This is a 4-by-4 transform matrix.

Inheritance diagram

Inheritance diagram of LMatrix4f

class CRow
CRow(LMatrix4f::CRow const&) = default

Defines a row-level constant accessor to the matrix.

int size(void)

Returns 4: the number of columns of a LMatrix4.

class Row

These helper classes are used to support two-level operator [].

Row(LMatrix4f::Row const&) = default

Defines a row-level index accessor to the matrix.

int size(void)

Returns 4: the number of columns of a LMatrix4.

LMatrix4f(void) = default
LMatrix4f(LMatrix4f const &other) = default
LMatrix4f(UnalignedLMatrix4f const &other)
LMatrix4f(float, float, float, float, float, float, float, float, float, float, float, float, float, float, float, float)
LMatrix4f(LVecBase4f const&, LVecBase4f const&, LVecBase4f const&, LVecBase4f const&)
LMatrix4f(LMatrix3f const &upper3)
LMatrix4f(LMatrix3f const &upper3, LVecBase3f const &trans)

Construct a 4x4 matrix given a 3x3 rotation matrix and an optional translation component.

Constructs the matrix from four individual rows.

void accumulate(LMatrix4f const &other, float weight)

Computes (*this) += other * weight.

std::size_t add_hash(std::size_t hash) const
std::size_t add_hash(std::size_t hash, float threshold) const

Adds the vector into the running hash.

bool almost_equal(LMatrix4f const &other, float threshold) const
bool almost_equal(LMatrix4f const &other) const

Returns true if two matrices are memberwise equal within a default tolerance based on the numeric type.

Returns true if two matrices are memberwise equal within a specified tolerance. This is faster than the equivalence operator as this doesn’t have to guarantee that it is transitive.

iterator begin(void)
const_iterator begin(void) const

Returns an iterator that may be used to traverse the elements of the matrix, STL-style.

int compare_to(LMatrix4f const &other) const
int compare_to(LMatrix4f const &other, float threshold) const

This flavor of compare_to uses a default threshold value based on the numeric type.

Sorts matrices lexicographically, componentwise. Returns a number less than 0 if this matrix sorts before the other one, greater than zero if it sorts after, 0 if they are equivalent (within the indicated tolerance).

void componentwise_mult(LMatrix4f const &other)
static LMatrix4f const &convert_mat(CoordinateSystem from, CoordinateSystem to)

Returns a matrix that transforms from the indicated coordinate system to the indicated coordinate system.

iterator end(void)
const_iterator end(void) const

Returns an iterator that may be used to traverse the elements of the matrix, STL-style.

void fill(float fill_value)

Sets each element of the matrix to the indicated fill_value. This is of questionable value, but is sometimes useful when initializing to zero.

void generate_hash(ChecksumHashGenerator &hashgen) const
void generate_hash(ChecksumHashGenerator &hashgen, float scale) const

Adds the vector to the indicated hash generator.

float get_cell(int row, int col) const

Returns a particular element of the matrix.

static TypeHandle get_class_type(void)
LVecBase4f get_col(int col) const

Retrieves the indicated column of the matrix as a 4-component vector.

LVecBase3f get_col3(int col) const

Retrieves the indicated column of the matrix as a 3-component vector, ignoring the last row.

float const *get_data(void) const

Returns the address of the first of the nine data elements in the matrix. The remaining elements occupy the next eight positions in row-major order.

std::size_t get_hash(void) const
std::size_t get_hash(float threshold) const

Returns a suitable hash for phash_map.

int get_num_components(void) const

Returns the number of elements in the matrix, 16.

LVecBase4f get_row(int row) const
void get_row(LVecBase4f &result_vec, int row) const

these versions inline better

Retrieves the indicated row of the matrix as a 4-component vector.

Stores the indicated row of the matrix as a 4-component vector.

LVecBase3f get_row3(int row) const
void get_row3(LVecBase3f &result_vec, int row) const

Retrieves the row column of the matrix as a 3-component vector, ignoring the last column.

Stores the row column of the matrix as a 3-component vector, ignoring the last column.

LMatrix3f get_upper_3(void) const

Retrieves the upper 3x3 submatrix.

LMatrix4f const &ident_mat(void)

Returns an identity matrix.

This function definition must appear first, since some inline functions below take advantage of it.

bool invert_affine_from(LMatrix4f const &other)

bugbug: we could optimize this for rotationscaletranslation matrices (transpose upper 3x3 and take negative of translation component)

bool invert_from(LMatrix4f const &other)

Computes the inverse of the other matrix, and stores the result in this matrix. This is a fully general operation and makes no assumptions about the type of transform represented by the matrix.

The other matrix must be a different object than this matrix. However, if you need to invert a matrix in place, see invert_in_place.

The return value is true if the matrix was successfully inverted, false if the was a singularity.

bool invert_in_place(void)

Inverts the current matrix. Returns true if the inverse is successful, false if the matrix was singular.

bool is_identity(void) const

Returns true if this is (close enough to) the identity matrix, false otherwise.

bool is_nan(void) const

Returns true if any component of the matrix is not-a-number, false otherwise.

void multiply(LMatrix4f const &other1, LMatrix4f const &other2)

this = other1 * other2

LMatrix4f const &ones_mat(void)

Returns an matrix filled with ones.

void output(std::ostream &out) const
void read_datagram(DatagramIterator &source)

Reads the matrix from the Datagram using get_stdfloat().

void read_datagram_fixed(DatagramIterator &scan)

Reads the matrix from the Datagram using get_float32() or get_float64(). See write_datagram_fixed().

LMatrix4f rotate_mat(float angle, LVecBase3f const &axis, CoordinateSystem cs = ::CS_default)

Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.

LMatrix4f rotate_mat_normaxis(float angle, LVecBase3f const &axis, CoordinateSystem cs = ::CS_default)

Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector. Assumes axis has been prenormalized.

LMatrix4f scale_mat(LVecBase3f const &scale)
LMatrix4f scale_mat(float sx, float sy, float sz)
LMatrix4f scale_mat(float scale)

Returns a matrix that applies the indicated scale in each of the three axes.

Returns a matrix that applies the indicated scale in each of the three axes.

Returns a matrix that applies the indicated uniform scale.

LMatrix4f scale_shear_mat(LVecBase3f const &scale, LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)
LMatrix4f scale_shear_mat(float sx, float sy, float sz, float shxy, float shxz, float shyz, CoordinateSystem cs = ::CS_default)

Returns a matrix that applies the indicated scale and shear.

void set(float e00, float e01, float e02, float e03, float e10, float e11, float e12, float e13, float e20, float e21, float e22, float e23, float e30, float e31, float e32, float e33)
void set_cell(int row, int col, float value)

Changes a particular element of the matrix.

void set_col(int col, LVecBase4f const &v)
void set_col(int col, LVecBase3f const &v)

Replaces the indicated column of the matrix.

Replaces the indicated column of the matrix with the indicated 3-component vector, ignoring the last row.

void set_rotate_mat(float angle, LVecBase3f const &axis, CoordinateSystem cs = ::CS_default)

Sets mat to a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.

void set_rotate_mat_normaxis(float angle, LVecBase3f const &axis, CoordinateSystem cs = ::CS_default)

Fills mat with a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector. Assumes axis has been prenormalized.

void set_row(int row, LVecBase4f const &v)
void set_row(int row, LVecBase3f const &v)

Replaces the indicated row of the matrix.

Replaces the indicated row of the matrix with the indicated 3-component vector, ignoring the last column.

void set_scale_mat(LVecBase3f const &scale)

Fills mat with a matrix that applies the indicated scale in each of the three axes.

void set_scale_shear_mat(LVecBase3f const &scale, LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)

Fills mat with a matrix that applies the indicated scale and shear.

void set_shear_mat(LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)

Fills mat with a matrix that applies the indicated shear in each of the three planes.

void set_translate_mat(LVecBase3f const &trans)

Fills mat with a matrix that applies the indicated translation.

void set_upper_3(LMatrix3f const &upper3)

Get and set the upper 3x3 rotation matrix.

Sets the upper 3x3 submatrix.

LMatrix4f shear_mat(LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)
LMatrix4f shear_mat(float shxy, float shxz, float shyz, CoordinateSystem cs = ::CS_default)

Returns a matrix that applies the indicated shear in each of the three planes.

int size(void)

Returns 4: the number of rows of a LMatrix4.

LMatrix4f translate_mat(LVecBase3f const &trans)
LMatrix4f translate_mat(float tx, float ty, float tz)

Returns a matrix that applies the indicated translation.

void transpose_from(LMatrix4f const &other)
void transpose_in_place(void)
bool validate_ptr(void const *ptr)
void write(std::ostream &out, int indent_level = 0) const
void write_datagram(Datagram &destination) const

Writes the matrix to the Datagram using add_stdfloat(). This is appropriate when you want to write the matrix using the standard width setting, especially when you are writing a bam file.

void write_datagram_fixed(Datagram &destination) const

Writes the matrix to the Datagram using add_float32() or add_float64(), depending on the type of floats in the matrix, regardless of the setting of Datagram::set_stdfloat_double(). This is appropriate when you want to write a fixed-width value to the datagram, especially when you are not writing a bam file.

LVecBase4f xform(LVecBase4f const &v) const

4-component vector or point times matrix. This is a fully general operation.

void xform_in_place(LVecBase4f &v) const

4-component vector or point times matrix. This is a fully general operation.

LVecBase3f xform_point(LVecBase3f const &v) const

The matrix transforms a 3-component point (including translation component) and returns the result. This assumes the matrix is an affine transform.

LVecBase3f xform_point_general(LVecBase3f const &v) const

The matrix transforms a 3-component point (including translation component) and returns the result, as a fully general operation.

void xform_point_general_in_place(LVecBase3f &v) const

The matrix transforms a 3-component point (including translation component), as a fully general operation.

void xform_point_in_place(LVecBase3f &v) const

The matrix transforms a 3-component point (including translation component). This assumes the matrix is an affine transform.

LVecBase3f xform_vec(LVecBase3f const &v) const

The matrix transforms a 3-component vector (without translation component) and returns the result. This assumes the matrix is an orthonormal transform.

LVecBase3f xform_vec_general(LVecBase3f const &v) const

The matrix transforms a 3-component vector (without translation component) and returns the result, as a fully general operation.

void xform_vec_general_in_place(LVecBase3f &v) const

The matrix transforms a 3-component vector (without translation component), as a fully general operation.

void xform_vec_in_place(LVecBase3f &v) const

The matrix transforms a 3-component vector (without translation component). This assumes the matrix is an orthonormal transform.

LMatrix4f const &y_to_z_up_mat(void)

Returns a matrix that transforms from the Y-up coordinate system to the Z-up coordinate system.

LMatrix4f const &z_to_y_up_mat(void)

Returns a matrix that transforms from the Y-up coordinate system to the Z-up coordinate system.

LMatrix4f const &zeros_mat(void)

Returns an matrix filled with zeros.