cloth2

view src/cloth.h @ 1:dc15b741486c

exploding cloth
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 11 Jan 2016 20:24:13 +0200
parents ef0c22554406
children
line source
1 #ifndef CLOTH_H_
2 #define CLOTH_H_
4 #include <vector>
5 #include <gmath/gmath.h>
6 #include "object.h"
8 using namespace gph;
10 struct ClothMass {
11 Vector3 pos, vel;
12 bool fixed;
13 };
15 class Cloth {
16 private:
17 float mass, elast; // global mass attributes
18 float spring_k; // spring constant for all springs
19 float damping;
20 Vector3 grav, forces;
22 std::vector<ClothMass> masses;
23 std::vector<std::vector<float> > conn; // spring lengths, <0 means not connected
25 std::vector<Object*> colliders;
27 bool find_collision(const Ray &ray, HitPoint *hit) const;
29 public:
30 Cloth();
32 void create_rect(int x, int y, float width, float height);
34 void set_mass(float m);
35 void set_elasticity(float e);
36 void set_spring_constant(float k);
37 void set_damping(float d);
38 void set_gravity(const Vector3 &g);
39 void set_force(const Vector3 &f);
41 void transform(const Matrix4x4 &xform);
43 void add_collider(Object *o);
45 void step(float dt);
47 void draw() const;
48 };
50 #endif // CLOTH_H_