00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef _MSVC
00025 #pragma warning (disable : 4786)
00026 #endif
00027
00028 #ifndef CMeshH
00029 #define CMeshH
00030
00031 #include "scenegraph/CGenericObject.h"
00032 #include "graphics/CMaterial.h"
00033 #include "graphics/CTexture2D.h"
00034 #include "graphics/CColor.h"
00035 #include <vector>
00036 #include <list>
00037
00038 using std::list;
00039 using std::vector;
00040
00041 class cWorld;
00042 class cTriangle;
00043 class cVertex;
00044
00045
00046
00054
00055
00056
00065
00066 class cMesh : public cGenericObject
00067 {
00068
00069 public:
00070
00071
00072
00073
00074
00076 cMesh(cWorld* a_world);
00077
00079 virtual ~cMesh();
00080
00081
00082
00083
00084
00085
00087 cWorld* getParentWorld() const { return (m_parentWorld); }
00088
00090 void setParentWorld(cWorld* a_world) { m_parentWorld = a_world; }
00091
00093 virtual bool loadFromFile(const string& a_fileName);
00094
00095
00096
00097
00098
00099
00101 unsigned int newVertex(const double a_x, const double a_y, const double a_z);
00102
00104 unsigned int newVertex(const cVector3d& a_pos) { return( newVertex(a_pos.x, a_pos.y, a_pos.z) ); }
00105
00107 void addVertices(const cVector3d* a_vertexPositions, const unsigned int& a_numVertices);
00108
00110 bool removeVertex(const unsigned int a_index);
00111
00113 cVertex* getVertex(unsigned int a_index, bool a_includeChildren = false);
00114
00116 inline const cVertex* getVertex(unsigned int a_index, bool a_includeChildren = false) const
00117 {
00118 return (const cVertex*)(getVertex(a_index,a_includeChildren));
00119 }
00120
00122 unsigned int getNumVertices(bool a_includeChildren = false) const;
00123
00125 inline virtual vector<cVertex>* pVertices() { return (&m_vertices); }
00126
00128 inline virtual const vector<cVertex>* pVertices() const { return (&m_vertices); }
00129
00131 virtual vector<cVertex>* pVerticesNonEmpty();
00132
00133
00134
00135
00136
00137
00139 unsigned int newTriangle(const unsigned int a_indexVertex0,
00140 const unsigned int a_indexVertex1, const unsigned int a_indexVertex2);
00141
00143 unsigned int newTriangle(const cVector3d& a_vertex0, const cVector3d& a_vertex1,
00144 const cVector3d& a_vertex2);
00145
00147 bool removeTriangle(const unsigned int a_index);
00148
00150 cTriangle* getTriangle(unsigned int a_index, bool a_includeChildren = false);
00151
00153 unsigned int getNumTriangles(bool a_includeChildren = false) const;
00154
00156 void clear();
00157
00159 inline vector<cTriangle>* pTriangles() { return (&m_triangles); }
00160
00161
00162
00163
00164
00165
00167 virtual void setTransparencyLevel(const float a_level,
00168 const bool a_applyToTextures=false,
00169 const bool a_affectChildren=true);
00170
00172 void setVertexColor(const cColorf& a_color, const bool a_affectChildren=true);
00173
00175 void useDisplayList(const bool a_useDisplayList, const bool a_affectChildren=true);
00176
00178 void useVertexArrays(const bool a_useVertexArrays, const bool a_affectChildren=true);
00179
00181 bool getDisplayListEnabled() const { return m_useDisplayList; }
00182
00184 void invalidateDisplayList(const bool a_affectChildren=true);
00185
00187 void setShowNormals(const bool& a_showNormals, const bool a_affectChildren=true, const bool a_trianglesOnly = false);
00188
00190 bool getShowNormals() const { return m_showNormals; }
00191
00193 void setNormalsProperties(const double a_length, const cColorf& a_color, const bool a_affectChildren);
00194
00196 bool getColorsEnabled() const { return m_useVertexColors; }
00197
00199 virtual void onDisplayReset(const bool a_affectChildren = true);
00200
00201
00202
00203
00204
00205
00207 virtual void createBruteForceCollisionDetector(bool a_affectChildren, bool a_useNeighbors);
00208
00210 virtual void createAABBCollisionDetector(double a_radius, bool a_affectChildren, bool a_useNeighbors);
00211
00213 virtual void createSphereTreeCollisionDetector(double a_radius, bool a_affectChildren, bool a_useNeighbors);
00214
00216 void createTriangleNeighborList(bool a_affectChildren);
00217
00219 void findNeighbors(std::vector<cTriangle*>* search1,
00220 std::vector<cTriangle*>* search2, const int& v1, const int& v2);
00221
00222
00223
00224
00225
00226
00228 void computeAllNormals(const bool a_affectChildren=false);
00229
00231 void extrude(const double a_extrudeDistance, const bool a_affectChildren=false,
00232 const bool a_updateCollisionDetector=false);
00233
00238 virtual void offsetVertices(const cVector3d& a_offset,
00239 const bool a_affectChildren=false,
00240 const bool a_updateCollisionDetector=true);
00241
00243 virtual void scaleObject(const cVector3d& a_scaleFactors);
00244
00246 inline virtual cMesh* createMesh() const { return new cMesh(m_parentWorld); }
00247
00249 virtual void renderMesh(const int a_renderMode=0);
00250
00252 virtual cVector3d getCenterOfMass(const bool a_includeChildren=0);
00253
00255 virtual void reverseAllNormals(const bool a_affectChildren=0);
00256
00258 virtual void removeRedundantTriangles(const bool a_affectChildren=0);
00259
00260
00261 protected:
00262
00263
00264
00265
00266
00268 virtual void render(const int a_renderMode=0);
00269
00271 virtual void renderNormals(const bool a_trianglesOnly=true);
00272
00274 virtual void updateGlobalPositions(const bool a_frameOnly);
00275
00277 virtual void updateBoundaryBox();
00278
00279
00280
00281
00282
00283
00285 cWorld *m_parentWorld;
00286
00288 bool m_showNormals;
00289
00291 bool m_showNormalsForTriangleVerticesOnly;
00292
00294 cColorf m_showNormalsColor;
00295
00297 double m_showNormalsLength;
00298
00300 bool m_useDisplayList;
00301
00303 bool m_useVertexArrays;
00304
00306 int m_displayList;
00307
00308
00309
00310
00311
00312
00314 vector<cVertex> m_vertices;
00315
00317 list<unsigned int> m_freeVertices;
00318
00320 vector<cTriangle> m_triangles;
00321
00323 list<unsigned int> m_freeTriangles;
00324 };
00325
00326
00327 #endif
00328
00329