comparison Engine/Graphics/stru9.cpp @ 2496:5abd8fc8f1c6

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