Mercurial > hg > forks > pwpunix
comparison final_isi/3d.c @ 69:c13a2f8c5b10
Rename files and some minor cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 01 Jun 2012 17:41:15 +0300 |
parents | final_isi/fisi3d.c@53676367d46f |
children | e76a4e19363d |
comparison
equal
deleted
inserted
replaced
68:48c3defeca8f | 69:c13a2f8c5b10 |
---|---|
1 #include "wrapper.h" | |
2 | |
3 /*****/ | |
4 | |
5 char txr_wsygn[16*16]={ /* syaani/sininen. hieno. parempi keltapunas„vyiss„? */ | |
6 0x11,0x19,0x97,0x97,0x97,0x11,0x11,0x11,0x79,0x97,0x97,0x97,0x11,0x11,0x11,0x11, | |
7 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x79,0x97,0x97,0x97,0x11,0x19,0x11,0x11, | |
8 0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x19,0x97,0x97,0x97,0x79,0x19,0x11,0x11, | |
9 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x11, | |
10 0x11,0x91,0x97,0x97,0x97,0x91,0x11,0x11,0x19,0x79,0x97,0x97,0x97,0x79,0x11,0x11, | |
11 0x11,0x19,0x97,0x77,0x97,0x11,0x11,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x11, | |
12 0x11,0x79,0x97,0x97,0x97,0x97,0x79,0x19,0x11,0x97,0x97,0x97,0x79,0x19,0x11,0x11, | |
13 0x11,0x11,0x91,0x97,0x77,0x97,0x19,0x11,0x11,0x91,0x97,0x97,0x97,0x79,0x10,0x10, | |
14 0x11,0x11,0x11,0x97,0x77,0x97,0x19,0x11,0x11,0x11,0x97,0x77,0x97,0x11,0x11,0x10, | |
15 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x10, | |
16 0x11,0x19,0x97,0x97,0x97,0x91,0x11,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x10, | |
17 0x11,0x19,0x97,0x77,0x97,0x11,0x11,0x11,0x11,0x97,0x77,0x97,0x79,0x19,0x11,0x11, | |
18 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x10,0x97,0x97,0x97,0x97,0x19,0x11,0x11, | |
19 0x11,0x11,0x91,0x97,0x97,0x97,0x19,0x11,0x19,0x79,0x97,0x97,0x97,0x11,0x11,0x11, | |
20 0x11,0x19,0x79,0x97,0x97,0x97,0x19,0x11,0x19,0x97,0x97,0x97,0x91,0x19,0x11,0x11, | |
21 0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x79,0x97,0x97,0x97,0x79,0x19,0x11,0x10 | |
22 }; | |
23 | |
24 | |
25 char txr_dunneon[16*16]={ /* neonjuovia. k„ytett„v„. */ | |
26 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
27 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
28 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
29 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
30 0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80, | |
31 0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, | |
32 0x80,0x80,0x08,0x00,0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, | |
33 0x80,0x80,0x08,0x00,0x80,0x80,0x08,0x08,0x80,0x80,0x80,0x08,0x08,0x80,0x80,0x80, | |
34 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
35 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80, | |
36 0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x80, | |
37 0x80,0x80,0x08,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, | |
38 0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x08,0x80,0x80,0x08,0x00,0x08,0x80,0x80,0x80, | |
39 0x80,0x80,0x08,0x00,0x80,0x80,0x80,0x08,0x80,0x80,0x08,0x08,0x08,0x80,0x80,0x80, | |
40 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x00,0x08,0x80,0x80,0x80, | |
41 0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x08,0x80,0x80,0x80,0x80 | |
42 }; | |
43 | |
44 char txr_unneon[16*16]={ | |
45 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
46 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
47 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
48 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
49 0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x78, | |
50 0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, | |
51 0x78,0x78,0x07,0x00,0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, | |
52 0x78,0x78,0x07,0x00,0x78,0x78,0x07,0x07,0x78,0x78,0x78,0x07,0x07,0x78,0x78,0x78, | |
53 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
54 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78, | |
55 0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x00,0x78,0x78,0x78,0x78, | |
56 0x78,0x78,0x07,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, | |
57 0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x07,0x78,0x78,0x07,0x00,0x07,0x78,0x78,0x78, | |
58 0x78,0x78,0x07,0x00,0x78,0x78,0x78,0x07,0x78,0x78,0x07,0x07,0x07,0x78,0x78,0x78, | |
59 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x00,0x07,0x78,0x78,0x78, | |
60 0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78,0x78,0x78,0x78,0x07,0x78,0x78,0x78,0x78 | |
61 }; | |
62 | |
63 char txr_neon[16*16]={ | |
64 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, | |
65 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00, | |
66 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, | |
67 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x5c,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, | |
68 0x00,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x00, | |
69 0x00,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, | |
70 0x00,0x00,0x04,0x5c,0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, | |
71 0x00,0x00,0x04,0x5c,0x00,0x00,0x04,0x40,0x00,0x00,0x00,0x40,0x04,0x00,0x00,0x00, | |
72 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00, | |
73 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00, | |
74 0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x5c,0x00,0x00,0x00,0x00, | |
75 0x00,0x00,0x04,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, | |
76 0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x40,0x00,0x00,0x04,0x5c,0x04,0x00,0x00,0x00, | |
77 0x00,0x00,0x04,0x5c,0x00,0x00,0x00,0x04,0x00,0x00,0x04,0x40,0x04,0x00,0x00,0x00, | |
78 0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x5c,0x04,0x00,0x00,0x00, | |
79 0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00 | |
80 }; | |
81 | |
82 char txr_gslime[16*16]={ | |
83 0x88,0x80,0x00,0x80,0x80,0x88,0x88,0x88,0x80,0x08,0x00,0x00,0x08,0x88,0x80,0x00, | |
84 0x80,0x08,0x00,0x08,0x80,0x80,0x80,0x80,0x00,0x00,0x00,0x80,0x88,0x80,0x08,0x00, | |
85 0x08,0x00,0x00,0x00,0x08,0x08,0x80,0x00,0x00,0x00,0x08,0x80,0x80,0x00,0x00,0x88, | |
86 0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x08,0x00,0x00,0x80,0x00,0x08,0x88,0x80, | |
87 0x00,0x08,0x80,0x08,0x00,0x00,0x08,0x88,0x88,0x88,0x00,0x80,0x00,0x08,0x80,0x00, | |
88 0x08,0x80,0x80,0x08,0x00,0x08,0x80,0x88,0x88,0x88,0x08,0x80,0x00,0x00,0x00,0x08, | |
89 0x88,0x88,0x88,0x80,0x00,0x08,0x80,0x88,0x88,0x88,0x80,0x80,0x00,0x00,0x08,0x80, | |
90 0x88,0x88,0x80,0x80,0x00,0x00,0x08,0x80,0x80,0x08,0x00,0x00,0x00,0x80,0x88,0x88, | |
91 0x88,0x88,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x88,0x88, | |
92 0x80,0x80,0x00,0x00,0x08,0x08,0x00,0x00,0x08,0x80,0x80,0x80,0x80,0x80,0x08,0x88, | |
93 0x08,0x00,0x08,0x80,0x80,0x80,0x00,0x00,0x00,0x00,0x08,0x08,0x80,0x80,0x08,0x88, | |
94 0x80,0x80,0x80,0x80,0x08,0x00,0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x80, | |
95 0x88,0x88,0x88,0x88,0x88,0x80,0x80,0x80,0x08,0x08,0x00,0x00,0x08,0x08,0x00,0x80, | |
96 0x88,0x88,0x88,0x88,0x88,0x80,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00, | |
97 0x88,0x88,0x88,0x08,0x00,0x00,0x00,0x00,0x08,0x08,0x08,0x00,0x00,0x80,0x80,0x00, | |
98 0x88,0x08,0x00,0x00,0x00,0x00,0x08,0x08,0x80,0x80,0x80,0x08,0x00,0x88,0x80,0x80 | |
99 }; | |
100 | |
101 char txr_slime[16*16]={ /* vihre„ laikukas. hienokiva. */ | |
102 0x22,0x20,0x00,0x20,0x20,0x22,0x22,0x22,0x20,0x02,0x00,0x00,0x02,0x22,0x20,0x00, | |
103 0x20,0x02,0x00,0x02,0x20,0x20,0x20,0x20,0x00,0x00,0x00,0x20,0x22,0x20,0x02,0x00, | |
104 0x02,0x00,0x00,0x00,0x02,0x02,0x20,0x00,0x00,0x00,0x02,0x20,0x20,0x00,0x00,0x22, | |
105 0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x20,0x00,0x02,0x22,0x20, | |
106 0x00,0x02,0x20,0x02,0x00,0x00,0x02,0x22,0x22,0x22,0x00,0x20,0x00,0x02,0x20,0x00, | |
107 0x02,0x20,0x20,0x02,0x00,0x02,0x20,0x22,0x22,0x22,0x02,0x20,0x00,0x00,0x00,0x02, | |
108 0x22,0x22,0x22,0x20,0x00,0x02,0x20,0x22,0x22,0x22,0x20,0x20,0x00,0x00,0x02,0x20, | |
109 0x22,0x22,0x20,0x20,0x00,0x00,0x02,0x20,0x20,0x02,0x00,0x00,0x00,0x20,0x22,0x22, | |
110 0x22,0x22,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x22,0x22, | |
111 0x20,0x20,0x00,0x00,0x02,0x02,0x00,0x00,0x02,0x20,0x20,0x20,0x20,0x20,0x02,0x22, | |
112 0x02,0x00,0x02,0x20,0x20,0x20,0x00,0x00,0x00,0x00,0x02,0x02,0x20,0x20,0x02,0x22, | |
113 0x20,0x20,0x20,0x20,0x02,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x20, | |
114 0x22,0x22,0x22,0x22,0x22,0x20,0x20,0x20,0x02,0x02,0x00,0x00,0x02,0x02,0x00,0x20, | |
115 0x22,0x22,0x22,0x22,0x22,0x20,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00, | |
116 0x22,0x22,0x22,0x02,0x00,0x00,0x00,0x00,0x02,0x02,0x02,0x00,0x00,0x20,0x20,0x00, | |
117 0x22,0x02,0x00,0x00,0x00,0x00,0x02,0x02,0x20,0x20,0x20,0x02,0x00,0x22,0x20,0x20 | |
118 }; | |
119 | |
120 typedef struct{signed int x,z,y;}xyz; | |
121 typedef struct{signed int a,r,y;}cyl; | |
122 typedef struct{int p[3]; int nn; char*txrf,*txrb;}face; | |
123 | |
124 typedef struct{ | |
125 | |
126 int numvxes; | |
127 cyl*vxes; | |
128 xyz*rotated; | |
129 | |
130 int numfaces; | |
131 face*faces; | |
132 | |
133 }obj3d; | |
134 | |
135 #define sint signed int | |
136 | |
137 /** XWING **/ | |
138 | |
139 /* | |
140 xyz cube_vxes[]={ | |
141 -6000,-1000,2000, | |
142 -6000,-1000,-2000, | |
143 6000,-1000,2000, | |
144 6000,-1000,-2000, | |
145 | |
146 -1500,2000,0, | |
147 -1500,-1000,0, | |
148 1500,2000,0, | |
149 1500,-100,0, | |
150 | |
151 0,2500,0, | |
152 | |
153 0,1000,-1500 | |
154 }; | |
155 | |
156 face cube_faces[]={ | |
157 0,4,5, 0, txr_wsygn,txr_dunneon, | |
158 1,5,4, 0, txr_wsygn,txr_dunneon, | |
159 2,7,6, 0, txr_wsygn,txr_dunneon, | |
160 3,6,7, 0, txr_wsygn,txr_dunneon, | |
161 | |
162 9,8,4, 0, txr_wsygn,NULL, | |
163 9,7,8, 0, txr_wsygn,NULL, | |
164 9,4,5, 0, txr_unneon,NULL, | |
165 9,7,6, 0, txr_unneon,NULL, | |
166 9,5,6, 0, txr_unneon,NULL | |
167 }; | |
168 */ | |
169 | |
170 /********/ | |
171 /********/ | |
172 | |
173 cyl xwing_vxes[]={ | |
174 134,6082,1000, | |
175 134,6082,-1000, | |
176 250,6082,1000, | |
177 250,6082,-1000, | |
178 91,3000,0, /* 2500 */ | |
179 151,1802,0, | |
180 37,3000,0, /* 2500 */ | |
181 254,1503,0, | |
182 64,2500,0, | |
183 64,1000,-750 | |
184 }; | |
185 | |
186 face xwing_faces[]={ | |
187 4,5,0, 0, txr_wsygn,txr_dunneon, | |
188 1,5,4, 0, txr_wsygn,txr_dunneon, | |
189 7,6,2, 0, txr_wsygn,txr_dunneon, | |
190 3,6,7, 0, txr_wsygn,txr_dunneon, | |
191 | |
192 9,8,4, 0, txr_wsygn,NULL, | |
193 9,7,8, 0, txr_wsygn,NULL, | |
194 9,4,5, 0, txr_unneon,NULL, | |
195 9,7,6, 0, txr_unneon,NULL, | |
196 9,5,6, 0, txr_unneon,NULL | |
197 }; | |
198 | |
199 obj3d xwing={ | |
200 10,xwing_vxes,NULL,9,xwing_faces | |
201 }; | |
202 | |
203 cyl bugi_vxes[]={ | |
204 96,2828,0, | |
205 32,2828,0, | |
206 224,2828,0, | |
207 160,2828,0, | |
208 0,0,-800, | |
209 45,6708,1000, | |
210 238,6708,1000, | |
211 173,6708,1000, | |
212 110,6708,1000 | |
213 }; | |
214 | |
215 face bugi_faces[]={ | |
216 4,1,0, 0, txr_slime,NULL, | |
217 4,2,1, 0, txr_slime,NULL, | |
218 4,3,2, 0, txr_slime,NULL, | |
219 4,0,3, 0, txr_slime,NULL, | |
220 | |
221 0,1,5, 0, txr_slime,txr_gslime, | |
222 1,2,6, 0, txr_slime,txr_gslime, | |
223 2,3,7, 0, txr_slime,txr_gslime, | |
224 3,0,8, 0, txr_slime,txr_gslime | |
225 }; | |
226 | |
227 obj3d bugi={ | |
228 9,bugi_vxes,NULL,8,bugi_faces | |
229 }; | |
230 | |
231 obj3d obu; | |
232 | |
233 #include "sini16.h" | |
234 | |
235 sint dvhtab[50]; | |
236 sint dutab[320]; | |
237 | |
238 eggine_init() | |
239 { | |
240 int i; | |
241 dvhtab[0]=32760; | |
242 for(i=1;i<50;i++)dvhtab[i]=4096/i; | |
243 dutab[0]=32760; | |
244 for(i=1;i<320;i++)dutab[i]=(64*256)/i; | |
245 } | |
246 | |
247 eggine_load(sint n) | |
248 { | |
249 obj3d*o; | |
250 if(!n)o=&xwing;else o=&bugi; | |
251 | |
252 if(o->rotated==NULL) | |
253 o->rotated=malloc(o->numvxes*sizeof(xyz)); | |
254 | |
255 memcpy(&obu,o,sizeof(obu)); | |
256 } | |
257 | |
258 extern int polytxloop | |
259 (sint h,char*di,unsigned int x1,sint dx0,sint dx1,char*txr, | |
260 sint dv,sint du); | |
261 | |
262 sint polytxr( | |
263 char*buf, | |
264 sint y,sint h,sint x0,sint x1,sint dx0,sint dx1, | |
265 char*txr){ | |
266 | |
267 register sint du; char joo=0; | |
268 | |
269 if(y+h>=50)h=49-y; | |
270 if(h>0)if(y>=0){ | |
271 | |
272 if((x0>x1)||((x0==x1)&&(dx0>dx1))) | |
273 {sint tmp=x0;x0=x1;x1=tmp; | |
274 tmp=dx0;dx0=dx1;dx1=tmp; | |
275 joo=1;} | |
276 x1-=x0;dx1-=dx0; | |
277 | |
278 du=x1>>6; | |
279 if(!du)du=((dx1-dx0)*h) >>6; /* dx1-dx0?? */ | |
280 if(du)du=(64*256)/du;/*dutab[du];*/ | |
281 | |
282 x1=polytxloop(h,buf+80*y+(x0>>8), | |
283 x1, | |
284 dx0, | |
285 dx1, | |
286 txr, | |
287 dvhtab[h], | |
288 du); | |
289 | |
290 return (!joo)?x0+x1+h*dx0:x1; | |
291 } | |
292 } | |
293 | |
294 /*******************************/ | |
295 | |
296 extern signed int mul32(signed int a,signed int b); | |
297 | |
298 #define jmul32(a,b) (((long)(a)*(long)(b))>>16) | |
299 | |
300 eggine_do(char*b,sint rot,int zoom,int basex,int basey) { | |
301 register sint i; sint j; sint fzed[20],fcez[20]; | |
302 | |
303 if(obu.faces==bugi_faces){ | |
304 bugi_vxes[5].y=bugi_vxes[6].y= | |
305 1000+mul32(700,sini16[(taimeri*13)&255]); | |
306 bugi_vxes[7].y=bugi_vxes[8].y= | |
307 1000+mul32(700,sini16[(taimeri*7)&255]); | |
308 } | |
309 | |
310 /***** rotate vertices *****/ | |
311 | |
312 {cyl*v=obu.vxes;xyz*r=obu.rotated; | |
313 | |
314 for(i=obu.numvxes;i;i--) { | |
315 r->y=mul32(v->y,zoom)+basey; | |
316 r->x=mul32(mul32(v->r,sini16[(rot+v->a)&255]),zoom)+basex; | |
317 r->z=mul32(mul32(v->r,sini16[(rot+v->a+64)&255]),zoom); | |
318 r++;v++; | |
319 }} | |
320 | |
321 /***** calc facezeds, sort faces *****/ | |
322 | |
323 {sint *t=fzed;face*f=obu.faces; for(i=obu.numfaces;i;i--){ | |
324 *t++=obu.rotated[f->p[0]].z+ obu.rotated[f->p[1]].z+ | |
325 obu.rotated[f->p[2]].z; f++; | |
326 }} | |
327 | |
328 {sint *t=fcez;sint j=0; for(i=obu.numfaces;i;i--)*t++=j++; } | |
329 | |
330 /* stupid bubblesort */ | |
331 | |
332 for(i=0;i<obu.numfaces-1;i++){ sint min=fzed[i],where=i; | |
333 for(j=i+1;j<obu.numfaces;j++){ | |
334 if(fzed[j]<min){min=fzed[j];where=j;} } | |
335 | |
336 {sint tmp=fzed[i];fzed[i]=fzed[where];fzed[where]=tmp;} {sint | |
337 tmp=fcez[i];fcez[i]=fcez[where];fcez[where]=tmp;} | |
338 } | |
339 | |
340 /***** draw faces *****/ | |
341 | |
342 {sint*fc=fcez; for(i=obu.numfaces;i;i--) { | |
343 face*f=&obu.faces[*fc++]; | |
344 | |
345 { sint x0,x1,x2,y0,y1,y2,nz; char*txr; | |
346 | |
347 /***************************************/ | |
348 | |
349 {xyz*tmp=obu.rotated; | |
350 x0=tmp[f->p[0]].x<<3; | |
351 y0=tmp[f->p[0]].y>>5; | |
352 x1=tmp[f->p[1]].x<<3; | |
353 y1=tmp[f->p[1]].y>>5; | |
354 x2=tmp[f->p[2]].x<<3; | |
355 y2=tmp[f->p[2]].y>>5; | |
356 } | |
357 | |
358 nz=((x1-x0)>>8)*(y2-y0)-((x2-x0)>>8)*(y1-y0); | |
359 if(nz<0)txr=f->txrf;else txr=f->txrb; | |
360 if(txr!=NULL) | |
361 { | |
362 | |
363 if(y0!=y2){ | |
364 | |
365 sint tmpk,tmpx2; | |
366 | |
367 if (y0!=y1) | |
368 tmpx2=polytxr(b,y0,y1-y0,x0,x0, | |
369 (x1-x0)/(y1-y0), | |
370 tmpk=(x2-x0)/(y2-y0), txr); | |
371 else {tmpk=(x2-x0)/(y2-y0);tmpx2=x0;} | |
372 | |
373 if (y1!=y2) | |
374 polytxr(b,y1,y2-y1,x1,tmpx2, | |
375 (x2-x1)/(y2-y1), | |
376 tmpk, txr); | |
377 } | |
378 } | |
379 /***************************************/ | |
380 } | |
381 | |
382 }}/* end drawfaces*/ | |
383 } |