f75e71b7cf98a8e24519b9b49cf40d00e67f2155
[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         float m;
10         int fixed;
11
12         /* used for stringing fixed masses together */
13         struct rsim_mass *next;
14 };
15
16 struct rsim_spring {
17         float rest_len, k;
18         struct rsim_mass *mass[2];
19 };
20
21 struct rsim_rope {
22         struct rsim_mass *masses;
23         int num_masses;
24         struct rsim_spring *springs;
25         int num_springs;
26
27         /* elements of the masses array which are fixed */
28         struct rsim_mass *fixedlist;
29
30         struct rsim_rope *next;
31 };
32
33 struct rsim_world {
34         struct rsim_rope *ropes;        /* list of ropes to simulate */
35
36         cgm_vec3 grav, extforce;
37         float damping;
38
39         float udt;      /* microstepping delta (valid if > 0) */
40         float udelta_acc;       /* dt leftover accumulator for microstepping */
41 };
42
43 int rsim_init(struct rsim_world *rsim);
44 void rsim_destroy(struct rsim_world *rsim);
45
46 int rsim_add_rope(struct rsim_world *rsim, struct rsim_rope *rope);
47
48 void rsim_step(struct rsim_world *rsim, float dt);
49
50 struct rsim_rope *rsim_alloc_rope(int nmasses, int nsprings);
51 void rsim_free_rope(struct rsim_rope *rope);
52 int rsim_init_rope(struct rsim_rope *rope, int nmasses, int nsprings);
53 void rsim_destroy_rope(struct rsim_rope *rope);
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_ */