Brian Paul | adb1a29 | 2003-02-25 19:27:06 +0000 | [diff] [blame^] | 1 | /* $Id: m_matrix.h,v 1.6 2003/02/25 19:27:06 brianp Exp $ */ |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| 5 | * Version: 3.5 |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 6 | * |
Brian Paul | d8bc5a9 | 2001-02-05 18:48:52 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 8 | * |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 15 | * |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 18 | * |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
Brian Paul | 449e47f | 2003-02-17 16:35:56 +0000 | [diff] [blame] | 27 | /** |
| 28 | * \file math/m_matrix.h |
| 29 | * \brief Defines basic structures for matrix-handling. |
| 30 | */ |
| 31 | |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 32 | |
| 33 | #ifndef _M_MATRIX_H |
| 34 | #define _M_MATRIX_H |
| 35 | |
| 36 | |
| 37 | |
| 38 | /* Give symbolic names to some of the entries in the matrix to help |
| 39 | * out with the rework of the viewport_map as a matrix transform. |
| 40 | */ |
| 41 | #define MAT_SX 0 |
| 42 | #define MAT_SY 5 |
| 43 | #define MAT_SZ 10 |
| 44 | #define MAT_TX 12 |
| 45 | #define MAT_TY 13 |
| 46 | #define MAT_TZ 14 |
| 47 | |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 48 | |
Brian Paul | 449e47f | 2003-02-17 16:35:56 +0000 | [diff] [blame] | 49 | /** |
| 50 | * \defgroup MatFlags MAT_FLAG_XXX-flags |
| 51 | * |
| 52 | * Bitmasks to indicate different kinds of 4x4 matrices in |
| 53 | * GLmatrix::flags |
| 54 | */ |
| 55 | /*@{*/ |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 56 | #define MAT_FLAG_IDENTITY 0 |
| 57 | #define MAT_FLAG_GENERAL 0x1 |
| 58 | #define MAT_FLAG_ROTATION 0x2 |
| 59 | #define MAT_FLAG_TRANSLATION 0x4 |
| 60 | #define MAT_FLAG_UNIFORM_SCALE 0x8 |
| 61 | #define MAT_FLAG_GENERAL_SCALE 0x10 |
| 62 | #define MAT_FLAG_GENERAL_3D 0x20 |
| 63 | #define MAT_FLAG_PERSPECTIVE 0x40 |
| 64 | #define MAT_FLAG_SINGULAR 0x80 |
| 65 | #define MAT_DIRTY_TYPE 0x100 |
| 66 | #define MAT_DIRTY_FLAGS 0x200 |
| 67 | #define MAT_DIRTY_INVERSE 0x400 |
Brian Paul | 449e47f | 2003-02-17 16:35:56 +0000 | [diff] [blame] | 68 | /*@}*/ |
| 69 | |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 70 | |
| 71 | #define MAT_FLAGS_ANGLE_PRESERVING (MAT_FLAG_ROTATION | \ |
| 72 | MAT_FLAG_TRANSLATION | \ |
| 73 | MAT_FLAG_UNIFORM_SCALE) |
| 74 | |
| 75 | #define MAT_FLAGS_LENGTH_PRESERVING (MAT_FLAG_ROTATION | \ |
| 76 | MAT_FLAG_TRANSLATION) |
| 77 | |
| 78 | #define MAT_FLAGS_3D (MAT_FLAG_ROTATION | \ |
| 79 | MAT_FLAG_TRANSLATION | \ |
| 80 | MAT_FLAG_UNIFORM_SCALE | \ |
| 81 | MAT_FLAG_GENERAL_SCALE | \ |
| 82 | MAT_FLAG_GENERAL_3D) |
| 83 | |
| 84 | #define MAT_FLAGS_GEOMETRY (MAT_FLAG_GENERAL | \ |
| 85 | MAT_FLAG_ROTATION | \ |
| 86 | MAT_FLAG_TRANSLATION | \ |
| 87 | MAT_FLAG_UNIFORM_SCALE | \ |
| 88 | MAT_FLAG_GENERAL_SCALE | \ |
| 89 | MAT_FLAG_GENERAL_3D | \ |
| 90 | MAT_FLAG_PERSPECTIVE | \ |
| 91 | MAT_FLAG_SINGULAR) |
| 92 | |
| 93 | #define MAT_DIRTY (MAT_DIRTY_TYPE | \ |
| 94 | MAT_DIRTY_FLAGS | \ |
| 95 | MAT_DIRTY_INVERSE) |
| 96 | |
| 97 | #define TEST_MAT_FLAGS(mat, a) \ |
| 98 | ((MAT_FLAGS_GEOMETRY & (~(a)) & ((mat)->flags) ) == 0) |
| 99 | |
| 100 | |
Brian Paul | adb1a29 | 2003-02-25 19:27:06 +0000 | [diff] [blame^] | 101 | enum matrix_type { |
| 102 | MATRIX_GENERAL, /**< general 4x4 matrix */ |
| 103 | MATRIX_IDENTITY, /**< identity matrix */ |
| 104 | MATRIX_3D_NO_ROT, /**< ortho projection and others... */ |
| 105 | MATRIX_PERSPECTIVE,/**< perspective projection matrix */ |
| 106 | MATRIX_2D, /**< 2-D transformation */ |
| 107 | MATRIX_2D_NO_ROT, /**< 2-D scale & translate only */ |
| 108 | MATRIX_3D /**< 3-D transformation */ |
| 109 | }; |
| 110 | |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 111 | typedef struct { |
| 112 | GLfloat *m; /* 16-byte aligned */ |
| 113 | GLfloat *inv; /* optional, 16-byte aligned */ |
Brian Paul | 449e47f | 2003-02-17 16:35:56 +0000 | [diff] [blame] | 114 | GLuint flags; /**< possible values determined by (of \link |
| 115 | MatFlags MAT_FLAG_* flags\endlink) */ |
Brian Paul | adb1a29 | 2003-02-25 19:27:06 +0000 | [diff] [blame^] | 116 | |
| 117 | enum matrix_type type; |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 118 | } GLmatrix; |
| 119 | |
| 120 | |
| 121 | |
| 122 | |
| 123 | extern void |
| 124 | _math_matrix_ctr( GLmatrix *m ); |
| 125 | |
| 126 | extern void |
| 127 | _math_matrix_dtr( GLmatrix *m ); |
| 128 | |
| 129 | extern void |
| 130 | _math_matrix_alloc_inv( GLmatrix *m ); |
| 131 | |
| 132 | extern void |
| 133 | _math_matrix_mul_matrix( GLmatrix *dest, const GLmatrix *a, const GLmatrix *b ); |
| 134 | |
| 135 | extern void |
| 136 | _math_matrix_mul_floats( GLmatrix *dest, const GLfloat *b ); |
| 137 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 138 | extern void |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 139 | _math_matrix_loadf( GLmatrix *mat, const GLfloat *m ); |
| 140 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 141 | extern void |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 142 | _math_matrix_translate( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); |
| 143 | |
| 144 | extern void |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 145 | _math_matrix_rotate( GLmatrix *m, GLfloat angle, |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 146 | GLfloat x, GLfloat y, GLfloat z ); |
| 147 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 148 | extern void |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 149 | _math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); |
| 150 | |
| 151 | extern void |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 152 | _math_matrix_ortho( GLmatrix *mat, |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 153 | GLfloat left, GLfloat right, |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 154 | GLfloat bottom, GLfloat top, |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 155 | GLfloat nearval, GLfloat farval ); |
| 156 | |
| 157 | extern void |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 158 | _math_matrix_frustum( GLmatrix *mat, |
Brian Paul | d8bc5a9 | 2001-02-05 18:48:52 +0000 | [diff] [blame] | 159 | GLfloat left, GLfloat right, |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 160 | GLfloat bottom, GLfloat top, |
Brian Paul | d8bc5a9 | 2001-02-05 18:48:52 +0000 | [diff] [blame] | 161 | GLfloat nearval, GLfloat farval ); |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 162 | |
| 163 | extern void |
| 164 | _math_matrix_set_identity( GLmatrix *dest ); |
| 165 | |
Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 166 | extern void |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 167 | _math_matrix_copy( GLmatrix *to, const GLmatrix *from ); |
| 168 | |
| 169 | extern void |
Keith Whitwell | ad2ac21 | 2000-11-24 10:25:05 +0000 | [diff] [blame] | 170 | _math_matrix_analyse( GLmatrix *mat ); |
Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 171 | |
| 172 | extern void |
| 173 | _math_matrix_print( const GLmatrix *m ); |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | /* Related functions that don't actually operate on GLmatrix structs: |
| 179 | */ |
| 180 | extern void |
| 181 | _math_transposef( GLfloat to[16], const GLfloat from[16] ); |
| 182 | |
| 183 | extern void |
| 184 | _math_transposed( GLdouble to[16], const GLdouble from[16] ); |
| 185 | |
| 186 | extern void |
| 187 | _math_transposefd( GLfloat to[16], const GLdouble from[16] ); |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | #endif |