# LMatrix3f¶

class LMatrix3f

This is a 3-by-3 transform matrix. It typically will represent either a rotation-and-scale (no translation) matrix in 3-d, or a full affine matrix (rotation, scale, translation) in 2-d, e.g. for a texture matrix.

Inheritance diagram

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

Defines a row-level constant accessor to the matrix.

int size(void)

Returns 3: the number of columns of a LMatrix3.

class Row

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

Row(LMatrix3f::Row const&) = default

Defines a row-level index accessor to the matrix.

int size(void)

Returns 3: the number of columns of a LMatrix3.

LMatrix3f(void)
LMatrix3f(LMatrix3f const &other)
LMatrix3f(float, float, float, float, float, float, float, float, float)
LMatrix3f(LVecBase3f const&, LVecBase3f const&, LVecBase3f const&)

Constructs the matrix from three individual rows.

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(LMatrix3f const &other, float threshold) const
bool almost_equal(LMatrix3f 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.

int compare_to(LMatrix3f const &other) const
int compare_to(LMatrix3f 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(LMatrix3f const &other)
static LMatrix3f const &convert_mat(CoordinateSystem from, CoordinateSystem to)

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

float determinant(void) const

Returns the determinant of the matrix.

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 threshold) 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)
LVecBase3f get_col(int col) const

Returns the indicated column of the matrix as a three-component vector.

LVecBase2f get_col2(int col) const

Returns the indicated column of the matrix as a two-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, nine.

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

these versions inline better

Returns the indicated row of the matrix as a three-component vector.

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

LVecBase2f get_row2(int row) const

Returns the indicated row of the matrix as a two-component vector, ignoring the last column.

LMatrix3f 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_from(LMatrix3f 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 there 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 invert_transpose_from(LMatrix3f const &other)
bool invert_transpose_from(LMatrix4f const &other)

Simultaneously computes the inverse of the indicated matrix, and then the transpose of that inverse.

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(LMatrix3f const &other1, LMatrix3f const &other2)

this = other1 * other2

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

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

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

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

LMatrix3f 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 normalized.

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

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

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

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.

LMatrix3f scale_shear_mat(LVecBase3f const &scale, LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)
LMatrix3f 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 e10, float e11, float e12, float e20, float e21, float e22)
void set_cell(int row, int col, float value)

Changes a particular element of the matrix.

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

Replaces the indicated column of the matrix from a three-component vector.

Replaces the indicated column of the matrix from a two-component vector, ignoring the last row.

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

Fills mat with a matrix that rotates by the given angle in degrees counterclockwise.

Fills mat with 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 normalized.

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

Replaces the indicated row of the matrix from a three-component vector.

Replaces the indicated row of the matrix from a two-component vector, ignoring the last column.

void set_scale_mat(LVecBase2f const &scale)
void set_scale_mat(LVecBase3f const &scale)

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

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(LVecBase2f const &trans)

Fills mat with a matrix that applies the indicated translation.

LMatrix3f shear_mat(LVecBase3f const &shear, CoordinateSystem cs = ::CS_default)
LMatrix3f 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 3: the number of rows of a LMatrix3.

LMatrix3f translate_mat(LVecBase2f const &trans)
LMatrix3f translate_mat(float tx, float ty)

Returns a matrix that applies the indicated translation.

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

LVecBase3f xform(LVecBase3f const &v) const

3-component vector or point times matrix.

void xform_in_place(LVecBase3f &v) const

3-component vector or point times matrix.

LVecBase2f xform_point(LVecBase2f const &v) const

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

void xform_point_in_place(LVecBase2f &v) const

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

LVecBase2f xform_vec(LVecBase2f const &v) const
LVecBase3f xform_vec(LVecBase3f const &v) const

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

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

In practice, this is the same computation as xform().

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(LVecBase2f &v) const
void xform_vec_in_place(LVecBase3f &v) const

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

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

In practice, this is the same computation as xform().