24# define M_PI 3.14159265
47 r1 = outer_radius - tooth_depth/2.0;
48 r2 = outer_radius + tooth_depth/2.0;
50 da = 2.0*
M_PI / teeth / 4.0;
58 for (i=0;i<=teeth;i++) {
59 angle = i * 2.0*
M_PI / teeth;
60 glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
61 glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
62 glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
63 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
69 da = 2.0*
M_PI / teeth / 4.0;
70 for (i=0;i<teeth;i++) {
71 angle = i * 2.0*
M_PI / teeth;
73 glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
74 glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
75 glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
76 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
85 for (i=0;i<=teeth;i++) {
86 angle = i * 2.0*
M_PI / teeth;
87 glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
88 glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
89 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
90 glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
96 da = 2.0*
M_PI / teeth / 4.0;
97 for (i=0;i<teeth;i++) {
98 angle = i * 2.0*
M_PI / teeth;
100 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
101 glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
102 glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
103 glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
110 for (i=0;i<teeth;i++) {
111 angle = i * 2.0*
M_PI / teeth;
113 glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 );
114 glVertex3f( r1*cos(angle), r1*sin(angle), -width*0.5 );
115 u = r2*cos(angle+da) - r1*cos(angle);
116 v = r2*sin(angle+da) - r1*sin(angle);
117 len = sqrt( u*u + v*v );
121 glVertex3f( r2*cos(angle+da), r2*sin(angle+da), width*0.5 );
122 glVertex3f( r2*cos(angle+da), r2*sin(angle+da), -width*0.5 );
124 glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5 );
125 glVertex3f( r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5 );
126 u = r1*cos(angle+3*da) - r2*cos(angle+2*da);
127 v = r1*sin(angle+3*da) - r2*sin(angle+2*da);
129 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 );
130 glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5 );
134 glVertex3f( r1*cos(0), r1*sin(0), width*0.5 );
135 glVertex3f( r1*cos(0), r1*sin(0), -width*0.5 );
144 for (i=0;i<=teeth;i++) {
145 angle = i * 2.0*
M_PI / teeth;
147 glVertex3f( r0*cos(angle), r0*sin(angle), -width*0.5 );
148 glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
155static GLfloat view_rotx=20.0, view_roty=30.0, view_rotz=0.0;
156static GLint gear1, gear2, gear3;
181 glRotatef( -2.0*angle-9.0, 0.0, 0.0, 1.0 );
187 glRotatef( -2.0*angle-25.0, 0.0, 0.0, 1.0 );
249 glFrustum( -1.0, 1.0, -h, h, 5.0, 60.0 );
259 static GLfloat pos[4] = {5.0, 5.0, 10.0, 0.0 };
260 static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
261 static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
262 static GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0 };
283 gear( 1.0, 4.0, 1.0, 20, 0.7 );
289 gear( 0.5, 2.0, 2.0, 10, 0.7 );
295 gear( 1.3, 2.0, 0.5, 10, 0.7 );
305 limit = atoi( argv[1] ) + 1;
311 return ui_loop(argc, argv,
"gears");
void glVertex3f(float x, float y, float z)
void glNormal3f(float x, float y, float z)
GLenum key(int k, GLenum mask)
int main(int argc, char **argv)
void reshape(int width, int height)
void glFrustum(double left, double right, double bottom, double top, double near, double far)
unsigned int glGenLists(int range)
void glCallList(unsigned int list)
void glClearColor(float r, float g, float b, float a)
void glShadeModel(int mode)
void glViewport(int x, int y, int width, int height)
void glNewList(unsigned int list, int mode)
void glMatrixMode(int mode)
void glLightfv(int light, int type, float *v)
void glMaterialfv(int mode, int type, float *v)
void glRotatef(float angle, float x, float y, float z)
void glTranslatef(float x, float y, float z)
void glLoadIdentity(void)
int ui_loop(int argc, char **argv, const char *name)