Rectangle.cc

Go to the documentation of this file.
00001 #include <esg/geometry/Rectangle.h>
00002 
00003 using namespace esg;
00004 
00005 void esg::Rectangle::_duplicate_attributes (const Geometry& src)
00006 {
00007     Polygon::_duplicate_attributes(src);
00008 
00009     _width = ((Rectangle&)src)._width;
00010     _width = ((Rectangle&)src)._height;
00011     _xDir.set(((Rectangle&)src)._xDir);
00012     _yDir.set(((Rectangle&)src)._yDir);
00013 }
00014 
00015 void esg::Rectangle::_rotateX(float a)
00016 {
00017     Matrix3d trMat;
00018     trMat.rotX(a);
00019     for (unsigned i = 0; i < _nVert; i++) {
00020         trMat.transform(_vertices[i]);
00021         if (haveVertNormals()) trMat.transform(_normals[i]);
00022     }
00023     trMat.transform(_normal);
00024     trMat.transform(_xDir);
00025     trMat.transform(_yDir);
00026     _set_edge_projection();
00027     _precompute_proj();
00028     _fxyz = - _normal.dot(_get_vertex(0));
00029 }
00030 
00031 void esg::Rectangle::_rotateY(float a)
00032 {
00033     Matrix3d trMat;
00034     trMat.rotY(a);
00035     for (unsigned i = 0; i < _nVert; i++) {
00036         trMat.transform(_vertices[i]);
00037         if (haveVertNormals()) trMat.transform(_normals[i]);
00038     }
00039     trMat.transform(_normal);
00040     trMat.transform(_xDir);
00041     trMat.transform(_yDir);
00042     _set_edge_projection();
00043     _precompute_proj();
00044     _fxyz = - _normal.dot(_get_vertex(0));
00045 }
00046 
00047 void esg::Rectangle::_rotateZ(float a)
00048 {
00049     Matrix3d trMat;
00050     trMat.rotZ(a);
00051     for (unsigned i = 0; i < _nVert; i++) {
00052         trMat.transform(_vertices[i]);
00053         if (haveVertNormals()) trMat.transform(_normals[i]);
00054     }
00055     trMat.transform(_normal);
00056     trMat.transform(_xDir);
00057     trMat.transform(_yDir);
00058     _set_edge_projection();
00059     _precompute_proj();
00060     _fxyz = - _normal.dot(_get_vertex(0));
00061 }
00062 
00063 void esg::Rectangle::_rotate(float a, const Vector3& axis)
00064 {
00065     Matrix4d trMat;
00066     Matrix3d rotMat;
00067     trMat.rotationGL(a, axis);
00068     trMat.get(rotMat);
00069     for (unsigned i = 0; i < _nVert; i++) {
00070         trMat.transform(_vertices[i]);
00071         if (haveVertNormals()) rotMat.transform(_normals[i]);
00072     }
00073     rotMat.transform(_normal);
00074     rotMat.transform(_xDir);
00075     rotMat.transform(_yDir);
00076     _set_edge_projection();
00077     _precompute_proj();
00078     _fxyz = - _normal.dot(_get_vertex(0));
00079 }
00080 
00081 void esg::Rectangle::_rotate(const Matrix3& rotMat)
00082 {
00083     for (unsigned i = 0; i < _nVert; i++) {
00084         rotMat.transform(_vertices[i]);
00085         if (haveVertNormals()) rotMat.transform(_normals[i]);
00086     }
00087     rotMat.transform(_normal);
00088     rotMat.transform(_xDir);
00089     rotMat.transform(_yDir);
00090     _set_edge_projection();
00091     _precompute_proj();
00092     _fxyz = - _normal.dot(_get_vertex(0));
00093 }
00094 
00095 void esg::Rectangle::_translate(float x, float y, float z)
00096 {
00097     for (unsigned i = 0; i < _nVert; i++) {
00098         _vertices[i].add(Vector3d(x,y,z));
00099     }
00100     _fxyz = - _normal.dot(_get_vertex(0));
00101 }
00102 
00103 void esg::Rectangle::_transform(const Matrix4& trMat)
00104 {
00105     Matrix3d rotMat;
00106     trMat.get(rotMat);
00107     for (unsigned i = 0; i < _nVert; i++) {
00108         trMat.transform(_vertices[i]);
00109         if (haveVertNormals()) rotMat.transform(_normals[i]);
00110     }
00111     rotMat.transform(_normal);
00112     rotMat.transform(_xDir);
00113     rotMat.transform(_yDir);
00114     _set_edge_projection();
00115     _precompute_proj();
00116     _fxyz = - _normal.dot(_get_vertex(0));
00117 }
00118 
00119 void esg::Rectangle::_scale(float s)
00120 {
00121     for (unsigned i = 0; i < _nVert; i++) _vertices[i].scale(s);
00122     _width  *= s;
00123     _height *= s;
00124     _precompute_proj();
00125     _fxyz *= s;
00126 }
00127 
00128 
00129 //-------- public ----------
00130 
00131 esg::Rectangle::Rectangle(const Vector3& corner,
00132                           const Vector3& u,
00133                           const Vector3& v,
00134                           const Vector2  uva[4],
00135                           bool           oneside)
00136 {
00137     _normals  = NULL;
00138     _uvCoords = NULL;
00139     _proj     = NULL;
00140     _nVert    = 4;
00141     _vertices = new Vector3d [4];
00142     
00143     _vertices[0].set(corner);
00144     _vertices[1].set(_vertices[0]); _vertices[1].add(u);
00145     _vertices[2].set(_vertices[1]); _vertices[2].add(v);
00146     _vertices[3].set(_vertices[0]); _vertices[3].add(v);
00147     
00148     if (uva) {
00149         _uvCoords = new Vector2 [4];
00150         for (unsigned i = 0; i < 4; i++) _uvCoords[i].set(uva[i]);
00151     }
00152     
00153     _normal.set(_get_facet_normal());
00154     _normalFixed = oneside;
00155     _fxyz = - _normal.dot(_get_vertex(0));
00156     _set_edge_projection();
00157 
00158     _width  = u.length();
00159     _height = v.length();
00160     _xDir.set(u); _xDir.normalize();
00161     _yDir.set(v); _yDir.normalize();
00162 }
00163 
00164 esg::Rectangle::Rectangle(const Vector3& corner,
00165                      const Vector3& u,
00166                      const Vector3& v,
00167                      const Vector2  uva[4],
00168                      bool           oneside,
00169                      const Vector3& normal)
00170 {
00171     _normals  = NULL;
00172     _uvCoords = NULL;
00173     _proj     = NULL;
00174     _nVert    = 4;
00175     _vertices = new Vector3d [4];
00176 
00177     _vertices[0].set(corner);
00178     _vertices[1].set(_vertices[0]); _vertices[1].add(u);
00179     _vertices[2].set(_vertices[1]); _vertices[2].add(v);
00180     _vertices[3].set(_vertices[0]); _vertices[3].add(v);
00181 
00182     if (uva) {
00183         _uvCoords = new Vector2 [4];
00184         for (unsigned i = 0; i < 4; i++) _uvCoords[i].set(uva[i]);
00185     }
00186 
00187     _normal.set(normal);
00188     _normalFixed = oneside;
00189     _fxyz = - _normal.dot(_get_vertex(0));
00190     _set_edge_projection();
00191 
00192     _width  = u.length();
00193     _height = v.length();
00194     _xDir.set(u); _xDir.normalize();
00195     _yDir.set(v); _yDir.normalize();
00196 }
00197 
00198 void esg::Rectangle::randomSample(int mask, PointEnv& pe, double* pdf)
00199 {
00200     pe.mask = ENV_HAVE_NOTHING;
00201 
00202     if (mask & (ENV_WANT_SURFACE_POINT|ENV_WANT_NORMAL|ENV_WANT_UV_COORD)) {
00203         double u = ESG_DBL_RAND * _width;
00204         double v = ESG_DBL_RAND * _height;
00205         Vector3 aux(_xDir);
00206         aux.scale(u);
00207         pe.intersection.set(_yDir);
00208         //fprintf(stderr,"1: %f %f %f\n",pe.intersection.x,pe.intersection.y,pe.intersection.z);
00209         pe.intersection.scaleAdd(v, aux);
00210         //fprintf(stderr,"2: %f %f %f\n",pe.intersection.x,pe.intersection.y,pe.intersection.z);
00211         pe.intersection.add(_get_vertex(0));
00212         //fprintf(stderr,"0: %f %f %f\n",_get_vertex(0).x,_get_vertex(0).y,_get_vertex(0).z);
00213         //fprintf(stderr,"3: %f %f %f\n",pe.intersection.x,pe.intersection.y,pe.intersection.z);
00214         pe.uvCoord.set(u,v);
00215         pe.mask |= (ENV_HAVE_SURFACE_POINT|ENV_HAVE_UV_COORD);
00216 
00217         if (mask & ENV_WANT_NORMAL) {
00218             pe.normal.set(_normal);
00219             pe.mask |= ENV_HAVE_NORMAL;
00220             pe.normalOrientation =
00221                 (_normalFixed) ? PointEnv::OUTWARDS_NORMAL : PointEnv::RANDOM_NORMAL;
00222         }
00223     }
00224 }
00225 

Generated on Wed Jun 28 12:24:32 2006 for esg by  doxygen 1.4.6