meshing recaclulation on the fly, picking, whatever
[antikythera] / src / gear.cc
index 6ce9d8a..10e8bc8 100644 (file)
@@ -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;