cloth2
diff src/cloth.h @ 0:ef0c22554406
cloth sim test, initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 11 Jan 2016 16:51:16 +0200 |
parents | |
children | dc15b741486c |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cloth.h Mon Jan 11 16:51:16 2016 +0200 1.3 @@ -0,0 +1,42 @@ 1.4 +#ifndef CLOTH_H_ 1.5 +#define CLOTH_H_ 1.6 + 1.7 +#include <vector> 1.8 +#include <gmath/gmath.h> 1.9 +#include "object.h" 1.10 + 1.11 +using namespace gph; 1.12 + 1.13 +struct ClothMass { 1.14 + Vector3 pos, vel; 1.15 + bool fixed; 1.16 +}; 1.17 + 1.18 +class Cloth { 1.19 +private: 1.20 + float mass, elast; // global mass attributes 1.21 + float spring_k; // spring constant for all springs 1.22 + Vector3 grav, forces; 1.23 + 1.24 + std::vector<ClothMass> masses; 1.25 + std::vector<std::vector<float> > conn; // spring lengths, <0 means not connected 1.26 + 1.27 + std::vector<Object*> colliders; 1.28 + 1.29 + bool find_collision(const Ray &ray, HitPoint *hit) const; 1.30 + 1.31 +public: 1.32 + Cloth(); 1.33 + 1.34 + void create_rect(int x, int y, float width, float height); 1.35 + 1.36 + void transform(const Matrix4x4 &xform); 1.37 + 1.38 + void add_collider(Object *o); 1.39 + 1.40 + void step(float dt); 1.41 + 1.42 + void draw() const; 1.43 +}; 1.44 + 1.45 +#endif // CLOTH_H_