00001
00002
00003 #ifndef __POLYGON_H
00004 #define __POLYGON_H
00005
00006 #include <esg/geometry/Geometry.h>
00007
00008 namespace esg {
00009
00014 class OGSCENE_EXPORT Polygon : public Geometry {
00015 public:
00016 enum edgeProjection { XY, YZ, XZ, NONE_PROJ };
00017
00018 protected:
00019 Vector3* _vertices;
00020 Vector3* _normals;
00021 Vector2* _uvCoords;
00022 unsigned _nVert;
00023 Vector3 _normal;
00024 bool _normalFixed;
00025 double _fxyz;
00026 edgeProjection _edgeProjection;
00027 double _area;
00028
00029 double (*_proj)[6];
00030
00031 protected:
00032 virtual Mesh* _mesh (int ) const;
00033 virtual void _duplicate_attributes (const Geometry&);
00034 virtual Vector3 _get_facet_normal (void) const;
00035 virtual Vector3 _get_vertex (unsigned) const;
00036 virtual Vector3 _get_vert_normal (unsigned) const;
00037 virtual Vector2 _get_vert_uv_coord (unsigned) const;
00038 virtual void _rotateX (float );
00039 virtual void _rotateY (float );
00040 virtual void _rotateZ (float );
00041 virtual void _rotate (float ,const Vector3& );
00042 virtual void _rotate (const Matrix3&);
00043 virtual void _translate (float , float , float );
00044 virtual void _transform (const Matrix4&);
00045 virtual void _scale (float);
00046
00047 void _set_edge_projection (void);
00048 double (*_precompute_proj (void)) [6];
00049 bool _separation_by_plane (const Geometry&) const;
00050 bool _separation_by_edges (Geometry&) const;
00051 bool _point_inside_polygon (const Vector3&, Vector3*, Vector2*);
00052 bool _coplanar_tri_collision(Polygon&,
00053 const Vector3& v0,
00054 const Vector3& v1,
00055 const Vector3& v2,
00056 const Vector3& u0,
00057 const Vector3& u1,
00058 const Vector3& u2);
00059
00077 int _triTriCollision (Polygon& );
00078
00079
00080
00081 public:
00085 Polygon();
00086
00095 Polygon (const Vector3* va,
00096 const Vector3* na,
00097 const Vector2* uva,
00098 unsigned n);
00099
00110 Polygon (const Vector3* va,
00111 const Vector3* na,
00112 const Vector2* uva,
00113 unsigned n,
00114 const Vector3& norm,
00115 bool fixedn);
00116
00120 virtual ~Polygon ();
00121
00122 virtual void rayIntersection (PointEnv* pPE,
00123 int mask,
00124 const Vector3& origin,
00125 const Vector3& direction,
00126 float maxD = MAXFLOAT);
00127
00128 virtual bool mapToUV (const Vector3& v, Vector2& uv);
00129
00130 virtual void randomSample (int mask, PointEnv& pe, double* pdf);
00131
00132 virtual bool randomDirection (const Vector3& pov,
00133 Vector3& dir,
00134 double* pdf);
00135
00136 virtual Interval extent (const Vector3& direction) const;
00137
00138 virtual Vector3 centroid (void) const;
00139
00140 virtual double radius (const Vector3& centroid) const;
00141
00142 virtual Geometry* clone (const Matrix4* pTrMat) const;
00143
00144 virtual bool separation (Geometry& geom, Vector3* pDir);
00145
00146 virtual double distance (const Geometry& geom, Vector3* pDir);
00147
00148 virtual void dump (const char* intent, const char* tab);
00149
00156 inline bool pointInsidePolygon (const Vector3& p,
00157 Vector3* n,
00158 Vector2* u) {
00159 return _point_inside_polygon(p,n,u);
00160 }
00161
00165 virtual Vector3 getFacetNormal (void) const;
00166
00171 virtual bool haveFixedNormal (void) const;
00172
00177 virtual Vector3 getVertex (unsigned index) const;
00178
00183 virtual Vector3 getVertNormal (unsigned index) const;
00184
00189 virtual bool haveVertNormals (void) const;
00190
00195 virtual Vector2 getVertUVCoord (unsigned) const;
00196
00201 virtual bool haveVertUVCoords (void) const;
00202
00206 virtual unsigned numVertices (void) const;
00207
00212 virtual double getFXYZ (void) const;
00213
00217 virtual edgeProjection getEdgeProjection (void) const;
00218
00228 bool setVertices(const Vector3* va, unsigned n);
00229
00238 bool setNormals(const Vector3* na);
00239
00248 bool setUVCoords(const Vector2* uva);
00249
00256 void setFacetNormal(const Vector3& norm, bool fixedn);
00257
00261 virtual void __debug (void);
00262 };
00263
00264 };
00265
00266 #endif // __POLYGON_H