1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
|
/*
* texas.c
*
* FUNCTION:
* Draws a brand in the shape of Texas. Both the handle, and the
* cross-section of the brand are in the shape of Texas.
*
* Note that the contours are specified in clockwise order.
* Thus, enabling backfacing polygon removal will cause the front
* polygons to disappear.
*
* 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 <linas@linas.org>
*
*/
/* required include files */
#include <math.h>
#include <stdlib.h>
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/gle.h>
#include "main.h"
/* =========================================================== */
#define HNUM 4
double brand_points[HNUM][3];
float brand_colors [HNUM][3];
#define TSCALE 4.0
#define BPTS(x,y,z) { \
brand_points[i][0] = TSCALE * (x); \
brand_points[i][1] = TSCALE * (y); \
brand_points[i][2] = TSCALE * (z); \
i++; \
}
#define BCOLS(r,g,b) { \
brand_colors[i][0] = (r); \
brand_colors[i][1] = (g); \
brand_colors[i][2] = (b); \
i++; \
}
#define NUMPOINTS 18
double tspine[NUMPOINTS][3];
float tcolors [NUMPOINTS][3];
#define TPTS(x,y) { \
tspine[i][0] = TSCALE * (x); \
tspine[i][1] = TSCALE * (y); \
tspine[i][2] = TSCALE * (0.0); \
i++; \
}
#define TCOLS(r,g,b) { \
tcolors[i][0] = (r); \
tcolors[i][1] = (g); \
tcolors[i][2] = (b); \
i++; \
}
/* =========================================================== */
static void init_spine (void)
{
int i;
int ir, ig, ib;
float r, g, b;
i=0;
TPTS (-1.5, 2.0); /* panhandle */
TPTS (-0.75, 2.0);
TPTS (-0.75, 1.38);
TPTS (-0.5, 1.25);
TPTS (0.88, 1.12);
TPTS (1.0, 0.62);
TPTS (1.12, 0.1);
TPTS (0.5, -0.5);
TPTS (0.2, -1.12); /* corpus */
TPTS (0.3, -1.5); /* brownsville */
TPTS (-0.25, -1.45);
TPTS (-1.06, -0.3);
TPTS (-1.38, -0.3);
TPTS (-1.65, -0.6);
TPTS (-2.5, 0.5); /* midland */
TPTS (-1.5, 0.5);
TPTS (-1.5, 2.0); /* panhandle */
TPTS (-0.75, 2.0);
ir = ig = ib = 0;
for (i=0; i<NUMPOINTS; i++) {
ir += 33; ig +=47; ib +=89;
ir %= 255; ig %= 255; ib %= 255;
r = ((float) ir) / 255.0;
g = ((float) ig) / 255.0;
b = ((float) ib) / 255.0;
tcolors[i][0] = (r);
tcolors[i][1] = (g);
tcolors[i][2] = (b);
}
i=0;
BPTS (0.0, 0.0, 0.1);
BPTS (0.0, 0.0, 0.0);
BPTS (0.0, 0.0, -5.0);
BPTS (0.0, 0.0, -5.1);
i=0;
BCOLS (1.0, 0.3, 0.0);
BCOLS (1.0, 0.3, 0.0);
BCOLS (1.0, 0.3, 0.0);
BCOLS (1.0, 0.3, 0.0);
}
/* =========================================================== */
#define SCALE 0.8
#define BORDER(x,y) { \
double ax, ay, alen; \
texas_xsection[i][0] = SCALE * (x); \
texas_xsection[i][1] = SCALE * (y); \
if (i!=0) { \
ax = texas_xsection[i][0] - texas_xsection[i-1][0]; \
ay = texas_xsection[i][1] - texas_xsection[i-1][1]; \
alen = 1.0 / sqrt (ax*ax + ay*ay); \
ax *= alen; ay *= alen; \
texas_normal [i-1][0] = - ay; \
texas_normal [i-1][1] = ax; \
} \
i++; \
}
#define NUM_TEXAS_PTS (17)
double texas_xsection [NUM_TEXAS_PTS][2];
double texas_normal [NUM_TEXAS_PTS][2];
static void init_xsection (void)
{
int i;
/* outline of extrusion */
i=0;
BORDER (-0.75, 2.0);
BORDER (-0.75, 1.38);
BORDER (-0.5, 1.25);
BORDER (0.88, 1.12);
BORDER (1.0, 0.62);
BORDER (1.12, 0.1);
BORDER (0.5, -0.5);
BORDER (0.2, -1.12); /* corpus */
BORDER (0.3, -1.5); /* brownsville */
BORDER (-0.25, -1.45);
BORDER (-1.06, -0.3);
BORDER (-1.38, -0.3);
BORDER (-1.65, -0.6);
BORDER (-2.5, 0.5); /* midland */
BORDER (-1.5, 0.5);
BORDER (-1.5, 2.0); /* panhandle */
BORDER (-0.75, 2.0);
}
/* =========================================================== */
void InitStuff (void)
{
int style;
/* configure the pipeline */
init_spine ();
init_xsection ();
style = TUBE_JN_CAP;
style |= TUBE_CONTOUR_CLOSED;
style |= TUBE_NORM_FACET;
style |= TUBE_JN_ANGLE;
gleSetJoinStyle (style);
}
/* =========================================================== */
void DrawStuff (void) {
#ifdef IBM_GL_32
scale (1.8, 1.8, 1.8);
lmcolor (material_mode);
(void) extrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal,
NULL, NUMPOINTS, tspine, tcolors);
(void) extrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal,
NULL, HNUM, brand_points, brand_colors);
lmcolor (LMC_COLOR);
#endif
#define OPENGL_10
#ifdef OPENGL_10
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
/* set up some matrices so that the object spins with the mouse */
glPushMatrix ();
glTranslatef (0.0, 0.0, -80.0);
glRotatef (lastx, 0.0, 1.0, 0.0);
glRotatef (lasty, 1.0, 0.0, 0.0);
/* draw the brand and the handle */
gleExtrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal,
NULL, NUMPOINTS, tspine, tcolors);
gleExtrusion (NUM_TEXAS_PTS-1, texas_xsection, texas_normal,
NULL, HNUM, brand_points, brand_colors);
glPopMatrix ();
glutSwapBuffers ();
}
#endif
/* ===================== END OF FILE ================== */
|