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)
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;
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
calc_matrix();
xform_valid = true;
}
- return xform;
+ return dir_xform;
}
float Gear::get_angular_pitch() const
abort();
}
}
- calc_matrix();
+ if(!xform_valid) {
+ calc_matrix();
+ }
glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT);
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;