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 __CUBO__
00025 #define __CUBO__
00026
00027 #include "jed_defs.h"
00028
00029 #ifndef __GEOMETRIA__
00030 #error "No incluya a cubo.h, incluya a geometria.h!"
00031 #endif
00032
00033 #ifdef VEL_ROSITA
00034 #include "toolkits/geom/geometria.h"
00035 #endif
00036
00037 class CUBO : public PRIMITIVA_GEOMETRICA
00038 {
00039 private:
00040 double _lado;
00041 IMAGEN *imagen;
00042 public:
00043 CUBO(double l);
00044 virtual ~CUBO();
00045 double lado(void);
00046 void set_lado(double l);
00047 void minmax(VECTOR *min, VECTOR *max);
00048 #ifdef GL_ENABLED
00049 void
00050 pintar_gl(CALIDAD_VISUAL *Calidad, MATERIAL* Material, CAMARA *Camara);
00051 #endif
00052 void pintar_povray(FILE *fd);
00053 void pintar_aqz(FILE *fd);
00054 void anexar_textura(IMAGEN *img);
00055 int clasificar_punto(VECTOR p);
00056 virtual GEOMETRIA *crear_copia(void);
00057 double interseccion(RAYO *Rayo, VECTOR &punto, VECTOR &normal);
00058 };
00059
00060
00061
00062
00063
00064 inline double
00065 CUBO::interseccion(RAYO *Rayo, VECTOR &punto, VECTOR &normal)
00074 {
00075 double t, min_t = INFINITO;
00076 double l2 = _lado/2;
00077 VECTOR p;
00078
00079
00080 if ( fabs(Rayo->direccion.z) > EPSILON ) {
00081
00082 t = (l2-Rayo->origen.z)/Rayo->direccion.z;
00083 if ( t > -EPSILON ) {
00084 p = Rayo->origen + Rayo->direccion * t;
00085 if ( p.x >= -l2 && p.x <= l2 &&
00086 p.y >= -l2 && p.y <= l2 ) {
00087 normal.x = normal.y = 0;
00088 normal.z = 1;
00089 punto = p;
00090 min_t = t;
00091 }
00092 }
00093 }
00094
00095
00096 if ( fabs(Rayo->direccion.z) > EPSILON ) {
00097
00098 t = (-l2-Rayo->origen.z)/Rayo->direccion.z;
00099 if ( t > -EPSILON && t < min_t ) {
00100 p = Rayo->origen + Rayo->direccion * t;
00101 if ( p.x >= -l2 && p.x <= l2 &&
00102 p.y >= -l2 && p.y <= l2 ) {
00103 normal.x = normal.y = 0;
00104 normal.z = -1;
00105 punto = p;
00106 min_t = t;
00107 }
00108 }
00109 }
00110
00111
00112 if ( fabs(Rayo->direccion.y) > EPSILON ) {
00113
00114 t = (l2-Rayo->origen.y)/Rayo->direccion.y;
00115 if ( t > -EPSILON && t < min_t ) {
00116 p = Rayo->origen + Rayo->direccion * t;
00117 if ( p.x >= -l2 && p.x <= l2 &&
00118 p.z >= -l2 && p.z <= l2 ) {
00119 normal.x = normal.z = 0;
00120 normal.y = 1;
00121 punto = p;
00122 min_t = t;
00123 }
00124 }
00125 }
00126
00127
00128 if ( fabs(Rayo->direccion.y) > EPSILON ) {
00129
00130 t = (-l2-Rayo->origen.y)/Rayo->direccion.y;
00131 if ( t > -EPSILON && t < min_t ) {
00132 p = Rayo->origen + Rayo->direccion * t;
00133 if ( p.x >= -l2 && p.x <= l2 &&
00134 p.z >= -l2 && p.z <= l2 ) {
00135 normal.x = normal.z = 0;
00136 normal.y = -1;
00137 punto = p;
00138 min_t = t;
00139 }
00140 }
00141 }
00142
00143
00144 if ( fabs(Rayo->direccion.x) > EPSILON ) {
00145
00146 t = (l2-Rayo->origen.x)/Rayo->direccion.x;
00147 if ( t > -EPSILON && t < min_t ) {
00148 p = Rayo->origen + Rayo->direccion * t;
00149 if ( p.y >= -l2 && p.y <= l2 &&
00150 p.z >= -l2 && p.z <= l2 ) {
00151 normal.y = normal.z = 0;
00152 normal.x = 1;
00153 punto = p;
00154 min_t = t;
00155 }
00156 }
00157 }
00158
00159
00160 if ( fabs(Rayo->direccion.x) > EPSILON ) {
00161
00162 t = (-l2-Rayo->origen.x)/Rayo->direccion.x;
00163 if ( t > -EPSILON && t < min_t ) {
00164 p = Rayo->origen + Rayo->direccion * t;
00165 if ( p.y >= -l2 && p.y <= l2 &&
00166 p.z >= -l2 && p.z <= l2 ) {
00167 normal.y = normal.z = 0;
00168 normal.x = -1;
00169 punto = p;
00170 min_t = t;
00171 }
00172 }
00173 }
00174
00175 if ( min_t < INFINITO ) return min_t;
00176 return 0;
00177 }
00178
00179 #endif
00180
00181
00182
00183
00184