SimpleNGL 1.0
include/Cloth.h
Go to the documentation of this file.
00001 #ifndef CLOTH_H
00002 #define CLOTH_H
00003 
00004 #include "vector"
00005 #include "ngl/Vector.h"
00006 
00009 
00011 enum INTEGRATION{EULER=0, VERLET};
00012 
00014 struct Particle
00015 {
00016     ngl::Vector pos, velocity, acceleration, lastPos;
00017     float mass;
00018     bool isConstrained;
00019     int id;
00020 };
00021 
00023 struct Spring
00024 {
00025     float restLength;
00026     Particle *p1,*p2;
00027 };
00028 
00032 class Cloth
00033 {
00034 public:
00035 
00040     Cloth(int _width, int _height, const float &_spacing);
00042     ~Cloth();
00043 
00045     bool init();
00047     void draw();
00050     void update(const float &_time);
00053     void changeGravity(const float &_value);
00058     void changeWind(const float &_x,const float &_y,const float &_z);
00061     inline void setIntegration(INTEGRATION _v){m_integration = _v;}
00062 
00064     float m_shearStiffness;
00066     float m_shearDamping;
00068     float m_structStiffness;
00070     float m_structDamping;
00072     float m_bendStiffness;
00074     float m_bendDamping;
00075 
00077     ngl::Vector m_gravity;
00079     ngl::Vector m_wind;
00081     ngl::Vector m_squall;
00082 
00084     void setupParticles();
00085 
00086 private:
00088     std::vector<Particle> m_particles;
00090     std::vector<Spring> m_shearSprings;
00092     std::vector<Spring> m_bendSprings;
00094     std::vector<Spring> m_structSprings;
00095 
00097     GLuint m_indices;
00098 
00100     INTEGRATION m_integration;
00101 
00103     int m_width;
00105     int m_height;
00106 
00108     float m_spacing;
00109 
00111     unsigned int m_VAO;
00112 
00114     GLuint m_PosVBO;
00116     GLuint m_NormalVBO;
00117 
00119     void setupBuffers();
00121     void setupSprings();
00122 
00124     void setupStructuredStrings();
00126     void setupShearSprings();
00128     void setupBendSprings();
00129 
00134     void calculateSpringForce(Spring &_spring, const float &_damping, const float &_stiffness);
00135 
00137     void accumulateForces();
00138 
00141     void euler(const float &_time);
00144     void verlet(const float &_time);
00145 };
00146 
00147 #endif // CLOTH_H
 All Classes Namespaces Files Functions Variables Enumerations Enumerator