/* * taper.c * * FUNCTION: * Draws a tapered screw shape. * * HISTORY: * -- created by Linas Vepstas October 1991 * -- heavily modified to draw more texas shapes, Feb 1993, Linas * -- converted to use GLUT -- December 1995, Linas * Copyright (c) 1991, 1993, 1995 Linas Vepstas * */ /* required include files */ #include #include #include #include #include #include "main.h" /* =========================================================== */ #define SCALE 3.33333 #define CONTOUR(x,y) { \ double ax, ay, alen; \ contour[i][0] = SCALE * (x); \ contour[i][1] = SCALE * (y); \ if (i!=0) { \ ax = contour[i][0] - contour[i-1][0]; \ ay = contour[i][1] - contour[i-1][1]; \ alen = 1.0 / sqrt (ax*ax + ay*ay); \ ax *= alen; ay *= alen; \ norms [i-1][0] = ay; \ norms [i-1][1] = -ax; \ } \ i++; \ } #define NUM_PTS (25) double contour [NUM_PTS][2]; double norms [NUM_PTS][2]; static void init_contour (void) { int i; /* outline of extrusion */ i=0; CONTOUR (1.0, 1.0); CONTOUR (1.0, 2.9); CONTOUR (0.9, 3.0); CONTOUR (-0.9, 3.0); CONTOUR (-1.0, 2.9); CONTOUR (-1.0, 1.0); CONTOUR (-2.9, 1.0); CONTOUR (-3.0, 0.9); CONTOUR (-3.0, -0.9); CONTOUR (-2.9, -1.0); CONTOUR (-1.0, -1.0); CONTOUR (-1.0, -2.9); CONTOUR (-0.9, -3.0); CONTOUR (0.9, -3.0); CONTOUR (1.0, -2.9); CONTOUR (1.0, -1.0); CONTOUR (2.9, -1.0); CONTOUR (3.0, -0.9); CONTOUR (3.0, 0.9); CONTOUR (2.9, 1.0); CONTOUR (1.0, 1.0); /* repeat so that last normal is computed */ } /* =========================================================== */ #define PSIZE 40 double path[PSIZE][3]; double twist[PSIZE]; double taper[PSIZE]; static void init_taper (void) { int j; double z, deltaz; double ang, dang; z = -10.0; deltaz = 0.5; ang = 0.0; dang = 20.0; for (j=0; j<40; j++) { path[j][0] = 0x0; path[j][1] = 0x0; path[j][2] = z; twist[j] = ang; ang += dang; taper[j] = 0.1 * sqrt (9.51*9.51 - z*z); z += deltaz; } taper[0] = taper[1]; taper[39] = taper[38]; } /* =========================================================== */ void InitStuff (void) { int style; /* configure the pipeline */ style = TUBE_JN_CAP; style |= TUBE_CONTOUR_CLOSED; style |= TUBE_NORM_FACET; style |= TUBE_JN_ANGLE; gleSetJoinStyle (style); lastx = 121.0; lasty = 121.0; init_contour(); init_taper(); } /* =========================================================== */ void gleTaper (int ncp, gleDouble contour[][2], gleDouble cont_normal[][2], gleDouble up[3], int npoints, gleDouble point_array[][3], float color_array[][3], gleDouble taper[], gleDouble twist[]) { int j; gleAffine *xforms; double co, si, angle; /* malloc the extrusion array and the twist array */ xforms = (gleAffine *) malloc (npoints * sizeof(gleAffine)); for (j=0; j