-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloth.h
59 lines (52 loc) · 1.41 KB
/
cloth.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#include <vector>
#include <glm/glm.hpp>
#include <GL/glew.h>
#include <GLFW/glfw3.h>
using namespace glm;
using namespace std;
class Directions {
public:
const int WEST = 1;
const int NORTHWEST = 2;
const int NORTH = 3;
const int NORTHEAST = 4;
const int EAST = 5;
const int SOUTHEAST = 6;
const int SOUTH = 7;
const int SOUTHWEST = 8;
};
class Cloth {
public:
Cloth();
Cloth(const int x, const int z, const int w, const int l);
~Cloth();
void draw(GLFWwindow* window);
void update(GLFWwindow* window, float delta);
vec3 gravity = vec3(0, -9.82f, 0);
private:
vector<vec3> initPositions;
vector<vec3> prevPositions;
vector<vec3> vertices;
vector<vec3> normals;
vector<vec2> uvs;
vector<vec3> forces;
vector<vec3> velocities;
vector<unsigned int> indices;
GLuint VAO, IBO, VBO, NBO, UVBO;
enum Attrib_IDs { vPosition1, vPosition2, vPosition3 };
int getVertex(int direction, int vertex);
vec3 getSpringForce(int direction, int vertex);
void springs(int v, vec3& spring, vector<vec3>& springDirections);
int width, height;
const int xParticles, zParticles;
bool playSimulation = false;
float restLengthX, restLengthZ, restLengthXZ = 0;
float springFactor = 1500.f;
float dampingFactor = 0.996f;
float airResistance = .05f;
Directions directions;
void Forces(GLFWwindow* window);
void verletIntegration(float delta, int n_iterations);
void eulerIntegration(float delta);
};