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 */
29 /* Some <math.h> files do not define M_PI... */
31 #define M_PI 3.14159265358979323846
41 /* =========================================================== */
43 #define NUM_TOID1_PTS 5
44 double toid1_points[NUM_TOID1_PTS][3];
45 float toid1_colors [NUM_TOID1_PTS][3];
46 double toid1_twists [NUM_TOID1_PTS];
51 toid1_points[i][0] = TSCALE * (x); \
52 toid1_points[i][1] = TSCALE * (y); \
53 toid1_points[i][2] = TSCALE * (0.0); \
57 #define TCOLS(r,g,b) { \
58 toid1_colors[i][0] = (r); \
59 toid1_colors[i][1] = (g); \
60 toid1_colors[i][2] = (b); \
65 toid1_twists[i] = 0.0; \
69 void init_toid1_line (void)
81 TCOLS (0.8, 0.8, 0.5);
82 TCOLS (0.8, 0.4, 0.5);
83 TCOLS (0.8, 0.8, 0.3);
84 TCOLS (0.4, 0.4, 0.5);
85 TCOLS (0.8, 0.8, 0.5);
95 /* =========================================================== */
98 #define TWIST(x,y) { \
99 double ax, ay, alen; \
100 twistation[i][0] = SCALE * (x); \
101 twistation[i][1] = SCALE * (y); \
103 ax = twistation[i][0] - twistation[i-1][0]; \
104 ay = twistation[i][1] - twistation[i-1][1]; \
105 alen = 1.0 / sqrt (ax*ax + ay*ay); \
106 ax *= alen; ay *= alen; \
107 twist_normal [i-1][0] = - ay; \
108 twist_normal [i-1][1] = ax; \
113 #define NUM_TWIS_PTS (20)
115 double twistation [NUM_TWIS_PTS][2];
116 double twist_normal [NUM_TWIS_PTS][2];
118 void init_tripples (void)
124 /* outline of extrusion */
126 /* first, draw a semi-curcular "hump" */
128 angle = M_PI * ((double) i) / 10.0;
131 TWIST ((-7.0 -3.0*co), 1.8*si);
134 /* now, a zig-zag corrugation */
135 while (i< NUM_TWIS_PTS) {
136 TWIST ((-10.0 +(double) i), 0.0);
137 TWIST ((-9.5 +(double) i), 1.0);
142 /* =========================================================== */
144 #define V3F(x,y,z) { \
146 vvv[0] = x; vvv[1] = y; vvv[2] = z; v3f (vvv); \
149 #define N3F(x,y,z) { \
151 nnn[0] = x; nnn[1] = y; nnn[2] = z; n3f (nnn); \
154 /* =========================================================== */
156 void DrawStuff_twistoid (void) {
159 toid1_twists[2] = (lastx-121.0) / 8.0;
163 TPTS (1.0, lasty /400.0);
164 TPTS (1.1, 1.1 * lasty / 400.0);
166 TPTS (1.0, -(lasty-121.0) /200.0);
167 TPTS (1.1, -1.1 * (lasty-121.0) / 200.0);
172 scale (1.8, 1.8, 1.8);
175 RGBcolor (178, 178, 204);
176 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
177 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
179 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
180 NULL, NUM_TOID1_PTS, toid1_points, toid1_colors, toid1_twists);
185 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
187 /* set up some matrices so that the object spins with the mouse */
189 glTranslatef (0.0, 0.0, -80.0);
190 glRotatef(rot_x, 1, 0, 0);
191 glRotatef(rot_y, 0, 1, 0);
192 glRotatef(rot_z, 0, 0, 1);
193 /* glRotated (43.0, 1.0, 0.0, 0.0); */
194 /* glRotated (43.0, 0.0, 1.0, 0.0); */
195 glScaled (1.8, 1.8, 1.8);
196 gleTwistExtrusion (NUM_TWIS_PTS, twistation, twist_normal,
197 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
203 /* =========================================================== */
205 void InitStuff_twistoid (void)
213 js = getjoinstyle ();
214 js &= ~TUBE_CONTOUR_CLOSED;
219 js = gleGetJoinStyle ();
220 js &= ~TUBE_CONTOUR_CLOSED;
221 gleSetJoinStyle (js);
226 /* ------------------ end of file -------------------- */