summaryrefslogtreecommitdiff
path: root/akamaru.h
blob: 1646a342e6bcb2e69d2b206663249200ce6d2f47 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef __AKAMARU_H__
#define __AKAMARU_H__

typedef struct _xy_pair Point;
typedef struct _xy_pair Vector;
struct _xy_pair {
  double x, y;
};

typedef struct _Object Object;
typedef struct _Stick Stick;
typedef struct _String String;
typedef struct _Spring Spring;
typedef struct _OffsetSpring OffsetSpring;
typedef struct _Spacer Spacer;
typedef struct _Polygon Polygon;
typedef struct _Offset Offset;
typedef struct _Model Model;

struct _Object {
  Vector force;

  Point position;
  Point previous_position;
  Vector velocity;

  double mass;
  double theta;
};

struct _Stick {
  Object *a, *b;
  int length;
};

struct _String {
  Object *a, *b;
  int length;
};

struct _Offset {
  int num_objects;
  Object **objects;
  int dx, dy;
};

struct _Spring {
  Object *a, *b;
  int length;
};

struct _OffsetSpring {
  Object *a, *b;
  int dx, dy;
};

struct _Spacer {
  Object *a, *b;
  int length;
};

struct _Polygon {
  int num_points;
  Point *points;
  Vector *normals;
  int edge;
};

struct _Model {
  int num_objects;
  Object *objects;
  int num_sticks;
  Stick *sticks;
  int num_strings;
  String *strings;
  int num_offsets;
  Offset *offsets;
  int num_springs;
  Spring *springs;
  int num_offset_springs;
  OffsetSpring *offset_springs;
  int num_spacers;
  Spacer *spacers;
  int num_polygons;
  Polygon *polygons;
  double k;
  double friction;

  Object *anchor_object;
  Vector anchor_position;

  double theta;
};

void object_init (Object *object, double x, double y, double mass);
void offset_spring_init (OffsetSpring *spring,
			 Object *a, Object *b, double dx, double dy);
void spring_init (Spring *spring, Object *a, Object *b, double length);
void stick_init (Stick *stick, Object *a, Object *b, double length);
void string_init (String *string, Object *a, Object *b, double length);
void spacer_init (Spacer *spacer, Object *a, Object *b, double length);

void polygon_init (Polygon *p, int num_points, ...);
void polygon_init_diamond (Polygon *polygon, double x, double y);
void polygon_init_rectangle (Polygon *polygon, double x0, double y0,
			     double x1, double y1);

void model_fini (Model *model);

void model_step (Model *model, double delta_t);

Object *model_find_nearest (Model *model, double x, double y);

#endif