X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=antikythera;a=blobdiff_plain;f=src%2Fgear.cc;h=10e8bc89b1535a9ed0fa1f695ed798a1b015b86a;hp=6ce9d8ac706151461e337f86d1c4fe7f1c9117a6;hb=014fccdee30291407985658e8cefd9be7dc9e9fa;hpb=2c8e92970f198061a0cefdb59c2d0ec8c58409c9 diff --git a/src/gear.cc b/src/gear.cc index 6ce9d8a..10e8bc8 100644 --- a/src/gear.cc +++ b/src/gear.cc @@ -29,7 +29,6 @@ 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; } void Gear::set_axis(const Vec3 &axis) @@ -54,6 +53,12 @@ Vec3 Gear::get_global_position() const return pos; // TODO } +Vec3 Gear::get_planar_position() const +{ + Mat4 inv_xform = transpose(get_dir_matrix()); + return inv_xform * pos; +} + void Gear::set_angle(float angle) { this->angle = angle; @@ -67,7 +72,8 @@ float Gear::get_angle() const float Gear::get_vis_rotation() const { - return fmod(init_angle + angle, M_PI * 2.0); + float fix_crooked_teeth = get_angular_pitch() * 3.0 / 8.0; + return fmod(init_angle + fix_crooked_teeth + angle, M_PI * 2.0); } const Mat4 &Gear::get_matrix() const @@ -85,7 +91,7 @@ const Mat4 &Gear::get_dir_matrix() const calc_matrix(); xform_valid = true; } - return xform; + return dir_xform; } float Gear::get_angular_pitch() const @@ -100,7 +106,9 @@ void Gear::draw() const abort(); } } - calc_matrix(); + if(!xform_valid) { + calc_matrix(); + } glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); @@ -132,6 +140,30 @@ void Gear::draw() const glPopAttrib(); } +void Gear::draw_wire(float wire_width) const +{ + if(!mesh) { + if(!((Gear*)this)->gen_mesh()) { + abort(); + } + } + if(!xform_valid) { + calc_matrix(); + } + + glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); + glLineWidth(wire_width); + glDisable(GL_LIGHTING); + + glPushMatrix(); + glMultMatrixf(xform[0]); + + mesh->draw_wire(); + + glPopMatrix(); + glPopAttrib(); +} + static Vec2 rev_pos(float u, float v, void *cls) { Gear *gear = (Gear*)cls;