00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00064
00065 class GfxGLWindowGLUI;
00066 class GfxGLTexture;
00067
00068 FREECLOTH_NAMESPACE_START
00069 class GeMesh;
00070 FREECLOTH_NAMESPACE_END
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081 class ClothApp : public GfxWindowObserver
00082 {
00083 public:
00084
00085 ClothApp();
00086 void runApp();
00087
00088 protected:
00089
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
00102
00103
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
00161 enum ConstraintType {
00162 CON_NONE,
00163
00164 CON_CENTRE,
00165 CON_CORNERS,
00166 CON_CORNERS2,
00167 CON_CORNERYANK,
00168 CON_TABLE_SQUARE,
00169 CON_TABLE_CIRCLE,
00170
00171 NB_CONSTRAINTS
00172 };
00173
00174
00175 static RCShdPtr<GeMesh> createRectMesh(
00176 Float size,
00177 UInt32 nbRows,
00178 UInt32 nbColumns
00179 );
00180 static void initMeshIndices(
00181 const GeMesh& mesh,
00182 std::vector<UInt32>& indices
00183 );
00184
00185
00186 void setupMesh();
00187 void setupSimulator();
00188 void setConstraints();
00189 void setupWindow();
00190 void initGL();
00191 void calcNormals();
00192 void renderCloth();
00193 void renderClothTriDebug( bool showStretch, bool showShear, bool showBend );
00194 void renderClothVertDebug();
00195 void renderClothOutline();
00196 void renderAxes();
00197 void renderFloor();
00198 void updateParamsUI();
00199
00200
00201 RCShdPtr<GeMesh> _initialMesh;
00202 RCShdPtr<GfxGLWindowGLUI> _glWindow;
00203 RCShdPtr<GfxGLTexture> _floorTexture, _clothTexture;
00204 RCShdPtr<SimSimulator> _simulator;
00205 GfxConfig _config;
00206
00207
00208 std::vector<UInt32> _meshIndices;
00209 std::vector<GeVector> _meshNormals;
00210 std::vector<GePoint> _meshTextureVertices;
00211 RCShdPtr<GeMeshWingedEdge> _meshWE;
00212 GePoint _meshPos;
00213
00214 SimSimulator::Params _params;
00215 UInt32 _nbPatches;
00216 Float _clothSize;
00217 Float _h;
00218 Float _rho;
00219 Float _pcgTolerance;
00220 ConstraintType _constraints;
00221
00222 bool _quitFlag;
00223 bool _rewindFlag;
00224 bool _freeRunFlag;
00225 bool _stopFlag;
00226 bool _stepFlag;
00227 bool _snapFlag;
00228 UInt32 _snapCount;
00229 UInt32 _nextMovieFrame;
00230
00231 bool _subStepFlag;
00232 };
00233
00234 #endif