24 void Gear::draw() const
27 if(!((Gear*)this)->gen_mesh()) {
34 glMultMatrixf(xform[0]);
39 glPushAttrib(GL_ENABLE_BIT);
40 glDisable(GL_LIGHTING);
49 static Vec2 rev_pos(float u, float v, void *cls)
51 Gear *gear = (Gear*)cls;
53 float y = ((v - 1.0 / 3.0) / (1.0 / 3.0) - 0.5);
54 if(y < -0.5) y = -0.5;
58 if(v < 0.001 || v > 0.999) {
62 float nt = (float)gear->nteeth * 4.0;
64 int part = (int)(u * nt) % 4; /* 4 parts to a tooth /#\_ */
65 float t = fmod(u * nt * 4.0, 1.0);
82 float inner_rad = gear->radius - gear->teeth_length;
83 return Vec2(inner_rad + offs * gear->teeth_length, -y);
89 gen_revol(mesh, nteeth * 4, 3, rev_pos, 0, this);
91 mesh->calc_face_normals();
94 rot.rotation_x(M_PI / 2.0);
95 mesh->apply_xform(rot, rot);
97 mesh->set_vis_vecsize(6.0);
101 void Gear::calc_matrix() const
103 Vec3 up = Vec3(0, 1, 0);
104 if(1.0 - fabs(dot(up, axis)) < 1e-4) {
107 Vec3 right = normalize(cross(up, axis));
108 up = cross(axis, right);
110 xform = Mat4(right, up, axis);
111 xform.translate(pos);