-
Notifications
You must be signed in to change notification settings - Fork 1
/
3deng.cpp
9366 lines (8545 loc) · 339 KB
/
3deng.cpp
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/********************************************************/
/* 3D ENGINE - Football 13/04/95 */
/********************************************************/
// By Laurent Noel
#include <unistd.h>
#include "defs.h"
/********************* HEADER FILES *********************/
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <fcntl.h>
#include <time.h>
#include <memory>
#include "3deng.h"
#include "data.h"
#include "vesa.h"
#include "mallocx.h"
#ifdef BLASTER
#include "3dblast.h"
#else
#include "3dbnull.h"
#ifdef NEW
#include "eurodefs.h"
#include "euro_fxd.h"
#include "euro.equ"
#include "euro_sym.h"
#include "euro_def.h"
//#include "euro_var.h"
#include "euro_mem.h"
#include "euro_spt.h"
#include "euro_gen.h"
#include "euro_grf.h"
#include "euro_cnt.h"
#include "euro_dsk.h"
#include "euro_sqd.h"
#include "euro_sel.h"
#include "euro_fix.h"
#include "euro_usr.h"
#include "euro_inf.h"
#include "euro_gdv.h"
//#include "euro_net.h"
#include "euro_cmd.h"
#include "euro_rnd.h"
#include "euro_int.h"
#endif
#define TEMPa 0
#define TEMPb 1
#endif
#include "game.equ"
#include "fap.equ"
#include "files.c"
#include "fgfx.c"
#include "andydefs.h"
#include "defines.h"
/***************** PRE-DEFINED CONSTANTS ****************/
#define SCREENDIST 15 // Screen clip plane z distance, set to avoid overflow
#define CUTOFFDIST 5 // Cutoff plane z distance (can be -ve!), set for nearest visibility
#define MAXOBJ 100 // Max number of objects in one sort
#define MAXPOL 1000 // Max number of polys in one sort
#define MAXPTS 500 // Max number of points in one object
#define MAXLOOP 100 // Max number of looping maps
#define MAX_FILES 500
// Undefined in C++ (?!)
#define min(a, b) (((a)<(b))?(a):(b))
#ifndef max
#define max(a, b) (((a)>(b))?(a):(b))
#endif
#define abs(a) (((a)>=0)?(a):-(a))
/*********************** PROTOTYPES *********************/
// From render.c :
// Line Drawing
extern void line(pnt *pts, word col); // Flat colour line
// Polygon drawing
extern void poly(pnt *pts, word np, word col); // Flat colour overlapping
extern void polyb(pnt *pts, word np, word col); // Flat colour
extern void polyf(pnt *pts, word np, filter col); // Filtered
extern void polyg(ppnt *pts, word np); // Gourad shading
extern void polym(pnt *pts, word np, word mapsel, // Texture mapped
dword *startsx, dword *startsy);
extern void polyl(pnt *pts, word np, word mapsel, // Looping texture mapped
dword *startsx, dword *startsy);
extern void polyt(pnt *pts, word np, word mapsel, // Transparent texture mapped
dword *startsx, dword *startsy);
extern void polyq(zpnt *pts, word np, BYTE *map, // Bi-Quadratic texture mapped
dword *startsx, dword *startsy);
extern void sprite3d(short x, short y, short ref); // Depth sorted sprites
// Dumps for various buffer types
void dumpMCGA(scrpt dispx, scrpt dispy);
void dumpMCGAs(scrpt dispx, scrpt dispy);
void dumpV256(scrpt dispx, scrpt dispy);
void dump3DB(scrpt dispx, scrpt dispy);
void dumpvidi1(scrpt dispx, scrpt dispy);
void dumpnull(scrpt dispx, scrpt dispy);
// Miscellaneous
extern float log_factor; // No of logic frames/update
extern char match_half;
extern char match_mode;
void draw_sprite(buff_info *buff, int sprite_no, int x, int y, BYTE col);
int draw_string(buff_info *buff, int font_no, int x, int y, const char *string, BYTE col, short just);
extern char keys[128]; // Key pressed array (indexed by scan-code)
extern char key_togs[128]; // Key toggled array (indexed by scan-code)
extern int icth,isth; // Integer cos and sin of theta
extern volatile int count; // Timer count
extern int network_on; // Network game
// Wind data
extern short wind_on;
extern float wind_x, wind_y;
extern float wind_speed;
/********************** GLOBAL VARS *********************/
// Setup data
setup_info setup; // Initialisation data
int performance; // Machine performance index
// Screen buffer info
buff_info main_buff; // Current main screen buffer info
buff_info vidi_buff; // Current vidi-buffer info
buff_info menu_buff; // Current menu buffer info
buff_info_ext render_buff; // Extended buffer info for rendering
word scrmode; // (S)VGA mode number (including VESA)
word scrmode3DB; // 3D Blaster mode number (-ve if not available)
word menx3DB, meny3DB; // Offset for menus on 3D Blastter
int mappages; // No of texture-map pages being used
int texaddr3DB[16]; // Internal 3DB addresses for gfx
int skyaddr3DB, pitchaddr3DB; // Internal 3DB addresses for gfx
BYTE *scr = (BYTE *) 0xa0000; // Address of (S)VGA display.
// Viewpoint vars
float cth, sth, cph, sph; // Cos & sin of theta and phi, the viewing angles
short q, oq; // Perspective scaling
float qr, qa; // Precalculations derived from above
float scrdr, persc; // Used for 'alternative perspective scaling', see below
qmat rot, tran; // Quick matrices for view and object rotation
// Object/polygon/point lists
objs *objlist; // List of objects [object z, object polygon list]
objs *curobj; // Current object pointer
pols *pollist; // List of polygons [polygon z, polygon point list]
pols *curpol; // Current polygon pointer
scrpt *ptslist; // List of polygon point data [nsides, col, nsides*{x,y}]
scrpt *curpts; // Current point pointer(!)
rotpt *rotlist; // List of rotated pts for object
#ifdef IMPLEMENT_ME
CGL_VERTEX2D_ST *curpts3DB; // For 3D Blaster sprites
CGL_TEXTURE2D_ST *curtex3DB; // --"--
#endif
int clip_tex; // Current clip texture map
plyrdat *ppt;
int timeit = 0;
BYTE *dumplbm;
char dumpstr[] = "dumpa.tga";
#ifdef COUNT
int numpols; // Count for number of polygons drawn
#endif
float mcap_ballx, mcap_bally, mcap_ballz;
/***************** INITIALISED STRUCTURES ***************/
// Unit matrix
mat unit =
{
{1.f, 0.f, 0.f, 0.f},
{0.f, 1.f, 0.f, 0.f},
{0.f, 0.f, 1.f, 0.f},
{0.f, 0.f, 0.f, 1.f},
};
//////////////////
// MEMORY AREAS //
// Texture map pages
#define X_BM 6 // Bitmap offset for extra maps
#define S_BM 8 // Bitmap offset for stand maps
#ifdef NEW
#define MAPPAGES (S_BM+8)
#else
#define MAPPAGES (S_BM+7)
#endif
#define MAPPAGES_4 (S_BM+2)
typedef BYTE mappage[256 * 256];
mappage *maps;
word mapsel[MAPPAGES + MAXLOOP + 1];
BYTE *sky; // Sky map
BYTE pitch3DB[64 * 64]; // Pitch map (3D Blaster)
/////////////////
// SCREEN INFO //
// Space for main screen buffer
BYTE *scrb;
// VESA mode list
#define VESAMODES 2
int modelist[VESAMODES + 1] = {0x100, 0x101, -1};
// Screen buffer information (w%8=0,h%2=0)
#define SCRSIZES 10
buff_info MCGA_buff[SCRSIZES] =
{
{NULL, 320, 200, 320, 200, 0.5, 0.5, dumpMCGA},
{NULL, 320, 200, 296, 184, 0.4625, 0.46, dumpMCGA},
{NULL, 320, 200, 320, 158, 0.5, 0.3975, dumpMCGA},
{NULL, 320, 200, 264, 166, 0.4125, 0.4175, dumpMCGA},
{NULL, 320, 200, 296, 142, 0.4625, 0.355, dumpMCGA},
{NULL, 320, 200, 240, 150, 0.375, 0.375, dumpMCGA},
{NULL, 320, 200, 264, 124, 0.4125, 0.3125, dumpMCGA},
{NULL, 320, 200, 216, 132, 0.3375, 0.3325, dumpMCGA},
{NULL, 320, 200, 240, 108, 0.375, 0.2725, dumpMCGA},
{NULL, 320, 200, 216, 92, 0.3375, 0.23, dumpMCGA},
};
buff_info VESA_buff[VESAMODES][SCRSIZES] =
{
{
{NULL, 640, 400, 640, 400, 1, 1, dumpV256},
{NULL, 640, 400, 584, 366, 0.9125, 0.9175, dumpV256},
{NULL, 640, 400, 640, 316, 1, 0.79, dumpV256},
{NULL, 640, 400, 528, 332, 0.825, 0.8325, dumpV256},
{NULL, 640, 400, 584, 284, 0.9125, 0.71, dumpV256},
{NULL, 640, 400, 480, 300, 0.75, 0.75, dumpV256},
{NULL, 640, 400, 528, 250, 0.825, 0.625, dumpV256},
{NULL, 640, 400, 424, 266, 0.6625, 0.6675, dumpV256},
{NULL, 640, 400, 480, 216, 0.75, 0.54, dumpV256},
{NULL, 640, 400, 424, 184, 0.6625, 0.46, dumpV256},
},
{
{NULL, 640, 480, 640, 480, 1, 1.2, dumpV256},
{NULL, 640, 480, 584, 440, 0.9125, 1.1, dumpV256},
{NULL, 640, 480, 640, 380, 1, 0.95, dumpV256},
{NULL, 640, 480, 528, 400, 0.825, 1, dumpV256},
{NULL, 640, 480, 584, 340, 0.9125, 0.85, dumpV256},
{NULL, 640, 480, 480, 360, 0.75, 0.9, dumpV256},
{NULL, 640, 480, 528, 300, 0.825, 0.75, dumpV256},
{NULL, 640, 480, 424, 320, 0.6625, 0.8, dumpV256},
{NULL, 640, 480, 480, 260, 0.75, 0.65, dumpV256},
{NULL, 640, 480, 424, 220, 0.6625, 0.55, dumpV256},
},
};
#define MODES_3DB 6
#ifndef BLASTDEMO
int modelist3DB[MODES_3DB + 1] = {0, 3, 5, -1};
int modelist3DBh[MODES_3DB + 1] = {0, 3, 5, -1};
#else
int modelist3DB[MODES_3DB+1]={3,4,5,3,4,5,-1};
//int modelist3DB[MODES_3DB+1]={0,1,2,3,4,5,-1};
int modelist3DBh[MODES_3DB+1]={3,4,5,3,4,5,-1};
//int modelist3DBh[MODES_3DB+1]={3,4,5,0,1,2,-1};
#endif
buff_info buff_3DB[MODES_3DB] =
{
{NULL, 320, 200, 320, 200, 0.5, 0.5, dump3DB},
{NULL, 320, 240, 320, 240, 0.5, 0.6, dump3DB},
{NULL, 640, 350, 640, 350, 1, 0.875, dump3DB},
{NULL, 640, 400, 640, 400, 1, 1, dump3DB},
{NULL, 640, 480, 640, 480, 1, 1.2, dump3DB},
{NULL, 800, 600, 800, 600, 1.25, 1.5, dump3DB},
};
buff_info vidi_buff_1 = {NULL, 256, 256, 128, 80, 0.175, 0.183, dumpnull};
buff_info vidi_buff_2 = {NULL, 256, 256, 128, 80, 0.175, 0.183, dumpvidi1};
// Palette
BYTE pal[768];
// Polygon filters
#define FILTERS 2
filter *filters;
//////////////////////
// TEXTURE MAP INFO //
// Team players:
// Texture 13 (1+12): Head A (End 61 (1+5*12))
// Texture 73 (61+12): Head B (End 121 (61+5*12))
// Texture 133 (121+12): Torso A (End 181 (121+5*12))
// Texture 193 (181+12): Torso B (End 241 (181+5*12))
// Texture 244 (241+3): Lower Leg A (End 248 (241+7))
// Texture 251 (248+3): Upper Arm A (End 255 (248+7))
// Texture 258 (255+3): Upper Leg A (End 262 (255+7))
// Texture 265 (262+3): Lower Arm A (End 269 (262+7))
// Texture 272 (269+3): Lower Leg B (End 276 (269+7))
// Texture 279 (276+3): Upper Arm B (End 283 (276+7))
// Texture 286 (283+3): Upper Leg B (End 290 (283+7))
// Texture 293 (290+3): Lower Arm B (End 297 (290+7))
// Texture 309 (297+12): Foot (End 357 (297+5*12))
// Referee & keeper:
// Texture 369 (357+12): Torso Referee (End 417 (357+5*12))
// Texture 429 (417+12): Torso Keeper (End 477 (417+5*12))
// Texture 480 (477+3): Lower Leg Referee (End 484 (477+7))
// Texture 487 (484+3): Upper Arm Referee (End 491 (484+7))
// Texture 494 (491+3): Upper Leg Referee (End 498 (491+7))
// Texture 501 (498+3): Lower Arm Referee (End 505 (498+7))
// Texture 508 (505+3): Lower Leg Keeper (End 512 (505+7))
// Texture 515 (512+3): Upper Arm Keeper (End 519 (512+7))
// Texture 522 (519+3): Upper Leg Keeper (End 526 (519+7))
// Texture 529 (526+3): Lower Arm Keeper (End 533 (526+7))
#define X_TM 533 // Offset for extra maps
#define X_TM_NO (52+419) // No of extra maps
#define N_TM (X_TM+52) // Alternate torsos
#define NT_TM (N_TM+412) // Netting
#define S_TM X_TM+X_TM_NO // Offset for stand maps
#define S_TM_MAX 500 // Maximum no of stadium maps
#define NOTEXTURES S_TM+S_TM_MAX
#define CLIP_TEXTURES 200
texture *textures;
// Misc looping textures
int noloop = 6;
struct {
int pos;
texture tex;
} texloop[] =
{
{
0x1c040,
{0x000000, 0x000000, 0x3fff00, 0x3fff00,
0x000000, 0x3fff00, 0x3fff00, 0x000000}
},
{
0x1c040,
{0x000000, 0x000000, 0x1fff00, 0x1fff00,
0x000000, 0x3fff00, 0x3fff00, 0x000000}
},
{
0x1c040,
{0x000000, 0x000000, 0x7fff00, 0x7fff00,
0x000000, 0x7fff00, 0x7fff00, 0x000000}
},
{
0x1c080,
{0x000000, 0x000000, 0x3fff00, 0x3fff00,
0x000000, 0x7fff00, 0x7fff00, 0x000000}
},
{
0x1c040,
{0x000000, 0x000000, 0xbfff00, 0xbfff00,
0x000000, 0xbfff00, 0xbfff00, 0x000000}
},
{
0x1c0c0,
{0x000000, 0x000000, 0x5fff00, 0x5fff00,
0x000000, 0xbfff00, 0xbfff00, 0x000000}
},
};
const char *lang[6][29] =
{
{
"GOAL SCORED BY: ",
"BOOKED, YELLOW CARD: ",
"RED CARD, SENT OFF: ",
"DIRECT FREE KICK",
"INDIRECT FREE KICK",
"PENALTY KICK",
"CORNER KICK",
"THROW IN",
"GOAL KICK",
"KICK OFF",
"OFFSIDE",
"PLAYER INJURED: ",
"FULL TIME",
"EXTRA TIME",
"HALF TIME",
"PENALTY SHOOTOUT",
"FINAL SCORE AFTER PENALTIES",
"OWN GOAL BY: ",
"REPLAY",
"SUBSTITUTION",
"FORMATION",
"CANCEL",
"SELECT",
"OFF",
"SUBSTITUTE",
"ON",
"DONE",
"OPTIONS",
"REFEREE : ",
},
{
"BUT DE: ",
"AVERT., C. JAUNE: ",
"C. ROUGE, RENV.: ",
"COUP FR. DIRECT",
"COUP FR. INDIR",
"PENALTY",
"CORNER",
"TOUCHE",
"TIR AU BUT",
"CP. D<ENVOI",
"HORS JEU",
"JOUEUR BLESSE: ",
"TPS TOTAL",
"PROLONG.",
"MI=TEMPS",
"PENALTIES",
"SCORE FINAL APRES PEN.",
"BUT CTRE SOM CAMP DE: ",
"REPLAY",
"REMPLACEMENT",
"FORMATION",
"ANNULER",
"SELECT",
"OFF",
"REMPLACANT",
"ON",
"FAIT",
"OPTIONS",
"ARBITRE : ",
},
{
"TORSCHUETZE: ",
"GELBE KARTE: ",
"ROTE KARTE: ",
"DIREKTER FREISTOSS",
"FREISTOSS",
"ELFMETER",
"ECKBALL",
"EINWURF",
"ABSTOSS",
"ANSTOSS",
"ABSEITS",
"SPIELER VERLETZT: ",
"ABPFIFF",
"VERLAENGERUNG",
"HALBZEIT",
"ELFMETERSCHIESSEN",
"ERGEBNIS NACH ELFMETERSCHIESSEN",
"EIGENTOR VON ",
"WIEDERHOLUNG",
"AUSWECHSLUNG",
"AUFSTELLUNG",
"ABBRUCH",
"AUSWAEHLEN",
"RAUS",
"AUSWECHSELN",
"REIN",
"FERTIG",
"OPTIONEN",
"SCHIEDSRICHTER : ",
},
{
"GOAL SCORED BY: ",
"BOOKED, YELLOW CARD: ",
"RED CARD, SENT OFF: ",
"DIRECT FREE KICK",
"INDIRECT FREE KICK",
"PENALTY KICK",
"CORNER KICK",
"THROW IN",
"GOAL KICK",
"KICK OFF",
"OFFSIDE",
"PLAYER INJURED: ",
"FULL TIME",
"EXTRA TIME",
"HALF TIME",
"PENALTY SHOOTOUT",
"FINAL SCORE AFTER PENALTIES",
"OWN GOAL BY: ",
"REPLAY",
"SUBSTITUTION",
"FORMATION",
"CANCEL",
"SELECT",
"OFF",
"SUBSTITUTE",
"ON",
"DONE",
"OPTIONS",
"REFEREE : ",
},
{
"BUT DE: ",
"AVERT., C. JAUNE: ",
"C. ROUGE, RENV.: ",
"COUP FR. DIRECT",
"COUP FR. INDIR",
"PENALTY",
"CORNER",
"TOUCHE",
"TIR AU BUT",
"CP. D<ENVOI",
"HORS JEU",
"JOUEUR BLESSE: ",
"TPS TOTAL",
"PROLONG.",
"MI=TEMPS",
"PENALTIES",
"SCORE FINAL APRES PEN.",
"BUT CTRE SOM CAMP DE: ",
"REPLAY",
"REMPLACEMENT",
"FORMATION",
"ANNULER",
"SELECT",
"OFF",
"REMPLACANT",
"ON",
"FAIT",
"OPTIONS",
"ARBITRE : ",
},
{
"M>L SCORET AV: ",
"GULT KORT: ",
"R&DT KORT, SENDT UT: ",
"DIREKTE FRISPARK",
"INDIREKTE FRISPARK",
"STRAFFESPARK",
"CORNER",
"INNKAST",
"UTSPILL FRA M>L",
"AVSPARK",
"OFFSIDE",
"SKADD SPILLER: ",
"FULL TID",
"OVERTID",
"HALVTID",
"STRAFFEKONKURRANSE",
"SLUTTRESULTAT ETTER STRAFFER",
"SELVM>L VED: ",
"REPRISE",
"INNBYTTE",
"FORMASJON",
"AVBRYT",
"VELG",
"AV",
"INNBYTTER",
"P>",
"FERDIG",
"VALG",
"DOMMER : ",
},
};
// Stadia objects
#define MAX_STAD_PTS 400
#define MAX_STAD_FACES 400
obj stad1, stad2, stad3, stad4;
datapt stad1_p[MAX_STAD_PTS * 3], stad2_p[MAX_STAD_PTS * 3], stad3_p[MAX_STAD_PTS * 3], stad4_p[MAX_STAD_PTS * 3];
word stad1_f[MAX_STAD_FACES * 6], stad2_f[MAX_STAD_FACES * 6], stad3_f[MAX_STAD_FACES * 6], stad4_f[MAX_STAD_FACES * 6];
float st_w, st_l, st_h;
/********************* FUNCTION CODE ********************/
/*******************/
/* MATRIX ROUTINES */
void matcop(mat dest, mat src)
// Matrix copy
{
short i;
float *p0, *p1;
p0 = &dest[0][0];
p1 = &src[0][0];
for (i = 0; i < 16; i++)
*p0++ = *p1++;
}
void matmul(mat m1, mat m2)
// Matrix multiply
{
short i, j;
mat res = { 0 };
float *wr = &res[0][0];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
*wr++ = m1[0][j] * m2[i][0] +
m1[1][j] * m2[i][1] +
m1[2][j] * m2[i][2] +
m1[3][j] * m2[i][3];
matcop(m1, res);
}
void matmultr(mat m1, mat m2)
// Reversed matrix multiply.
{
short i, j;
mat res = { 0 };
float *wr = &res[0][0];
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
*wr++ = m1[0][j] * m2[0][i] +
m1[1][j] * m2[1][i] +
m1[2][j] * m2[2][i] +
m1[3][j] * m2[3][i];
matcop(m1, res);
}
/*********************************************/
/* DRAW GROUND (SPECIALIZED TEXTURE MAPPING) */
//dword grtexx[]={0x00000000,0x003fffff,0x003fffff,0x00000000};
//dword grtexy[]={0x00000000,0x00000000,0x003fffff,0x003fffff};
dword grtexx[] = {0x00000000, 0x07ffffff, 0x07ffffff, 0x00000000};
dword grtexy[] = {0x00000000, 0x00000000, 0x057fffff, 0x057fffff};
void ground(float vr, float vwy, datapt vx, datapt vy, datapt vz) {
#ifdef IMPLEMENT_ME
scrpt y, ys[4], ye, yd;
rotpt rx[4], ry[4], rz[4], ze;
float t, d, z, tx, tz, dw1, dw2, sa, sw;
BYTE *scr, *scrline, *cpyline;
word w, flrsel, psh, pan;
static dword td[5] = {0, 0, 0, 0, 0};
// Find highest pt of pitch
ry[0] = -st_l * rot.e.r10 + st_w * rot.e.r12 + rot.e.r13;
rz[0] = -st_l * rot.e.r20 + st_w * rot.e.r22 + rot.e.r23;
ry[1] = (1280 + st_l) * rot.e.r10 + st_w * rot.e.r12 + rot.e.r13;
rz[1] = (1280 + st_l) * rot.e.r20 + st_w * rot.e.r22 + rot.e.r23;
ry[2] = (1280 + st_l) * rot.e.r10 - (800 + st_w) * rot.e.r12 + rot.e.r13;
rz[2] = (1280 + st_l) * rot.e.r20 - (800 + st_w) * rot.e.r22 + rot.e.r23;
ry[3] = -st_l * rot.e.r10 - (800 + st_w) * rot.e.r12 + rot.e.r13;
rz[3] = -st_l * rot.e.r20 - (800 + st_w) * rot.e.r22 + rot.e.r23;
if (scrmode3DB >= 0) {
rx[0] = -st_l * rot.e.r00 + st_w * rot.e.r02 + rot.e.r03;
rx[1] = (1280 + st_l) * rot.e.r00 + st_w * rot.e.r02 + rot.e.r03;
rx[2] = (1280 + st_l) * rot.e.r00 - (800 + st_w) * rot.e.r02 + rot.e.r03;
rx[3] = -st_l * rot.e.r00 - (800 + st_w) * rot.e.r02 + rot.e.r03;
CGL_VERTEX2D_ST *pts3d;
CGL_TEXTURE3D_ST *tex3d;
word np, p, pt, pl;
short i, j, k;
float fc, fc2;
float tpts1[24];
float tpts2[24];
float ttex1[24];
float ttex2[24];
dword *polytexx, *polytexy;
np = 4;
pt = 0;
for (j = 0; j < np; j++) {
k = j + 1;
if (k == np) k = 0;
if (rz[j] >= SCREENDIST)
if (rz[k] >= SCREENDIST) {
tpts2[pt] = rx[k];
ttex2[pt++] = grtexx[k];
tpts2[pt] = ry[k];
ttex2[pt++] = grtexy[k];
tpts2[pt++] = rz[k];
} else {
fc = (float) (rz[j] - SCREENDIST) / (rz[j] - rz[k]);
tpts2[pt] = rx[j] + (fc * (rx[k] - rx[j]));
ttex2[pt++] = grtexx[j] + (fc * (grtexx[k] - grtexx[j]));
tpts2[pt] = ry[j] + (fc * (ry[k] - ry[j]));
ttex2[pt++] = grtexy[j] + (fc * (grtexy[k] - grtexy[j]));
tpts2[pt++] = SCREENDIST;
}
else if (rz[k] >= SCREENDIST) {
fc = (float) (rz[k] - SCREENDIST) / (rz[k] - rz[j]);
tpts2[pt] = rx[k] + (fc * (rx[j] - rx[k]));
ttex2[pt++] = grtexx[k] + (fc * (grtexx[j] - grtexx[k]));
tpts2[pt] = ry[k] + (fc * (ry[j] - ry[k]));
ttex2[pt++] = grtexy[k] + (fc * (grtexy[j] - grtexy[k]));
tpts2[pt++] = SCREENDIST;
tpts2[pt] = rx[k];
ttex2[pt++] = grtexx[k];
tpts2[pt] = ry[k];
ttex2[pt++] = grtexy[k];
tpts2[pt++] = rz[k];
}
}
for (j = 0; j < pt; j += 3) {
tpts2[j] = q * tpts2[j] / tpts2[j + 2] + render_buff.clip_xmid;
tpts2[j + 1] = q * tpts2[j + 1] / tpts2[j + 2] + render_buff.clip_ymid;
}
SetPerspTextureQuadOutput3DB(texaddr3DB[0]);
pts3d = &Vertex[0];
tex3d = (CGL_TEXTURE3D_ST * ) & Texture[0];
p = 0;
for (j = 0; j < pt; j += 3) {
k = j + 3;
if (k == pt) k = 0;
if (tpts2[j] >= 0)
if (tpts2[k] >= 0) {
tpts1[p] = tpts2[k];
ttex1[p++] = ttex2[k];
tpts1[p] = tpts2[k + 1];
ttex1[p++] = ttex2[k + 1];
tpts1[p++] = tpts2[k + 2];
} else {
fc = (float) tpts2[j] / (tpts2[j] - tpts2[k]);
fc2 = (float) tpts2[j + 2] / (tpts2[k + 2] * (float) -tpts2[k] / tpts2[j] + tpts2[j + 2]);
tpts1[p] = 0;
ttex1[p++] = ttex2[j] + (fc2 * (ttex2[k] - ttex2[j]));
tpts1[p] = tpts2[j + 1] + (fc * (tpts2[k + 1] - tpts2[j + 1]));
ttex1[p++] = ttex2[j + 1] + (fc2 * (ttex2[k + 1] - ttex2[j + 1]));
tpts1[p++] = tpts2[j + 2] + (fc2 * (tpts2[k + 2] - tpts2[j + 2]));
}
else if (tpts2[k] >= 0) {
fc = (float) tpts2[k] / (tpts2[k] - tpts2[j]);
fc2 = (float) tpts2[k + 2] / (tpts2[j + 2] * (float) -tpts2[j] / tpts2[k] + tpts2[k + 2]);
tpts1[p] = 0;
ttex1[p++] = ttex2[k] + (fc2 * (ttex2[j] - ttex2[k]));
tpts1[p] = tpts2[k + 1] + (fc * (tpts2[j + 1] - tpts2[k + 1]));
ttex1[p++] = ttex2[k + 1] + (fc2 * (ttex2[j + 1] - ttex2[k + 1]));
tpts1[p++] = tpts2[k + 2] + (fc2 * (tpts2[j + 2] - tpts2[k + 2]));
tpts1[p] = tpts2[k];
ttex1[p++] = ttex2[k];
tpts1[p] = tpts2[k + 1];
ttex1[p++] = ttex2[k + 1];
tpts1[p++] = tpts2[k + 2];
}
}
pt = 0;
for (j = 0; j < p; j += 3) {
k = j + 3;
if (k == p) k = 0;
if (tpts1[j] <= render_buff.clip_wid)
if (tpts1[k] <= render_buff.clip_wid) {
tpts2[pt] = tpts1[k];
ttex2[pt++] = ttex1[k];
tpts2[pt] = tpts1[k + 1];
ttex2[pt++] = ttex1[k + 1];
tpts2[pt++] = tpts1[k + 2];
} else {
fc = (float) (render_buff.clip_wid - tpts1[j]) / (tpts1[k] - tpts1[j]);
fc2 = (float) tpts1[j + 2] / (tpts1[k + 2] * (float) (tpts1[k] - render_buff.clip_wid) /
(render_buff.clip_wid - tpts1[j]) + tpts1[j + 2]);
tpts2[pt] = render_buff.clip_wid;
ttex2[pt++] = ttex1[j] + (fc2 * (ttex1[k] - ttex1[j]));
tpts2[pt] = tpts1[j + 1] + (fc * (tpts1[k + 1] - tpts1[j + 1]));
ttex2[pt++] = ttex1[j + 1] + (fc2 * (ttex1[k + 1] - ttex1[j + 1]));
tpts2[pt++] = tpts1[j + 2] + (fc2 * (tpts1[k + 2] - tpts1[j + 2]));
}
else if (tpts1[k] <= render_buff.clip_wid) {
fc = (float) (render_buff.clip_wid - tpts1[k]) / (tpts1[j] - tpts1[k]);
fc2 = (float) tpts1[k + 2] /
(tpts1[j + 2] * (float) (tpts1[j] - render_buff.clip_wid) / (render_buff.clip_wid - tpts1[k]) +
tpts1[k + 2]);
tpts2[pt] = render_buff.clip_wid;
ttex2[pt++] = ttex1[k] + (fc2 * (ttex1[j] - ttex1[k]));
tpts2[pt] = tpts1[k + 1] + (fc * (tpts1[j + 1] - tpts1[k + 1]));
ttex2[pt++] = ttex1[k + 1] + (fc2 * (ttex1[j + 1] - ttex1[k + 1]));
tpts2[pt++] = tpts1[k + 2] + (fc2 * (tpts1[j + 2] - tpts1[k + 2]));
tpts2[pt] = tpts1[k];
ttex2[pt++] = ttex1[k];
tpts2[pt] = tpts1[k + 1];
ttex2[pt++] = ttex1[k + 1];
tpts2[pt++] = tpts1[k + 2];
}
}
p = 0;
for (j = 0; j < pt; j += 3) {
k = j + 3;
if (k == pt) k = 0;
if (tpts2[j + 1] >= 0)
if (tpts2[k + 1] >= 0) {
tpts1[p] = tpts2[k];
ttex1[p++] = ttex2[k];
tpts1[p] = tpts2[k + 1];
ttex1[p++] = ttex2[k + 1];
tpts1[p++] = tpts2[k + 2];
} else {
fc = (float) tpts2[j + 1] / (tpts2[j + 1] - tpts2[k + 1]);
fc2 = (float) tpts2[j + 2] / (tpts2[k + 2] * (float) -tpts2[k + 1] / tpts2[j + 1] + tpts2[j + 2]);
tpts1[p] = tpts2[j] + (fc * (tpts2[k] - tpts2[j]));
ttex1[p++] = ttex2[j] + (fc2 * (ttex2[k] - ttex2[j]));
tpts1[p] = 0;
ttex1[p++] = ttex2[j + 1] + (fc2 * (ttex2[k + 1] - ttex2[j + 1]));
tpts1[p++] = tpts2[j + 2] + (fc2 * (tpts2[k + 2] - tpts2[j + 2]));
}
else if (tpts2[k + 1] >= 0) {
fc = (float) tpts2[k + 1] / (tpts2[k + 1] - tpts2[j + 1]);
fc2 = (float) tpts2[k + 2] / (tpts2[j + 2] * (float) -tpts2[j + 1] / tpts2[k + 1] + tpts2[k + 2]);
tpts1[p] = tpts2[k] + (fc * (tpts2[j] - tpts2[k]));
ttex1[p++] = ttex2[k] + (fc2 * (ttex2[j] - ttex2[k]));
tpts1[p] = 0;
ttex1[p++] = ttex2[k + 1] + (fc2 * (ttex2[j + 1] - ttex2[k + 1]));
tpts1[p++] = tpts2[k + 2] + (fc2 * (tpts2[j + 2] - tpts2[k + 2]));
tpts1[p] = tpts2[k];
ttex1[p++] = ttex2[k];
tpts1[p] = tpts2[k + 1];
ttex1[p++] = ttex2[k + 1];
tpts1[p++] = tpts2[k + 2];
}
}
pt = 0;
for (j = 0; j < p; j += 3) {
k = j + 3;
if (k == p) k = 0;
if (tpts1[j + 1] <= render_buff.clip_hgtl)
if (tpts1[k + 1] <= render_buff.clip_hgtl) {
pts3d[pt].x = (int) tpts1[k] << 16;
tex3d[pt].s = ttex1[k];
pts3d[pt].y = (int) tpts1[k + 1] << 16;
tex3d[pt].t = ttex1[k + 1];
tex3d[pt++].q = tpts1[k + 2];
} else {
fc = (float) (render_buff.clip_hgtl - tpts1[j + 1]) / (tpts1[k + 1] - tpts1[j + 1]);
fc2 = (float) tpts1[j + 2] / (tpts1[k + 2] * (float) (tpts1[k + 1] - render_buff.clip_hgt) /
(render_buff.clip_hgt - tpts1[j + 1]) + tpts1[j + 2]);
pts3d[pt].x = (int) (tpts1[j] + (fc * (tpts1[k] - tpts1[j]))) << 16;
tex3d[pt].s = ttex1[j] + (int) (fc2 * (ttex1[k] - ttex1[j]));
pts3d[pt].y = render_buff.clip_hgtl << 16;
tex3d[pt].t = ttex1[j + 1] + (int) (fc2 * (ttex1[k + 1] - ttex1[j + 1]));
tex3d[pt++].q = tpts1[j + 2] + (int) (fc2 * (tpts1[k + 2] - tpts1[j + 2]));
}
else if (tpts1[k + 1] <= render_buff.clip_hgtl) {
fc = (float) (render_buff.clip_hgtl - tpts1[k + 1]) / (tpts1[j + 1] - tpts1[k + 1]);
fc2 = tpts1[k + 2] / (tpts1[j + 2] * (float) (tpts1[j + 1] - render_buff.clip_hgt) /
(render_buff.clip_hgt - tpts1[k + 1]) + tpts1[k + 2]);
pts3d[pt].x = (int) (tpts1[k] + (fc * (tpts1[j] - tpts1[k]))) << 16;
tex3d[pt].s = ttex1[k] + (int) (fc2 * (ttex1[j] - ttex1[k]));
pts3d[pt].y = render_buff.clip_hgtl << 16;
tex3d[pt].t = ttex1[k + 1] + (int) (fc2 * (ttex1[j + 1] - ttex1[k + 1]));
tex3d[pt++].q = tpts1[k + 2] + (int) (fc2 * (tpts1[j + 2] - tpts1[k + 2]));
pts3d[pt].x = (int) tpts1[k] << 16;
tex3d[pt].s = ttex1[k];
pts3d[pt].y = (int) tpts1[k + 1] << 16;
tex3d[pt].t = ttex1[k + 1];
tex3d[pt++].q = tpts1[k + 2];
}
}
p = 0;
pl = pt;
while (pl > 4) {
p += 4;
pt += 2;
pl -= 2;
for (j = pt - 1; j > p; j--) {
pts3d[j].x = pts3d[j - 2].x;
pts3d[j].y = pts3d[j - 2].y;
tex3d[j].s = tex3d[j - 2].s;
tex3d[j].t = tex3d[j - 2].t;
tex3d[j].q = tex3d[j - 2].q;
}
pts3d[p].x = pts3d[0].x;
pts3d[p].y = pts3d[0].y;
tex3d[p].s = tex3d[0].s;
tex3d[p].t = tex3d[0].t;
tex3d[p].q = tex3d[0].q;
}
p += pl;
if (pl == 3) {
pts3d[p].x = pts3d[0].x;
pts3d[p].y = pts3d[0].y;
tex3d[p].s = tex3d[0].s;
tex3d[p].t = tex3d[0].t;
tex3d[p].q = tex3d[0].q;
p++;
}
int mz;
float tq;
for (k = 0; k < p; k += 4) {
mz = tex3d[k].q;
for (j = 1; j < 4; j++)
if (tex3d[k + j].q < mz) mz = tex3d[k + j].q;
for (j = 0; j < 4; j++) {
tq = (float) mz / tex3d[k + j].q;
tex3d[k + j].s *= tq;
tex3d[k + j].t *= tq;
tex3d[k + j].q = tq * 65536;
}
}
pts3d += p;
tex3d += p;
if ((p = pts3d - Vertex) > 0) {
SetPerspTextureQuadOutput3DB(pitchaddr3DB);
Render3DB(p);
}
// Find lowest pt of sky
#define ST_DP 200
ry[0] = -(st_l + ST_DP) * rot.e.r10 + st_h * rot.e.r11 + (st_w + ST_DP) * rot.e.r12 + rot.e.r13;
rz[0] = -(st_l + ST_DP) * rot.e.r20 + st_h * rot.e.r21 + (st_w + ST_DP) * rot.e.r22 + rot.e.r23;
ry[1] = (1280 + st_l + ST_DP) * rot.e.r10 + st_h * rot.e.r11 + (st_w + ST_DP) * rot.e.r12 + rot.e.r13;
rz[1] = (1280 + st_l + ST_DP) * rot.e.r20 + st_h * rot.e.r21 + (st_w + ST_DP) * rot.e.r22 + rot.e.r23;
ry[2] = (1280 + st_l + ST_DP) * rot.e.r10 + st_h * rot.e.r11 - (800 + st_w + ST_DP) * rot.e.r12 + rot.e.r13;
rz[2] = (1280 + st_l + ST_DP) * rot.e.r20 + st_h * rot.e.r21 - (800 + st_w + ST_DP) * rot.e.r22 + rot.e.r23;
ry[3] = -(st_l + ST_DP) * rot.e.r10 + st_h * rot.e.r11 - (800 + st_w + ST_DP) * rot.e.r12 + rot.e.r13;
rz[3] = -(st_l + ST_DP) * rot.e.r20 + st_h * rot.e.r21 - (800 + st_w + ST_DP) * rot.e.r22 + rot.e.r23;
if (rz[0] > 0)
ye = q * ry[0] / rz[0], ze = rz[0];
else
ye = render_buff.clip_ymid, ze = 0;
if (rz[1] > ze) ye = q * ry[1] / rz[1], ze = rz[1];
if (rz[2] > ze) ye = q * ry[2] / rz[2], ze = rz[2];
if (rz[3] > ze) ye = q * ry[3] / rz[3], ze = rz[3];
if (ye <= -render_buff.clip_ymid) ye = -render_buff.clip_ymid + 1;
if (ye < render_buff.clip_ymid) {
SetRectangleOutput3DBx(skyaddr3DB);
Vertex[0].x = render_buff.clip_widl << 16;
Vertex[0].y = render_buff.clip_hgt << 16;
Vertex[1].x = 0;
Vertex[1].y = (ye + render_buff.clip_ymid) << 16;
sa = atan(512 / (q * 512 / (640 * ((render_buff.scale_x + render_buff.scale_y) / 2))));
if (sth < 0) {
Texture[0].s = ((int) (512 * acos((double) cth) / sa) % 512) << 16;
Texture[1].s = (511 + ((int) (512 * acos((double) cth) / sa) % 512)) << 16;
} else {
Texture[0].s = -((int) (512 * acos((double) cth) / sa) % 512) << 16;
Texture[1].s = (511 - ((int) (512 * acos((double) cth) / sa) % 512)) << 16;