m_matrix.h revision 22144ab7552f0799bcfca506bf4ffa7f70a06649
122144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes/* $Id: m_matrix.h,v 1.4 2001/03/12 00:48:41 gareth Exp $ */ 223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* 423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Mesa 3-D graphics library 523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Version: 3.5 622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 7d8bc5a9eba720ffb6a503d32715f895dbdad7197Brian Paul * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Permission is hereby granted, free of charge, to any person obtaining a 1023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * copy of this software and associated documentation files (the "Software"), 1123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * to deal in the Software without restriction, including without limitation 1223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * and/or sell copies of the Software, and to permit persons to whom the 1423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Software is furnished to do so, subject to the following conditions: 1522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 1623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * The above copyright notice and this permission notice shall be included 1723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * in all copies or substantial portions of the Software. 1822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes * 1923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 2023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 2623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 2723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 2823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#ifndef _M_MATRIX_H 2923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define _M_MATRIX_H 3023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 3123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 3223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 3323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Give symbolic names to some of the entries in the matrix to help 3423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * out with the rework of the viewport_map as a matrix transform. 3523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 3623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_SX 0 3723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_SY 5 3823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_SZ 10 3923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_TX 12 4023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_TY 13 4123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_TZ 14 4223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 4323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* 4423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell * Different kinds of 4x4 transformation matrices: 4523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 4623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_GENERAL 0 /* general 4x4 matrix */ 4723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_IDENTITY 1 /* identity matrix */ 4823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_3D_NO_ROT 2 /* ortho projection and others... */ 4923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_PERSPECTIVE 3 /* perspective projection matrix */ 5023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_2D 4 /* 2-D transformation */ 5123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_2D_NO_ROT 5 /* 2-D scale & translate only */ 5223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MATRIX_3D 6 /* 3-D transformation */ 5323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 5423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_IDENTITY 0 5523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_GENERAL 0x1 5623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_ROTATION 0x2 5723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_TRANSLATION 0x4 5823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_UNIFORM_SCALE 0x8 5923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_GENERAL_SCALE 0x10 6023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_GENERAL_3D 0x20 6123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_PERSPECTIVE 0x40 6223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAG_SINGULAR 0x80 6323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_DIRTY_TYPE 0x100 6423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_DIRTY_FLAGS 0x200 6523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_DIRTY_INVERSE 0x400 6623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 6723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAGS_ANGLE_PRESERVING (MAT_FLAG_ROTATION | \ 6823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_TRANSLATION | \ 6923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_UNIFORM_SCALE) 7023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 7123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAGS_LENGTH_PRESERVING (MAT_FLAG_ROTATION | \ 7223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_TRANSLATION) 7323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 7423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAGS_3D (MAT_FLAG_ROTATION | \ 7523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_TRANSLATION | \ 7623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_UNIFORM_SCALE | \ 7723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_GENERAL_SCALE | \ 7823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_GENERAL_3D) 7923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 8023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_FLAGS_GEOMETRY (MAT_FLAG_GENERAL | \ 8123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_ROTATION | \ 8223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_TRANSLATION | \ 8323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_UNIFORM_SCALE | \ 8423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_GENERAL_SCALE | \ 8523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_GENERAL_3D | \ 8623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_PERSPECTIVE | \ 8723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_FLAG_SINGULAR) 8823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 8923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define MAT_DIRTY (MAT_DIRTY_TYPE | \ 9023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_DIRTY_FLAGS | \ 9123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell MAT_DIRTY_INVERSE) 9223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 9323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#define TEST_MAT_FLAGS(mat, a) \ 9423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell ((MAT_FLAGS_GEOMETRY & (~(a)) & ((mat)->flags) ) == 0) 9523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 9623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 9723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwelltypedef struct { 9823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat *m; /* 16-byte aligned */ 9923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat *inv; /* optional, 16-byte aligned */ 10023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLuint flags; 10123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLuint type; /* one of the MATRIX_* values */ 10223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell} GLmatrix; 10323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 10423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 10523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 10623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 10723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 10823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_ctr( GLmatrix *m ); 10923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 11023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 11123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_dtr( GLmatrix *m ); 11223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 11323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 11423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_alloc_inv( GLmatrix *m ); 11523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 11623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 11723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_mul_matrix( GLmatrix *dest, const GLmatrix *a, const GLmatrix *b ); 11823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 11923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 12023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_mul_floats( GLmatrix *dest, const GLfloat *b ); 12123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 12222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesextern void 12323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_loadf( GLmatrix *mat, const GLfloat *m ); 12423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 12522144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesextern void 12623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); 12723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 12823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 12922144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes_math_matrix_rotate( GLmatrix *m, GLfloat angle, 13023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat x, GLfloat y, GLfloat z ); 13123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 13222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesextern void 13323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); 13423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 13523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 13622144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes_math_matrix_ortho( GLmatrix *mat, 13723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat left, GLfloat right, 13822144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLfloat bottom, GLfloat top, 13923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell GLfloat nearval, GLfloat farval ); 14023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 14123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 14222144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes_math_matrix_frustum( GLmatrix *mat, 143d8bc5a9eba720ffb6a503d32715f895dbdad7197Brian Paul GLfloat left, GLfloat right, 14422144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughes GLfloat bottom, GLfloat top, 145d8bc5a9eba720ffb6a503d32715f895dbdad7197Brian Paul GLfloat nearval, GLfloat farval ); 14623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 14723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 14823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_set_identity( GLmatrix *dest ); 14923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 15022144ab7552f0799bcfca506bf4ffa7f70a06649Gareth Hughesextern void 15123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_copy( GLmatrix *to, const GLmatrix *from ); 15223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 15323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 154ad2ac216fa0cbebc36530bf9e5256e902710b892Keith Whitwell_math_matrix_analyse( GLmatrix *mat ); 15523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 15623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 15723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_matrix_print( const GLmatrix *m ); 15823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 15923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 16023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 16123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 16223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell/* Related functions that don't actually operate on GLmatrix structs: 16323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell */ 16423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 16523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_transposef( GLfloat to[16], const GLfloat from[16] ); 16623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 16723caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 16823caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_transposed( GLdouble to[16], const GLdouble from[16] ); 16923caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17023caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwellextern void 17123caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell_math_transposefd( GLfloat to[16], const GLdouble from[16] ); 17223caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17323caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17423caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17523caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell 17623caf20169ac38436ee9c13914f1d6aa7cf6bb5eKeith Whitwell#endif 177