5 * Show extrusion of open contours. Also, show how torsion is applied.
8 * -- linas Vepstas October 1991
9 * -- heavily modified to draw corrugated surface, Feb 1993, Linas
10 * -- modified to demo twistoid March 1993
11 * -- port to glut Linas Vepstas March 1995
14 #include "extrusion.h"
19 /* Some <math.h> files do not define M_PI... */
21 #define M_PI 3.14159265358979323846
24 /* controls shape of object */
29 /* =========================================================== */
31 #define NUM_TOID1_PTS 5
32 static double toid1_points[NUM_TOID1_PTS][3];
33 static float toid1_colors [NUM_TOID1_PTS][3];
34 static double toid1_twists [NUM_TOID1_PTS];
39 toid1_points[i][0] = TSCALE * (x); \
40 toid1_points[i][1] = TSCALE * (y); \
41 toid1_points[i][2] = TSCALE * (0.0); \
45 #define TCOLS(r,g,b) { \
46 toid1_colors[i][0] = (r); \
47 toid1_colors[i][1] = (g); \
48 toid1_colors[i][2] = (b); \
53 toid1_twists[i] = 0.0; \
57 static void init_toid1_line (void)
69 TCOLS (0.8, 0.8, 0.5);
70 TCOLS (0.8, 0.4, 0.5);
71 TCOLS (0.8, 0.8, 0.3);
72 TCOLS (0.4, 0.4, 0.5);
73 TCOLS (0.8, 0.8, 0.5);
83 /* =========================================================== */
86 #define TWIST(x,y) { \
87 double ax, ay, alen; \
88 twistation[i][0] = SCALE * (x); \
89 twistation[i][1] = SCALE * (y); \
91 ax = twistation[i][0] - twistation[i-1][0]; \
92 ay = twistation[i][1] - twistation[i-1][1]; \
93 alen = 1.0 / sqrt (ax*ax + ay*ay); \
94 ax *= alen; ay *= alen; \
95 twist_normal [i-1][0] = - ay; \
96 twist_normal [i-1][1] = ax; \
101 #define NUM_TWIS_PTS (20)
103 static double twistation [NUM_TWIS_PTS][2];
104 static double twist_normal [NUM_TWIS_PTS][2];
106 static void init_tripples (void)
112 /* outline of extrusion */
114 /* first, draw a semi-curcular "hump" */
116 angle = M_PI * ((double) i) / 10.0;
119 TWIST ((-7.0 -3.0*co), 1.8*si);
122 /* now, a zig-zag corrugation */
123 while (i< NUM_TWIS_PTS) {
124 TWIST ((-10.0 +(double) i), 0.0);
125 TWIST ((-9.5 +(double) i), 1.0);
130 /* =========================================================== */
132 #define V3F(x,y,z) { \
134 vvv[0] = x; vvv[1] = y; vvv[2] = z; v3f (vvv); \
137 #define N3F(x,y,z) { \
139 nnn[0] = x; nnn[1] = y; nnn[2] = z; n3f (nnn); \
142 /* =========================================================== */
144 void DrawStuff_twistoid (void) {
147 toid1_twists[2] = (lastx-121.0) / 8.0;
151 TPTS (1.0, lasty /400.0);
152 TPTS (1.1, 1.1 * lasty / 400.0);
154 TPTS (1.0, -(lasty-121.0) /200.0);
155 TPTS (1.1, -1.1 * (lasty-121.0) / 200.0);
160 scale (1.8, 1.8, 1.8);
163 RGBcolor (178, 178, 204);
164 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
165 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
167 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
168 NULL, NUM_TOID1_PTS, toid1_points, toid1_colors, toid1_twists);
173 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
175 glFrontFace(GL_CW); /* jwz */
177 /* set up some matrices so that the object spins with the mouse */
179 /* glTranslatef (0.0, 0.0, -80.0); */
180 /* glRotated (43.0, 1.0, 0.0, 0.0); */
181 /* glRotated (43.0, 0.0, 1.0, 0.0); */
182 glScaled (1.8, 1.8, 1.8);
183 gleTwistExtrusion (NUM_TWIS_PTS, twistation, twist_normal,
184 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
190 /* =========================================================== */
192 void InitStuff_twistoid (void)
200 js = getjoinstyle ();
201 js &= ~TUBE_CONTOUR_CLOSED;
206 js = gleGetJoinStyle ();
207 js &= ~TUBE_CONTOUR_CLOSED;
208 gleSetJoinStyle (js);
213 /* ------------------ end of file -------------------- */