X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=antikythera;a=blobdiff_plain;f=src%2Fgear.cc;h=865679c155c0aab3d9234ec1f0ebe168f64cc5fd;hp=6450c65d09238abdb148466d10e7c8ad45cb753e;hb=a88a9ac53952e1bb3768b147a043c19392e3d5d1;hpb=ae60a8cb1a30e204e7f60969fe6245e510cca0ff diff --git a/src/gear.cc b/src/gear.cc index 6450c65..865679c 100644 --- a/src/gear.cc +++ b/src/gear.cc @@ -12,6 +12,7 @@ Gear::Gear() teeth_length = 5; thickness = 5; bevel = 1.5; + init_angle = 0; mesh = 0; } @@ -21,6 +22,24 @@ Gear::~Gear() delete mesh; } +void Gear::set_teeth(int nt, float tooth_pitch) +{ + float circ = tooth_pitch * nt; + radius = circ / (2.0 * M_PI); + nteeth = nt; + init_angle = get_angular_pitch() * 3.0 / 8.0; +} + +float Gear::get_rotation() const +{ + return fmod(init_angle + angle, M_PI * 2.0); +} + +float Gear::get_angular_pitch() const +{ + return 2.0 * M_PI / (float)nteeth; +} + void Gear::draw() const { if(!mesh) { @@ -35,13 +54,16 @@ void Gear::draw() const mesh->draw(); - /* glPushAttrib(GL_ENABLE_BIT); glDisable(GL_LIGHTING); - glColor3f(0, 1, 0); - mesh->draw_normals(); + + glLineWidth(2.0); + glBegin(GL_LINES); + glColor3f(0, 0, 1); + glVertex3f(0, 0, -10); + glVertex3f(0, 0, 10); + glEnd(); glPopAttrib(); - */ glPopMatrix(); } @@ -108,5 +130,6 @@ void Gear::calc_matrix() const up = cross(axis, right); xform = Mat4(right, up, axis); + xform.rotate_z(get_rotation()); xform.translate(pos); }