initial commit, first gear
[antikythera] / src / gear.h
1 #ifndef GEAR_H_
2 #define GEAR_H_
3
4 #include <vector>
5 #include <gmath/gmath.h>
6 #include "mesh.h"
7
8 /* distance unit: millimeters
9  * angle unit: radians
10  */
11
12 class Gear;
13 struct GearPin;
14 struct GearSlot;
15
16 struct GearPin {
17         float radius;
18         float height;
19
20         Gear *parent;
21         /* position in polar coordinates on the parent gear */
22         float pos_dist, pos_angle;
23
24         GearSlot *conn_slot;    /* slot connection */
25 };
26
27 struct GearSlot {
28         float radius, length;
29
30         Gear *parent;
31         /* position in polar coordinates on the parent gear */
32         float pos_dist_min, pos_dist_max, pos_angle;
33
34         GearPin *conn_pin;              /* pin connection */
35 };
36
37 class Gear {
38 private:
39         Mesh *mesh;
40
41         mutable Mat4 xform;
42         void calc_matrix() const;
43
44         float contour(float u);
45
46 public:
47         Vec3 pos, axis; /* implicitly defines a plane eqn. */
48         float pdist;    /* derived: distance of plane from origin */
49
50         float angle;    /* current angle of the gear */
51
52         int nteeth;             /* number of teeth */
53
54         float radius;   /* total radius of the gear, including teeth */
55         float teeth_length;     /* how far teeth extend past the radius */
56         float thickness;        /* thickness of the gear along the Z axis */
57
58         float bevel;    /* bevel size */
59
60         std::vector<GearPin> pins;
61         std::vector<GearSlot> slots;
62
63         Gear();
64         ~Gear();
65
66         void draw() const;
67
68         bool gen_mesh();
69 };
70
71 #endif  // GEAR_H_