-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCloth.h
More file actions
44 lines (31 loc) · 1.19 KB
/
Cloth.h
File metadata and controls
44 lines (31 loc) · 1.19 KB
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
#pragma once
#include <vector>
#include "Particle.h"
#include "Constraint.h"
class Cloth {
public:
std::vector<Particle*> m_particles;
std::vector<Constraint*> m_constraints;
// Number of substeps we will use when calculating
uint32_t solver_iterations;
uint32_t sub_steps;
// Constants
sf::Vector2f gravity;
float friction_coef = 0.5f;
Cloth(int width, int height, int spacing, int start_x, int start_y);
const std::vector<Constraint*>& get_constraints() const {return m_constraints;}
const std::vector<Particle*>& get_particles() const {return m_particles;}
void update(float dt);
void apply_force_on_cloth(sf::Vector2f position, float radius, sf::Vector2f force);
void tear_cloh(sf::Vector2f position, float radius);
private:
void apply_gravity();
void apply_air_friction();
void update_positions(float dt);
void update_derivatives(float dt);
void solve_constraints();
bool is_in_radius(const Particle* p, sf::Vector2f center, float radius) {
const sf::Vector2f v = center - p->get_position();
return (v.x * v.x + v.y * v.y) < radius * radius;
}
};