00001 /********************************************************************* 00002 * lescegra * 00003 * * 00004 * http://geeky.kicks-ass.org/projects/lescegra.html * 00005 * * 00006 * Copyright 2003 by Enno Cramer <uebergeek@web.de> * 00007 * * 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Library General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Library General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Library General Public * 00019 * License along with this library; if not, write to the Free * 00020 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * 00021 *********************************************************************/ 00022 00023 #ifndef LSG_MATRIX_H 00024 #define LSG_MATRIX_H 1 00025 00026 /** 00027 * \file matrix.h 00028 * \brief 4x4 Matrix 00029 */ 00030 00031 #include <lescegra/util/vertex.h> 00032 00033 /** 00034 * \brief 4x4 matrix 00035 * 00036 * A 4x4 matrix 00037 */ 00038 typedef float Matrix[16]; 00039 00040 /** 00041 * The identity matrix 00042 */ 00043 extern const Matrix matrix_identity; 00044 00045 /** 00046 * Reset a matrix to the identity. 00047 * @param m The matrix to reset 00048 */ 00049 void matrix_load_identity(Matrix m); 00050 00051 /** 00052 * Create a translation matrix. 00053 * @param m The destination matrix 00054 * @param x The first translation component 00055 * @param y The second translation component 00056 * @param z The third translation component 00057 */ 00058 void matrix_load_translate(Matrix m, float x, float y, float z); 00059 00060 /** 00061 * Create a translation matrix from a vertex. 00062 * @param m The destination matrix 00063 * @param v The translation vertex 00064 */ 00065 void matrix_load_translatev(Matrix m, Vertex v); 00066 00067 /** 00068 * Create a scaling matrix. 00069 * @param m The destination matrix 00070 * @param x The first scaling component 00071 * @param y The second scaling component 00072 * @param z The third scaling component 00073 */ 00074 void matrix_load_scale(Matrix m, float x, float y, float z); 00075 00076 /** 00077 * Create a scaling matrix from a scaling vertex. 00078 * @param m The destination matrix 00079 * @param v The scaling vertex 00080 */ 00081 void matrix_load_scalev(Matrix m, Vertex v); 00082 00083 /** 00084 * Create a rotation matrix. 00085 */ 00086 void matrix_load_rotate(Matrix m, float x, float y, float z); 00087 void matrix_load_rotatev(Matrix m, Vertex v); 00088 00089 /** 00090 * Create an orthogonal projection matrix. 00091 */ 00092 void matrix_load_ortho(Matrix m, float x1, float x2, float y1, float y2, float z1, float z2); 00093 00094 /** 00095 * Create a frustum projection matrix. 00096 */ 00097 void matrix_load_frustum(Matrix m, float x1, float x2, float y1, float y2, float z1, float z2); 00098 00099 /** 00100 * Create a perspective projection matrix. 00101 */ 00102 void matrix_load_perspective(Matrix m, float fovy, float aspect, float near, float far); 00103 00104 /** 00105 * Create a lookat matrix. 00106 */ 00107 void matrix_load_lookat(Matrix m, Vertex from, Vertex to, Vertex up); 00108 00109 /** 00110 * Create a pick matrix. 00111 */ 00112 void matrix_load_pick(Matrix m, float x, float y, float w, float h, 00113 float vp_x, float vp_y, float vp_w, float vp_h); 00114 00115 /** 00116 * Copy a matrix into another. 00117 * @param dst The destination matrix 00118 * @param src The source matrix 00119 */ 00120 void matrix_copy(Matrix dst, const Matrix src); 00121 00122 /** 00123 * Post-Multiply a matrix with another. 00124 * @param dst The destination matrix 00125 * @param src The source matrix 00126 */ 00127 void matrix_mult(Matrix dst, const Matrix src); 00128 00129 /** 00130 * Pre-Multiply a matrix with another. 00131 * @param dst The destination matrix 00132 * @param src The source matrix 00133 */ 00134 void matrix_premult(Matrix dst, const Matrix src); 00135 00136 /** 00137 * Transpose a matrix. 00138 * @param m The matrix to transpose 00139 */ 00140 void matrix_transpose(Matrix m); 00141 00142 /** 00143 * Invert a matrix. 00144 * @param m The matrix to invert 00145 */ 00146 void matrix_invert(Matrix m); 00147 00148 /** 00149 * Post-Multiply a matrix and a vertex. 00150 * v = M * v 00151 * @param m The transformation matrix 00152 * @param v The vertex to be transformed 00153 */ 00154 void matrix_apply(const Matrix m, Vertex v); 00155 00156 /** 00157 * Pre-Multiply a matrix and a vertex. 00158 * v = v * M 00159 * @param m The transformation matrix 00160 * @param v The vertex to be transformed 00161 */ 00162 void matrix_preapply(const Matrix m, Vertex v); 00163 00164 #endif