World of Might and Magic  0.2.0
Open reimplementation of Might and Magic 6 7 8 game engine
stru9.cpp
См. документацию.
2 
3 #include "Engine/Engine.h"
4 
5 #include "IndoorCameraD3D.h"
6 
7 //----- (00498377) --------------------------------------------------------
8 bool stru9::_498377(struct RenderVertexSoft *pPortalBounding, // test skipping this
9  unsigned int uNumVertices,
11  RenderVertexSoft *pVertices2,
12  unsigned int *pOutNumVertices) {
13  int result; // eax@7
14  RenderVertexSoft *v9; // ecx@9
15  RenderVertexSoft *v19; // [sp+14h] [bp-14h]@0
16  int v21; // [sp+1Ch] [bp-Ch]@7
17 
18  // __debugbreak();
19  // thisa = this;
20 
21 
22  return true; // testing bypass
23 
24 
25 
26  static RenderVertexSoft static_AE3FB4;
27  /*static bool __init_flag1 = false;
28  if (!__init_flag1) {
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  __init_flag2 = true;
38 
39  //stru312::stru312(&static_AE3FA4);
40  }*/
41 
42  static VertexBuffer static_AE33A0; // idb
43  /*static bool __init_flag3 = false;
44  if (!__init_flag3) {
45  __init_flag3 = true;
46 
47  //VertexBuffer::VertexBuffer(&static_AE33A0);
48  }*/
49 
50  result = false;
51  // v7 = pOutNumVertices;
52  v21 = 0;
53  if ((signed int)uNumVertices <= 0) {
54  *pOutNumVertices = 0;
55  return true;
56  }
57  // a2 = a1;
58  // v8 = (char *)&a3->y;
59  // v18 = (char *)&a3->y;
60  // do
61  for (uint j = 0; j < uNumVertices; j++) {
62  // v17 = result + 1;
63  result = j;
64  v9 = &pPortalBounding[(j + 1) % (signed int)uNumVertices];
65  if (pPortalBounding->vWorldPosition.x != v9->vWorldPosition.x ||
66  pPortalBounding->vWorldPosition.y != v9->vWorldPosition.y ||
67  pPortalBounding->vWorldPosition.z != v9->vWorldPosition.z) {
68  // v10 = a3->z;
69  // v11 = a3->y;
70  ++v21;
71  // result = 0;
72  static_AE33A0.uNumVertices = 0;
73  // a3a = 0;
74  static_AE3FA4.x = pVertices->x;
75  static_AE3FA4.y = pVertices->y;
76  static_AE3FA4.z = pVertices->z;
77  if ((signed int)*pOutNumVertices <= 0) {
78  *pOutNumVertices = 0;
79  return true;
80  }
81  // do
82  for (int i = 0; i < (signed int)*pOutNumVertices; i++) {
83  // v12 = &pVertices[result];
84  if (result) {
85  if (DoDecalVertsNeedClipping(&pVertices2[i], &pVertices2[i], pPortalBounding,
86  &static_AE3FA4) &&
87  ClipDecalVertsToFace(&pVertices2[i], &pVertices2[i], pPortalBounding,
88  &static_AE3FA4, &static_AE3FB4))
89  AddVertex(&static_AE33A0, &static_AE3FB4);
90  } else {
91  v19 = &pVertices2[i];
92  }
93  // v20 = v12;
94  if (AreVectorsCollinear(&pVertices2[i], pPortalBounding,
95  &static_AE3FA4))
96  AddVertex(&static_AE33A0, &pVertices2[i]);
97  // pOutNumVertices = pOutNumVertices;
98  // a3a++;
99  }
100  // while ( a3a < (signed int)*pOutNumVertices );
101  if (!static_AE33A0.uNumVertices) {
102  *pOutNumVertices = 0;
103  return true;
104  }
105  if (DoDecalVertsNeedClipping(&pVertices2[result], v19, pPortalBounding,
106  &static_AE3FA4) &&
107  ClipDecalVertsToFace(&pVertices2[result], v19, pPortalBounding,
108  &static_AE3FA4, &static_AE3FB4))
109  AddVertex(&static_AE33A0, &static_AE3FB4);
110 
111  for (uint i = 0; i < static_AE33A0.uNumVertices; ++i) {
112  pVertices2[i].vWorldPosition.x =
113  static_AE33A0.pVertices[i].vWorldPosition.x;
114  pVertices2[i].vWorldPosition.y =
115  static_AE33A0.pVertices[i].vWorldPosition.y;
116  pVertices2[i].vWorldPosition.z =
117  static_AE33A0.pVertices[i].vWorldPosition.z;
118  pVertices2[i].u = static_AE33A0.pVertices[i].u;
119  pVertices2[i].v = static_AE33A0.pVertices[i].v;
120  }
121 
122  // v13 = static_AE33A0.uNumVertices;
123  /*a3b = 0;
124  if ( static_AE33A0.uNumVertices > 0 )
125  {
126  v14 = &static_AE33A0;
127  v15 = (char *)&pVertices->vWorldPosition.y;
128  for ( i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y -
129  (char *)pVertices;
130  ;
131  i = (char *)&static_AE33A0.pVertices[0].vWorldPosition.y -
132  (char *)pVertices )
133  {
134  ++a3b;
135  pVertices->vWorldPosition.x =
136  v14->pVertices[0].vWorldPosition.x; v14 = (VertexBuffer *)((char
137  *)v14 + 48); pVertices->vWorldPosition.y = *(float *)&v15[(char
138  *)&static_AE33A0 - (char *)pVertices]; pVertices->vWorldPosition.z =
139  *(float *)&v15[i]; pVertices->u = *(float *)&v15[(char
140  *)&static_AE33A0.pVertices[0]._rhw - (char *)pVertices];
141  pVertices->v = *(float *)&v15[(char
142  *)&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) *pOutNumVertices = 0;
161  return true;
162 }
163 
164 bool stru9::AdjustVerticesToFrustumPlane(RenderVertexSoft *pInVertices, signed int pInNumVertices,
165  RenderVertexSoft *pOutVertices,
166  unsigned int *pOutNumVertices,
167  struct Vec3_float_ *CamFrustumNormal, float CamDotDistance, char *VertsAdjusted,
168  int unused) {
169  // this cycles through adjust vertice posisiton to supplied frustum plane
170  // points are inside frstum plane when point dot product is greater than camera dot distance
171 
172  RenderVertexSoft *pLineEnd; // ecx@9
173  double pLinelength2; // st7@9
174  double t; // st6@12
175 
176  RenderVertexSoft *pLineStart = &pInVertices[0];
177  // pVertices = a3;
178  double pLinelength1 = CamFrustumNormal->x * pInVertices[0].vWorldPosition.x +
179  pInVertices[0].vWorldPosition.y * CamFrustumNormal->y +
180  pInVertices[0].vWorldPosition.z * CamFrustumNormal->z;
181  // v20 = v13;
182  bool Vert1Inside = pLinelength1 >= CamDotDistance;
183 
184  *pOutNumVertices = 0;
185  if (pInNumVertices <= 0) return false;
186 
187  int VertCounter = 1;
188 
189  while (true) {
190  if (Vert1Inside) {
191  // ++pVertices;
192  memcpy(pOutVertices, pLineStart, sizeof(RenderVertexSoft));
193  ++*pOutNumVertices;
194  // v10 = a5;
195  pOutVertices++;
196  // v9 = a1;
197  }
198  bool Vert2Inside = false;
199  pLineEnd = &pInVertices[VertCounter % pInNumVertices];
200  pLinelength2 = CamFrustumNormal->x * pLineEnd->vWorldPosition.x +
201  pLineEnd->vWorldPosition.y * CamFrustumNormal->y +
202  pLineEnd->vWorldPosition.z * CamFrustumNormal->z;
203  if (pLinelength2 >= CamDotDistance) Vert2Inside = true;
204 
205  if (Vert1Inside != Vert2Inside) {
206  t = (CamDotDistance - pLinelength1) / (pLinelength2 - pLinelength1);
207  pOutVertices->vWorldPosition.x =
208  pLineStart->vWorldPosition.x +
209  (pLineEnd->vWorldPosition.x - pLineStart->vWorldPosition.x) * t;
210  pOutVertices->vWorldPosition.y =
211  pLineStart->vWorldPosition.y +
212  (pLineEnd->vWorldPosition.y - pLineStart->vWorldPosition.y) * t;
213  pOutVertices->vWorldPosition.z =
214  pLineStart->vWorldPosition.z +
215  (pLineEnd->vWorldPosition.z - pLineStart->vWorldPosition.z) * t;
216  pOutVertices->u = pLineStart->u + (pLineEnd->u - pLineStart->u) * t;
217  pOutVertices->v = pLineStart->v + (pLineEnd->v - pLineStart->v) * t;
218  ++pOutVertices;
219  // a3 = pVertices;
220  ++*pOutNumVertices;
221  *VertsAdjusted = true;
222  }
223 
224  pLineStart++;
225  Vert1Inside = Vert2Inside;
226  pLinelength1 = pLinelength2;
227  if (VertCounter >= pInNumVertices) break;
228  // v9 = a1;
229  VertCounter++;
230  }
231 
232  return *pOutNumVertices >= 3;
233 }
234 
235 //----- (00498737) --------------------------------------------------------
236 void stru9::AddVertex(struct VertexBuffer *pVertexBuffer,
237  struct RenderVertexSoft *pVertex) {
238  pVertexBuffer->pVertices[pVertexBuffer->uNumVertices].vWorldPosition.x =
239  pVertex->vWorldPosition.x;
240  pVertexBuffer->pVertices[pVertexBuffer->uNumVertices].vWorldPosition.y =
241  pVertex->vWorldPosition.y;
242  pVertexBuffer->pVertices[pVertexBuffer->uNumVertices].vWorldPosition.z =
243  pVertex->vWorldPosition.z;
244  pVertexBuffer->pVertices[pVertexBuffer->uNumVertices].u = pVertex->u;
245  pVertexBuffer->pVertices[pVertexBuffer->uNumVertices].v = pVertex->v;
246  ++pVertexBuffer->uNumVertices;
247 }
248 
249 //----- (00498774) --------------------------------------------------------
251  struct RenderVertexSoft *a3, struct stru312 *a4,
252  struct RenderVertexSoft *a5) {
253  // this looks like it is meant to clip the light map / decal verts to the face plane verts
254 
255  // a1 - decal vert1
256  // a2 - decal vert2
257  // a3 - face vertex to clip to
258  // a4 - vec along plane perp to decal verts
259  // a5 - verts out
260 
261 
262  RenderVertexSoft *v6; // ecx@5
263  int result; // eax@5
264  double v8; // st7@5
265  // __int16 v9; // fps@5
266  double v10; // st7@6
267  double v11; // st6@8
268  double v12; // st6@18
269  char v13; // c0@24
270  char v14; // c2@24
271  char v15; // c3@24
272  float a1a; // [sp+10h] [bp+8h]@5
273 
274  // __debugbreak();
275 
276  static stru312 static_AE3388;
277  static stru312 static_AE3378;
278 
279  v6 = a1;
280  static_AE3378.x = a1->vWorldPosition.x - a3->vWorldPosition.x;
281  static_AE3378.y = a1->vWorldPosition.y - a3->vWorldPosition.y;
282  HEXRAYS_HIWORD(result) = HEXRAYS_HIWORD(a4);
283  static_AE3378.z = a1->vWorldPosition.z - a3->vWorldPosition.z;
284  static_AE3388.x = a2->vWorldPosition.x - a1->vWorldPosition.x;
285  static_AE3388.y = a2->vWorldPosition.y - a1->vWorldPosition.y;
286  static_AE3388.z = a2->vWorldPosition.z - a1->vWorldPosition.z;
287  a1a = static_AE3388.x * a4->x + static_AE3388.z * a4->z +
288  static_AE3388.y * a4->y;
289  v8 = static_AE3378.x * a4->x + static_AE3378.z * a4->z +
290  static_AE3378.y * a4->y;
291  // UNDEF(v9);
292  if (a1a != 0.0) {
293  v10 = -(v8 / a1a);
294  if (a1a <= 0.0) {
295  if (v10 <= 0.0)
296  v12 = 0.0;
297  else
298  v12 = v10;
299  if (v12 <= 1.0) {
300  if (v10 <= 0.0) v10 = (float)0.0;
301  } else {
302  v10 = 1.0;
303  }
304  } else {
305  if (v10 >= 1.0)
306  v11 = 1.0;
307  else
308  v11 = v10;
309  if (v11 >= 0.0) {
310  if (v10 >= 1.0) v10 = (float)1.0;
311  } else {
312  v10 = 0.0;
313  }
314  }
315  result = (bool)a5;
316  a5->vWorldPosition.x =
317  (a2->vWorldPosition.x - v6->vWorldPosition.x) * v10 +
318  v6->vWorldPosition.x;
319  a5->vWorldPosition.y =
320  (a2->vWorldPosition.y - v6->vWorldPosition.y) * v10 +
321  v6->vWorldPosition.y;
322  a5->vWorldPosition.z =
323  (a2->vWorldPosition.z - v6->vWorldPosition.z) * v10 +
324  v6->vWorldPosition.z;
325  a5->u = (a2->u - v6->u) * v10 + v6->u;
326  a5->v = (a2->v - v6->v) * v10 + v6->v;
327  return 1;
328  }
329  v13 = v8 < 0.0;
330  v14 = 0;
331  v15 = v8 == 0.0;
332  // BYTE1(result) = HIBYTE(v9);
333  if (v8 < 0.0) return 1;
334  return 0;
335 }
336 // AE3398: using guessed type char static_init_flag__AE3388_bit1__AE3378_bit2;
337 
338 //----- (0049895A) --------------------------------------------------------
340  struct RenderVertexSoft *a2,
341  struct stru312 *a3) {
342  // is vector a2->a1 in same semiplane as a3
343 
344  /*static */stru312 static_F942A0;
345 
346  static_F942A0.x = a1->vWorldPosition.x - a2->vWorldPosition.x;
347  static_F942A0.y = a1->vWorldPosition.y - a2->vWorldPosition.y;
348  static_F942A0.z = a1->vWorldPosition.z - a2->vWorldPosition.z;
349 
350  /*static*/ float flt_F942B4 = static_F942A0.z * a3->z +
351  static_F942A0.y * a3->y + static_F942A0.x * a3->x;
352  if (flt_F942B4 >= 0) return true;
353  return false;
354 }
355 
356 //----- (004989E1) --------------------------------------------------------
358  struct RenderVertexSoft *a3, struct stru312 *a4) {
359  // lightmap/decal first two verts
360  // 3rd is face vert
361  // 4th is vec along face
362 
363  bool r1;
364  bool r2;
365 
366  // checks if vector a3->a1 is in the same semiplane as vec a4
367 
368  r1 = AreVectorsCollinear(a1, a3, a4);
369  r2 = AreVectorsCollinear(a2, a3, a4);
370 
371  // if one vert is in and one is out, we need clipping
372 
373  bool result = ((!r1) && (r2 == 1)) || ((r1 == 1) && (!r2));
374 
375  return result;
376 }
377 
378 //----- (004980B9) --------------------------------------------------------
379 bool stru9::_4980B9(RenderVertexSoft *a1, unsigned int uNumVertices,
380  float pNormalX, float pNormalY, float pNormalZ,
381  RenderVertexSoft *pOutVertices,
382  signed int *pOutNumVertices) {
383  // first two are for the face
384  // last two are light map / decal
385 
386 
387  RenderVertexSoft *v12; // ecx@9
388  double v13; // st7@12
389  double v14; // st6@12
390  double v15; // st5@12
391  signed int v25; // [sp+18h] [bp-Ch]@7
392 
393  static RenderVertexSoft stru_AE4BFC;
394  static stru312 static_sub_4980B9_stru_AE4BEC; // idb
395  static VertexBuffer static_sub_4980B9_stru_AE3FE8; // idb
396 
397  v25 = 0;
398  if (uNumVertices <= 0) {
399  *pOutNumVertices = 0;
400  return true;
401  }
402 
403  for (uint i = 0; i < uNumVertices; ++i) {
404  v12 = &a1[(i + 1) % uNumVertices];
405  if (a1[i].vWorldPosition.x != v12->vWorldPosition.x ||
406  a1[i].vWorldPosition.y != v12->vWorldPosition.y ||
407  a1[i].vWorldPosition.z != v12->vWorldPosition.z) {
408  v13 = v12->vWorldPosition.x - a1[i].vWorldPosition.x;
409  v14 = v12->vWorldPosition.y - a1[i].vWorldPosition.y;
410  v15 = v12->vWorldPosition.z - a1[i].vWorldPosition.z;
411  ++v25;
412 
413  static_sub_4980B9_stru_AE3FE8.uNumVertices = 0;
414  // cross product of face normals and vec ab gives vec running along face plane
415  static_sub_4980B9_stru_AE4BEC.x = pNormalY * v15 - v14 * pNormalZ;
416  static_sub_4980B9_stru_AE4BEC.y = v13 * pNormalZ - v15 * pNormalX;
417  static_sub_4980B9_stru_AE4BEC.z = v14 * pNormalX - v13 * pNormalY;
418  if (*pOutNumVertices == 0) return true;
419 
420  for (uint j = 0; j < *pOutNumVertices; ++j) {
421  if (j) {
422  if (DoDecalVertsNeedClipping(&pOutVertices[j - 1], &pOutVertices[j], &a1[i],
423  &static_sub_4980B9_stru_AE4BEC) &&
424  ClipDecalVertsToFace(&pOutVertices[j - 1], &pOutVertices[j], &a1[i],
425  &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC))
426  AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
427  }
428 
429  if (AreVectorsCollinear(&pOutVertices[j], &a1[i],
430  &static_sub_4980B9_stru_AE4BEC))
431  AddVertex(&static_sub_4980B9_stru_AE3FE8, &pOutVertices[j]);
432  }
433 
434  if (!static_sub_4980B9_stru_AE3FE8.uNumVertices) {
435  *pOutNumVertices = 0;
436  return true;
437  }
438  if (DoDecalVertsNeedClipping(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0],
439  &a1[i], &static_sub_4980B9_stru_AE4BEC) &&
440  ClipDecalVertsToFace(&pOutVertices[*pOutNumVertices - 1], &pOutVertices[0],
441  &a1[i], &static_sub_4980B9_stru_AE4BEC, &stru_AE4BFC))
442  AddVertex(&static_sub_4980B9_stru_AE3FE8, &stru_AE4BFC);
443 
444  for (uint j = 0; j < static_sub_4980B9_stru_AE3FE8.uNumVertices;
445  ++j) {
446  pOutVertices[j].vWorldPosition.x =
447  static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.x;
448  pOutVertices[j].vWorldPosition.y =
449  static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.y;
450  pOutVertices[j].vWorldPosition.z =
451  static_sub_4980B9_stru_AE3FE8.pVertices[j].vWorldPosition.z;
452  pOutVertices[j].u =
453  static_sub_4980B9_stru_AE3FE8.pVertices[j].u;
454  pOutVertices[j].v =
455  static_sub_4980B9_stru_AE3FE8.pVertices[j].v;
456  }
457  *pOutNumVertices = static_sub_4980B9_stru_AE3FE8.uNumVertices;
458  }
459  }
460 
461  if (v25 < 3) *pOutNumVertices = 0;
462 
463  return true;
464 }
465 // AE4C2C: using guessed type char static_sub_4980B9_byte_AE4C2C_init_flag;
Vec3_float_
Definition: VectorTypes.h:74
Vec3_float_::x
float x
Definition: VectorTypes.h:89
RenderVertexSoft::u
float u
Definition: IRender.h:121
stru312::x
float x
Definition: stru9.h:25
stru9.h
IndoorCameraD3D_Vec4
Definition: IndoorCameraD3D.h:32
stru312
Definition: stru9.h:21
stru9::AreVectorsCollinear
bool AreVectorsCollinear(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct stru312 *a3)
Definition: stru9.cpp:339
Vec3_float_::y
float y
Definition: VectorTypes.h:90
Vec3_float_::z
float z
Definition: VectorTypes.h:91
Engine.h
result
GLuint64EXT * result
Definition: SDL_opengl_glext.h:9435
stru9::AdjustVerticesToFrustumPlane
bool AdjustVerticesToFrustumPlane(RenderVertexSoft *pInVertices, signed int pInNumVertices, RenderVertexSoft *pOutVertices, unsigned int *pOutNumVertices, struct Vec3_float_ *CamFrustumNormal, float CamDotDistance, char *VertsAdjusted, int unused)
Definition: stru9.cpp:164
pVertices
struct RenderVertexD3D3 pVertices[50]
Definition: Render.cpp:50
stru312::z
float z
Definition: stru9.h:27
stru9::_4980B9
bool _4980B9(struct RenderVertexSoft *a1, unsigned int uNumVertices, float a3, float a4, float a5, struct RenderVertexSoft *pOutVertices, signed int *pOutNumVertices)
Definition: stru9.cpp:379
stru9::DoDecalVertsNeedClipping
bool DoDecalVertsNeedClipping(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4)
Definition: stru9.cpp:357
stru9::_498377
bool _498377(struct RenderVertexSoft *pPortalBounding, unsigned int uNumVertices, struct IndoorCameraD3D_Vec4 *pVertices, struct RenderVertexSoft *pVertices2, unsigned int *pOutNumVertices)
Definition: stru9.cpp:8
stru9::ClipDecalVertsToFace
bool ClipDecalVertsToFace(struct RenderVertexSoft *a1, struct RenderVertexSoft *a2, struct RenderVertexSoft *a3, struct stru312 *a4, struct RenderVertexSoft *a5)
Definition: stru9.cpp:250
t
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
VertexBuffer::uNumVertices
int uNumVertices
Definition: stru9.h:15
stru9::AddVertex
void AddVertex(struct VertexBuffer *pVertexBuffer, struct RenderVertexSoft *pVertex)
Definition: stru9.cpp:236
RenderVertexSoft::v
float v
Definition: IRender.h:122
uint
unsigned int uint
Definition: MM7.h:4
IndoorCameraD3D.h
RenderVertexSoft::vWorldPosition
Vec3_float_ vWorldPosition
Definition: IRender.h:116
VertexBuffer
Definition: stru9.h:6
stru312::y
float y
Definition: stru9.h:26
RenderVertexSoft
Definition: IRender.h:113
VertexBuffer::pVertices
RenderVertexSoft pVertices[64]
Definition: stru9.h:14