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