]> git.cworth.org Git - akamaru/blob - akamaru.h
Add new Spacer constraint and a 'dock' model.
[akamaru] / akamaru.h
1 #ifndef __AKAMARU_H__
2 #define __AKAMARU_H__
3
4 typedef struct _xy_pair Point;
5 typedef struct _xy_pair Vector;
6 struct _xy_pair {
7   double x, y;
8 };
9
10 typedef struct _Object Object;
11 typedef struct _Stick Stick;
12 typedef struct _String String;
13 typedef struct _Spring Spring;
14 typedef struct _OffsetSpring OffsetSpring;
15 typedef struct _Spacer Spacer;
16 typedef struct _Polygon Polygon;
17 typedef struct _Offset Offset;
18 typedef struct _Model Model;
19
20 struct _Object {
21   Vector force;
22
23   Point position;
24   Point previous_position;
25   Vector velocity;
26
27   double mass;
28   double theta;
29 };
30
31 struct _Stick {
32   Object *a, *b;
33   int length;
34 };
35
36 struct _String {
37   Object *a, *b;
38   int length;
39 };
40
41 struct _Offset {
42   int num_objects;
43   Object **objects;
44   int dx, dy;
45 };
46
47 struct _Spring {
48   Object *a, *b;
49   int length;
50 };
51
52 struct _OffsetSpring {
53   Object *a, *b;
54   int dx, dy;
55 };
56
57 struct _Spacer {
58   Object *a, *b;
59   int length;
60 };
61
62 struct _Polygon {
63   int num_points;
64   Point *points;
65   Vector *normals;
66   int edge;
67 };
68
69 struct _Model {
70   int num_objects;
71   Object *objects;
72   int num_sticks;
73   Stick *sticks;
74   int num_strings;
75   String *strings;
76   int num_offsets;
77   Offset *offsets;
78   int num_springs;
79   Spring *springs;
80   int num_offset_springs;
81   OffsetSpring *offset_springs;
82   int num_spacers;
83   Spacer *spacers;
84   int num_polygons;
85   Polygon *polygons;
86   double k;
87   double friction;
88
89   Object *anchor_object;
90   Vector anchor_position;
91
92   double theta;
93 };
94
95 void object_init (Object *object, double x, double y, double mass);
96 void offset_spring_init (OffsetSpring *spring,
97                          Object *a, Object *b, double dx, double dy);
98 void spring_init (Spring *spring, Object *a, Object *b, double length);
99 void stick_init (Stick *stick, Object *a, Object *b, double length);
100 void string_init (String *string, Object *a, Object *b, double length);
101 void spacer_init (Spacer *spacer, Object *a, Object *b, double length);
102
103 void polygon_init (Polygon *p, int num_points, ...);
104 void polygon_init_diamond (Polygon *polygon, double x, double y);
105 void polygon_init_rectangle (Polygon *polygon, double x0, double y0,
106                              double x1, double y1);
107
108 void model_fini (Model *model);
109
110 void model_step (Model *model, double delta_t);
111
112 Object *model_find_nearest (Model *model, double x, double y);
113
114 #endif