removed clang-format and clang_complete files from the repo
[dosdemo] / tools / ropesim / src / ropesim.h
1 #ifndef ROPESIM_H_
2 #define ROPESIM_H_
3
4 #include "cgmath/cgmath.h"
5
6 struct rsim_mass {
7         cgm_vec3 p;
8         cgm_vec3 v;
9         cgm_vec3 f;
10         float m;
11         int fixed;
12
13         /* used for stringing fixed masses together */
14         struct rsim_mass *next;
15 };
16
17 struct rsim_spring {
18         float rest_len, k;
19 };
20
21 struct rsim_rope {
22         struct rsim_mass *masses;
23         int num_masses;
24         struct rsim_spring *springs;    /* adjacency matrix */
25
26         struct rsim_rope *next;
27 };
28
29 struct rsim_world {
30         struct rsim_rope *ropes;        /* list of ropes to simulate */
31
32         cgm_vec3 grav, extforce;
33         float damping;
34
35         float udt;      /* microstepping delta (valid if > 0) */
36         float udelta_acc;       /* dt leftover accumulator for microstepping */
37 };
38
39 int rsim_init(struct rsim_world *rsim);
40 void rsim_destroy(struct rsim_world *rsim);
41
42 int rsim_add_rope(struct rsim_world *rsim, struct rsim_rope *rope);
43
44 void rsim_step(struct rsim_world *rsim, float dt);
45
46 struct rsim_rope *rsim_alloc_rope(int nmasses);
47 void rsim_free_rope(struct rsim_rope *rope);
48 int rsim_init_rope(struct rsim_rope *rope, int nmasses);
49 void rsim_destroy_rope(struct rsim_rope *rope);
50
51 #define RSIM_RLEN_DEFAULT       (-1.0f)
52 int rsim_set_rope_spring(struct rsim_rope *rope, int ma, int mb, float k, float rlen);
53 int rsim_have_spring(struct rsim_rope *rope, int ma, int mb);
54
55 int rsim_freeze_rope_mass(struct rsim_rope *rope, struct rsim_mass *m);
56 int rsim_unfreeze_rope_mass(struct rsim_rope *rope, struct rsim_mass *m);
57
58 #endif  /* ROPESIM_H_ */