Página principal | Jerarquía de la clase | Lista alfabética | Lista de componentes | Lista de archivos | Miembros de las clases | Archivos de los miembros | Páginas relacionadas

masa_puntual.C

Ir a la documentación de este archivo.
00001 //===========================================================================
00002 //= masa_puntual.cc                                           Julio de 1998 =
00003 //=-------------------------------------------------------------------------=
00004 //= Definiciones de la clase COSA                                           =
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 #include "jed_gl.h"
00023 #include "core/cosas/cosa.h"
00024 #include "lista.cc"
00025 #include "toolkits/media/jed_img.h"
00026 #include "toolkits/geom/mesh.h"
00027 #include "toolkits/util/3dsload.h"
00028 #include "matriz4.h"
00029 
00030 #include <ctype.h>
00031 #include <string.h>
00032 #include <stdlib.h>
00033 
00034 //===========================================================================
00035 //= VARIABLES GLOBALES Y MACROS                                             =
00036 //===========================================================================
00037 
00038 #define ESPERO(tipo, msg) \
00039     if ( tipo_token != (tipo) ) { \
00040         fprintf(stderr, "<COSA/MASA_PUNTUAL> ERROR: Esperaba %s y recibi [%s].\n", \
00041           (msg), cad); fflush(stderr);  return FALSE; \
00042     }
00043 
00044 //===========================================================================
00045 //= Clase MASA_PUNTUAL                                                      =
00046 //===========================================================================
00047 
00048 MASA_PUNTUAL::MASA_PUNTUAL() : COSA()
00049 {
00050     _tipo_de_cosa = CC_MASA_PUNTUAL;
00051     en_colision = FALSE;
00052 }
00053 
00054 MASA_PUNTUAL::~MASA_PUNTUAL()
00055 {
00056     if ( _nombre_padre ) delete _nombre_padre;
00057 }
00058 
00059 BOOLEAN
00060 MASA_PUNTUAL::consultar_variable(const char *nombre_variable, int &tipo, void **ref)
00061 {
00062     // Deberia responder a solicitudes de orientacion con un quaternion por
00063     // defecto de "orientacion nula" o algo asi.  Eso permitiria que las
00064     // camaras pudiesen asociarse a masas puntuales...
00065 
00066     if ( strcmp(nombre_variable, "centro_de_masa") == 0 ) {
00067         tipo = T_VECTOR;    (*ref) = &_posicion;    return TRUE;
00068       }
00069       else {
00070         return COSA::consultar_variable(nombre_variable, tipo, ref);
00071       }
00072     ;
00073 }
00074 
00075 COSA *
00076 MASA_PUNTUAL::crear_copia(void)
00080 {
00081     MASA_PUNTUAL *m;
00082 
00083     m = new MASA_PUNTUAL;
00084     if ( !m ) return NULL;
00085     (*m) = (*this);
00086     return (COSA *)m;
00087 }
00088 
00089 GEOMETRIA *
00090 MASA_PUNTUAL::geometria(void)
00091 {
00092     return NULL;
00093 }
00094 
00095 void
00096 MASA_PUNTUAL::minmax(VECTOR *min, VECTOR *max)
00097 {
00098     min->x = _posicion.x - EPSILON;
00099     min->y = _posicion.y - EPSILON;
00100     min->z = _posicion.z - EPSILON;
00101     max->x = _posicion.x + EPSILON;
00102     max->y = _posicion.y + EPSILON;
00103     max->z = _posicion.z + EPSILON;
00104 }
00105 
00106 #ifdef GL_ENABLED
00107 void
00108 MASA_PUNTUAL::pintar_gl(CALIDAD_VISUAL * /*Calidad*/, CAMARA * /*Camara*/)
00116 {
00117     glDisable(GL_LIGHTING);
00118     glColor3f(_color.r, _color.g, _color.b);
00119     glPointSize(4);
00120     glBegin(GL_POINTS);
00121         glVertex3d(_posicion.x, _posicion.y, _posicion.z);
00122     glEnd();
00123 
00124     #define L 0.05
00125 
00126     if ( en_colision ) {
00127         VECTOR mmin(-L, -L, -L), mmax(L, L, L);
00128 
00129         glPushMatrix();
00130         glTranslatef((float)_posicion.x,
00131                      (float)_posicion.y, (float)_posicion.z);
00132         pintar_paralelepipedo(mmin, mmax);
00133         en_colision = FALSE;
00134         glPopMatrix();
00135     }
00136 }
00137 #endif // GL_ENABLED
00138 
00139 void
00140 MASA_PUNTUAL::pintar_povray(FILE *fd)
00143 {
00144     fprintf(fd, 
00145         "sphere {\n"
00146         "    <%f, %f, %f>, 0.05\n"
00147         "    texture { pigment { color rgb <%f, %f, %f> } }"
00148         "}\n",
00149         _posicion.x, _posicion.y, _posicion.z,
00150         _color.r, _color.g, _color.b
00151     );
00152 }
00153 
00154 void
00155 MASA_PUNTUAL::actualizar(double delta_t)
00156 {
00157     SOLVER_EULER solver(this);
00158 
00159     solver.ejecutar_solucion(delta_t);
00160 }
00161 
00162 void
00163 MASA_PUNTUAL::grabar(FILE *fd)
00164 {
00165     fprintf(fd, "// COSA (MASA_PUNTUAL sin metodo de grabar!)\n");
00166 }
00167 
00168 BOOLEAN
00169 MASA_PUNTUAL::leer(TOKENIZADOR *Sabiondo)
00170 {
00171     char cad[1000];
00172     int tipo_token = TK_DESCONOCIDO, pos;
00173     BOOLEAN con_mi_color = FALSE;
00174 
00175     pos = 1;
00176     while ( tipo_token != TK_CERRAR ) {
00177         tipo_token = Sabiondo->siguiente_token(cad);
00178         switch ( pos ) {
00179             case 1:
00180               ESPERO(TK_CADENA, "una cadena");
00181               if ( strlen(cad) > MAX_CAD-1 ) cad[MAX_CAD-1] = '\0'; 
00182               des_comille(cad);
00183               set_nombre(cad);
00184               pos++;
00185               break;
00186             case 2:  ESPERO(TK_ABRIR, "\"{\"");  pos++; break;
00187             default:
00188               if ( tipo_token == TK_CERRAR ) break;
00189               ESPERO(TK_IDENTIFICADOR, "un identificador (1)");
00190               if ( strcmp(cad, "espacio") == 0 ) {
00191                   tipo_token = Sabiondo->siguiente_token(cad);
00192                   ESPERO(TK_CADENA, "una cadena");
00193                   // OJO: Es responsabilidad del UNIVERSO asignarme luego
00194                   // mi ESPACIO
00195                   //printf("  - espacio: %s\n", cad); 
00196                 }
00197                 else if ( !leer_basico(Sabiondo, cad, &con_mi_color) ) {
00198                   return FALSE;
00199                 }
00200               ;
00201               break;
00202         }
00203     }
00204 
00205     if ( !con_mi_color ) _color = Material->difusa();
00206 
00207     return TRUE;
00208 }
00209 
00210 //= SERVICIOS DE ECUACION DIFERENCIAL! ======================================
00211 
00212 int
00213 MASA_PUNTUAL::ODE_numero_de_variables_de_estado(void)
00214 {
00215     if ( _estoy_fijo ) return 0;
00216     return 6;
00217 }
00218 
00219 void
00220 MASA_PUNTUAL::ODE_reportar_variables_de_estado(double *Datos)
00221 {
00222     if ( _estoy_fijo ) return;
00223 
00224     Datos[0] = _posicion.x;
00225     Datos[1] = _posicion.y;
00226     Datos[2] = _posicion.z;
00227     Datos[3] = _velocidad.x;
00228     Datos[4] = _velocidad.y;
00229     Datos[5] = _velocidad.z;
00230 }
00231 
00232 void
00233 MASA_PUNTUAL::ODE_actualizar_variables_de_estado(double *Datos)
00234 {
00235     if ( _estoy_fijo ) return;
00236 
00237     _posicion.x = Datos[0];
00238     _posicion.y = Datos[1];
00239     _posicion.z = Datos[2];
00240     _velocidad.x = Datos[3];
00241     _velocidad.y = Datos[4];
00242     _velocidad.z = Datos[5];
00243 }
00244 
00245 void
00246 MASA_PUNTUAL::ODE_calcular_la_primera_derivada(double *Datos)
00258 {
00259     //- 1. CALCULE LA CONTRIBUCION TOTAL DE LAS FUERZAS ---------------------
00260     VECTOR f(0, 0, 0);
00261     int i;
00262 
00263     for ( i = 0; i < lista_fuerzas_externas.tam(); i++ ) {
00264         f = f + lista_fuerzas_externas[i]->fuerza;
00265     }
00266     limpiar_fuerzas();
00267 
00268     if ( _estoy_fijo ) return;
00269 
00270     //- 2. ACTUALICE LA POSICION Y LA VELOCIDAD DE LA PARTICULA -------------
00271     Datos[0] = _velocidad.x;
00272     Datos[1] = _velocidad.y;
00273     Datos[2] = _velocidad.z;
00274     Datos[3] = f.x / _masa;
00275     Datos[4] = f.y / _masa;
00276     Datos[5] = f.z / _masa;
00277 }
00278 
00279 //===========================================================================
00280 //= EOF                                                                     =
00281 //===========================================================================
00282 

Este archivo HTML ha sido generado automáticamente a partir del código fuente AQUYNZA. NO LO EDITE. Para mayor información contacte al autor.