00001 //=========================================================================== 00002 //= matriz4.h Agosto de 1998 = 00003 //=-------------------------------------------------------------------------= 00004 //= Definicion de la clase MATRIZ_4x4 = 00005 //=-------------------------------------------------------------------------= 00006 //= ADVERTENCIA: ESTE SOFTWARE NO ESTA CONCEBIDO NI DISENNADO PARA EL USO = 00007 //= EN EQUIPO DE CONTROL EN LINEA EN ENTORNOS PELIGROSOS QUE REQUIERAN UN = 00008 //= DESEMPENNO LIBRE DE FALLAS, COMO LA OPERACION DE PLANTAS NUCLEARES, = 00009 //= SISTEMAS DE NAVEGACION O COMUNICACION EN AVIONES, TRAFICO AEREO, = 00010 //= EQUIPO MEDICO DEL CUAL DEPENDAN VIDAS HUMANAS O SISTEMAS DE ARMAMENTO, = 00011 //= EN LOS CUALES UNA FALLA EN EL SOFTWARE PUEDA IMPLICAR DIRECTAMENTE LA = 00012 //= MUERTE, DANNOS PERSONALES O DANNOS FISICOS Y/O AMBIENTALES GRAVES = 00013 //= ("ACTIVIDADES DE ALGO RIESGO"). = 00014 //=-------------------------------------------------------------------------= 00015 //= Autor original: Oscar J. Chavarro G. A.K.A. JEDILINK. Copyright (c), = 00016 //= 1997 - 2003, oscarchavarro@hotmail.com = 00017 //= AQUYNZA es software libre, y se rige bajo los terminos de la licencia = 00018 //= LGPL de GNU (http://www.gnu.org). Para mayor informacion respecto a la = 00019 //= licencia de uso, consulte el archivo ./doc/LICENCIA en la distribucion. = 00020 //=========================================================================== 00021 00022 #ifndef __MATRIZ_4x4__ 00023 #define __MATRIZ_4x4__ 00024 00025 #include "jed_defs.h" // Incluir antes que nada, en ese modulo se definen 00026 // aspectos importantes para la portabilidad del sistema 00027 #include "quaternion.h" 00028 00029 class MATRIZ_4x4 00045 { 00046 public: 00047 //- Operaciones basicas -------------------------------------------------- 00048 MATRIZ_4x4(); // Crear matriz 00049 ~MATRIZ_4x4(); // Destruir matriz 00050 00051 double M[4][4]; // OJO: Es importante que sea publico (por eficiencia!) 00052 00053 //- Operaciones aritmeticas --------------------------------------------- 00054 // OJO: Faltan cosas como '-', '/', '+=', '-=' y '*='... 00055 MATRIZ_4x4 operator + (MATRIZ_4x4 b); 00056 MATRIZ_4x4 operator * (MATRIZ_4x4 N); 00057 //MATRIZ_4x4 operator = (MATRIZ_4x4 N); // OJO: NO definir! 00058 inline VECTOR operator * (VECTOR v); 00059 00060 //- Operaciones especificas del algebra de matrices --------------------- 00061 void identidad(void); 00062 //MATRIZ_4x4 transpuesta(void); 00063 MATRIZ_4x4 inversa(void); 00064 double determinante(void); 00065 00066 //- Operaciones geometricas --------------------------------------------- 00067 MATRIZ_4x4 operator * (double a); // Esto es escalamiento! 00068 void translacion(double transx, double transy, double transz); 00069 void rotacion_eje(double angulo, double x, double y, double z); 00070 void rotacion_angulos_euler(double yaw, double pitch, double roll); 00071 void rotacion_punto_punto(VECTOR p1, VECTOR p2); 00072 00073 //- Operaciones matematicas especiales ---------------------------------- 00074 void importar_quaternion(QUATERNION a); 00075 QUATERNION exportar_quaternion(void); 00076 void exportar_angulos_euler(double *yaw, double *pitch, double *roll); 00077 //void importar_asterisco(VECTOR a); 00078 void frustum(double plano_izquierdo, double plano_derecho, 00079 double plano_inferior, double plano_superior, 00080 double plano_cercano, double plano_lejano); 00081 void ortho(double plano_izquierdo, double plano_derecho, 00082 double plano_inferior, double plano_superior, 00083 double plano_cercano, double plano_lejano); 00084 00085 //- Operaciones de consulta --------------------------------------------- 00086 void imprimir(void); 00087 #ifdef GL_ENABLED 00088 void cargar_gl(void); 00089 void importar_gl(void); 00090 #endif 00091 void activar_povray(FILE *fd); 00092 }; 00093 00094 //=========================================================================== 00095 //= Metodos inline de la clase MATRIZ_4x4 = 00096 //=========================================================================== 00097 00098 inline VECTOR 00099 MATRIZ_4x4::operator *(VECTOR E) 00122 { 00123 VECTOR R; 00124 00125 R.x = M[0][0] * E.x + M[0][1] * E.y + M[0][2] * E.z + M[0][3]; 00126 R.y = M[1][0] * E.x + M[1][1] * E.y + M[1][2] * E.z + M[1][3]; 00127 R.z = M[2][0] * E.x + M[2][1] * E.y + M[2][2] * E.z + M[2][3]; 00128 00129 return R; 00130 00131 #ifdef NO_COMPILAR 00132 VECTOR R; // Resultado 00133 double aux[4], aux2[4], acumulado; 00134 int columna, fila; 00135 00136 aux[0]=E.x; // Esto es un vector columna con filas de 0 a 3 00137 aux[1]=E.y; 00138 aux[2]=E.z; 00139 aux[3]=1; // Notese que W = 1 significa que se usan coordenadas 00140 // normalizadas 00141 00142 for( fila = 0; fila < 4; fila++ ) { 00143 acumulado = 0; 00144 for( columna = 0; columna < 4; columna++ ) { 00145 acumulado += (M[fila][columna] * aux[columna]); 00146 } 00147 aux2[fila] = acumulado; 00148 } 00149 00150 R.x=aux2[0]; 00151 R.y=aux2[1]; 00152 R.z=aux2[2]; 00153 00154 return R; 00155 #endif 00156 } 00157 00158 #endif 00159 00160 //=========================================================================== 00161 //= EOF = 00162 //=========================================================================== 00163