-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_draw.c
379 lines (351 loc) · 12.4 KB
/
c_draw.c
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
#include "c_includ.h"
/*
* c_draw.c
* Todd W Mummert, CMU, January 1991
*
* This is an attempt at cleaning up the drawing routines.
*/
/*
* this routine is for points which cannot change their bearing and have
* no moving parts; i.e., blocks.
*/
void calcpointsI(dc, method, index, g, pl)
DCp dc;
Methodp method;
int index;
Genericp g, pl;
{
int i;
float xpoff, ypoff, prx, pry, prz, dx, dy;
Coord2dp new;
Coord3dp old;
old = dc->s->object+index;
new = dc->points+index;
dx = pl->x - dc->pos.x;
dy = pl->y - dc->pos.y;
for (i=0; i<method->num; i++, old++, new++) {
xpoff = old->x - dx;
ypoff = old->y - dy;
prx = xpoff * pl->ca + ypoff * pl->sa;
pry = -xpoff * pl->sa + ypoff * pl->ca;
if (pry < 10.0)
pry = 10.0;
prz = old->z + dc->pos.z;
new->x = 500 + prx / pry * 450;
new->y = 260 - prz / pry * 450;
}
}
/*
* this routine is for points which may change their bearing, but do not
* have moving parts.
*/
void calcpointsII(dc, method, index, g, pl)
DCp dc;
Methodp method;
int index;
Genericp g, pl;
{
int i;
float csa, ssa, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry;
Coord2dp new;
Coord3dp old;
old = dc->s->object+index;
new = dc->points+index;
csa = cos(g->azm);
ssa = sin(g->azm);
dx = pl->x - dc->pos.x;
dy = pl->y - dc->pos.y;
xn = dx * csa + dy * ssa;
yn = -dx * ssa + dy * csa;
cn = pl->ca * csa + pl->sa * ssa;
sn = pl->sa * csa - ssa * pl->ca;
for (i=0; i<method->num; i++, old++, new++) {
rx = old->x - xn;
ry = old->y - yn;
prx = rx * cn + ry * sn;
pry = -rx * sn + ry * cn;
if (pry < 10.0)
pry = 10.0;
prz = old->z + dc->pos.z;
new->x = 500 + prx / pry * 450;
new->y = 260 - prz / pry * 450;
}
}
/*
* this routine is for points which do not change their bearing,
* but have moving parts which rotate around the center of the
* object.
*/
void calcpointsIII(dc, method, index, g, pl)
DCp dc;
Methodp method;
int index;
Genericp g, pl;
{
int i;
float temp, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry;
Coord2dp new;
Coord3dp old;
old = dc->s->object+index;
new = dc->points+index;
temp = dc->cta;
dc->cta = dc->cta * method->vars[0] - dc->sta * method->vars[1];
dc->sta = dc->sta * method->vars[0] + temp * method->vars[1];
dx = pl->x - dc->pos.x;
dy = pl->y - dc->pos.y;
xn = dx * dc->cta + dy * dc->sta;
yn = -dx * dc->sta + dy * dc->cta;
cn = pl->ca * dc->cta + pl->sa * dc->sta;
sn = pl->sa * dc->cta - pl->ca * dc->sta;
for (i=0; i<method->num; i++, old++, new++) {
rx = old->x - xn;
ry = old->y - yn;
prx = rx * cn + ry * sn;
pry = -rx * sn + ry * cn;
if (pry < 10.0)
pry = 10.0;
prz = old->z + dc->pos.z;
new->x = 500 + prx / pry * 450;
new->y = 260 - prz / pry * 450;
}
}
/*
* this routine is for points which do change their bearing,
* and have moving parts which do not rotate around the center of the
* object. an example is the offset radar dish of the normal tanks.
*/
void calcpointsIV(dc, method, index, g, pl)
DCp dc;
Methodp method;
int index;
Genericp g, pl;
{
int i;
float temp, dx, dy, xn, yn, cn, sn, prx, pry, prz, rx, ry, csa, ssa;
Coord2dp new;
Coord3dp old;
Float2d pivot;
old = dc->s->object+index;
new = dc->points+index;
temp = dc->cta;
dc->cta = dc->cta * method->vars[0] - dc->sta * method->vars[1];
dc->sta = dc->sta * method->vars[0] + temp * method->vars[1];
csa = cos(g->azm);
ssa = sin(g->azm);
dx = pl->x - dc->pos.x;
dy = pl->y - dc->pos.y;
xn = dx * csa + dy * ssa;
yn = -dx * ssa + dy * csa;
cn = pl->ca * csa + pl->sa * ssa;
sn = pl->sa * csa - ssa * pl->ca;
pivot.x = method->vars[2] - xn;
pivot.y = method->vars[3] - yn;
for (i=0; i<method->num; i++, old++, new++) {
rx = old->x * dc->cta - old->y * dc->sta + pivot.x;
ry = old->x * dc->sta + old->y * dc->cta + pivot.y;
prx = rx * cn + ry * sn;
pry = -rx * sn + ry * cn;
if (pry < 10.0)
pry = 10.0;
prz = old->z + dc->pos.z;
new->x = 500 + prx / pry * 450;
new->y = 260 - prz / pry * 450;
}
}
/*
* draw plines and mlines
*
*/
void displayobject(dc)
DCp dc;
{
Coord2dp point;
int *i;
point=dc->points;
for (i=dc->s->pnum; *i; i++) {
polyline(point, *i);
point += *i;
}
for (i=dc->s->mnum; *i; i++) {
multiline(point, *i>>1);
point += *i;
}
}
void drawobject(g, pl)
Genericp g, pl;
{
static Coord3d cube[] = {
-40, 40, -40, -40, 40, 40, 40, 40, 40, 40, 40, -40,
-40, 40, -40, -40, -40, -40, 40, -40, -40, 40, -40, 40,
-40, -40, 40, -40, -40, -40, -40, -40, 40, -40, 40, 40,
40, -40, 40, 40, 40, 40, 40, -40, -40, 40, 40, -40};
static int cubepnum[] = {10, 0};
static int cubemnum[] = {6, 0};
static Method cubemethods[] = {16, calcpointsI, NULL,
0, NULL, NULL};
static Coord3d pyramid[] = {
-40, 40, -40, 40, 40, -40, 40, -40, -40, 40, 40, -40,
0, 0, 40, -40, 40, -40, -40, -40, -40, 0, 0, 40,
40, -40, -40, -40, -40, -40};
static int pyramidpnum[] = {10, 0};
static int pyramidmnum[] = {0};
static Method pyramidmethods[] = {10, calcpointsI, NULL,
0, NULL, NULL};
static Coord3d salvo[] = {
0, -10, -8, 8, -10, 0, 0, -10, 8, 8, -10, 0,
0, 10, 0, 0, -10, 8, -8, -10, 0, 0, 10, 0,
0, -10, -8, -8, -10, 0};
static int salvopnum[] = {10, 0};
static int salvomnum[] = {0};
static Method salvomethods[] = {10, calcpointsII, NULL,
0, NULL, NULL};
static Coord3d lander[] = {
0, 0, 20, 80, 0, -20, 40, 0, -40, -40, 0, -40,
-80, 0, -20, 0, 0, 20, 0, 80, -20, 0, 40, -40,
0, -40, -40, 0, -80, -20, 0, 0, 20, -57, -57, -20,
-28, -28, -40, 28, 28, -40, 57, 57, -20, 0, 0, 20,
57, -57, -20, 28, -28, -40, -28, 28, -40, -57, 57, -20,
0, 0, 20};
static int landerpnum[] = {21, 0};
static int landermnum[] = {0};
static float landervars[] = {0.996195, 0.087156};
static Method landermethods[] = {21, calcpointsIII, landervars,
0, NULL, NULL};
static Coord3d missile[] = {
15, -30, -25, 25, -30, 0, 0, -45, 0, 15, -30, -25,
-15, -30, -25, 0, -45, 0, 15, -30, 25, -15, -30, 25,
0, -45, 0, -25, -30, 0, -15, -30, 25, 15, -30, -25,
0, 50, 0, 25, -30, 0, 15, -30, 25, 0, 50, 0,
-15, -30, -25, -25, -30, 0, 0, 50, 0, -15, -30, 25,
13, -17, -21, 15, -30, -25, 23, -38, -40, 23, 0, -40,
13, -17, -21, -13, -17, -21, -15, -30, -25, -23, -38, -40,
-23, 0, -40, -13, -17, -21};
static int missilepnum[] = {11, 9, 5, 5, 0};
static int missilemnum[] = {0};
static Method missilemethods[] = {30, calcpointsII, NULL,
0, NULL, NULL};
static Coord3d copter[] = {
6, 100, 30, -6, -100, 30, 6, -100, 30,
-6, 100, 30, 6, 100, 30, 0, -114, -10,
7, -30, -34, 10, -34, -14, 0, -116, 0,
0, -134, 28, 0, -144, 28, 0, -130, -10,
0, -114, -10, -7, -30, -34, -10, -34, -14,
0, -116, 0, -14, 34, -34, 14, 34, -34,
0, 60, -14, -14, 34, -34, -7, -30, -34,
7, -30, -34, 14, 34, -34, 26, 34, -14,
0, 60, -14, -26, 34, -14, -10, -34, -14,
10, -34, -14, 26, 34, -14, 4, 20, 16,
0, 22, 16, -4, 20, 16, -4, -22, 16,
4, -22, 16, 4, 20, 16, 0, 0, 16,
0, 0, 36, -14, -30, -40, -14, 40, -40,
-14, 40, -40, -14, 44, -36, 14, -30, -40,
14, 40, -40, 14, 40, -40, 14, 44, -36,
-10, -34, -14, -4, -22, 16, 10, -34, -14,
4, -22, 16, 0, 22, 16, 0, 60, -14,
-14, 34, -34, -26, 34, -14, -26, 34, -14,
-4, 20, 16};
static int copterpnum[] = {5, 11, 19, 0};
static int coptermnum[] = {10, 10, 0};
static float coptervars[] = {0.819152, 0.573576};
static Method coptermethods[] = {5, calcpointsIII, coptervars,
50, calcpointsII, NULL,
0, NULL, NULL};
static Coord3d super[] = {
3, 55, -6, 3, 55, 0, -3, 55, 0, -3, 55, -6,
3, 55, -6, 0, 35, -33, 13, -60, -6, 11, -60, 4,
11, -25, 4, 0, 35, -33, -13, -60, -6, -11, -60, 4,
-11, -25, 4, 0, 35, -33, 15, 60, -40, 30, -60, -40,
30, -60, -6, 15, 60, -40, -15, 60, -40, -30, -60, -40,
-30, -60, -6, -15, 60, -40, 22, -52, -8, 22, -52, 28,
3, -17, 0, 3, 55, 0, -3, -17, 0, -3, 55, 0,
3, -8, -6, 3, 55, -6, -3, -8, -6, -3, 55, -6,
11, -60, 4, -11, -60, 4, 11, -25, 4, -11, -25, 4,
-30, -60, -6, 30, -60, -6, -30, -60, -40, 30, -60, -40};
static int superpnum[] = {5, 9, 8, 0};
static int supermnum[] = {2, 8, 4, 4, 0};
static Method supermethods[] = {40, calcpointsII, NULL,
0, NULL, NULL};
static Coord3d tank[] = {
3, 0, 13, 5, 3, 15, 5, 3, 19, 3, 0, 21,
-3, 0, 21, -5, 3, 19, -5, 3, 15, -3, 0, 13,
3, 0, 13, -3, 60, -3, 3, 60, -3, 3, 60, 3,
-3, 60, 3, -3, 60, -3, -10, -45, 10, -10, -13, 10,
10, -13, 10, 10, -45, 10, 25, -50, -11, 25, 60, -20,
10, -13, 10, -10, -13, 10, -25, 60, -20, -25, -50, -11,
-10, -45, 10, 10, -45, 10, 30, -53, -40, 35, -60, -10,
35, 60, -20, 30, 37, -40, -30, 37, -40, -35, 60, -20,
-35, -60, -10, -30, -53, -40, 30, -53, -40, 30, 37, -40,
5, -40, 10, 5, -40, 13, 3, 4, 3, 3, 60, 3,
-3, 4, 3, -3, 60, 3, -3, 19, -3, -3, 60, -3,
3, 19, -3, 3, 60, -3, 35, -60, -10, -35, -60, -10,
35, 60, -20, -35, 60, -20, -30, -53, -40, -30, 37, -40};
static int tankpnum[] = {9, 5, 12, 10, 0};
static int tankmnum[] = {2, 8, 6, 0};
static float tankvars[] = {0.996195, 0.087156, 5, -40};
static Method tankmethods[] = {9, calcpointsIV, tankvars,
43, calcpointsII, NULL,
0, NULL, NULL};
static StaticDC staticdcs[] = {
pyramid, pyramidpnum, pyramidmnum, pyramidmethods, COLOR_PYRAMID,
cube, cubepnum, cubemnum, cubemethods, COLOR_CUBE,
tank, tankpnum, tankmnum, tankmethods, COLOR_TANK,
super, superpnum, supermnum, supermethods, COLOR_SUPER,
missile, missilepnum, missilemnum, missilemethods, COLOR_MISSILE,
copter, copterpnum, coptermnum, coptermethods, COLOR_COPTER,
lander, landerpnum, landermnum, landermethods, COLOR_LANDER,
salvo, salvopnum, salvomnum, salvomethods, COLOR_ESALVO };
int color, i;
DCp dc;
Methodp methods;
dc = &g->dc[0];
if (dc->last) {
gprsetdrawvalue(opt->cpi[COLOR_BG]);
displayobject(dc);
}
if (g->attr & ERASE) return;
if (!(g->attr & HAS_DC)) {
g->attr |= HAS_DC;
dc->s = staticdcs+g->lntype;
switch (g->type) {
case IS_CUBE:
case IS_PYRAMID:
case IS_LANDER:
case IS_MISSILE:
case IS_COPTER:
case IS_SUPER:
case IS_TANK:
dc->fades = opt->fading_colors - 1;
dc->basecolor = dc->s->basecolor;
break;
case IS_SALVO:
dc->fades = False;
if (g->salvo == pl)
dc->basecolor = COLOR_PSALVO;
else
dc->basecolor = COLOR_ESALVO;
break;
}
}
if (dc->seen) {
if (dc->fades) {
color = g->range/OUT_OF_DRAWING_RANGE * opt->fading_colors;
if (color >= opt->fading_colors)
color = opt->fading_colors-1;
}
else
color = 0;
gprsetdrawvalue(color + opt->cpi[dc->basecolor]);
dc->pos.x = g->x;
dc->pos.y = g->y;
dc->pos.z = g->z;
methods = dc->s->methods;
for (i=0; methods->num; methods++) {
methods->calc(dc, methods, i, g, pl);
i += methods->num;
}
displayobject(dc);
dc->last = True;
}
else
dc->last = False;
}