Main Page   Class Hierarchy   Compound List   File List   Compound Members  

clothApp.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_clothApp_clothApp_h
00020 #define freecloth_clothApp_clothApp_h
00021 
00022 #ifndef freecloth_clothApp_package_h
00023 #include <freecloth/clothApp/package.h>
00024 #endif
00025 
00026 #ifndef freecloth_simulator_simSimulator_h
00027 #include <freecloth/simulator/simSimulator.h>
00028 #endif
00029 
00030 #ifndef freecloth_base_vector
00031 #include <freecloth/base/vector>
00032 #endif
00033 
00034 #ifndef freecloth_resmgt_rcShdPtr_h
00035 #include <freecloth/resmgt/rcShdPtr.h>
00036 #endif
00037 
00038 #ifndef freecloth_gfx_gfxConfig_h
00039 #include <freecloth/gfx/gfxConfig.h>
00040 #endif
00041 
00042 #ifndef freecloth_geom_gePoint_h
00043 #include <freecloth/geom/gePoint.h>
00044 #endif
00045 
00046 #ifndef freecloth_geom_geVector_h
00047 #include <freecloth/geom/geVector.h>
00048 #endif
00049 
00050 #ifndef freecloth_geom_geMeshWingedEdge_h
00051 #include <freecloth/geom/geMeshWingedEdge.h>
00052 #endif
00053 
00054 #ifndef freecloth_gfx_gfxGLWindowGLUI_h
00055 #include <freecloth/gfx/gfxGLWindowGLUI.h>
00056 #endif
00057 
00058 #ifndef freecloth_gfx_gfxWindowObserver_h
00059 #include <freecloth/gfx/gfxWindowObserver.h>
00060 #endif
00061 
00062 ////////////////////////////////////////////////////////////////////////////////
00063 // FORWARD DECLARATIONS
00064 
00065 class GfxGLWindowGLUI;
00066 class GfxGLTexture;
00067 
00068 FREECLOTH_NAMESPACE_START
00069     class GeMesh;
00070 FREECLOTH_NAMESPACE_END
00071 
00072 ////////////////////////////////////////////////////////////////////////////////
00073 /*!
00074  * \class ClothApp freecloth/clothApp/clothApp.h
00075  * \brief Demonstration application for Freecloth simulator
00076  *
00077  * This demonstration application shows off the capabilities of the Freecloth
00078  * simulator. A lot of auxiliary classes are needed to pull this off, mostly in
00079  * the gfx/ subdirectory.
00080  */
00081 class ClothApp : public GfxWindowObserver
00082 {
00083 public:
00084     // ----- member functions -----
00085     ClothApp();
00086     void runApp();
00087 
00088 protected:
00089     // ----- member functions -----
00090     void keyPressed( GfxWindow&, GfxWindow::KeyID, GfxWindow::ModBitfield );
00091     void windowResized( GfxWindow&, UInt32 x, UInt32 y, UInt32 w, UInt32 h );
00092     void displayReceived( GfxWindow& );
00093     void closeReceived( GfxWindow& );
00094     void uiReceived( GfxWindow&, UInt32 uid );
00095     void idleReceived();
00096 
00097     void render( bool debug_stretch, bool debug_shear, bool debug_bend );
00098     void snap( bool debug );
00099 
00100 private:
00101     // ----- types and enumerations -----
00102 
00103     //! Control IDs
00104     enum {
00105         ID_CAMERA_ROTATE,
00106         ID_ZOOM,
00107         ID_LIGHT,
00108         ID_FOG_START,
00109         ID_FOG_END,
00110         ID_AXES,
00111         ID_WIREFRAME,
00112         ID_CLOTH_SIZE,
00113 
00114         ID_RUN,
00115         ID_STOP,
00116         ID_STEP,
00117         ID_REWIND,
00118         ID_TIME,
00119         ID_PATCHES,
00120         ID_TIMESTEP,
00121         ID_PCG_TOLERANCE,
00122 
00123         ID_PAR_K_STRETCH,
00124         ID_PAR_K_SHEAR,
00125         ID_PAR_K_BEND_U,
00126         ID_PAR_K_BEND_V,
00127         ID_PAR_K_DAMP,
00128         ID_PAR_K_DRAG,
00129         ID_PAR_B_U,
00130         ID_PAR_B_V,
00131         ID_PAR_RHO,
00132         ID_PAR_G,
00133         ID_PAR_RESET,
00134 
00135         ID_CONSTRAINTS,
00136 
00137         ID_EN_STRETCH,
00138         ID_EN_SHEAR,
00139         ID_EN_BEND,
00140 
00141         ID_TRI_STRETCH,
00142         ID_TRI_SHEAR,
00143         ID_TRI_BEND,
00144 
00145         ID_VERT_VEL,
00146         ID_VERT_FORCE,
00147         ID_VERT_FORCE_DAMP,
00148         ID_VERT_FORCE_STRETCH,
00149         ID_VERT_FORCE_SHEAR,
00150         ID_VERT_FORCE_BEND,
00151         ID_VERT_FORCE_GRAVITY,
00152         ID_VERT_FORCE_DRAG,
00153 
00154         ID_SNAPSHOT,
00155         ID_MOVIE,
00156 
00157         ID_QUIT
00158     };
00159 
00160     //! Constraint IDs
00161     enum ConstraintType {
00162         CON_NONE,
00163 
00164         CON_CENTRE,
00165         CON_CORNERS4,
00166         CON_CORNERS3a,
00167         CON_CORNERS3b,
00168         CON_CORNERS1c,
00169         CON_CORNERS1d,
00170         CON_CORNERYANK,
00171         CON_TABLE_SQUARE,
00172         CON_TABLE_CIRCLE,
00173 
00174         NB_CONSTRAINTS
00175     };
00176     
00177     // ----- static member functions -----
00178     static RCShdPtr<GeMesh> createRectMesh(
00179         Float size,
00180         UInt32 nbRows,
00181         UInt32 nbColumns
00182     );
00183     static void initMeshIndices(
00184         const GeMesh& mesh,
00185         std::vector<UInt32>& indices
00186     );
00187 
00188     // ----- member functions -----
00189     void setupMesh();
00190     void setupSimulator();
00191     void setConstraints();
00192     void setupWindow();
00193     void initGL();
00194     void calcNormals();
00195     void renderCloth();
00196     void renderClothTriDebug( bool showStretch, bool showShear, bool showBend );
00197     void renderClothVertDebug();
00198     void renderClothOutline();
00199     void renderAxes();
00200     void renderFloor();
00201     void updateParamsUI();
00202 
00203     // ----- data members -----
00204     RCShdPtr<GeMesh>            _initialMesh;
00205     RCShdPtr<GfxGLWindowGLUI>   _glWindow;
00206     RCShdPtr<GfxGLTexture>      _floorTexture, _clothTexture;
00207     RCShdPtr<SimSimulator>      _simulator;
00208     GfxConfig                   _config;
00209 
00210     //! Preprocessed list of indices into mesh vertex array.
00211     std::vector<UInt32>     _meshIndices;
00212     std::vector<GeVector>   _meshNormals;
00213     std::vector<GePoint>    _meshTextureVertices;
00214     RCShdPtr<GeMeshWingedEdge> _meshWE;
00215     GePoint                 _meshPos;
00216 
00217     SimSimulator::Params    _params;
00218     UInt32                  _nbPatches;
00219     Float                   _clothSize;
00220     Float                   _h;
00221     Float                   _rho;
00222     Float                   _pcgTolerance;
00223     ConstraintType          _constraints;
00224 
00225     bool _quitFlag;
00226     bool _rewindFlag;
00227     bool _freeRunFlag;
00228     bool _stopFlag;
00229     bool _stepFlag;
00230     bool _snapFlag;
00231     UInt32 _snapCount;
00232     UInt32 _nextMovieFrame;
00233 
00234     bool _subStepFlag;
00235 };
00236 
00237 #endif

Generated on Fri May 2 16:51:12 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002