00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __PARALELEPIPEDO__
00025 #define __PARALELEPIPEDO__
00026
00027 #include "jed_defs.h"
00028
00029 #ifndef __GEOMETRIA__
00030 #error "No incluya a paralele.h, incluya a geometria.h!"
00031 #endif
00032
00033 #ifdef VEL_ROSITA
00034 #include "toolkits/geom/geometria.h"
00035 #endif
00036
00037 class PARALELEPIPEDO : public PRIMITIVA_GEOMETRICA
00038 {
00039 private:
00040 VECTOR _lados;
00041 IMAGEN *imagen;
00042 public:
00043 PARALELEPIPEDO(VECTOR l);
00044 PARALELEPIPEDO(double lx, double ly, double lz);
00045 virtual ~PARALELEPIPEDO();
00046 VECTOR lados(void);
00047 void set_lados(VECTOR l);
00048 void minmax(VECTOR *min, VECTOR *max);
00049
00050 #ifdef GL_ENABLED
00051 void
00052 pintar_gl(CALIDAD_VISUAL *Calidad, MATERIAL* Material, CAMARA *Camara);
00053 #endif
00054 void pintar_povray(FILE *fd);
00055 void pintar_aqz(FILE *fd);
00056 void pintar_vrml(FILE *fd);
00057 void anexar_textura(IMAGEN *img);
00058 int clasificar_punto(VECTOR p);
00059 virtual GEOMETRIA *crear_copia(void);
00060 double interseccion(RAYO *Rayo, VECTOR &punto, VECTOR &normal);
00061 };
00062
00063
00064
00065
00066
00067 inline double
00068 PARALELEPIPEDO::interseccion(RAYO *Rayo, VECTOR &punto, VECTOR &normal)
00079 {
00080 double t, min_t = INFINITO;
00081 double l2x = _lados.x/2;
00082 double l2y = _lados.y/2;
00083 double l2z = _lados.z/2;
00084 VECTOR p;
00085
00086
00087 if ( fabs(Rayo->direccion.z) > EPSILON ) {
00088
00089 t = (l2z-Rayo->origen.z)/Rayo->direccion.z;
00090 if ( t > -EPSILON ) {
00091 p = Rayo->origen + Rayo->direccion * t;
00092 if ( p.x >= -l2x && p.x <= l2x &&
00093 p.y >= -l2y && p.y <= l2y ) {
00094 normal.x = normal.y = 0;
00095 normal.z = 1;
00096 punto = p;
00097 min_t = t;
00098 }
00099 }
00100 }
00101
00102
00103 if ( fabs(Rayo->direccion.z) > EPSILON ) {
00104
00105 t = (-l2z-Rayo->origen.z)/Rayo->direccion.z;
00106 if ( t > -EPSILON && t < min_t ) {
00107 p = Rayo->origen + Rayo->direccion * t;
00108 if ( p.x >= -l2x && p.x <= l2x &&
00109 p.y >= -l2y && p.y <= l2y ) {
00110 normal.x = normal.y = 0;
00111 normal.z = -1;
00112 punto = p;
00113 min_t = t;
00114 }
00115 }
00116 }
00117
00118
00119 if ( fabs(Rayo->direccion.y) > EPSILON ) {
00120
00121 t = (l2y-Rayo->origen.y)/Rayo->direccion.y;
00122 if ( t > -EPSILON && t < min_t ) {
00123 p = Rayo->origen + Rayo->direccion * t;
00124 if ( p.x >= -l2x && p.x <= l2x &&
00125 p.z >= -l2z && p.z <= l2z ) {
00126 normal.x = normal.z = 0;
00127 normal.y = 1;
00128 punto = p;
00129 min_t = t;
00130 }
00131 }
00132 }
00133
00134
00135 if ( fabs(Rayo->direccion.y) > EPSILON ) {
00136
00137 t = (-l2y-Rayo->origen.y)/Rayo->direccion.y;
00138 if ( t > -EPSILON && t < min_t ) {
00139 p = Rayo->origen + Rayo->direccion * t;
00140 if ( p.x >= -l2x && p.x <= l2x &&
00141 p.z >= -l2z && p.z <= l2z ) {
00142 normal.x = normal.z = 0;
00143 normal.y = -1;
00144 punto = p;
00145 min_t = t;
00146 }
00147 }
00148 }
00149
00150
00151 if ( fabs(Rayo->direccion.x) > EPSILON ) {
00152
00153 t = (l2x-Rayo->origen.x)/Rayo->direccion.x;
00154 if ( t > -EPSILON && t < min_t ) {
00155 p = Rayo->origen + Rayo->direccion * t;
00156 if ( p.y >= -l2y && p.y <= l2y &&
00157 p.z >= -l2z && p.z <= l2z ) {
00158 normal.y = normal.z = 0;
00159 normal.x = 1;
00160 punto = p;
00161 min_t = t;
00162 }
00163 }
00164 }
00165
00166
00167 if ( fabs(Rayo->direccion.x) > EPSILON ) {
00168
00169 t = (-l2x-Rayo->origen.x)/Rayo->direccion.x;
00170 if ( t > -EPSILON && t < min_t ) {
00171 p = Rayo->origen + Rayo->direccion * t;
00172 if ( p.y >= -l2y && p.y <= l2y &&
00173 p.z >= -l2z && p.z <= l2z ) {
00174 normal.y = normal.z = 0;
00175 normal.x = -1;
00176 punto = p;
00177 min_t = t;
00178 }
00179 }
00180 }
00181
00182 if ( min_t < INFINITO ) return min_t;
00183 return 0;
00184 }
00185
00186 #endif
00187
00188
00189
00190
00191