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 /* required include files */
22 /*#include <GL/glut.h>*/
29 /* Some <math.h> files do not define M_PI... */
31 #define M_PI 3.14159265358979323846
34 /* controls shape of object */
39 /* =========================================================== */
41 #define NUM_TOID1_PTS 5
42 static double toid1_points[NUM_TOID1_PTS][3];
43 static float toid1_colors [NUM_TOID1_PTS][3];
44 static double toid1_twists [NUM_TOID1_PTS];
49 toid1_points[i][0] = TSCALE * (x); \
50 toid1_points[i][1] = TSCALE * (y); \
51 toid1_points[i][2] = TSCALE * (0.0); \
55 #define TCOLS(r,g,b) { \
56 toid1_colors[i][0] = (r); \
57 toid1_colors[i][1] = (g); \
58 toid1_colors[i][2] = (b); \
63 toid1_twists[i] = 0.0; \
67 static void init_toid1_line (void)
79 TCOLS (0.8, 0.8, 0.5);
80 TCOLS (0.8, 0.4, 0.5);
81 TCOLS (0.8, 0.8, 0.3);
82 TCOLS (0.4, 0.4, 0.5);
83 TCOLS (0.8, 0.8, 0.5);
93 /* =========================================================== */
96 #define TWIST(x,y) { \
97 double ax, ay, alen; \
98 twistation[i][0] = SCALE * (x); \
99 twistation[i][1] = SCALE * (y); \
101 ax = twistation[i][0] - twistation[i-1][0]; \
102 ay = twistation[i][1] - twistation[i-1][1]; \
103 alen = 1.0 / sqrt (ax*ax + ay*ay); \
104 ax *= alen; ay *= alen; \
105 twist_normal [i-1][0] = - ay; \
106 twist_normal [i-1][1] = ax; \
111 #define NUM_TWIS_PTS (20)
113 static double twistation [NUM_TWIS_PTS][2];
114 static double twist_normal [NUM_TWIS_PTS][2];
116 static void init_tripples (void)
122 /* outline of extrusion */
124 /* first, draw a semi-curcular "hump" */
126 angle = M_PI * ((double) i) / 10.0;
129 TWIST ((-7.0 -3.0*co), 1.8*si);
132 /* now, a zig-zag corrugation */
133 while (i< NUM_TWIS_PTS) {
134 TWIST ((-10.0 +(double) i), 0.0);
135 TWIST ((-9.5 +(double) i), 1.0);
140 /* =========================================================== */
142 #define V3F(x,y,z) { \
144 vvv[0] = x; vvv[1] = y; vvv[2] = z; v3f (vvv); \
147 #define N3F(x,y,z) { \
149 nnn[0] = x; nnn[1] = y; nnn[2] = z; n3f (nnn); \
152 /* =========================================================== */
154 void DrawStuff_twistoid (void) {
157 toid1_twists[2] = (lastx-121.0) / 8.0;
161 TPTS (1.0, lasty /400.0);
162 TPTS (1.1, 1.1 * lasty / 400.0);
164 TPTS (1.0, -(lasty-121.0) /200.0);
165 TPTS (1.1, -1.1 * (lasty-121.0) / 200.0);
170 scale (1.8, 1.8, 1.8);
173 RGBcolor (178, 178, 204);
174 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
175 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
177 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
178 NULL, NUM_TOID1_PTS, toid1_points, toid1_colors, toid1_twists);
183 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
185 glFrontFace(GL_CW); /* jwz */
187 /* set up some matrices so that the object spins with the mouse */
189 /* glTranslatef (0.0, 0.0, -80.0); */
190 /* glRotated (43.0, 1.0, 0.0, 0.0); */
191 /* glRotated (43.0, 0.0, 1.0, 0.0); */
192 glScaled (1.8, 1.8, 1.8);
193 gleTwistExtrusion (NUM_TWIS_PTS, twistation, twist_normal,
194 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
200 /* =========================================================== */
202 void InitStuff_twistoid (void)
210 js = getjoinstyle ();
211 js &= ~TUBE_CONTOUR_CLOSED;
216 js = gleGetJoinStyle ();
217 js &= ~TUBE_CONTOUR_CLOSED;
218 gleSetJoinStyle (js);
223 /* ------------------ end of file -------------------- */