00001 #ifndef CLOTH_H 00002 #define CLOTH_H 00003 00004 #include <ngl/Vector.h> 00005 #include <ngl/Colour.h> 00006 #include "Mass.h" 00007 #include "Integrator.h" 00008 #include "Spring.h" 00009 #include "Triangle.h" 00010 #include "Edge.h" 00011 #include "Face.h" 00012 #include <vector> 00013 #include <ngl/Transformation.h> 00014 #include <ngl/TransformStack.h> 00015 #include <ngl/Obj.h> 00016 00017 00018 class Spring; 00019 class Integrator; 00020 class ObjObject; 00021 //---------------------------------------------------------------------------------------------------------------------- 00030 00034 //---------------------------------------------------------------------------------------------------------------------- 00035 00036 struct ConstraintPoint 00037 { 00038 public: 00039 bool isActive; 00040 int massNumber; 00041 }; 00042 00043 enum IntegrationMethod 00044 { 00045 EULER_FORWARD, 00046 VERLET, 00047 RK_4 00048 }; 00049 00050 class Cloth 00051 { 00052 00053 public: 00054 00067 Cloth(float clothSize, 00068 int _massesNum, 00069 float _damping, 00070 float _springDamping, 00071 float _timeStep, 00072 float _gravity, 00073 float _stiffeness, 00074 float _criticalDistance, 00075 float _friction, 00076 float _bumpiness, 00077 ngl::TransformStack *_transform); 00078 00079 ~Cloth(); 00080 00081 //---------------------------------------------------------------------------------------------------------------------- 00086 //---------------------------------------------------------------------------------------------------------------------- 00087 void createCloth(std::vector <ngl::Vector> vertexList, 00088 std::vector <ngl::Face> facesList, 00089 std::vector <ngl::Vector> normalsList); 00090 00093 ConstraintPoint* activeConstraint; 00094 00096 std::vector <ngl::Vector> m_vertexList; 00097 00099 std::vector <ngl::Face> m_facesList; 00100 00102 std::vector <ngl::Vector> m_normalsList; 00103 00105 ConstraintPoint* constraintPoint1; 00106 00108 ConstraintPoint* constraintPoint2; 00109 00111 ConstraintPoint* constraintPoint3; 00112 00114 ConstraintPoint* constraintPoint4; 00115 00117 bool isWind; 00118 00120 IntegrationMethod m_integrationMethod; 00121 00122 //---------------------------------------------------------------------------------------------------------------------- 00125 //---------------------------------------------------------------------------------------------------------------------- 00126 void DrawLine(ngl::Vector * points); 00127 00128 //---------------------------------------------------------------------------------------------------------------------- 00131 //---------------------------------------------------------------------------------------------------------------------- 00132 void setClothSize(float _clothSize) {clothSize = _clothSize;} 00133 00134 00135 //---------------------------------------------------------------------------------------------------------------------- 00137 //---------------------------------------------------------------------------------------------------------------------- 00138 void updateSprings(); 00139 00140 //---------------------------------------------------------------------------------------------------------------------- 00144 //---------------------------------------------------------------------------------------------------------------------- 00145 void setActiveMass(bool _isActive, int constraintNumber); 00146 00147 //---------------------------------------------------------------------------------------------------------------------- 00150 //---------------------------------------------------------------------------------------------------------------------- 00151 void moveActiveMass(ngl::Vector _displaysment); 00152 00153 //---------------------------------------------------------------------------------------------------------------------- 00157 //---------------------------------------------------------------------------------------------------------------------- 00158 void setConstraintPoint1(int massNum, bool _activated); 00159 //---------------------------------------------------------------------------------------------------------------------- 00163 //---------------------------------------------------------------------------------------------------------------------- 00164 void setConstraintPoint2(int massNum, bool _activated); 00165 00166 //---------------------------------------------------------------------------------------------------------------------- 00170 //---------------------------------------------------------------------------------------------------------------------- 00171 void setConstraintPoint3(int massNum, bool _activated); 00172 00173 //---------------------------------------------------------------------------------------------------------------------- 00177 //---------------------------------------------------------------------------------------------------------------------- 00178 void setConstraintPoint4(int massNum, bool _activated); 00179 00180 //---------------------------------------------------------------------------------------------------------------------- 00182 //---------------------------------------------------------------------------------------------------------------------- 00183 float getClothSize() {return clothSize;} 00184 00185 //---------------------------------------------------------------------------------------------------------------------- 00188 //---------------------------------------------------------------------------------------------------------------------- 00189 void setMassesNum(int _massesNum) {massesNum = _massesNum;} 00190 00191 //---------------------------------------------------------------------------------------------------------------------- 00193 //---------------------------------------------------------------------------------------------------------------------- 00194 float getMassesNum() {return massesNum;} 00195 00196 //---------------------------------------------------------------------------------------------------------------------- 00198 //---------------------------------------------------------------------------------------------------------------------- 00199 std::string getIntegrationMethod(); 00200 00201 00202 //---------------------------------------------------------------------------------------------------------------------- 00204 //---------------------------------------------------------------------------------------------------------------------- 00205 void calculateClothNormals(); 00206 00207 00210 void setDumping(float _dumping) {DAMPING = _dumping;} 00211 00214 void setTimeStep(float _timeStep) {TIME_STEPSIZE = _timeStep;} 00215 00218 00219 void setSpringDumping(float _dumping) {springDAMPING = _dumping;} 00220 00223 void setGravity(float _gravity) {GRAVITY = _gravity;} 00224 00227 void setCriticalDistance(float _criticalDistance) {CRITICAL_DISTANCE = _criticalDistance;} 00228 00231 void setFricition(float _friction) {FRICITION = _friction;} 00232 00235 void setBumpiness(float _bumpiness) {BUMPINESS = _bumpiness;} 00236 00239 void setStiffness(float _stifness) {STIFFENESS = _stifness;} 00240 00242 float getSpringDamping() {return springDAMPING;} 00243 00245 float getDamping() {return DAMPING;} 00246 00248 float getStiffeness() {return STIFFENESS;} 00249 00251 float getTimeStep() {return TIME_STEPSIZE;} 00252 00254 float getGravity() {return GRAVITY;} 00255 00257 float getCriticalDistance() {return CRITICAL_DISTANCE;} 00258 00260 float getFriction() {return FRICITION;} 00261 00263 float getBumpiness() {return BUMPINESS;} 00264 00266 void setIntegrationMethod(bool isEuler); 00267 00270 Mass* getMass(int massNumber); 00271 00276 void makeSpring(Mass *_mass1, Mass *_mass2, ngl::TransformStack *_transform); 00277 00279 void update(); 00280 00282 void draw(); 00283 00286 void addForce(const ngl::Vector direction); 00287 00288 //---------------------------------------------------------------------------------------------------------------------- 00290 //---------------------------------------------------------------------------------------------------------------------- 00291 std::vector <Mass*> masses; // all masses that are part of this cloth 00292 00293 //---------------------------------------------------------------------------------------------------------------------- 00295 //---------------------------------------------------------------------------------------------------------------------- 00296 std::vector <Face> faces; // all faces that are part of this cloth 00297 00298 int m_activeConstraintNumber; 00299 00300 private: 00302 float DAMPING; 00303 00304 00306 float springDAMPING; 00307 00309 float TIME_STEPSIZE; 00310 00312 float STIFFENESS; 00313 00314 //---------------------------------------------------------------------------------------------------------------------- 00316 //---------------------------------------------------------------------------------------------------------------------- 00317 float clothSize; 00318 //---------------------------------------------------------------------------------------------------------------------- 00320 //---------------------------------------------------------------------------------------------------------------------- 00321 bool restShapeCalculated; 00322 00323 //---------------------------------------------------------------------------------------------------------------------- 00325 //---------------------------------------------------------------------------------------------------------------------- 00326 int massesNum; // number of masses 00327 00328 00329 00330 //---------------------------------------------------------------------------------------------------------------------- 00332 //---------------------------------------------------------------------------------------------------------------------- 00333 std::vector <Spring*> springs; 00334 00336 float GRAVITY; 00337 00339 float CRITICAL_DISTANCE; 00341 float FRICITION; 00343 float BUMPINESS; 00344 00345 00346 protected: 00347 //---------------------------------------------------------------------------------------------------------------------- 00349 //---------------------------------------------------------------------------------------------------------------------- 00350 ngl::TransformStack *m_transform; 00351 00352 }; 00353 00354 #endif // CLOTH_H