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 /*#include <GL/glut.h>*/
30 #define NULL ((void *) 0x0)
33 /* Some <math.h> files do not define M_PI... */
35 #define M_PI 3.14159265358979323846
38 /* =========================================================== */
41 #define CONTOUR(x,y) { \
42 double ax, ay, alen; \
43 contour[i][0] = SCALE * (x); \
44 contour[i][1] = SCALE * (y); \
46 ax = contour[i][0] - contour[i-1][0]; \
47 ay = contour[i][1] - contour[i-1][1]; \
48 alen = 1.0 / sqrt (ax*ax + ay*ay); \
49 ax *= alen; ay *= alen; \
50 norms [i-1][0] = ay; \
51 norms [i-1][1] = -ax; \
58 static double contour [NUM_PTS][2];
59 static double norms [NUM_PTS][2];
61 static void init_contour (void)
65 /* outline of extrusion */
91 CONTOUR (1.0, 1.0); /* repeat so that last normal is computed */
94 /* =========================================================== */
97 static double path[PSIZE][3];
98 static double twist[PSIZE];
99 static double taper[PSIZE];
101 static void init_taper (void) {
111 for (j=0; j<40; j++) {
119 taper[j] = 0.1 * sqrt (9.51*9.51 - z*z);
125 taper[39] = taper[38];
129 /* =========================================================== */
137 void InitStuff_taper (void)
141 /* configure the pipeline */
143 style |= TUBE_CONTOUR_CLOSED;
144 style |= TUBE_NORM_FACET;
145 style |= TUBE_JN_ANGLE;
146 gleSetJoinStyle (style);
152 /* =========================================================== */
154 static void gleTaper (int ncp,
155 gleDouble contour[][2],
156 gleDouble cont_normal[][2],
159 gleDouble point_array[][3],
160 float color_array[][3],
166 double co, si, angle;
168 /* malloc the extrusion array and the twist array */
169 xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine));
171 for (j=0; j<npoints; j++) {
172 angle = (M_PI/180.0) * twist[j];
175 xforms[j][0][0] = taper[j] * co;
176 xforms[j][0][1] = - taper[j] * si;
177 xforms[j][0][2] = 0.0;
178 xforms[j][1][0] = taper[j] * si;
179 xforms[j][1][1] = taper[j] * co;
180 xforms[j][1][2] = 0.0;
183 gleSuperExtrusion (ncp, /* number of contour points */
184 contour, /* 2D contour */
185 cont_normal, /* 2D contour normals */
186 up, /* up vector for contour */
187 npoints, /* numpoints in poly-line */
188 point_array, /* polyline */
189 color_array, /* color of polyline */
195 /* =========================================================== */
197 void DrawStuff_taper (void) {
206 ponent = fabs (lastx/540.0);
207 for (j=1; j<39; j++) {
211 taper[j] = pow ((1.0 - pow (fabs(z), 1.0/ponent)), ponent);
215 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
216 glColor3f (0.5, 0.6, 0.6);
218 /* set up some matrices so that the object spins with the mouse */
220 glTranslatef (0.0, 0.0, -80.0);
221 glRotatef(rot_x, 1, 0, 0);
222 glRotatef(rot_y, 0, 1, 0);
223 glRotatef(rot_z, 0, 0, 1);
225 /* glRotatef (130.0, 0.0, 1.0, 0.0); */
226 /* glRotatef (65.0, 1.0, 0.0, 0.0); */
228 /* draw the brand and the handle */
229 gleTaper (20, contour, norms, NULL, 40, path, NULL, taper, twist);
234 /* ===================== END OF FILE ================== */