File: hsi_header.c

package info (click to toggle)
acm 5.0-23.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 8,364 kB
  • ctags: 4,793
  • sloc: ansic: 42,444; makefile: 706; cpp: 293; perl: 280; sh: 198
file content (351 lines) | stat: -rw-r--r-- 7,928 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
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
#include <stdio.h>
#include <math.h>
#include <Vlib.h>
#include <VFont.h>
#include <imath.h>
#include <string.h>

#ifndef DEGtoRAD
#define DEGtoRAD(a)	(a * M_PI / 180.0)
#endif

#define MAJOR_TICK	0.93
#define MINOR_TICK	0.97
#define CHAR_BASELINE	0.78
#define CHAR_WIDTH	(0.025 * 3.9)
#define FONT_SCALE	(0.025 * 3.9)

#define LEGEND_TICK	1.1
#define PLANE_HEIGHT	0.4
#define PLANE_WING	0.25
#define PLANE_TAIL	0.13

#define CDI_WIDTH	0.08
#define CDI_HEIGHT	1.00
#define CDI_DOT_RADIUS	0.02
#define CDI_DOT_SPACE	0.125
#define SCP_HEIGHT	0.32
#define SCP_ARROW_START 0.20

#define GS_DOT_RADIUS	0.05
#define GS_DOT_SPACE	0.35
#define GS_Y		1.4

#define VOR_DIR_WIDTH	(CDI_WIDTH * 1.7)
#define VOR_DIR_HEIGHT	(CDI_WIDTH * 1.7 * 0.867)
#define VOR_DIR_BASE	0.24

extern void DrawStrokeString();

VGlyphPath	paths[1024];
VGlyphVertex3	verticies[4096];

int path_count = 0;
int vertex_count = 0;

VPoint vertx[16];
int nvert;

#define PrintPoint(a,b,c) { vertx[nvert].x = (a); \
	vertx[nvert].y = (b); vertx[nvert].z = (c); ++ nvert; }

void
PrintPath (v, vcnt)
VPoint	*v;
int	vcnt;
{
	paths[path_count].vertex_count = vcnt;
	paths[path_count++].vertex_start = vertex_count;
	for (; vcnt > 0; --vcnt) {
		verticies[vertex_count].x = (short) (v->x * UNITY);
		verticies[vertex_count].y = (short) (v->y * UNITY);
		verticies[vertex_count++].z = (short) (v->z * UNITY);
		++v;
	}
}

void
Circle (y, z, radius, nseg)
double	y, z, radius;
int	nseg;
{

	int	i;
	VPoint	pt, first_pt;
	double	a, incr = 360.0 / nseg;

	pt.x = 1.0;

	nvert = 0;

	for (i=0; i<nseg; ++i) {

		a = DEGtoRAD (incr * i);
		pt.y = sin(a) * radius + y;
		pt.z = cos(a) * radius + z;
		PrintPoint (pt.x, pt.y, pt.z);
		if (i == 0)
			first_pt = pt;
	}

	PrintPoint (first_pt.x, first_pt.y, first_pt.z);

	PrintPath (vertx, nvert);
}

void
DashedLine (x1, y1, z1, x2, y2, z2)
double x1, y1, z1, x2, y2, z2;
{
	VPoint	v;
	register double t, scale, seg;
	register int i;

	v.x = x2 - x1;
	v.y = y2 - y1;
	v.z = z2 - z1;

#define NSEG	3
#define ON_FRACTION	0.7

	scale = 1.0 / (ON_FRACTION * NSEG + (1.0 - ON_FRACTION) * (NSEG - 1));

	seg = ON_FRACTION * scale;

	t = 0.0;
	for (i=0; i < NSEG; ++ i) {
		nvert = 0;
		PrintPoint (x1 + v.x * t, y1 + v.y * t, z1 + v.z * t);
		PrintPoint (x1 + v.x * (t + seg), y1 + v.y * (t + seg),
			z1 + v.z * (t + seg));
		PrintPath (vertx, nvert);
		t += scale;
	}
}

void WriteSegmentTables (file, prefix)
FILE	*file;
char	*prefix;
{

	int	i;

	printf ("VGlyphPath %s_path [] = {\n", prefix);
	for (i=0; i<path_count; ++i)
		printf ("  { %d, %d },\n",
			paths[i].vertex_count, paths[i].vertex_start);

	printf ("};\nVGlyphVertex3 %s_vertex [] = {\n", prefix);

	for (i=0; i<vertex_count; ++i)
		printf ("  { %d, %d, %d },\n",
			verticies[i].x,
			verticies[i].y,
			verticies[i].z);

	printf ("};\n\n");

	path_count = vertex_count = 0;

}

main () {

	char		*s, buf[64];
	int		i;
	double		hdg;
	VMatrix		mat;
	VPoint		f, a, b;

	for (i=0; i<72; ++ i) {

		hdg = DEGtoRAD((double) i * 5.0);

		a.x = 1.0;
		a.y = sin (hdg);
		a.z = cos (hdg);

		b = a;

		if ((i % 2) == 0) {
			b.y *= MAJOR_TICK;
			b.z *= MAJOR_TICK;
		}
		else {
			b.y *= MINOR_TICK;
			b.z *= MINOR_TICK;
		}

		nvert = 0;
		PrintPoint (a.x, a.y, a.z);
		PrintPoint (b.x, b.y, b.z);
		PrintPath (vertx, nvert);

		VIdentMatrix (&mat);
		VRotate (&mat, XRotation, - hdg);

		if ((i % 6) == 0) {

			if (i == 0) {
				s = "N";
			}
			else if (i == 18) {
				s = "E";
			}
			else if (i == 36) {
				s = "S";
			}
			else if (i == 54) {
				s = "W";
			}
			else {
				sprintf (buf, "%d", i / 2);
				s = buf;
			}

			f.x = 1.0;
			f.z = CHAR_BASELINE;

			if (strlen (s) == 1)
				f.y = - CHAR_WIDTH / 2.0;
			else
				f.y = - CHAR_WIDTH;

			DrawStrokeString (&f, s, strlen (s),
				FONT_SCALE, &mat, 0);
		}
	}

/*
 *  Now create the output file
 */

	printf ("/*\n *  This file created by tools/hsi_heading.c\n */\n");
	printf ("#include <VFont.h>\n");

	WriteSegmentTables (stdout, "heading");

/*
 * build the legend
 */

	a.x = b.x = 1.0;

	for (i=0; i < 8; ++i) {

		hdg = DEGtoRAD((double) i * 45.0);
		a.y = sin (hdg);
		a.z = cos (hdg);
		b.y = a.y * LEGEND_TICK;
		b.z = a.z * LEGEND_TICK;

		nvert = 0;
		PrintPoint (a.x, a.y, a.z);
		PrintPoint (b.x, b.y, b.z);
		PrintPath (vertx, nvert);
	}

	nvert = 0;
	PrintPoint (1.0, CDI_WIDTH / 2.0, PLANE_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, - PLANE_HEIGHT / 2.0);
	PrintPoint (1.0, PLANE_TAIL, - PLANE_HEIGHT / 2.0);
	PrintPath (vertx, nvert);

	nvert = 0;
	PrintPoint (1.0, - CDI_WIDTH / 2.0, PLANE_HEIGHT / 2.0);
	PrintPoint (1.0, - CDI_WIDTH / 2.0, - PLANE_HEIGHT / 2.0);
	PrintPoint (1.0, - PLANE_TAIL, - PLANE_HEIGHT / 2.0);
	PrintPath (vertx, nvert);

	nvert = 0;
	PrintPoint (1.0, CDI_WIDTH / 2.0, PLANE_HEIGHT / 6.0);
	PrintPoint (1.0, PLANE_WING, PLANE_HEIGHT / 6.0);
	PrintPath (vertx, nvert);

	nvert = 0;
	PrintPoint (1.0, - CDI_WIDTH / 2.0, PLANE_HEIGHT / 6.0);
	PrintPoint (1.0, - PLANE_WING, PLANE_HEIGHT / 6.0);
	PrintPath (vertx, nvert);

	WriteSegmentTables (stdout, "legend");

	nvert = 0;
	PrintPoint (1.0, CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0);
	PrintPoint (1.0, - CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0);
	PrintPoint (1.0, - CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPath (vertx, nvert);

	WriteSegmentTables (stdout, "cdi");

	nvert = 0;
	PrintPoint (1.0, CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0 + SCP_ARROW_START);
	PrintPoint (1.0, 0.0, CDI_HEIGHT / 2.0 + SCP_HEIGHT);
	PrintPoint (1.0, - CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0 + SCP_ARROW_START);
	PrintPoint (1.0, - CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, CDI_HEIGHT / 2.0);
	PrintPath (vertx, nvert);

	nvert = 0;
	PrintPoint (1.0, CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0 - SCP_ARROW_START);
	PrintPoint (1.0, -CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0 - SCP_ARROW_START);
	PrintPoint (1.0, -CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0);
	PrintPoint (1.0, CDI_WIDTH / 2.0, - CDI_HEIGHT / 2.0);
	PrintPath (vertx, nvert);

	Circle (5.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (- 5.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (4.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (- 4.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (3.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (- 3.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (2.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (- 2.0 * CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);
	Circle (- CDI_DOT_SPACE, 0.0, CDI_DOT_RADIUS, 8);  

	WriteSegmentTables (stdout, "scp");

	Circle (GS_Y, 2.0 * GS_DOT_SPACE, GS_DOT_RADIUS, 8);
	Circle (GS_Y, - 2.0 * GS_DOT_SPACE, GS_DOT_RADIUS, 8);
	Circle (GS_Y, GS_DOT_SPACE, GS_DOT_RADIUS, 8);
	Circle (GS_Y, - GS_DOT_SPACE, GS_DOT_RADIUS, 8);

	hdg = GS_DOT_RADIUS;
	nvert = 0;
	PrintPoint (1.0, GS_Y + hdg, hdg * 0.6);
	PrintPoint (1.0, GS_Y - hdg, hdg * 0.6);
	PrintPoint (1.0, GS_Y - hdg, - hdg * 0.6);
	PrintPoint (1.0, GS_Y + hdg, - hdg * 0.6);
	PrintPoint (1.0, GS_Y + hdg, hdg * 0.6);
	PrintPath (vertx, nvert);

	WriteSegmentTables (stdout, "gs_scale");

	hdg = GS_DOT_RADIUS;
	nvert = 0;
	PrintPoint (1.0, GS_Y - hdg, hdg);
	PrintPoint (1.0, GS_Y - hdg, - hdg);
	PrintPoint (1.0, GS_Y - (4.0 * hdg), - (2.0 * hdg));
	PrintPoint (1.0, GS_Y - (4.0 * hdg), (2.0 * hdg));
	PrintPoint (1.0, GS_Y - hdg, hdg);
	PrintPath (vertx, nvert);

	WriteSegmentTables (stdout, "gs_pointer");

	nvert = 0;
	PrintPoint (1.0, 0.0, VOR_DIR_BASE + VOR_DIR_HEIGHT);
	PrintPoint (1.0, VOR_DIR_WIDTH / 2.0, VOR_DIR_BASE);
	PrintPoint (1.0, -VOR_DIR_WIDTH / 2.0, VOR_DIR_BASE);
	PrintPoint (1.0, 0.0, VOR_DIR_BASE + VOR_DIR_HEIGHT);
	PrintPath (vertx, nvert);

	WriteSegmentTables (stdout, "vor_to_from");

	exit (0);
	return 0;

}