Panda3D
Classes | Public Member Functions | Static Public Member Functions

Mat4 Class Reference

This is a 4-by-4 transform matrix. More...

List of all members.

Classes

class  CRow
class  Row

Public Member Functions

 Mat4 ()
 Mat4 (Mat3 const upper3)
 Mat4 (Mat4 const other)
 Mat4 (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)
 Mat4 (Mat3 const upper3, VBase3 const trans)
unsigned int addHash (unsigned int hash)
 Adds the vector into the running hash.
unsigned int addHash (unsigned int hash, float threshold)
 Adds the vector into the running hash.
bool almostEqual (Mat4 const other)
 Returns true if two matrices are memberwise equal within a default tolerance based on the numeric type.
bool almostEqual (Mat4 const other, float threshold)
 Returns true if two matrices are memberwise equal within a specified tolerance.
 begin ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style.
 begin ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style.
int compareTo (Mat4 const other)
 This flavor of compare_to uses a default threshold value based on the numeric type.
int compareTo (Mat4 const other, float threshold)
 Sorts matrices lexicographically, componentwise.
 end ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style.
 end ()
 Returns an iterator that may be used to traverse the elements of the matrix, STL-style.
 fill (float fill_value)
 Sets each element of the matrix to the indicated fill_value.
float getCell (int row, int col)
 Returns a particular element of the matrix.
VBase4 getCol (int col)
 Retrieves the indicated column of the matrix as a 4-component vector.
VBase3 getCol3 (int col)
 Retrieves the indicated column of the matrix as a 3-component vector, ignoring the last row.
list getCols ()
 getData ()
 Returns the address of the first of the nine data elements in the matrix.
unsigned int getHash ()
 Returns a suitable hash for phash_map.
unsigned int getHash (float threshold)
 Returns a suitable hash for phash_map.
int getNumComponents ()
 Returns the number of elements in the matrix, 16.
 getRow (VBase4 result_vec, int row)
VBase4 getRow (int row)
 Retrieves the indicated row of the matrix as a 4-component vector.
 getRow3 (VBase3 result_vec, int row)
VBase3 getRow3 (int row)
 Retrieves the row column of the matrix as a 3-component vector, ignoring the last column.
list getRow3s ()
list getRows ()
Mat3 getUpper3 ()
 Retrieves the upper 3x3 submatrix.
bool invertAffineFrom (Mat4 const other)
 Performs an invert of the indicated matrix, storing the result in this matrix.
bool invertFrom (Mat4 const other)
 Computes the inverse of the other matrix, and stores the result in this matrix.
bool invertInPlace ()
 Inverts the current matrix.
bool isNan ()
 Returns true if any component of the matrix is not-a-number, false otherwise.
 multiply (Mat4 const other1, Mat4 const other2)
 operator new (unsigned int size)
bool operator!= (Mat4 const other)
 operator() (int row, int col)
float operator() (int row, int col)
Mat4 operator* (float scalar)
Mat4 operator* (Mat4 const other)
Mat4 operator*= (float scalar)
Mat4 operator*= (Mat4 const other)
Mat4 operator+= (Mat4 const other)
 Performs a memberwise addition between two matrices.
Mat4 operator-= (Mat4 const other)
 Performs a memberwise addition between two matrices.
Mat4 operator/ (float scalar)
Mat4 operator/= (float scalar)
bool operator< (Mat4 const other)
 This performs a lexicographical comparison.
Mat4 operator= (float fill_value)
Mat4 operator= (Mat4 const other)
bool operator== (Mat4 const other)
CRow operator[] (int i)
Row operator[] (int i)
 output (ostream out)
 pythonRepr (ostream out, string class_name)
PyObject reduce (PyObject self)
 This special Python method is implement to provide support for the pickle module.
 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)
 setCell (int row, int col, float value)
 Changes a particular element of the matrix.
 setCol (int col, VBase3 const v)
 Replaces the indicated column of the matrix with the indicated 3-component vector, ignoring the last row.
 setCol (int col, VBase4 const v)
 Replaces the indicated column of the matrix.
 setRotateMat (float angle, VBase3 const axis, CoordinateSystem cs)
 Sets mat to a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
 setRotateMat (float angle, VBase3 const axis)
 Sets mat to a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
 setRotateMatNormaxis (float angle, VBase3 const axis)
 Fills mat with a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
 setRotateMatNormaxis (float angle, VBase3 const axis, CoordinateSystem cs)
 Fills mat with a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
 setRow (int row, VBase3 const v)
 Replaces the indicated row of the matrix with the indicated 3-component vector, ignoring the last column.
 setRow (int row, VBase4 const v)
 Replaces the indicated row of the matrix.
 setScaleMat (VBase3 const scale)
 Fills mat with a matrix that applies the indicated scale in each of the three axes.
 setScaleShearMat (VBase3 const scale, VBase3 const shear, CoordinateSystem cs)
 Fills mat with a matrix that applies the indicated scale and shear.
 setScaleShearMat (VBase3 const scale, VBase3 const shear)
 Fills mat with a matrix that applies the indicated scale and shear.
 setShearMat (VBase3 const shear)
 Fills mat with a matrix that applies the indicated shear in each of the three planes.
 setShearMat (VBase3 const shear, CoordinateSystem cs)
 Fills mat with a matrix that applies the indicated shear in each of the three planes.
 setTranslateMat (VBase3 const trans)
 Fills mat with a matrix that applies the indicated translation.
 setUpper3 (Mat3 const upper3)
 Sets the upper 3x3 submatrix.
 transposeFrom (Mat4 const other)
 transposeInPlace ()
 write (ostream out)
 write (ostream out, int indent_level)
VBase4 xform (VBase4 const v)
 4-component vector or point times matrix.
VBase3 xformPoint (VBase3 const v)
 The matrix transforms a 3-component point (including translation component) and returns the result.
VBase3 xformVec (VBase3 const v)
 The matrix transforms a 3-component vector (without translation component) and returns the result.
VBase3 xformVecGeneral (VBase3 const v)
 The matrix transforms a 3-component vector (without translation component) and returns the result, as a fully general operation.

Static Public Member Functions

static Mat4 const convertMat (CoordinateSystem from, CoordinateSystem to)
 Returns a matrix that transforms from the indicated coordinate system to the indicated coordinate system.
static TypeHandle getClassType ()
static Mat4 const identMat ()
 Returns an identity matrix.
static Mat4 const onesMat ()
 Returns an matrix filled with ones.
static Mat4 rotateMat (float angle, VBase3 const axis)
 Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
static Mat4 rotateMat (float angle, VBase3 const axis, CoordinateSystem cs)
 Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
static Mat4 rotateMatNormaxis (float angle, VBase3 const axis, CoordinateSystem cs)
 Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
static Mat4 rotateMatNormaxis (float angle, VBase3 const axis)
 Returns a matrix that rotates by the given angle in degrees counterclockwise about the indicated vector.
static Mat4 scaleMat (VBase3 const scale)
 Returns a matrix that applies the indicated scale in each of the three axes.
static Mat4 scaleMat (float scale)
 Returns a matrix that applies the indicated uniform scale.
static Mat4 scaleMat (float sx, float sy, float sz)
 Returns a matrix that applies the indicated scale in each of the three axes.
static Mat4 scaleShearMat (VBase3 const scale, VBase3 const shear, CoordinateSystem cs)
 Returns a matrix that applies the indicated scale and shear.
static Mat4 scaleShearMat (VBase3 const scale, VBase3 const shear)
 Returns a matrix that applies the indicated scale and shear.
static Mat4 scaleShearMat (float sx, float sy, float sz, float shxy, float shxz, float shyz, CoordinateSystem cs)
 Returns a matrix that applies the indicated scale and shear.
static Mat4 scaleShearMat (float sx, float sy, float sz, float shxy, float shxz, float shyz)
 Returns a matrix that applies the indicated scale and shear.
static Mat4 shearMat (VBase3 const shear)
 Returns a matrix that applies the indicated shear in each of the three planes.
static Mat4 shearMat (float shxy, float shxz, float shyz, CoordinateSystem cs)
 Returns a matrix that applies the indicated shear in each of the three planes.
static Mat4 shearMat (float shxy, float shxz, float shyz)
 Returns a matrix that applies the indicated shear in each of the three planes.
static Mat4 shearMat (VBase3 const shear, CoordinateSystem cs)
 Returns a matrix that applies the indicated shear in each of the three planes.
static int size ()
 Returns 4: the number of rows of a LMatrix4.
static Mat4 translateMat (VBase3 const trans)
 Returns a matrix that applies the indicated translation.
static Mat4 translateMat (float tx, float ty, float tz)
 Returns a matrix that applies the indicated translation.
static Mat4 const yToZUpMat ()
 Returns a matrix that transforms from the Y-up coordinate system to the Z-up coordinate system.
static Mat4 const zerosMat ()
 Returns an matrix filled with zeros.
static Mat4 const zToYUpMat ()
 Returns a matrix that transforms from the Y-up coordinate system to the Z-up coordinate system.

Detailed Description

This is a 4-by-4 transform matrix.


Constructor & Destructor Documentation

Mat4 ( )
Mat4 ( Mat3 const  upper3)
Mat4 ( Mat3 const  upper3,
VBase3 const  trans 
)
Mat4 ( Mat4 const  other)
Mat4 ( 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 
)

Member Function Documentation

unsigned int addHash ( unsigned int  hash)

Adds the vector into the running hash.

unsigned int addHash ( unsigned int  hash,
float  threshold 
)

Adds the vector into the running hash.

bool almostEqual ( Mat4 const  other)

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

bool almostEqual ( Mat4 const  other,
float  threshold 
)

Returns true if two matrices are memberwise equal within a specified tolerance.

begin ( )

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

begin ( )

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

int compareTo ( Mat4 const  other,
float  threshold 
)

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

int compareTo ( Mat4 const  other)

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

static Mat4 const convertMat ( CoordinateSystem  from,
CoordinateSystem  to 
) [static]

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

end ( )

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

end ( )

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

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.

float getCell ( int  row,
int  col 
)

Returns a particular element of the matrix.

static TypeHandle getClassType ( ) [static]
VBase4 getCol ( int  col)

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

VBase3 getCol3 ( int  col)

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

list getCols ( )
getData ( )

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.

unsigned int getHash ( )

Returns a suitable hash for phash_map.

unsigned int getHash ( float  threshold)

Returns a suitable hash for phash_map.

int getNumComponents ( )

Returns the number of elements in the matrix, 16.

getRow ( VBase4  result_vec,
int  row 
)
VBase4 getRow ( int  row)

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

getRow3 ( VBase3  result_vec,
int  row 
)
VBase3 getRow3 ( int  row)

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

list getRow3s ( )
list getRows ( )
Mat3 getUpper3 ( )

Retrieves the upper 3x3 submatrix.

static Mat4 const identMat ( ) [static]

Returns an identity matrix.

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

bool invertAffineFrom ( Mat4 const  other)

Performs an invert of the indicated matrix, storing the result in this matrix.

The calculation is only correct of the other matrix represents an affine transform.

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. bugbug: we could optimize this for rotation/scale/translation matrices (transpose upper 3x3 and take negative of translation component)

bool invertFrom ( Mat4 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 invertInPlace ( )

Inverts the current matrix.

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

bool isNan ( )

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

multiply ( Mat4 const  other1,
Mat4 const  other2 
)
static Mat4 const onesMat ( ) [static]

Returns an matrix filled with ones.

operator new ( unsigned int  size)
bool operator!= ( Mat4 const  other)
operator() ( int  row,
int  col 
)
float operator() ( int  row,
int  col 
)
Mat4 operator* ( Mat4 const  other)
Mat4 operator* ( float  scalar)
Mat4 operator*= ( Mat4 const  other)
Mat4 operator*= ( float  scalar)
Mat4 operator+= ( Mat4 const  other)

Performs a memberwise addition between two matrices.

Mat4 operator-= ( Mat4 const  other)

Performs a memberwise addition between two matrices.

Mat4 operator/ ( float  scalar)
Mat4 operator/= ( float  scalar)
bool operator< ( Mat4 const  other)

This performs a lexicographical comparison.

It's of questionable mathematical meaning, but sometimes has a practical purpose for sorting unique vectors, especially in an STL container. Also see compare_to().

Mat4 operator= ( Mat4 const  other)
Mat4 operator= ( float  fill_value)
bool operator== ( Mat4 const  other)
CRow operator[] ( int  i)
Row operator[] ( int  i)
output ( ostream  out)
pythonRepr ( ostream  out,
string  class_name 
)
PyObject reduce ( PyObject  self)

This special Python method is implement to provide support for the pickle module.

static Mat4 rotateMat ( float  angle,
VBase3 const  axis,
CoordinateSystem  cs 
) [static]

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

static Mat4 rotateMat ( float  angle,
VBase3 const  axis 
) [static]

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

static Mat4 rotateMatNormaxis ( float  angle,
VBase3 const  axis 
) [static]

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

Assumes axis has been prenormalized.

static Mat4 rotateMatNormaxis ( float  angle,
VBase3 const  axis,
CoordinateSystem  cs 
) [static]

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

Assumes axis has been prenormalized.

static Mat4 scaleMat ( VBase3 const  scale) [static]

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

static Mat4 scaleMat ( float  scale) [static]

Returns a matrix that applies the indicated uniform scale.

static Mat4 scaleMat ( float  sx,
float  sy,
float  sz 
) [static]

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

static Mat4 scaleShearMat ( VBase3 const  scale,
VBase3 const  shear,
CoordinateSystem  cs 
) [static]

Returns a matrix that applies the indicated scale and shear.

static Mat4 scaleShearMat ( float  sx,
float  sy,
float  sz,
float  shxy,
float  shxz,
float  shyz,
CoordinateSystem  cs 
) [static]

Returns a matrix that applies the indicated scale and shear.

static Mat4 scaleShearMat ( float  sx,
float  sy,
float  sz,
float  shxy,
float  shxz,
float  shyz 
) [static]

Returns a matrix that applies the indicated scale and shear.

static Mat4 scaleShearMat ( VBase3 const  scale,
VBase3 const  shear 
) [static]

Returns a matrix that applies the indicated scale and shear.

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 
)
setCell ( int  row,
int  col,
float  value 
)

Changes a particular element of the matrix.

setCol ( int  col,
VBase3 const  v 
)

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

setCol ( int  col,
VBase4 const  v 
)

Replaces the indicated column of the matrix.

setRotateMat ( float  angle,
VBase3 const  axis,
CoordinateSystem  cs 
)

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

setRotateMat ( float  angle,
VBase3 const  axis 
)

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

setRotateMatNormaxis ( float  angle,
VBase3 const  axis,
CoordinateSystem  cs 
)

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

Assumes axis has been prenormalized.

setRotateMatNormaxis ( float  angle,
VBase3 const  axis 
)

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

Assumes axis has been prenormalized.

setRow ( int  row,
VBase4 const  v 
)

Replaces the indicated row of the matrix.

setRow ( int  row,
VBase3 const  v 
)

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

setScaleMat ( VBase3 const  scale)

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

setScaleShearMat ( VBase3 const  scale,
VBase3 const  shear 
)

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

setScaleShearMat ( VBase3 const  scale,
VBase3 const  shear,
CoordinateSystem  cs 
)

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

setShearMat ( VBase3 const  shear,
CoordinateSystem  cs 
)

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

setShearMat ( VBase3 const  shear)

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

setTranslateMat ( VBase3 const  trans)

Fills mat with a matrix that applies the indicated translation.

setUpper3 ( Mat3 const  upper3)

Sets the upper 3x3 submatrix.

static Mat4 shearMat ( VBase3 const  shear,
CoordinateSystem  cs 
) [static]

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

static Mat4 shearMat ( float  shxy,
float  shxz,
float  shyz 
) [static]

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

static Mat4 shearMat ( float  shxy,
float  shxz,
float  shyz,
CoordinateSystem  cs 
) [static]

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

static Mat4 shearMat ( VBase3 const  shear) [static]

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

static int size ( ) [static]

Returns 4: the number of rows of a LMatrix4.

static Mat4 translateMat ( float  tx,
float  ty,
float  tz 
) [static]

Returns a matrix that applies the indicated translation.

static Mat4 translateMat ( VBase3 const  trans) [static]

Returns a matrix that applies the indicated translation.

transposeFrom ( Mat4 const  other)
transposeInPlace ( )
write ( ostream  out)
write ( ostream  out,
int  indent_level 
)
VBase4 xform ( VBase4 const  v)

4-component vector or point times matrix.

This is a fully general operation.

VBase3 xformPoint ( VBase3 const  v)

The matrix transforms a 3-component point (including translation component) and returns the result.

This assumes the matrix is an affine transform.

VBase3 xformVec ( VBase3 const  v)

The matrix transforms a 3-component vector (without translation component) and returns the result.

This assumes the matrix is an orthonormal transform.

VBase3 xformVecGeneral ( VBase3 const  v)

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

static Mat4 const yToZUpMat ( ) [static]

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

static Mat4 const zerosMat ( ) [static]

Returns an matrix filled with zeros.

static Mat4 const zToYUpMat ( ) [static]

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

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties