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 */
21 /* Some <math.h> files do not define M_PI... */
23 #define M_PI 3.14159265358979323846
33 /* =========================================================== */
35 #define NUM_TOID1_PTS 5
36 double toid1_points[NUM_TOID1_PTS][3];
37 float toid1_colors [NUM_TOID1_PTS][3];
38 double toid1_twists [NUM_TOID1_PTS];
43 toid1_points[i][0] = TSCALE * (x); \
44 toid1_points[i][1] = TSCALE * (y); \
45 toid1_points[i][2] = TSCALE * (0.0); \
49 #define TCOLS(r,g,b) { \
50 toid1_colors[i][0] = (r); \
51 toid1_colors[i][1] = (g); \
52 toid1_colors[i][2] = (b); \
57 toid1_twists[i] = 0.0; \
61 void init_toid1_line (void)
73 TCOLS (0.8, 0.8, 0.5);
74 TCOLS (0.8, 0.4, 0.5);
75 TCOLS (0.8, 0.8, 0.3);
76 TCOLS (0.4, 0.4, 0.5);
77 TCOLS (0.8, 0.8, 0.5);
87 /* =========================================================== */
90 #define TWIST(x,y) { \
91 double ax, ay, alen; \
92 twistation[i][0] = SCALE * (x); \
93 twistation[i][1] = SCALE * (y); \
95 ax = twistation[i][0] - twistation[i-1][0]; \
96 ay = twistation[i][1] - twistation[i-1][1]; \
97 alen = 1.0 / sqrt (ax*ax + ay*ay); \
98 ax *= alen; ay *= alen; \
99 twist_normal [i-1][0] = - ay; \
100 twist_normal [i-1][1] = ax; \
105 #define NUM_TWIS_PTS (20)
107 double twistation [NUM_TWIS_PTS][2];
108 double twist_normal [NUM_TWIS_PTS][2];
110 void init_tripples (void)
116 /* outline of extrusion */
118 /* first, draw a semi-curcular "hump" */
120 angle = M_PI * ((double) i) / 10.0;
123 TWIST ((-7.0 -3.0*co), 1.8*si);
126 /* now, a zig-zag corrugation */
127 while (i< NUM_TWIS_PTS) {
128 TWIST ((-10.0 +(double) i), 0.0);
129 TWIST ((-9.5 +(double) i), 1.0);
134 /* =========================================================== */
136 #define V3F(x,y,z) { \
138 vvv[0] = x; vvv[1] = y; vvv[2] = z; v3f (vvv); \
141 #define N3F(x,y,z) { \
143 nnn[0] = x; nnn[1] = y; nnn[2] = z; n3f (nnn); \
146 /* =========================================================== */
148 void DrawStuff_twistoid (void) {
151 toid1_twists[2] = (lastx-121.0) / 8.0;
155 TPTS (1.0, lasty /400.0);
156 TPTS (1.1, 1.1 * lasty / 400.0);
158 TPTS (1.0, -(lasty-121.0) /200.0);
159 TPTS (1.1, -1.1 * (lasty-121.0) / 200.0);
164 scale (1.8, 1.8, 1.8);
167 RGBcolor (178, 178, 204);
168 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
169 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
171 twist_extrusion (NUM_TWIS_PTS, twistation, twist_normal,
172 NULL, NUM_TOID1_PTS, toid1_points, toid1_colors, toid1_twists);
177 glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
179 /* set up some matrices so that the object spins with the mouse */
181 glTranslatef (0.0, 0.0, -80.0);
182 glRotatef(rot_x, 1, 0, 0);
183 glRotatef(rot_y, 0, 1, 0);
184 glRotatef(rot_z, 0, 0, 1);
185 /* glRotated (43.0, 1.0, 0.0, 0.0); */
186 /* glRotated (43.0, 0.0, 1.0, 0.0); */
187 glScaled (1.8, 1.8, 1.8);
188 gleTwistExtrusion (NUM_TWIS_PTS, twistation, twist_normal,
189 NULL, NUM_TOID1_PTS, toid1_points, NULL, toid1_twists);
195 /* =========================================================== */
197 void InitStuff_twistoid (void)
205 js = getjoinstyle ();
206 js &= ~TUBE_CONTOUR_CLOSED;
211 js = gleGetJoinStyle ();
212 js &= ~TUBE_CONTOUR_CLOSED;
213 gleSetJoinStyle (js);
218 /* ------------------ end of file -------------------- */