00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef __CAMARA__
00023 #define __CAMARA__
00024
00025 #include "jed_defs.h"
00026
00027 #include "entidad.h"
00028 #include "jed_gl.h"
00029 #include "color.h"
00030 #include "matriz4.h"
00031 #include "quaternion.h"
00032 #include "toolkits/entorno/rayo.h"
00033
00034 enum ENUM_MODOS_DE_CAMARA {
00035 CAM_GLOBAL = 1,
00036 CAM_POS_MODELO,
00037 CAM_TOTAL_MODELO
00038 };
00039
00040 enum ENUM_MODOS_DE_CONTROL_CAMARA {
00041 CAM_STANDARD = 4,
00042 CAM_VUELO
00043 };
00044
00045 enum ENUM_TIPOS_PERSPECTIVAS {
00046 CAM_PERSPECTIVA = 6,
00047 CAM_PARALELA
00048 };
00049
00050 enum ENUM_TIPOS_BILLBOARD {
00051 CAM_NO_CUADRAR = 0,
00052 CAM_CUADRAR_X,
00053 CAM_CUADRAR_Y,
00054 CAM_CUADRAR_MENOR
00055 };
00056
00057 #define ACTIVAR_TRANSPARENCIA(t) \
00058 if ( (t) > 1.0 ) (t) = 1.0; \
00059 if ( (t) < 0 ) (t) = 0; \
00060 if ( (t) < 1.0 - EPSILON ) { \
00061 glEnable(GL_BLEND); \
00062 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); \
00063 }
00064
00065
00066
00067
00068 class CAMARA : public ENTIDAD
00100 {
00101 private:
00102
00103 VECTOR _posicion;
00104 QUATERNION _orientacion;
00105 double _fov;
00106 double _near_plane;
00107
00108
00109 double _far_plane;
00110
00111
00112 int _modo_proyeccion;
00113 double _zoom_paralelo;
00114
00115
00116
00117
00118 ENTIDAD *_Padre;
00119 char *_nombre_padre;
00120
00121 BOOLEAN mostrar_etiqueta;
00122
00123
00124 double transparencia_etiqueta;
00125
00126 COLOR color_etiqueta;
00127
00128 int tipo_modelo;
00129 int modo_seguimiento;
00130 int modo_control;
00131
00132
00146 int _ventana_xtam;
00147 int _ventana_ytam;
00148
00166 BOOLEAN _con_posicion;
00167
00177 VECTOR _up;
00178 VECTOR _right;
00179 VECTOR _dir;
00180 VECTOR _pos;
00181
00182
00183 void pintar_base_gl(void);
00184 void pintar_volumen_gl(void);
00185
00186 public:
00187
00188 CAMARA();
00189 virtual ~CAMARA();
00190
00191 VECTOR posicion(void);
00192 void set_posicion(VECTOR p);
00193 QUATERNION orientacion(void);
00194 void set_orientacion(QUATERNION o);
00195 double fov(void);
00196 void set_fov(double in_nuevo_fov);
00197 double far_plane(void);
00198 void set_far_plane(double f);
00199 double near_plane(void);
00200 void set_near_plane(double f);
00201 int modelo(void);
00202 void set_modelo(int val);
00203
00204
00205 void asociar_padre(ENTIDAD *p);
00206 char *nombre_padre(void);
00207 void preprocesar_vista(void);
00208 inline RAYO generar_rayo(int x, int y);
00209 void imprimir(void);
00210 BOOLEAN minmax_visible(VECTOR esquinas[8]);
00211 MATRIZ_4x4 calcular_matriz_de_proyeccion(int modo_stereo = 0);
00212 BOOLEAN proyectar_punto(VECTOR *in_P, double *out_U, double *out_V);
00213
00214
00215 BOOLEAN
00216 consultar_variable(const char *nombre_variable, int &tipo, void **ref);
00217
00218
00219 #ifdef GL_ENABLED
00220 void pintar_gl(void);
00221 void activar_gl(int modo_stereo = 0);
00222 void activar_centro_gl(void);
00223 void billboard_gl(int tipo);
00224 void subbillboard_gl(int tam, int x, int y, int dx, int dy, int cuadre);
00225 #endif
00226 void activar_povray(FILE *fd);
00227
00228
00229 BOOLEAN procesar_teclado(EVENTO_GUI *e);
00230 BOOLEAN procesar_mouse(EVENTO_GUI *e);
00231 void procesar_resize(int xtam, int ytam);
00232 double factor_font(void);
00233
00234
00235 BOOLEAN leer(TOKENIZADOR *Sabiondo);
00236 };
00237
00238
00239
00240
00241
00242 inline RAYO
00243 CAMARA::generar_rayo(int x, int y)
00263 {
00264 RAYO rayo;
00265 double mi_x, mi_y;
00266 VECTOR dx, dy;
00267 double vxt = (double)_ventana_xtam, vyt = (double)(_ventana_ytam);
00268
00269
00270 mi_x = (x - vxt/2.0) / vxt;
00271 mi_y = ((vyt - y - 1) - vyt/2.0) / vyt;
00272
00273
00274 rayo.origen.x = _pos.x;
00275 rayo.origen.y = _pos.y;
00276 rayo.origen.z = _pos.z;
00277
00278 dy = _up * mi_y;
00279 dx = _right * mi_x;
00280 rayo.direccion = dx + dy;
00281 rayo.direccion = rayo.direccion + _dir;
00282 rayo.direccion.normalizar();
00283
00284
00285 return rayo;
00286 }
00287
00288 #endif // __CAMARA__
00289
00290
00291
00292
00293