- Main Page
- Modules
- Classes
- Files

- File List
- File Members

# D:/CHAI3D/build-2-0-0/2.0.0/win32/src/scenegraph/CMesh.h

Go to the documentation of this file.

    00001 //===========================================================================
    00002 /*
    00003     This file is part of the CHAI 3D visualization and haptics libraries.
    00004     Copyright (C) 2003-2009 by CHAI 3D. All rights reserved.
    00005
    00006     This library is free software; you can redistribute it and/or modify
    00007     it under the terms of the GNU General Public License("GPL") version 2
    00008     as published by the Free Software Foundation.
    00009
    00010     For using the CHAI 3D libraries with software that can not be combined
    00011     with the GNU GPL, and for taking advantage of the additional benefits
    00012     of our support services, please contact CHAI 3D about acquiring a
    00013     Professional Edition License.
    00014
    00015     \author    <http://www.chai3d.org>
    00016     \author    Francois Conti
    00017     \author    Dan Morris
    00018     \author    Chris Sewell
    00019     \version   2.0.0 $Rev: 264 $
    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     // CONSTRUCTOR & DESTRUCTOR:
    00073     //-----------------------------------------------------------------------
    00074
    00076     cMesh(cWorld* a_world);
    00077
    00079     virtual ~cMesh();
    00080
    00081
    00082     //-----------------------------------------------------------------------
    00083     // METHODS - GENERAL
    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     // METHODS - VERTICES
    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     // METHODS - TRIANGLES
    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     // METHODS - GRAPHIC RENDERING
    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     // METHODS - COLLISION DETECTION:
    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     // METHODS - MESH MANIPULATION:
    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     // METHODS:
    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     // MEMBERS - DISPLAY PROPERTIES:
    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     // MEMBERS - ARRAYS:
    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

CHAI3D 2.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2009 - CHAI 3D
All Rights Reserved.