LMatrix4d

class LMatrix4d

Bases: MemoryBase

This is a 4-by-4 transform matrix.

Inheritance diagram

Inheritance diagram of LMatrix4d

class CRow
CRow(LMatrix4d::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(LMatrix4d::Row const&) = default

Defines a row-level index accessor to the matrix.

int size(void)

Returns 4: the number of columns of a LMatrix4.

LMatrix4d(void) = default
LMatrix4d(LMatrix4d const &other) = default
LMatrix4d(UnalignedLMatrix4d const &other)
LMatrix4d(double, double, double, double, double, double, double, double, double, double, double, double, double, double, double, double)
LMatrix4d(LVecBase4d const&, LVecBase4d const&, LVecBase4d const&, LVecBase4d const&)
LMatrix4d(LMatrix3d const &upper3)
LMatrix4d(LMatrix3d const &upper3, LVecBase3d 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(LMatrix4d const &other, double weight)

Computes (*this) += other * weight.

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

Adds the vector into the running hash.

bool almost_equal(LMatrix4d const &other, double threshold) const
bool almost_equal(LMatrix4d 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(LMatrix4d const &other) const
int compare_to(LMatrix4d const &other, double 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(LMatrix4d const &other)
static LMatrix4d 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(double 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, double scale) const

Adds the vector to the indicated hash generator.

double get_cell(int row, int col) const

Returns a particular element of the matrix.

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

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

LVecBase3d get_col3(int col) const

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

double 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(double threshold) const

Returns a suitable hash for phash_map.

int get_num_components(void) const

Returns the number of elements in the matrix, 16.

LVecBase4d get_row(int row) const
void get_row(LVecBase4d &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.

LVecBase3d get_row3(int row) const
void get_row3(LVecBase3d &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.

LMatrix3d get_upper_3(void) const

Retrieves the upper 3x3 submatrix.

LMatrix4d 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(LMatrix4d const &other)

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

bool invert_from(LMatrix4d 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(LMatrix4d const &other1, LMatrix4d const &other2)

this = other1 * other2

LMatrix4d 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().

LMatrix4d rotate_mat(double angle, LVecBase3d const &axis, CoordinateSystem cs = ::CS_default)

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

LMatrix4d rotate_mat_normaxis(double angle, LVecBase3d 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.

LMatrix4d scale_mat(LVecBase3d const &scale)
LMatrix4d scale_mat(double sx, double sy, double sz)
LMatrix4d scale_mat(double 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.

LMatrix4d scale_shear_mat(LVecBase3d const &scale, LVecBase3d const &shear, CoordinateSystem cs = ::CS_default)
LMatrix4d scale_shear_mat(double sx, double sy, double sz, double shxy, double shxz, double shyz, CoordinateSystem cs = ::CS_default)

Returns a matrix that applies the indicated scale and shear.

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

Changes a particular element of the matrix.

void set_col(int col, LVecBase4d const &v)
void set_col(int col, LVecBase3d 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(double angle, LVecBase3d 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(double angle, LVecBase3d 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, LVecBase4d const &v)
void set_row(int row, LVecBase3d 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(LVecBase3d const &scale)

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

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

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

void set_shear_mat(LVecBase3d 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(LVecBase3d const &trans)

Fills mat with a matrix that applies the indicated translation.

void set_upper_3(LMatrix3d const &upper3)

Get and set the upper 3x3 rotation matrix.

Sets the upper 3x3 submatrix.

LMatrix4d shear_mat(LVecBase3d const &shear, CoordinateSystem cs = ::CS_default)
LMatrix4d shear_mat(double shxy, double shxz, double 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.

LMatrix4d translate_mat(LVecBase3d const &trans)
LMatrix4d translate_mat(double tx, double ty, double tz)

Returns a matrix that applies the indicated translation.

void transpose_from(LMatrix4d 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.

LVecBase4d xform(LVecBase4d const &v) const

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

void xform_in_place(LVecBase4d &v) const

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

LVecBase3d xform_point(LVecBase3d 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.

LVecBase3d xform_point_general(LVecBase3d 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(LVecBase3d &v) const

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

void xform_point_in_place(LVecBase3d &v) const

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

LVecBase3d xform_vec(LVecBase3d 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.

LVecBase3d xform_vec_general(LVecBase3d 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(LVecBase3d &v) const

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

void xform_vec_in_place(LVecBase3d &v) const

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

LMatrix4d const &y_to_z_up_mat(void)

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

LMatrix4d const &z_to_y_up_mat(void)

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

LMatrix4d const &zeros_mat(void)

Returns an matrix filled with zeros.