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