00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef __BSP_2D__
00030 #define __BSP_2D__
00031
00032 #include "jed_defs.h"
00033 #include "toolkits/util/jed_wad.h"
00034 #include "toolkits/geom/geometria.h"
00035
00036
00037
00038
00039
00040 class _BSP2D_ARCO;
00041 class _BSP2D_SECTOR;
00042 class _BSP2D_SEGMENTOi;
00043 class _BSP2D_PARED;
00044 class _BSP2D_HOJA;
00045 class _BSP2D_NODO;
00046 class BSP_2D;
00047
00048 class _BSP2D_CONTORNOi
00049
00050
00051
00052 {
00053 private:
00054 LISTA <_BSP2D_ARCO *> arcos;
00055 friend class _BSP2D_SECTOR;
00056 };
00057
00058
00059
00060
00061
00062 class _BSP2D_VERTICEi
00071 {
00072 private:
00073 int x;
00074 int y;
00075
00076 friend class _BSP2D_PARED;
00077 friend class _BSP2D_ARCO;
00078 friend class _BSP2D_SECTOR;
00079 friend class BSP_2D;
00080 friend class _BSP2D_SEGMENTOi;
00081 friend class _BSP2D_NODO;
00082 };
00083
00084
00085 #define ARCO_IMPASABLE(a) (a).flags & 0x01
00086 #define ARCO_DOBLE_CARA(a) (a).flags & 0x04
00087 #define ARCO_SECRETO(a) (a).flags & 0x10
00088 #define ARCO_BLOQUEA_SONIDO() (a).flags & 0x20
00089
00090 class _BSP2D_ARCO {
00091 private:
00092 BSP_2D *Padre;
00093 WORD v_origen;
00094 WORD v_destino;
00095 _BSP2D_PARED *Izq;
00096 _BSP2D_PARED *Der;
00097 WORD sector_id;
00098 WORD flags;
00099
00100 friend class BSP_2D;
00101 friend class _BSP2D_SECTOR;
00102 friend class _BSP2D_SEGMENTOi;
00103 friend class _BSP2D_PARED;
00104
00105 public:
00106 _BSP2D_ARCO();
00107
00108 void importe_wad(BSP_2D *p, WAD_LEVEL *Nivel_wad, long int pos);
00109 void pintar_gl_3D(void);
00110 };
00111
00112 class _BSP2D_PARED
00128 {
00129 private:
00130 _BSP2D_VERTICEi v1;
00131 _BSP2D_VERTICEi v2;
00132 WORD altura1, altura2;
00133
00134 _BSP2D_ARCO *Arco_padre;
00135 _BSP2D_PARED *Del_otro_lado;
00136
00137 char textura_superior[9];
00138 char textura_media[9];
00139 char textura_inferior[9];
00140 int textura_superior_id;
00141 int textura_media_id;
00142 int textura_inferior_id;
00143
00144
00145 VECTOR n;
00146 WORD dx;
00147 WORD dy;
00148 BSP_2D *Padre;
00149
00150
00151 WORD sector_id;
00152
00153 friend class _BSP2D_ARCO;
00154 friend class _BSP2D_SECTOR;
00155 friend class _BSP2D_SEGMENTOi;
00156
00157 public:
00158 _BSP2D_PARED();
00159 void importe_wad(BSP_2D *Padre, WAD_LEVEL *Nivel_wad, long int pos);
00160 void calcule_normal(void);
00161 void pintar_gl_3D(void);
00162
00163 };
00164
00165 class _BSP2D_SEGMENTOi
00169 {
00170 private:
00171 BSP_2D *Padre;
00172 WORD sector_id;
00173
00174 WORD v_origen;
00175 WORD v_destino;
00176
00177 WORD angulo;
00178 WORD arco_i;
00179 WORD direccion;
00180 WORD offset;
00181
00182 double angulo_recta;
00183 _BSP2D_PARED *Pared;
00184
00185 friend class _BSP2D_SECTOR;
00186 friend class _BSP2D_HOJA;
00187
00188 public:
00189 _BSP2D_SEGMENTOi();
00190 void importe_wad(BSP_2D *pp, WAD_LEVEL *Nivel_wad, long int pos);
00191 #ifdef GL_ENABLED
00192 void pintar_gl_2D(double angulo_camara);
00193 void pintar_gl_3D(CALIDAD_VISUAL *Calidad, double angulo_camara);
00194 #endif
00195 void anexe_vertices(LISTA <_BSP2D_VERTICEi *> *Vertices);
00196 };
00197
00198 class _BSP2D_SECTOR
00209 {
00210 private:
00211 WORD id;
00212
00213 WORD altura_piso;
00214 WORD altura_techo;
00215
00216 double min_x;
00217 double min_y;
00218 double max_x;
00219 double max_y;
00220
00221 BSP_2D *Padre;
00222
00223 char textura_piso[9];
00224 char textura_techo[9];
00225 int textura_piso_id;
00226 int textura_techo_id;
00227
00228 long int num_triangulos;
00229 double *Triangulos;
00230
00231 BOOLEAN marcado;
00232 BOOLEAN con_paredes;
00233
00234 long int pos;
00235
00236 friend class _BSP2D_PARED;
00237 friend class _BSP2D_HOJA;
00238 friend class _BSP2D_SEGMENTOi;
00239 friend class BSP_2D;
00240
00241 public:
00242 _BSP2D_SECTOR();
00243
00244 BOOLEAN altura(double x, double y, double *Altura);
00245 void importe_wad(BSP_2D *pp, WAD_LEVEL *Nivel_wad, long int pos);
00246 #ifdef GL_ENABLED
00247 void pintar_gl_3D(CALIDAD_VISUAL *Calidad);
00248 #endif
00249 void triangularize(void);
00250 };
00251
00252
00253
00254
00255
00256 class _BSP2D_ELEMENTO {
00257 protected:
00258 BSP_2D *Padre;
00259
00260 public:
00261 char mi_tipo;
00262 _BSP2D_ELEMENTO();
00263 virtual ~_BSP2D_ELEMENTO();
00264
00265 void init(BSP_2D *p);
00266 virtual void elim(void) = 0;
00267 virtual void importe_wad(WAD_LEVEL *Nivel_wad, long int pos) = 0;
00268 #ifdef GL_ENABLED
00269 virtual void pintar_gl_2D(
00270 VECTOR posicion_camara, VECTOR orientacion_camara,
00271 CALIDAD_VISUAL *Calidad) = 0;
00272 virtual void pintar_gl_3D(
00273 VECTOR posicion_camara, VECTOR orientacion_camara,
00274 CALIDAD_VISUAL *Calidad) = 0;
00275 #endif
00276 virtual double altura_cuadro(WORD x, WORD y) = 0;
00277 virtual void mover(_BSP2D_VERTICEi delta) = 0;
00278 };
00279
00280 class _BSP2D_HOJA : public _BSP2D_ELEMENTO
00288 {
00289 private:
00290 WORD num_segmentos;
00291 WORD primer_segmento;
00292 public:
00293
00294 _BSP2D_HOJA();
00295 ~_BSP2D_HOJA();
00296
00297 void elim(void);
00298 void importe_wad(WAD_LEVEL *Nivel_wad, long int pos);
00299
00300 double altura_cuadro(WORD x, WORD y);
00301 void mover(_BSP2D_VERTICEi delta);
00302
00303
00304
00305 #ifdef GL_ENABLED
00306 void pintar_gl_2D(
00307 VECTOR posicion_camara, VECTOR orientacion_camara,
00308 CALIDAD_VISUAL *Calidad);
00309 void pintar_gl_3D(
00310 VECTOR posicion_camara, VECTOR orientacion_camara,
00311 CALIDAD_VISUAL *Calidad);
00312 #endif
00313 };
00314
00315 class _BSP2D_NODO : public _BSP2D_ELEMENTO
00321 {
00322 private:
00323 int linea_x;
00324 int linea_y;
00325 int linea_dx;
00326 int linea_dy;
00327 _BSP2D_VERTICEi min_izq;
00328 _BSP2D_VERTICEi max_izq;
00329 _BSP2D_VERTICEi min_der;
00330 _BSP2D_VERTICEi max_der;
00331 _BSP2D_ELEMENTO *Izq;
00332 _BSP2D_ELEMENTO *Der;
00333
00334 public:
00335
00336 _BSP2D_NODO();
00337 ~_BSP2D_NODO();
00338
00339 void elim(void);
00340 void importe_wad(WAD_LEVEL *Nivel_wad, long int pos);
00341
00342 double altura_cuadro(WORD x, WORD y);
00343 void mover(_BSP2D_VERTICEi delta);
00344
00345
00346
00347 #ifdef GL_ENABLED
00348 void pintar_gl_2D(
00349 VECTOR posicion_camara, VECTOR orientacion_camara,
00350 CALIDAD_VISUAL *Calidad);
00351 void pintar_gl_3D(
00352 VECTOR posicion_camara, VECTOR orientacion_camara,
00353 CALIDAD_VISUAL *Calidad);
00354 #endif
00355 };
00356
00357
00358
00359
00360
00361 class BSP_2D : public GEOMETRIA_3D
00383 {
00384 private:
00385
00386 WAD_DATABASE *datos_wad;
00387
00388
00389 PALETA paleta_para_texturas;
00390 LISTA <IMAGEN *> flats;
00391 LISTA <IMAGEN *> sprites;
00392 LISTA <char *> nombres_flats;
00393 LISTA <char *> nombres_sprites;
00394 _BSP2D_VERTICEi min;
00395 _BSP2D_VERTICEi max;
00396
00397
00398 long int num_vertices;
00399 _BSP2D_VERTICEi *Vertices;
00400
00401 long int num_arcos;
00402 _BSP2D_ARCO *Arcos;
00403
00404 long int num_paredes;
00405 _BSP2D_PARED *Paredes;
00406
00407 long int num_segmentos;
00408 _BSP2D_SEGMENTOi *Segmentos;
00409
00410 long int num_sectores;
00411 _BSP2D_SECTOR *Sectores;
00412
00413
00414 long int num_hojas;
00415 _BSP2D_HOJA *Hojas;
00416 long int num_nodos;
00417 _BSP2D_NODO *Nodos;
00418 _BSP2D_NODO *Raiz;
00419
00420
00421 friend class _BSP2D_ARCO;
00422 friend class _BSP2D_SECTOR;
00423 friend class _BSP2D_SEGMENTOi;
00424 friend class _BSP2D_HOJA;
00425 friend class _BSP2D_NODO;
00426 friend class _BSP2D_PARED;
00427
00428
00429 #ifdef GL_ENABLED
00430 void pintar_gl_3D(CALIDAD_VISUAL *Calidad);
00431 void pintar_gl_3D_wireframe(CALIDAD_VISUAL *Calidad);
00432 #endif
00433 void activar_calidad(CALIDAD_VISUAL *Calidad, MATERIAL *Material);
00434 void mover(_BSP2D_VERTICEi delta);
00435
00436 int deme_flat(char *nombre);
00437 int deme_textura(char *nombre);
00438
00439 public:
00440
00441 BSP_2D();
00442 virtual ~BSP_2D();
00443 BOOLEAN importe_wadlevel(WAD_DATABASE *w, int id_nivel);
00444
00445
00446 void anexar_textura(IMAGEN *img);
00447 int clasificar_punto(VECTOR p);
00448 GEOMETRIA *crear_copia(void);
00449
00450
00451 #ifdef GL_ENABLED
00452 void
00453 pintar_gl(CALIDAD_VISUAL *Calidad, MATERIAL *Material, CAMARA *Camara);
00454 void
00455 pintar_bsp(CALIDAD_VISUAL *Calidad, MATERIAL *Material, CAMARA *Camara);
00456 #endif
00457 void pintar_povray(FILE *fd);
00458 void pintar_aqz(FILE *fd);
00459 double altura(double x, double y);
00460 };
00461
00462 #endif // __BSP_2D__
00463
00464
00465
00466
00467