5 * Draws a tapered screw shape.
8 * -- created by Linas Vepstas October 1991
9 * -- heavily modified to draw more texas shapes, Feb 1993, Linas
10 * -- converted to use GLUT -- December 1995, Linas
14 /* required include files */
22 #define NULL ((void *) 0x0)
25 /* Some <math.h> files do not define M_PI... */
27 #define M_PI 3.14159265358979323846
30 /* =========================================================== */
33 #define CONTOUR(x,y) { \
34 double ax, ay, alen; \
35 contour[i][0] = SCALE * (x); \
36 contour[i][1] = SCALE * (y); \
38 ax = contour[i][0] - contour[i-1][0]; \
39 ay = contour[i][1] - contour[i-1][1]; \
40 alen = 1.0 / sqrt (ax*ax + ay*ay); \
41 ax *= alen; ay *= alen; \
42 norms [i-1][0] = ay; \
43 norms [i-1][1] = -ax; \
50 double contour [NUM_PTS][2];
51 double norms [NUM_PTS][2];
53 static void init_contour (void)
57 /* outline of extrusion */
83 CONTOUR (1.0, 1.0); /* repeat so that last normal is computed */
86 /* =========================================================== */
89 double path[PSIZE][3];
93 void init_taper (void) {
103 for (j=0; j<40; j++) {
111 taper[j] = 0.1 * sqrt (9.51*9.51 - z*z);
117 taper[39] = taper[38];
121 /* =========================================================== */
129 void InitStuff_taper (void)
133 /* configure the pipeline */
135 style |= TUBE_CONTOUR_CLOSED;
136 style |= TUBE_NORM_FACET;
137 style |= TUBE_JN_ANGLE;
138 gleSetJoinStyle (style);
144 /* =========================================================== */
146 void gleTaper (int ncp,
147 gleDouble contour[][2],
148 gleDouble cont_normal[][2],
151 gleDouble point_array[][3],
152 float color_array[][3],
158 double co, si, angle;
160 /* malloc the extrusion array and the twist array */
161 xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine));
163 for (j=0; j<npoints; j++) {
164 angle = (M_PI/180.0) * twist[j];
167 xforms[j][0][0] = taper[j] * co;
168 xforms[j][0][1] = - taper[j] * si;
169 xforms[j][0][2] = 0.0;
170 xforms[j][1][0] = taper[j] * si;
171 xforms[j][1][1] = taper[j] * co;
172 xforms[j][1][2] = 0.0;
175 gleSuperExtrusion (ncp, /* number of contour points */
176 contour, /* 2D contour */
177 cont_normal, /* 2D contour normals */
178 up, /* up vector for contour */
179 npoints, /* numpoints in poly-line */
180 point_array, /* polyline */
181 color_array, /* color of polyline */
187 /* =========================================================== */
189 void DrawStuff_taper (void) {
198 ponent = fabs (lastx/540.0);
199 for (j=1; j<39; j++) {
203 taper[j] = pow ((1.0 - pow (fabs(z), 1.0/ponent)), ponent);
207 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
208 glColor3f (0.5, 0.6, 0.6);
210 /* set up some matrices so that the object spins with the mouse */
212 glTranslatef (0.0, 0.0, -80.0);
213 glRotatef(rot_x, 1, 0, 0);
214 glRotatef(rot_y, 0, 1, 0);
215 glRotatef(rot_z, 0, 0, 1);
217 /* glRotatef (130.0, 0.0, 1.0, 0.0); */
218 /* glRotatef (65.0, 1.0, 0.0, 0.0); */
220 /* draw the brand and the handle */
221 gleTaper (20, contour, norms, NULL, 40, path, NULL, taper, twist);
226 /* ===================== END OF FILE ================== */