core | glapi | vbo | math | shader | swrast | swrast_setup | tnl | tnl_dd

m_matrix.h File Reference


Detailed Description

Defines basic structures for matrix-handling.


Data Structures

struct  GLmatrix
 Matrix type to represent 4x4 transformation matrices. More...

Related functions that don't actually operate on GLmatrix structs

#define TRANSFORM_POINT(Q, M, P)
#define TRANSFORM_POINT3(Q, M, P)
#define TRANSFORM_NORMAL(TO, N, MAT)
#define TRANSFORM_DIRECTION(TO, DIR, MAT)
 Transform a direction by a matrix.
void _math_transposef (GLfloat to[16], const GLfloat from[16])
 Transpose a GLfloat matrix.
void _math_transposed (GLdouble to[16], const GLdouble from[16])
 Transpose a GLdouble matrix.
void _math_transposefd (GLfloat to[16], const GLdouble from[16])
 Transpose a GLdouble matrix and convert to GLfloat.
void _mesa_transform_vector (GLfloat u[4], const GLfloat v[4], const GLfloat m[16])
 Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix.

Defines

Symbolic names to some of the entries in the matrix
These are handy for the viewport mapping, which is expressed as a matrix.

#define MAT_SX   0
#define MAT_SY   5
#define MAT_SZ   10
#define MAT_TX   12
#define MAT_TY   13
#define MAT_TZ   14

Enumerations

enum  GLmatrixtype {
  MATRIX_GENERAL, MATRIX_IDENTITY, MATRIX_3D_NO_ROT, MATRIX_PERSPECTIVE,
  MATRIX_2D, MATRIX_2D_NO_ROT, MATRIX_3D
}
 Different kinds of 4x4 transformation matrices. More...

Functions

void _math_matrix_ctr (GLmatrix *m)
 Matrix constructor.
void _math_matrix_dtr (GLmatrix *m)
 Matrix destructor.
void _math_matrix_alloc_inv (GLmatrix *m)
 Allocate a matrix inverse.
void _math_matrix_mul_matrix (GLmatrix *dest, const GLmatrix *a, const GLmatrix *b)
 Matrix multiplication.
void _math_matrix_mul_floats (GLmatrix *dest, const GLfloat *b)
 Matrix multiplication.
void _math_matrix_loadf (GLmatrix *mat, const GLfloat *m)
 Loads a matrix array into GLmatrix.
void _math_matrix_translate (GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z)
 Multiply a matrix with a translation matrix.
void _math_matrix_rotate (GLmatrix *m, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
 Generate a 4x4 transformation matrix from glRotate parameters, and post-multiply the input matrix by it.
void _math_matrix_scale (GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z)
 Multiply a matrix with a general scaling matrix.
void _math_matrix_ortho (GLmatrix *mat, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearval, GLfloat farval)
 Apply an orthographic projection matrix.
void _math_matrix_frustum (GLmatrix *mat, GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat nearval, GLfloat farval)
 Apply a perspective projection matrix.
void _math_matrix_viewport (GLmatrix *m, GLint x, GLint y, GLint width, GLint height, GLfloat zNear, GLfloat zFar, GLfloat depthMax)
 Set matrix to do viewport and depthrange mapping.
void _math_matrix_set_identity (GLmatrix *dest)
 Set a matrix to the identity matrix.
void _math_matrix_copy (GLmatrix *to, const GLmatrix *from)
 Copy a matrix.
void _math_matrix_analyse (GLmatrix *mat)
 Analyze and update a matrix.
void _math_matrix_print (const GLmatrix *m)
 Dumps the contents of a GLmatrix structure.
GLboolean _math_matrix_is_length_preserving (const GLmatrix *m)
 Test if the given matrix preserves vector lengths.
GLboolean _math_matrix_has_rotation (const GLmatrix *m)
 Test if the given matrix does any rotation.
GLboolean _math_matrix_is_general_scale (const GLmatrix *m)
GLboolean _math_matrix_is_dirty (const GLmatrix *m)


Define Documentation

#define MAT_SX   0

#define MAT_SY   5

#define MAT_SZ   10

#define MAT_TX   12

#define MAT_TY   13

#define MAT_TZ   14

#define TRANSFORM_DIRECTION ( TO,
DIR,
MAT   ) 

Value:

do {                                                            \
   TO[0] = DIR[0] * MAT[0] + DIR[1] * MAT[4] + DIR[2] * MAT[8]; \
   TO[1] = DIR[0] * MAT[1] + DIR[1] * MAT[5] + DIR[2] * MAT[9]; \
   TO[2] = DIR[0] * MAT[2] + DIR[1] * MAT[6] + DIR[2] * MAT[10];\
} while (0)
Transform a direction by a matrix.

#define TRANSFORM_NORMAL ( TO,
N,
MAT   ) 

Value:

do {                                                            \
   TO[0] = N[0] * MAT[0] + N[1] * MAT[1] + N[2] * MAT[2];       \
   TO[1] = N[0] * MAT[4] + N[1] * MAT[5] + N[2] * MAT[6];       \
   TO[2] = N[0] * MAT[8] + N[1] * MAT[9] + N[2] * MAT[10];      \
} while (0)

#define TRANSFORM_POINT ( Q,
M,
 ) 

Value:

Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] *  P[2] + M[12] * P[3]; \
   Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] *  P[2] + M[13] * P[3];      \
   Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14] * P[3];      \
   Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15] * P[3];

#define TRANSFORM_POINT3 ( Q,
M,
 ) 

Value:

Q[0] = M[0] * P[0] + M[4] * P[1] + M[8] *  P[2] + M[12];        \
   Q[1] = M[1] * P[0] + M[5] * P[1] + M[9] *  P[2] + M[13];     \
   Q[2] = M[2] * P[0] + M[6] * P[1] + M[10] * P[2] + M[14];     \
   Q[3] = M[3] * P[0] + M[7] * P[1] + M[11] * P[2] + M[15];


Enumeration Type Documentation

enum GLmatrixtype

Different kinds of 4x4 transformation matrices.

We use these to select specific optimized vertex transformation routines.

Enumerator:
MATRIX_GENERAL  general 4x4 matrix
MATRIX_IDENTITY  identity matrix
MATRIX_3D_NO_ROT  orthogonal projection and others.

..

MATRIX_PERSPECTIVE  perspective projection matrix
MATRIX_2D  2-D transformation
MATRIX_2D_NO_ROT  2-D scale & translate only
MATRIX_3D  3-D transformation


Function Documentation

void _math_matrix_alloc_inv ( GLmatrix m  ) 

Allocate a matrix inverse.

Parameters:
m matrix.
Allocates the matrix inverse, GLmatrix::inv, and sets it to Identity.

void _math_matrix_analyse ( GLmatrix mat  ) 

Analyze and update a matrix.

Parameters:
mat matrix.
If the matrix type is dirty then calls either analyse_from_scratch() or analyse_from_flags() to determine its type, according to whether the flags are dirty or not, respectively. If the matrix has an inverse and it's dirty then calls matrix_invert(). Finally clears the dirty flags.

void _math_matrix_copy ( GLmatrix to,
const GLmatrix from 
)

Copy a matrix.

Parameters:
to destination matrix.
from source matrix.
Copies all fields in GLmatrix, creating an inverse array if necessary.

void _math_matrix_ctr ( GLmatrix m  ) 

Matrix constructor.

Parameters:
m matrix.
Initialize the GLmatrix fields.

void _math_matrix_dtr ( GLmatrix m  ) 

Matrix destructor.

Parameters:
m matrix.
Frees the data in a GLmatrix.

void _math_matrix_frustum ( GLmatrix mat,
GLfloat  left,
GLfloat  right,
GLfloat  bottom,
GLfloat  top,
GLfloat  nearval,
GLfloat  farval 
)

Apply a perspective projection matrix.

Parameters:
mat matrix to apply the projection.
left left clipping plane coordinate.
right right clipping plane coordinate.
bottom bottom clipping plane coordinate.
top top clipping plane coordinate.
nearval distance to the near clipping plane.
farval distance to the far clipping plane.
Creates the projection matrix and multiplies it with mat, marking the MAT_FLAG_PERSPECTIVE flag.

GLboolean _math_matrix_has_rotation ( const GLmatrix m  ) 

Test if the given matrix does any rotation.

(or perhaps if the upper-left 3x3 is non-identity)

GLboolean _math_matrix_is_dirty ( const GLmatrix m  ) 

GLboolean _math_matrix_is_general_scale ( const GLmatrix m  ) 

GLboolean _math_matrix_is_length_preserving ( const GLmatrix m  ) 

Test if the given matrix preserves vector lengths.

void _math_matrix_loadf ( GLmatrix mat,
const GLfloat *  m 
)

Loads a matrix array into GLmatrix.

Parameters:
m matrix array.
mat matrix.
Copies m into GLmatrix::m and marks the MAT_FLAG_GENERAL and MAT_DIRTY flags.

void _math_matrix_mul_floats ( GLmatrix dest,
const GLfloat *  m 
)

Matrix multiplication.

Parameters:
dest left and destination matrix.
m right matrix array.
Marks the matrix flags with general flag, and type and inverse dirty flags. Calls matmul4() for the multiplication.

void _math_matrix_mul_matrix ( GLmatrix dest,
const GLmatrix a,
const GLmatrix b 
)

Matrix multiplication.

Parameters:
dest destination matrix.
a left matrix.
b right matrix.
Joins both flags and marks the type and inverse as dirty. Calls matmul34() if both matrices are 3D, or matmul4() otherwise.

void _math_matrix_ortho ( GLmatrix mat,
GLfloat  left,
GLfloat  right,
GLfloat  bottom,
GLfloat  top,
GLfloat  nearval,
GLfloat  farval 
)

Apply an orthographic projection matrix.

Parameters:
mat matrix to apply the projection.
left left clipping plane coordinate.
right right clipping plane coordinate.
bottom bottom clipping plane coordinate.
top top clipping plane coordinate.
nearval distance to the near clipping plane.
farval distance to the far clipping plane.
Creates the projection matrix and multiplies it with mat, marking the MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags.

void _math_matrix_print ( const GLmatrix m  ) 

Dumps the contents of a GLmatrix structure.

Parameters:
m pointer to the GLmatrix structure.

void _math_matrix_rotate ( GLmatrix mat,
GLfloat  angle,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Generate a 4x4 transformation matrix from glRotate parameters, and post-multiply the input matrix by it.

Author:
This function was contributed by Erich Boleyn (erich@uruk.org). Optimizations contributed by Rudolf Opalla (rudi@khm.de).

void _math_matrix_scale ( GLmatrix mat,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Multiply a matrix with a general scaling matrix.

Parameters:
mat matrix.
x x axis scale factor.
y y axis scale factor.
z z axis scale factor.
Multiplies in-place the elements of mat by the scale factors. Checks if the scales factors are roughly the same, marking the MAT_FLAG_UNIFORM_SCALE flag, or MAT_FLAG_GENERAL_SCALE. Marks the MAT_DIRTY_TYPE and MAT_DIRTY_INVERSE dirty flags.

void _math_matrix_set_identity ( GLmatrix mat  ) 

Set a matrix to the identity matrix.

Parameters:
mat matrix.
Copies Identity into GLmatrix::m, and into GLmatrix::inv if not NULL. Sets the matrix type to identity, and clear the dirty flags.

void _math_matrix_translate ( GLmatrix mat,
GLfloat  x,
GLfloat  y,
GLfloat  z 
)

Multiply a matrix with a translation matrix.

Parameters:
mat matrix.
x translation vector x coordinate.
y translation vector y coordinate.
z translation vector z coordinate.
Adds the translation coordinates to the elements of mat in-place. Marks the MAT_FLAG_TRANSLATION flag, and the MAT_DIRTY_TYPE and MAT_DIRTY_INVERSE dirty flags.

void _math_matrix_viewport ( GLmatrix m,
GLint  x,
GLint  y,
GLint  width,
GLint  height,
GLfloat  zNear,
GLfloat  zFar,
GLfloat  depthMax 
)

Set matrix to do viewport and depthrange mapping.

Transforms Normalized Device Coords to window/Z values.

void _math_transposed ( GLdouble  to[16],
const GLdouble  from[16] 
)

Transpose a GLdouble matrix.

Parameters:
to destination array.
from source array.

void _math_transposef ( GLfloat  to[16],
const GLfloat  from[16] 
)

Transpose a GLfloat matrix.

Parameters:
to destination array.
from source array.

void _math_transposefd ( GLfloat  to[16],
const GLdouble  from[16] 
)

Transpose a GLdouble matrix and convert to GLfloat.

Parameters:
to destination array.
from source array.

void _mesa_transform_vector ( GLfloat  u[4],
const GLfloat  v[4],
const GLfloat  m[16] 
)

Transform a 4-element row vector (1x4 matrix) by a 4x4 matrix.

This function is used for transforming clipping plane equations and spotlight directions. Mathematically, u = v * m. Input: v - input vector m - transformation matrix Output: u - transformed vector


Generated on Sun Sep 27 06:47:50 2009 for Mesa math module by  doxygen 1.5.4