2496
|
1 #define _CRTDBG_MAP_ALLOC
|
|
2 #include <stdlib.h>
|
|
3 #include <crtdbg.h>
|
|
4
|
|
5 #define _CRT_SECURE_NO_WARNINGS
|
|
6 #include "stru9.h"
|
|
7 #include "IndoorCameraD3D.h"
|
|
8
|
2499
|
9 #include "../mm7_data.h"
|
2496
|
10
|
|
11
|
|
12
|
|
13 //----- (00498377) --------------------------------------------------------
|
|
14 bool stru9::_498377(struct RenderVertexSoft *pPortalBounding, unsigned int uNumVertices, struct IndoorCameraD3D_Vec4 *pVertices, struct RenderVertexSoft *pVertices2, unsigned int *pOutNumVertices)
|
|
15 {
|
|
16 int result; // eax@7
|
|
17 RenderVertexSoft *v9; // ecx@9
|
|
18 RenderVertexSoft *v19; // [sp+14h] [bp-14h]@0
|
|
19 signed int v21; // [sp+1Ch] [bp-Ch]@7
|
|
20
|
|
21 //__debugbreak();
|
|
22 //thisa = this;
|
|
23 return true;
|
|
24
|
|
25 static RenderVertexSoft static_AE3FB4;
|
|
26 /*static bool __init_flag1 = false;
|
|
27 if (!__init_flag1)
|
|
28 {
|
|
29 __init_flag1 = true;
|
|
30
|
|
31 static_AE3FB4.flt_2C = 0.0;
|
|
32 }*/
|
|
33
|
|
34 static stru312 static_AE3FA4; // idb
|
|
35 /*static bool __init_flag2 = false;
|
|
36 if (!__init_flag2)
|
|
37 {
|
|
38 __init_flag2 = true;
|
|
39
|
|
40 //stru312::stru312(&static_AE3FA4);
|
|
41 }*/
|
|
42
|
|
43 static VertexBuffer static_AE33A0; // idb
|
|
44 /*static bool __init_flag3 = false;
|
|
45 if (!__init_flag3)
|
|
46 {
|
|
47 __init_flag3 = true;
|
|
48
|
|
49 //VertexBuffer::VertexBuffer(&static_AE33A0);
|
|
50 }*/
|
|
51
|
|
52 result = false;
|
|
53 //v7 = pOutNumVertices;
|
|
54 v21 = 0;
|
|
55 if ( (signed int)uNumVertices <= 0 )
|
|
56 {
|
|
57 *pOutNumVertices = 0;
|
|
58 return true;
|
|
59 }
|
|
60 //a2 = a1;
|
|
61 //v8 = (char *)&a3->y;
|
|
62 //v18 = (char *)&a3->y;
|
|
63 //do
|
|
64 for (uint j = 0; j < uNumVertices; j++ )
|
|
65 {
|
|
66 //v17 = result + 1;
|
|
67 result = j;
|
|
68 v9 = &pPortalBounding[(j + 1) % (signed int)uNumVertices];
|
|
69 if ( pPortalBounding->vWorldPosition.x != v9->vWorldPosition.x
|
|
70 || pPortalBounding->vWorldPosition.y != v9->vWorldPosition.y
|
|
71 || pPortalBounding->vWorldPosition.z != v9->vWorldPosition.z )
|
|
72 {
|
|
73 //v10 = a3->z;
|
|
74 //v11 = a3->y;
|
|
75 ++v21;
|
|
76 //result = 0;
|
|
77 static_AE33A0.uNumVertices = 0;
|
|
78 //a3a = 0;
|
|
79 static_AE3FA4.x = pVertices->x;
|
|
80 static_AE3FA4.y = pVertices->y;
|
|
81 static_AE3FA4.z = pVertices->z;
|
|
82 if ( (signed int)*pOutNumVertices <= 0 )
|
|
83 {
|
|
84 *pOutNumVertices = 0;
|
|
85 return true;
|
|
86 }
|
|
87 //do
|
|
88 for ( int i = 0; i < (signed int)*pOutNumVertices; i++ )
|
|
89 {
|
|
90 //v12 = &pVertices[result];
|
|
91 if ( result )
|
|
92 {
|
|
93 if ( _4989E1(&pVertices2[i], &pVertices2[i], pPortalBounding, &static_AE3FA4)
|
|
94 && _498774(&pVertices2[i], &pVertices2[i], pPortalBounding, &static_AE3FA4, &static_AE3FB4) )
|
|
95 AddVertex(&static_AE33A0, &static_AE3FB4);
|
|
96 }
|
|
97 else
|
|
98 {
|
|
99 v19 = &pVertices2[i];
|
|
100 }
|
|
101 //v20 = v12;
|
|
102 if ( AreVectorsCollinear(&pVertices2[i], pPortalBounding, &static_AE3FA4) )
|
|
103 AddVertex(&static_AE33A0, &pVertices2[i]);
|
|
104 //pOutNumVertices = pOutNumVertices;
|
|
105 //a3a++;
|
|
106 }
|
|
107 //while ( a3a < (signed int)*pOutNumVertices );
|
|
108 if ( !static_AE33A0.uNumVertices )
|
|
109 {
|
|
110 *pOutNumVertices = 0;
|
|
111 return true;
|
|
112 }
|
|
113 if ( _4989E1(&pVertices2[result], v19, pPortalBounding, &static_AE3FA4)
|
|
114 && _498774(&pVertices2[result], v19, pPortalBounding, &static_AE3FA4, &static_AE3FB4) )
|
|
115 AddVertex(&static_AE33A0, &static_AE3FB4);
|
|
116
|
|
117 for (uint i = 0; i < static_AE33A0.uNumVertices; ++i)
|
|
118 {
|
|
119 pVertices2[i].vWorldPosition.x = static_AE33A0.pVertices[i].vWorldPosition.x;
|
|
120 pVertices2[i].vWorldPosition.y = static_AE33A0.pVertices[i].vWorldPosition.y;
|
|
121 pVertices2[i].vWorldPosition.z = static_AE33A0.pVertices[i].vWorldPosition.z;
|
|
122 pVertices2[i].u = static_AE33A0.pVertices[i].u;
|
|
123 pVertices2[i].v = static_AE33A0.pVertices[i].v;
|
|
124 }
|
|
125
|
|
126 //v13 = static_AE33A0.uNumVertices;
|
|
127 /*a3b = 0;
|
|
128 if ( static_AE33A0.uNumVertices > 0 )
|
|
129 {
|
|
130 v14 = &static_AE33A0;
|
|
131 v15 = (char *)&pVertices->vWorldPosition.y;
|
|
132 for ( i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y - (char *)pVertices;
|
|
133 ;
|
|
134 i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y - (char *)pVertices )
|
|
135 {
|
|
136 ++a3b;
|
|
137 pVertices->vWorldPosition.x = v14->pVertices[0].vWorldPosition.x;
|
|
138 v14 = (VertexBuffer *)((char *)v14 + 48);
|
|
139 pVertices->vWorldPosition.y = *(float *)&v15[(char *)&static_AE33A0 - (char *)pVertices];
|
|
140 pVertices->vWorldPosition.z = *(float *)&v15[i];
|
|
141 pVertices->u = *(float *)&v15[(char *)&static_AE33A0.pVertices[0]._rhw - (char *)pVertices];
|
|
142 pVertices->v = *(float *)&v15[(char *)&static_AE33A0.pVertices[0].u - (char *)pVertices];
|
|
143 //static_AE33A0.uNumVertices = static_AE33A0.uNumVertices;
|
|
144 v15 += 48;
|
|
145 if ( a3b >= static_AE33A0.uNumVertices )
|
|
146 break;
|
|
147 }
|
|
148 }*/
|
|
149
|
|
150 //v7 = pOutNumVertices;
|
|
151 //a3->y = a3->y;
|
|
152 *pOutNumVertices = static_AE33A0.uNumVertices;
|
|
153 }
|
|
154 //result = v17;
|
|
155 ++pPortalBounding;
|
|
156 pVertices++;
|
|
157 //v18 = (char *)&a3->y;
|
|
158 }
|
|
159 //while ( v17 < (signed int)uNumVertices );
|
|
160 if ( v21 < 3 )
|
|
161 *pOutNumVertices = 0;
|
|
162 return true;
|
|
163 }
|
|
164
|
|
165
|
|
166 //----- (004985FB) --------------------------------------------------------
|
|
167 bool stru9::CalcPortalShape(struct RenderVertexSoft *a1, signed int a2, struct RenderVertexSoft *pVertices, unsigned int *pOutNumVertices, struct Vec3_float_ *a5, float a6, char *a7, int unused)
|
|
168 {
|
|
169 //RenderVertexSoft *v9; // ecx@1
|
|
170 //Vec3_float_ *v10; // esi@1
|
|
171 //char *v11; // ebx@1
|
|
172 //RenderVertexSoft *pVertices; // edi@1
|
|
173 double pLinelength1; // st7@1
|
|
174 //bool result; // eax@4
|
|
175 signed int v15; // edx@9
|
|
176 RenderVertexSoft *pLineEnd; // ecx@9
|
|
177 double pLinelength2; // st7@9
|
|
178 double t; // st6@12
|
|
179 signed int v19; // [sp+Ch] [bp-Ch]@7
|
|
180 //float v20; // [sp+10h] [bp-8h]@1
|
|
181 bool v21; // [sp+14h] [bp-4h]@2
|
|
182
|
|
183 //v9 = a1;
|
|
184 //v10 = a5;
|
|
185 //v11 = (char *)&a1->vWorldPosition.z;
|
|
186 RenderVertexSoft* pLineStart = &a1[0];
|
|
187 //pVertices = a3;
|
|
188 pLinelength1 = a5->x * a1[0].vWorldPosition.x + a1[0].vWorldPosition.y * a5->y + a1[0].vWorldPosition.z * a5->z;
|
|
189 //v20 = v13;
|
|
190 v21 = pLinelength1 >= a6;
|
|
191
|
|
192 *pOutNumVertices = 0;
|
|
193 if ( a2 <= 0 )
|
|
194 return false;
|
|
195 v19 = 1;
|
|
196
|
|
197 while ( 1 )
|
|
198 {
|
|
199 if ( v21 )
|
|
200 {
|
|
201 //++pVertices;
|
|
202 memcpy(pVertices, pLineStart, sizeof(RenderVertexSoft));
|
|
203 ++*pOutNumVertices;
|
|
204 //v10 = a5;
|
|
205 pVertices++;
|
|
206 //v9 = a1;
|
|
207 }
|
|
208 v15 = 0;
|
|
209 pLineEnd = &a1[v19 % a2];
|
|
210 pLinelength2 = a5->x * pLineEnd->vWorldPosition.x + pLineEnd->vWorldPosition.y * a5->y + pLineEnd->vWorldPosition.z * a5->z;
|
|
211 if ( pLinelength2 >= a6 )
|
|
212 v15 = 1;
|
|
213
|
|
214 if ( v21 != v15 )
|
|
215 {
|
|
216 t = (a6 - pLinelength1) / (pLinelength2 - pLinelength1);
|
|
217 pVertices->vWorldPosition.x = pLineStart->vWorldPosition.x + (pLineEnd->vWorldPosition.x - pLineStart->vWorldPosition.x) * t;
|
|
218 pVertices->vWorldPosition.y = pLineStart->vWorldPosition.y + (pLineEnd->vWorldPosition.y - pLineStart->vWorldPosition.y) * t;
|
|
219 pVertices->vWorldPosition.z = pLineStart->vWorldPosition.z + (pLineEnd->vWorldPosition.z - pLineStart->vWorldPosition.z) * t;
|
|
220 pVertices->u = pLineStart->u + (pLineEnd->u - pLineStart->u) * t;
|
|
221 pVertices->v = pLineStart->v + (pLineEnd->v - pLineStart->v) * t;
|
|
222 ++pVertices;
|
|
223 //a3 = pVertices;
|
|
224 ++*pOutNumVertices;
|
|
225 *a7 = 1;
|
|
226 }
|
|
227
|
|
228 pLineStart++;
|
|
229 v21 = v15;
|
|
230 pLinelength1 = pLinelength2;
|
|
231 if ( v19 >= a2 )
|
|
232 break;
|
|
233 //v9 = a1;
|
|
234 v19++;
|
|
235 }
|
|
236
|
|
237 return *pOutNumVertices >= 3;
|
|
238 }
|
|
239
|
|
240 //----- (00498737) --------------------------------------------------------
|
|
241 void stru9::AddVertex(struct VertexBuffer *pVertexBuffer, struct RenderVertexSoft *pVertex)
|
|
242 {
|
|
243 // __debugbreak();
|
|
244 RenderVertexSoft *v3; // eax@1
|
|
245
|
|
246 v3 = &pVertexBuffer->pVertices[pVertexBuffer->uNumVertices];
|
|
247 v3->vWorldPosition.x = pVertex->vWorldPosition.x;
|
|
248 v3->vWorldPosition.y = pVertex->vWorldPosition.y;
|
|
249 v3->vWorldPosition.z = pVertex->vWorldPosition.z;
|
|
250 v3->u = pVertex->u;
|
|
251 v3->v = pVertex->v;
|
|
252 ++pVertexBuffer->uNumVertices;
|
|
253 }
|
|
254
|
|
255 //----- (00498774) --------------------------------------------------------
|
|
256 bool stru9::_498774(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4, struct RenderVertexSoft *a5)
|
|
257 {
|
|
258 RenderVertexSoft *v6; // ecx@5
|
|
259 int result; // eax@5
|
|
260 double v8; // st7@5
|
|
261 __int16 v9; // fps@5
|
|
262 double v10; // st7@6
|
|
263 double v11; // st6@8
|
|
264 double v12; // st6@18
|
|
265 char v13; // c0@24
|
|
266 char v14; // c2@24
|
|
267 char v15; // c3@24
|
|
268 float a1a; // [sp+10h] [bp+8h]@5
|
|
269
|
|
270 __debugbreak();
|
|
271
|
|
272 static stru312 static_AE3388;
|
|
273 static stru312 static_AE3378;
|
|
274
|
|
275 v6 = a1;
|
|
276 static_AE3378.x = a1->vWorldPosition.x - a3->vWorldPosition.x;
|
|
277 static_AE3378.y = a1->vWorldPosition.y - a3->vWorldPosition.y;
|
|
278 HIWORD(result) = HIWORD(a4);
|
|
279 static_AE3378.z = a1->vWorldPosition.z - a3->vWorldPosition.z;
|
|
280 static_AE3388.x = a2->vWorldPosition.x - a1->vWorldPosition.x;
|
|
281 static_AE3388.y = a2->vWorldPosition.y - a1->vWorldPosition.y;
|
|
282 static_AE3388.z = a2->vWorldPosition.z - a1->vWorldPosition.z;
|
|
283 a1a = static_AE3388.x * a4->x + static_AE3388.z * a4->z + static_AE3388.y * a4->y;
|
|
284 v8 = static_AE3378.x * a4->x + static_AE3378.z * a4->z + static_AE3378.y * a4->y;
|
|
285 //UNDEF(v9);
|
|
286 if ( a1a != 0.0 )
|
|
287 {
|
|
288 v10 = -(v8 / a1a);
|
|
289 if ( a1a <= 0.0 )
|
|
290 {
|
|
291 if ( v10 <= 0.0 )
|
|
292 v12 = 0.0;
|
|
293 else
|
|
294 v12 = v10;
|
|
295 if ( v12 <= 1.0 )
|
|
296 {
|
|
297 if ( v10 <= 0.0 )
|
|
298 v10 = (float)0.0;
|
|
299 }
|
|
300 else
|
|
301 v10 = 1.0;
|
|
302 }
|
|
303 else
|
|
304 {
|
|
305 if ( v10 >= 1.0 )
|
|
306 v11 = 1.0;
|
|
307 else
|
|
308 v11 = v10;
|
|
309 if ( v11 >= 0.0 )
|
|
310 {
|
|
311 if ( v10 >= 1.0 )
|
|
312 v10 = (float)1.0;
|
|
313 }
|
|
314 else
|
|
315 v10 = 0.0;
|
|
316 }
|
|
317 result = (bool)a5;
|
|
318 a5->vWorldPosition.x = (a2->vWorldPosition.x - v6->vWorldPosition.x) * v10 + v6->vWorldPosition.x;
|
|
319 a5->vWorldPosition.y = (a2->vWorldPosition.y - v6->vWorldPosition.y) * v10 + v6->vWorldPosition.y;
|
|
320 a5->vWorldPosition.z = (a2->vWorldPosition.z - v6->vWorldPosition.z) * v10 + v6->vWorldPosition.z;
|
|
321 a5->u = (a2->u - v6->u) * v10 + v6->u;
|
|
322 a5->v = (a2->v - v6->v) * v10 + v6->v;
|
|
323 return 1;
|
|
324 }
|
|
325 v13 = v8 < 0.0;
|
|
326 v14 = 0;
|
|
327 v15 = v8 == 0.0;
|
|
328 // BYTE1(result) = HIBYTE(v9);
|
|
329 if ( v8 < 0.0 )
|
|
330 return 1;
|
|
331 return 0;
|
|
332 }
|
|
333 // AE3398: using guessed type char static_init_flag__AE3388_bit1__AE3378_bit2;
|
|
334
|
|
335 //----- (0049895A) --------------------------------------------------------
|
|
336 bool stru9::AreVectorsCollinear(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct stru312 *a3)
|
|
337 {
|
|
338 static stru312 static_F942A0;
|
|
339
|
|
340 static_F942A0.x = a1->vWorldPosition.x - a2->vWorldPosition.x;
|
|
341 static_F942A0.y = a1->vWorldPosition.y - a2->vWorldPosition.y;
|
|
342 static_F942A0.z = a1->vWorldPosition.z - a2->vWorldPosition.z;
|
|
343
|
|
344 static float flt_F942B4 = static_F942A0.z * a3->z + static_F942A0.y * a3->y + static_F942A0.x * a3->x;
|
|
345 if (flt_F942B4 >= 0)
|
|
346 return true;
|
|
347 return false;
|
|
348 }
|
|
349
|
|
350
|
|
351 //----- (004989E1) --------------------------------------------------------
|
|
352 bool stru9::_4989E1(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4)
|
|
353 {
|
|
354 bool r1;
|
|
355 bool r2;
|
|
356
|
|
357 r1 = AreVectorsCollinear(a1, a3, a4);
|
|
358 r2 = AreVectorsCollinear(a2, a3, a4);
|
|
359 return !r1 && r2 == 1 ||
|
|
360 r1 == 1 && !r2;
|
|
361 }
|
|
362
|
|
363 //----- (004980B9) --------------------------------------------------------
|
2532
|
364 bool stru9::_4980B9(RenderVertexSoft *a1, unsigned int uNumVertices, float a3, float a4, float a5, RenderVertexSoft *pOutVertices, signed int *pOutNumVertices)
|
2496
|
365 {
|
|
366 RenderVertexSoft *v12; // ecx@9
|
|
367 double v13; // st7@12
|
|
368 double v14; // st6@12
|
|
369 double v15; // st5@12
|
|
370 signed int v25; // [sp+18h] [bp-Ch]@7
|
|
371
|
|
372 static RenderVertexSoft stru_AE4BFC;
|
|
373 static stru312 static_sub_4980B9_stru_AE4BEC; // idb
|
|
374 static VertexBuffer static_sub_4980B9_stru_AE3FE8; // idb
|
|
375
|
|
376 v25 = 0;
|
|
377 if (uNumVertices <= 0)
|
|
378 {
|
|
379 *pOutNumVertices = 0;
|
|
380 return true;
|
|
381 }
|
|
382
|
|
383 for (uint i = 0; i < uNumVertices; ++i)
|
|
384 {
|
|
385 v12 = &a1[(i + 1) % uNumVertices];
|
|
386 if (a1[i].vWorldPosition.x != v12->vWorldPosition.x ||
|
|
387 a1[i].vWorldPosition.y != v12->vWorldPosition.y ||
|
|
388 a1[i].vWorldPosition.z!= v12->vWorldPosition.z)
|
|
389 {
|
|
390 v13 = v12->vWorldPosition.x - a1[i].vWorldPosition.x;
|
|
391 v14 = v12->vWorldPosition.y - a1[i].vWorldPosition.y;
|
|
392 v15 = v12->vWorldPosition.z - a1[i].vWorldPosition.z;
|
|
393 ++v25;
|
|
394
|
|
395 static_sub_4980B9_stru_AE3FE8.uNumVertices = 0;
|
|
396 static_sub_4980B9_stru_AE4BEC.x = a4 * v15 - v14 * a5;
|
|
397 static_sub_4980B9_stru_AE4BEC.y = v13 * a5 - v15 * a3;
|
|
398 static_sub_4980B9_stru_AE4BEC.z = v14 * a3 - v13 * a4;
|
|
399 if (*pOutNumVertices == 0)
|
|
400 return true;
|
|
401
|
|
402 for (uint j = 0; j < *pOutNumVertices; ++j)
|
|
403 {
|
|
404 if (j)
|
|
405 {
|
|
406 if (_4989E1(&pOutVertices[j - 1], &pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC) &&
|
|
407 _498774(&pOutVertices[j - 1], &pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC))
|
|
408 AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
|
|
409 }
|
|
410
|
|
411 if (AreVectorsCollinear(&pOutVertices[j], &a1[i], &static_sub_4980B9_stru_AE4BEC))
|
|
412 AddVertex(&static_sub_4980B9_stru_AE3FE8, &pOutVertices[j]);
|
|
413 }
|
|
414
|
|
415 if (!static_sub_4980B9_stru_AE3FE8.uNumVertices)
|
|
416 {
|
|
417 *pOutNumVertices = 0;
|
|
418 return true;
|
|
419 }
|
|
420 if (_4989E1(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0], &a1[i], &static_sub_4980B9_stru_AE4BEC) &&
|
|
421 _498774(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0], &a1[i], &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC) )
|
|
422 AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
|
|
423
|
|
424 for (uint j = 0; j < static_sub_4980B9_stru_AE3FE8.uNumVertices; ++j)
|
|
425 {
|
|
426 pOutVertices[j].vWorldPosition.y = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.x;
|
|
427 pOutVertices[j].vWorldPosition.y = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.y;
|
|
428 pOutVertices[j].vWorldPosition.z = static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.z;
|
|
429 pOutVertices[j].u = static_sub_4980B9_stru_AE3FE8.pVertices[j].u;
|
|
430 pOutVertices[j].v = static_sub_4980B9_stru_AE3FE8.pVertices[j].v;
|
|
431 }
|
|
432 *pOutNumVertices = static_sub_4980B9_stru_AE3FE8.uNumVertices;
|
|
433 }
|
|
434 }
|
|
435
|
|
436 if (v25 < 3)
|
|
437 *pOutNumVertices = 0;
|
|
438
|
|
439 return true;
|
|
440 }
|
|
441 // AE4C2C: using guessed type char static_sub_4980B9_byte_AE4C2C_init_flag; |