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 /* =========================================================== */
131 /* controls shape of object */
135 void InitStuff_taper (void)
139 /* configure the pipeline */
141 style |= TUBE_CONTOUR_CLOSED;
142 style |= TUBE_NORM_FACET;
143 style |= TUBE_JN_ANGLE;
144 gleSetJoinStyle (style);
150 /* =========================================================== */
152 static void gleTaper (int ncp,
153 gleDouble contour[][2],
154 gleDouble cont_normal[][2],
157 gleDouble point_array[][3],
158 float color_array[][3],
164 double co, si, angle;
166 /* malloc the extrusion array and the twist array */
167 xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine));
169 for (j=0; j<npoints; j++) {
170 angle = (M_PI/180.0) * twist[j];
173 xforms[j][0][0] = taper[j] * co;
174 xforms[j][0][1] = - taper[j] * si;
175 xforms[j][0][2] = 0.0;
176 xforms[j][1][0] = taper[j] * si;
177 xforms[j][1][1] = taper[j] * co;
178 xforms[j][1][2] = 0.0;
181 gleSuperExtrusion (ncp, /* number of contour points */
182 contour, /* 2D contour */
183 cont_normal, /* 2D contour normals */
184 up, /* up vector for contour */
185 npoints, /* numpoints in poly-line */
186 point_array, /* polyline */
187 color_array, /* color of polyline */
193 /* =========================================================== */
195 void DrawStuff_taper (void) {
204 ponent = fabs (lastx/540.0);
205 for (j=1; j<39; j++) {
209 taper[j] = pow ((1.0 - pow (fabs(z), 1.0/ponent)), ponent);
213 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
214 glColor3f (0.5, 0.6, 0.6);
216 /* set up some matrices so that the object spins with the mouse */
218 /* glTranslatef (0.0, 0.0, -80.0); */
219 /* glRotatef (130.0, 0.0, 1.0, 0.0); */
220 /* glRotatef (65.0, 1.0, 0.0, 0.0); */
222 /* draw the brand and the handle */
223 gleTaper (20, contour, norms, NULL, 40, path, NULL, taper, twist);
228 /* ===================== END OF FILE ================== */