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 #include "extrusion.h"
20 #define NULL ((void *) 0x0)
23 /* Some <math.h> files do not define M_PI... */
25 #define M_PI 3.14159265358979323846
28 /* =========================================================== */
31 #define CONTOUR(x,y) { \
32 double ax, ay, alen; \
33 contour[i][0] = SCALE * (x); \
34 contour[i][1] = SCALE * (y); \
36 ax = contour[i][0] - contour[i-1][0]; \
37 ay = contour[i][1] - contour[i-1][1]; \
38 alen = 1.0 / sqrt (ax*ax + ay*ay); \
39 ax *= alen; ay *= alen; \
40 norms [i-1][0] = ay; \
41 norms [i-1][1] = -ax; \
48 static double contour [NUM_PTS][2];
49 static double norms [NUM_PTS][2];
51 static void init_contour (void)
55 /* outline of extrusion */
81 CONTOUR (1.0, 1.0); /* repeat so that last normal is computed */
84 /* =========================================================== */
87 static double path[PSIZE][3];
88 static double twist[PSIZE];
89 static double taper[PSIZE];
91 static void init_taper (void) {
101 for (j=0; j<40; j++) {
109 taper[j] = 0.1 * sqrt (9.51*9.51 - z*z);
115 taper[39] = taper[38];
119 /* =========================================================== */
121 /* controls shape of object */
125 void InitStuff_taper (void)
129 /* configure the pipeline */
131 style |= TUBE_CONTOUR_CLOSED;
132 style |= TUBE_NORM_FACET;
133 style |= TUBE_JN_ANGLE;
134 gleSetJoinStyle (style);
140 /* =========================================================== */
142 static void gleTaper (int ncp,
143 gleDouble contour[][2],
144 gleDouble cont_normal[][2],
147 gleDouble point_array[][3],
148 float color_array[][3],
154 double co, si, angle;
156 /* malloc the extrusion array and the twist array */
157 xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine));
159 for (j=0; j<npoints; j++) {
160 angle = (M_PI/180.0) * twist[j];
163 xforms[j][0][0] = taper[j] * co;
164 xforms[j][0][1] = - taper[j] * si;
165 xforms[j][0][2] = 0.0;
166 xforms[j][1][0] = taper[j] * si;
167 xforms[j][1][1] = taper[j] * co;
168 xforms[j][1][2] = 0.0;
171 gleSuperExtrusion (ncp, /* number of contour points */
172 contour, /* 2D contour */
173 cont_normal, /* 2D contour normals */
174 up, /* up vector for contour */
175 npoints, /* numpoints in poly-line */
176 point_array, /* polyline */
177 color_array, /* color of polyline */
183 /* =========================================================== */
185 void DrawStuff_taper (void) {
194 ponent = fabs (lastx/540.0);
195 for (j=1; j<39; j++) {
199 taper[j] = pow ((1.0 - pow (fabs(z), 1.0/ponent)), ponent);
203 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
204 glColor3f (0.5, 0.6, 0.6);
206 /* set up some matrices so that the object spins with the mouse */
208 /* glTranslatef (0.0, 0.0, -80.0); */
209 /* glRotatef (130.0, 0.0, 1.0, 0.0); */
210 /* glRotatef (65.0, 1.0, 0.0, 0.0); */
212 /* draw the brand and the handle */
213 gleTaper (20, contour, norms, NULL, 40, path, NULL, taper, twist);
218 /* ===================== END OF FILE ================== */