X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=antikythera;a=blobdiff_plain;f=src%2Fgear.cc;h=c916e765c389519e8405ce3059f220ef3ed0406e;hp=6ce9d8ac706151461e337f86d1c4fe7f1c9117a6;hb=b29d7193d03833109cfdda3ab576fe183efd8acf;hpb=84484521a697fe60f63bff077b9ba7475a45e54e diff --git a/src/gear.cc b/src/gear.cc index 6ce9d8a..c916e76 100644 --- a/src/gear.cc +++ b/src/gear.cc @@ -24,12 +24,22 @@ Gear::~Gear() delete mesh; } +void Gear::set_angular_offset(float offs) +{ + init_angle = offs; + xform_valid = false; +} + +float Gear::get_angular_offset() const +{ + return init_angle; +} + 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) @@ -38,6 +48,11 @@ void Gear::set_axis(const Vec3 &axis) xform_valid = false; } +const Vec3 &Gear::get_axis() const +{ + return axis; +} + void Gear::set_position(const Vec3 &pos) { this->pos = pos; @@ -54,6 +69,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 +88,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 +107,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 +122,9 @@ void Gear::draw() const abort(); } } - calc_matrix(); + if(!xform_valid) { + calc_matrix(); + } glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); @@ -132,6 +156,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;