File: joinoffset.c

package info (click to toggle)
gle 3.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,416 kB
  • sloc: ansic: 10,025; cpp: 5,378; sh: 3,160; makefile: 291; python: 102
file content (154 lines) | stat: -rw-r--r-- 3,419 bytes parent folder | download | duplicates (9)
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

/*
 * FILE:
 * joinoffset.c
 * 
 * FUNCTION:
 * this demo demonstrates the various join styles 
 *
 * HISTORY:
 * Copyright (c) 1995 Linas Vepstas <linas@linas.org>
 */


/* required include files */
#include <GL/gl.h>
#include <GL/glut.h>
#include <GL/gle.h>
#include "main.h"

/* ------------------------------------------------------- */

/* the arrays in which we will store the polyline */
#define NPTS 100
double points [NPTS][3];
float colors [NPTS][3];
int idx = 0;

/* some utilities for filling that array */
#define PSCALE 0.5
#define PNT(x,y,z) { 			\
   points[idx][0] = PSCALE * x; 	\
   points[idx][1] = PSCALE * y; 	\
   points[idx][2] = PSCALE * z;		\
   idx ++;				\
}

#define COL(r,g,b) { 			\
   colors[idx][0] = r; 			\
   colors[idx][1] = g; 			\
   colors[idx][2] = b;			\
}

/* the arrays in which we will store the contour */
#define NCONTOUR 100
double contour_points [NCONTOUR][2];
int cidx = 0;

/* some utilities for filling that array */
#define C_PNT(x,y) { 			\
   contour_points[cidx][0] = x;		\
   contour_points[cidx][1] = y; 	\
   cidx ++;				\
}


/* ------------------------------------------------------- */
/* 
 * Initialize a bent shape with three segments. 
 * The data format is a polyline.
 *
 * NOTE that neither the first, nor the last segment are drawn.
 * The first & last segment serve only to determine that angle 
 * at which the endcaps are drawn.
 */

void InitStuff (void) 
{
   COL (0.0, 0.0, 0.0);
   PNT (16.0, 0.0, 0.0);

   COL (0.2, 0.8, 0.5);
   PNT (0.0, -16.0, 0.0);

   COL (0.0, 0.8, 0.3);
   PNT (-16.0, 0.0, 0.0);

   COL (0.8, 0.3, 0.0);
   PNT (0.0, 16.0, 0.0);

   COL (0.2, 0.3, 0.9);
   PNT (16.0, 0.0, 0.0);

   COL (0.2, 0.8, 0.5);
   PNT (0.0, -16.0, 0.0);

   COL (0.0, 0.0, 0.0);
   PNT (-16.0, 0.0, 0.0);

   C_PNT (-0.8, -0.5);
   C_PNT (-1.8, 0.0);
   C_PNT (-1.2, 0.3);
   C_PNT (-0.7, 0.8);
   C_PNT (-0.2, 1.3);
   C_PNT (0.0, 1.6);
   C_PNT (0.2, 1.3);
   C_PNT (0.7, 0.8);
   C_PNT (1.2, 0.3);
   C_PNT (1.8, 0.0);
   C_PNT (0.8, -0.5);

   gleSetJoinStyle (TUBE_JN_ANGLE | TUBE_CONTOUR_CLOSED | TUBE_JN_CAP);
}

double up_vector[3] = {1.0, 0.0, 0.0};

/* ------------------------------------------------------- */
/* draw the extrusion */

void DrawStuff (void) 
{
   double moved_contour [NCONTOUR][2];
   int style, save_style;
   int i;

   for (i=0; i<cidx; i++) {
      moved_contour[i][0] = contour_points [i][0];
      moved_contour[i][1] = contour_points [i][1] + 0.05 * (lasty-200.0);
   }

   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, 4.0, -80.0);
   glRotatef (0.5*lastx, 0.0, 1.0, 0.0);

   gleExtrusion (cidx, moved_contour, contour_points, up_vector, 
                 idx, points, colors);

   glPopMatrix ();


   /* draw a seond copy, this time with the raw style, to compare
    * things against */
   glPushMatrix ();
   glTranslatef (0.0, -4.0, -80.0);
   glRotatef (0.5*lastx, 0.0, 1.0, 0.0);

   save_style = gleGetJoinStyle ();
   style = save_style;
   style &= ~TUBE_JN_MASK;
   style |= TUBE_JN_RAW;
   gleSetJoinStyle (style);

   gleExtrusion (cidx, moved_contour, contour_points, up_vector, 
                 idx, points, colors);

   gleSetJoinStyle (save_style);
   glPopMatrix ();

   glutSwapBuffers ();
}

/* ------------------ end of file ----------------------------- */