Mercurial > mm7
annotate Vis.cpp @ 1041:c5498375832a
m
author | Gloval |
---|---|
date | Thu, 23 May 2013 08:26:51 +0400 |
parents | 306ec23b37df |
children | 39f42990698f 010a844ef4a0 |
rev | line source |
---|---|
194 | 1 #include <assert.h> |
2 | |
1016 | 3 #include "BSPModel.h" |
0 | 4 #include "Vis.h" |
5 #include "Outdoor.h" | |
6 #include "Game.h" | |
7 #include "Actor.h" | |
8 #include "IndoorCamera.h" | |
9 #include "Viewport.h" | |
227 | 10 #include "Log.h" |
0 | 11 |
12 #include "mm7_data.h" | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
13 #include "MM7.h" |
0 | 14 |
15 | |
194 | 16 static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; |
17 | |
18 Vis_SelectionFilter vis_sprite_filter_1 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E1C | |
19 Vis_SelectionFilter vis_sprite_filter_2 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E30 | |
20 Vis_SelectionFilter vis_face_filter = {VisObjectType_Face, OBJECT_Any, -1, 0, 0}; // 00F93E44 | |
21 Vis_SelectionFilter vis_door_filter = {VisObjectType_Face, OBJECT_BLVDoor, -1, 0x100000, 0}; // 00F93E58 | |
22 Vis_SelectionFilter vis_sprite_filter_3 = {VisObjectType_Sprite, OBJECT_Decoration, -1, 0, 4}; // 00F93E6C | |
23 Vis_SelectionFilter vis_sprite_filter_4 = {VisObjectType_Any, OBJECT_Item, -1, 0, 0}; // static to sub_44EEA7 | |
0 | 24 |
25 | |
26 | |
27 //----- (004C1026) -------------------------------------------------------- | |
916 | 28 Vis_ObjectInfo *Vis::DetermineFacetIntersection(BLVFace *face, unsigned int a3, float pick_depth) |
0 | 29 { |
30 char *v4; // eax@4 | |
31 signed int v5; // ecx@4 | |
32 RenderVertexSoft pRay[2]; // [sp+20h] [bp-70h]@17 | |
33 int v20; // [sp+84h] [bp-Ch]@10 | |
34 | |
916 | 35 static Vis_SelectionList static_DetermineFacetIntersection_stru_F8FE00; |
36 static_DetermineFacetIntersection_stru_F8FE00.uNumPointers = 0; | |
0 | 37 |
38 static bool _init_flag = false; | |
916 | 39 static RenderVertexSoft static_DetermineFacetIntersection_array_F8F200[64]; |
0 | 40 if (!_init_flag) |
41 { | |
42 _init_flag = true; | |
43 for (uint i = 0; i < 64; ++i) | |
916 | 44 static_DetermineFacetIntersection_array_F8F200[i].flt_2C = 0.0f; |
0 | 45 } |
46 | |
196 | 47 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
0 | 48 { |
196 | 49 if ( (signed int)face->uNumVertices > 0 ) |
0 | 50 { |
742 | 51 for ( int i = 0; i < face->uNumVertices; i++) |
0 | 52 { |
916 | 53 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.x = (double)pIndoor->pVertices[face->pVertexIDs[i]].x; |
54 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.y = (double)pIndoor->pVertices[face->pVertexIDs[i]].y; | |
55 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.z = (double)pIndoor->pVertices[face->pVertexIDs[i]].z; | |
0 | 56 } |
196 | 57 } |
58 } | |
59 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
60 { | |
61 uint bmodel_id = a3 >> 9; | |
62 auto v = (Vec3_int_ *)pOutdoor->pBModels[bmodel_id].pVertices.pVertices; | |
63 for (uint i = 0; i < face->uNumVertices; ++i) | |
64 { | |
916 | 65 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.x = v[face->pVertexIDs[i]].x; |
66 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.y = v[face->pVertexIDs[i]].y; | |
67 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.z = v[face->pVertexIDs[i]].z; | |
0 | 68 } |
69 } | |
196 | 70 else assert(false); |
71 | |
916 | 72 pGame->pIndoorCameraD3D->ViewTransform(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices); |
73 pGame->pIndoorCameraD3D->Project(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, 1); | |
196 | 74 |
75 //v15 = this; | |
916 | 76 SortVectors_x(static_DetermineFacetIntersection_array_F8F200, 0, face->uNumVertices - 1); |
77 if (static_DetermineFacetIntersection_array_F8F200[0].vWorldViewPosition.x > pick_depth) | |
196 | 78 return nullptr; |
79 | |
80 float screenspace_center_x, | |
81 screenspace_center_y; | |
916 | 82 GetPolygonScreenSpaceCenter(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, &screenspace_center_x, &screenspace_center_y); |
83 if (IsPolygonOccludedByBillboard(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, screenspace_center_x, screenspace_center_y)) | |
196 | 84 return nullptr; |
85 | |
86 CastPickRay(pRay, screenspace_center_x, screenspace_center_y, pick_depth); | |
87 | |
88 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
916 | 89 PickOutdoorFaces_Mouse(pick_depth, pRay, &static_DetermineFacetIntersection_stru_F8FE00, &vis_face_filter, true); |
196 | 90 else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
916 | 91 PickIndoorFaces_Mouse(pick_depth, pRay, &static_DetermineFacetIntersection_stru_F8FE00, &vis_face_filter); |
196 | 92 else assert(false); |
93 | |
916 | 94 static_DetermineFacetIntersection_stru_F8FE00.create_object_pointers(); |
95 sort_object_pointers(static_DetermineFacetIntersection_stru_F8FE00.object_pointers, 0, static_DetermineFacetIntersection_stru_F8FE00.uNumPointers - 1); | |
96 if (!static_DetermineFacetIntersection_stru_F8FE00.uNumPointers) | |
196 | 97 return nullptr; |
98 | |
916 | 99 if (!static_DetermineFacetIntersection_stru_F8FE00.sub_4C2551(2, a3)) |
196 | 100 return nullptr; |
101 | |
916 | 102 if (static_DetermineFacetIntersection_stru_F8FE00.uNumPointers) |
103 return static_DetermineFacetIntersection_stru_F8FE00.object_pointers[0]; | |
196 | 104 else return nullptr; |
0 | 105 } |
916 | 106 // F91E08: using guessed type char static_DetermineFacetIntersection_byte_F91E08__init_flags; |
0 | 107 |
108 //----- (004C12C3) -------------------------------------------------------- | |
196 | 109 bool Vis::IsPolygonOccludedByBillboard(RenderVertexSoft *vertices, int num_vertices, float x, float y) |
0 | 110 { |
196 | 111 //signed int v5; // esi@1 |
112 //RenderBillboardD3D *v6; // edi@2 | |
113 //double v7; // st7@9 | |
114 //int v8; // edx@9 | |
115 //RenderVertexSoft *v9; // ecx@10 | |
116 //char result; // al@24 | |
117 //Vis *thisa; // [sp+10h] [bp-8h]@1 | |
118 //float thisb; // [sp+10h] [bp-8h]@9 | |
119 //signed int v13; // [sp+14h] [bp-4h]@1 | |
120 //float a3a; // [sp+28h] [bp+10h]@9 | |
121 //float a4a; // [sp+2Ch] [bp+14h]@9 | |
0 | 122 |
196 | 123 int v13 = -1; |
124 //v5 = 0; | |
125 //thisa = this; | |
126 | |
127 //v6 = pRenderer->pBillboardRenderListD3D; | |
128 for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) | |
82 | 129 { |
196 | 130 auto billboard = pRenderer->pBillboardRenderListD3D + i; |
131 if (IsPointInsideD3DBillboard(billboard, x, y)) | |
0 | 132 { |
196 | 133 if (v13 == -1) |
134 v13 = i; | |
135 else if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) | |
136 v13 = i; | |
0 | 137 } |
138 } | |
196 | 139 |
140 if ( v13 == -1 ) | |
141 return false; | |
142 | |
143 //v8 = num_vertices; | |
144 //v7 = 3.4028235e38; | |
145 float min_x = FLT_MAX; | |
146 //a4a = 3.4028235e38; | |
147 float min_y = FLT_MAX; | |
148 //a3a = -3.4028235e38; | |
149 float max_x = -FLT_MAX; | |
150 //thisb = -3.4028235e38; | |
151 float max_y = -FLT_MAX; | |
152 for (uint i = 0; i < num_vertices; ++i) | |
153 { | |
154 //v9 = a1; | |
155 //do | |
156 //{ | |
157 auto v = vertices + i; | |
158 | |
159 if (v->vWorldViewProjX < min_x) | |
160 min_x = v->vWorldViewProjX; | |
161 if (v->vWorldViewProjX > max_x) | |
162 max_x = v->vWorldViewProjX; | |
163 | |
164 if (v->vWorldViewProjY < min_y) | |
165 min_y = v->vWorldViewProjY; | |
166 if (v->vWorldViewProjY > max_y) | |
167 max_y = v->vWorldViewProjY; | |
168 //++v9; | |
169 //--v8; | |
170 //} | |
171 //while ( v8 ); | |
172 } | |
173 | |
174 if (min_x < pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.x || pRenderer->pBillboardRenderListD3D[v13].pQuards[0].pos.y > min_y || | |
175 pRenderer->pBillboardRenderListD3D[v13].pQuards[3].pos.x < max_x || pRenderer->pBillboardRenderListD3D[v13].pQuards[1].pos.y < max_y) | |
176 return false; | |
177 | |
178 return true; | |
0 | 179 } |
180 | |
181 //----- (004C1417) -------------------------------------------------------- | |
182 void Vis::GetPolygonCenter(RenderVertexD3D3 *pVertices, unsigned int uNumVertices, float *pCenterX, float *pCenterY) | |
183 { | |
184 static RenderVertexD3D3 unk_F8EA00[64]; | |
185 | |
186 memcpy(unk_F8EA00, pVertices, 32 * uNumVertices); | |
187 | |
188 SortVerticesByX(unk_F8EA00, 0, uNumVertices - 1); | |
189 *pCenterX = (unk_F8EA00[uNumVertices - 1].pos.x - unk_F8EA00[0].pos.x) * 0.5 + unk_F8EA00[0].pos.x; | |
190 | |
191 SortVerticesByY(unk_F8EA00, 0, uNumVertices - 1); | |
192 *pCenterY = (unk_F8EA00[uNumVertices - 1].pos.y - unk_F8EA00[0].pos.y) * 0.5 + unk_F8EA00[0].pos.y; | |
193 } | |
194 | |
195 //----- (004C1495) -------------------------------------------------------- | |
196 | 196 void Vis::GetPolygonScreenSpaceCenter(RenderVertexSoft *vertices, int num_vertices, float *out_center_x, float *out_center_y) |
0 | 197 { |
198 char *v5; // eax@2 | |
199 signed int v6; // ecx@2 | |
200 float *result; // eax@5 | |
201 | |
202 static RenderVertexSoft static_sub_4C1495_array_F8DDF8[64]; | |
203 | |
196 | 204 memcpy(static_sub_4C1495_array_F8DDF8, vertices, 48 * num_vertices); |
0 | 205 |
196 | 206 SortByScreenSpaceX(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); |
207 *out_center_x = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjX - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX; | |
208 | |
209 SortByScreenSpaceY(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); | |
210 *out_center_y = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjY - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY; | |
0 | 211 } |
212 | |
213 //----- (004C1542) -------------------------------------------------------- | |
194 | 214 void Vis::PickBillboards_Mouse(float fPickDepth, float fX, float fY, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 215 { |
194 | 216 for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) |
0 | 217 { |
916 | 218 auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; |
194 | 219 if (is_part_of_selection((void *)i, filter) && IsPointInsideD3DBillboard(d3d_billboard, fX, fY)) |
0 | 220 { |
194 | 221 if (DoesRayIntersectBillboard(fPickDepth, i)) |
0 | 222 { |
194 | 223 auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; |
224 | |
225 list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); | |
0 | 226 } |
227 } | |
228 } | |
229 } | |
230 | |
231 //----- (004C1607) -------------------------------------------------------- | |
232 bool Vis::IsPointInsideD3DBillboard(RenderBillboardD3D *a1, float x, float y) | |
233 { | |
194 | 234 //RenderBillboardD3D *result; // eax@1 |
0 | 235 double v5; // st7@2 |
236 float v6; // ecx@2 | |
237 float v7; // ST00_4@3 | |
238 __int16 v8; // fps@6 | |
239 double v9; // st6@6 | |
240 char v10; // c0@6 | |
241 char v11; // c2@6 | |
242 char v12; // c3@6 | |
243 __int16 v13; // fps@7 | |
244 double v14; // st6@7 | |
245 unsigned __int8 v15; // c0@7 | |
246 char v16; // c2@7 | |
247 unsigned __int8 v17; // c3@7 | |
248 __int16 v18; // fps@8 | |
249 double v19; // st6@8 | |
250 char v20; // c0@8 | |
251 char v21; // c2@8 | |
252 char v22; // c3@8 | |
253 __int16 v23; // fps@9 | |
254 double v24; // st6@9 | |
255 unsigned __int8 v25; // c0@9 | |
256 char v26; // c2@9 | |
257 unsigned __int8 v27; // c3@9 | |
258 float v28; // [sp+4h] [bp-8h]@2 | |
259 float v29; // [sp+8h] [bp-4h]@2 | |
260 float a1a; // [sp+14h] [bp+8h]@2 | |
261 | |
262 if ( a1->uParentBillboardID == -1 ) | |
194 | 263 return false; |
264 | |
265 //result = a1; | |
0 | 266 v5 = a1->pQuards[0].pos.x; |
267 a1a = a1->pQuards[3].pos.x; | |
194 | 268 v6 = a1->pQuards[0].pos.y; |
269 //result = (RenderBillboardD3D *)LODWORD(result->pQuards[1].pos.y); | |
0 | 270 v29 = v6; |
194 | 271 v28 = a1->pQuards[1].pos.y; |
0 | 272 if ( v5 > a1a ) |
273 { | |
274 v7 = v5; | |
194 | 275 //HIWORD(result) = HIWORD(v7); |
0 | 276 v5 = a1a; |
277 a1a = v7; | |
278 } | |
279 if ( v6 > (double)v28 ) | |
280 { | |
194 | 281 //result = (RenderBillboardD3D *)LODWORD(v28); |
0 | 282 v28 = v6; |
194 | 283 v29 = v28; |
0 | 284 } |
285 v9 = x + 1.0; | |
286 //UNDEF(v8); | |
29 | 287 //v10 = v9 < v5; |
288 //v11 = 0; | |
289 //v12 = v9 == v5; | |
290 //BYTE1(result) = HIBYTE(v8);//crash | |
194 | 291 if (v9 >= v5 && |
292 (v14 = x - 1.0, v14<=a1a) &&///*UNDEF(v13),*/ v15 = v14 < a1a, v16 = 0, v17 = v14 == a1a, BYTE1(result) = HIBYTE(v13), v15 | v17) | |
293 (v19 = y + 1.0, v19>=v29) &&///*UNDEF(v18),*/ v20 = v19 < v29, v21 = 0, v22 = v19 == v29, BYTE1(result) = HIBYTE(v18), v19 >= v29) | |
294 (v24 = y - 1.0, v24<=v28))///*UNDEF(v23),*/ v25 = v24 < v28, v26 = 0, v27 = v24 == v28, BYTE1(result) = HIBYTE(v23), v25 | v27) ) | |
295 return true; | |
0 | 296 else |
194 | 297 return false; |
0 | 298 } |
299 | |
300 //----- (004C16B4) -------------------------------------------------------- | |
196 | 301 void Vis::PickIndoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 302 { |
303 int v5; // eax@1 | |
742 | 304 signed int pFaceID; // edi@2 |
0 | 305 int v8; // ecx@7 |
306 int v9; // eax@7 | |
307 unsigned int *pNumPointers; // eax@7 | |
308 unsigned int v11; // ecx@7 | |
194 | 309 Vis_ObjectInfo *v12; // edi@7 |
0 | 310 RenderVertexSoft a1; // [sp+Ch] [bp-44h]@1 |
742 | 311 BLVFace *pFace; // [sp+3Ch] [bp-14h]@7 |
0 | 312 void *v15; // [sp+40h] [bp-10h]@7 |
313 int v17; // [sp+48h] [bp-8h]@1 | |
196 | 314 |
0 | 315 v5 = 0; |
316 v17 = 0; | |
676
ecfb1b3c9a39
BLV: when standing right on the portal (orange wall) everything looks fine
Nomad
parents:
618
diff
changeset
|
317 for ( a1.flt_2C = 0.0; v17 < (signed int)pBspRenderer->num_faces; ++v17 ) |
0 | 318 { |
742 | 319 pFaceID = pBspRenderer->faces[v5].uFaceID; |
320 if ( pFaceID >= 0 ) | |
0 | 321 { |
742 | 322 if ( pFaceID < (signed int)pIndoor->uNumFaces ) |
0 | 323 { |
742 | 324 if ( is_part_of_selection(&pIndoor->pFaces[pFaceID], filter) ) |
0 | 325 { |
742 | 326 if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) ) |
0 | 327 { |
742 | 328 if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, &pIndoor->pFaces[pFaceID], 0xFFFFFFFFu) ) |
0 | 329 { |
742 | 330 pGame->pIndoorCameraD3D->ViewTransform(&a1, 1); |
1029 | 331 v9 = fixpoint_from_float(/*v8, */a1.vWorldViewPosition.x); |
0 | 332 LOWORD(v9) = 0; |
862 | 333 v15 = (void *)((PID(OBJECT_BModel,pFaceID)) + v9); |
194 | 334 pNumPointers = &list->uNumPointers; |
742 | 335 //v16 = 2; |
336 //v11 = list->uNumPointers; | |
337 pFace = &pIndoor->pFaces[pFaceID]; | |
338 v12 = &list->object_pool[list->uNumPointers]; | |
339 v12->object = &pIndoor->pFaces[pFaceID]; | |
194 | 340 v12 = (Vis_ObjectInfo *)((char *)v12 + 4); |
341 v12->object = v15; | |
742 | 342 v12->sZValue = 2; |
0 | 343 ++*pNumPointers; |
344 } | |
345 } | |
346 } | |
347 } | |
348 } | |
349 v5 = v17 + 1; | |
350 } | |
351 } | |
352 | |
353 //----- (004C17CF) -------------------------------------------------------- | |
323 | 354 void Vis::PickOutdoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter, bool only_reachable) |
196 | 355 { |
0 | 356 if (!pOutdoor) |
357 return; | |
196 | 358 |
359 for (uint i = 0; i < pOutdoor->uNumBModels; ++i) | |
0 | 360 { |
323 | 361 int reachable; |
362 if (!IsBModelVisible(i, &reachable)) | |
196 | 363 continue; |
323 | 364 if (!reachable && only_reachable) |
196 | 365 continue; |
366 | |
367 auto bmodel = &pOutdoor->pBModels[i]; | |
368 for (uint j = 0; j < bmodel->uNumFaces; ++j) | |
0 | 369 { |
1025 | 370 //if ( i == 77 && j == 17 )// |
371 //__debugbreak();// | |
916 | 372 auto face = &bmodel->pFaces[j]; |
196 | 373 if (is_part_of_selection(face, filter)) |
0 | 374 { |
196 | 375 BLVFace blv_face; |
376 blv_face.FromODM(face); | |
377 | |
378 RenderVertexSoft intersection; | |
379 if (Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &intersection, &blv_face, i)) | |
0 | 380 { |
916 | 381 pGame->pIndoorCameraD3D->ViewTransform(&intersection, 1); |
1029 | 382 int v13 = fixpoint_from_float(/*v12, */intersection.vWorldViewPosition.x); |
383 v13 &= 0xFFFF0000; | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
384 v13 += PID(OBJECT_BModel, j | (i << 6)); |
196 | 385 |
386 list->AddObject(face, VisObjectType_Face, v13); | |
0 | 387 } |
323 | 388 |
389 if (blv_face.uAttributes & 0x80000000) | |
390 face->uAttributes |= FACE_OUTLINED; | |
391 else | |
392 face->uAttributes &= ~FACE_OUTLINED; | |
0 | 393 } |
394 } | |
395 } | |
396 } | |
397 | |
398 //----- (004C1930) -------------------------------------------------------- | |
399 //bool Vis::j_DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) | |
400 //{return DoesRayIntersectBillboard(fDepth, uD3DBillboardIdx);} | |
401 | |
402 //----- (004C1944) -------------------------------------------------------- | |
295 | 403 int Vis::PickClosestActor(int object_id, unsigned int pick_depth, int a4, int a5, int a6) |
0 | 404 { |
295 | 405 //float v6; // ST00_4@3 |
406 //int result; // eax@4 | |
194 | 407 Vis_SelectionFilter v8; // [sp+18h] [bp-20h]@3 |
295 | 408 //__int64 v9; // [sp+2Ch] [bp-Ch]@3 |
409 //Vis *v14; // [sp+34h] [bp-4h]@1 | |
0 | 410 |
295 | 411 //v14 = this; |
0 | 412 |
194 | 413 static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; |
295 | 414 |
415 v8.object_type = VisObjectType_Sprite; | |
194 | 416 v8.object_id = object_id; |
0 | 417 v8.field_8 = a6; |
418 v8.field_C = a5; | |
419 v8.field_10 = a4; | |
420 Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0; | |
295 | 421 PickBillboards_Keyboard(pick_depth, &Vis_static_sub_4C1944_stru_F8BDE8, &v8); |
194 | 422 Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(Vis_SelectionList::Unique); |
0 | 423 sort_object_pointers( |
194 | 424 Vis_static_sub_4C1944_stru_F8BDE8.object_pointers, |
0 | 425 0, |
426 Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers - 1); | |
295 | 427 |
428 if (!Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers) | |
429 return -1; | |
430 return Vis_static_sub_4C1944_stru_F8BDE8.object_pointers[0]->sZValue; | |
0 | 431 } |
432 | |
433 //----- (004C1A02) -------------------------------------------------------- | |
434 void Vis::_4C1A02() | |
435 { | |
436 RenderVertexSoft v1; // [sp+8h] [bp-C0h]@1 | |
437 RenderVertexSoft v2; // [sp+38h] [bp-90h]@1 | |
438 RenderVertexSoft v3; // [sp+68h] [bp-60h]@1 | |
439 RenderVertexSoft v4; // [sp+98h] [bp-30h]@1 | |
440 | |
441 v4.flt_2C = 0.0; | |
442 v4.vWorldPosition.x = 0.0; | |
443 v4.vWorldPosition.y = 65536.0; | |
444 v4.vWorldPosition.z = 0.0; | |
445 v3.flt_2C = 0.0; | |
446 v3.vWorldPosition.x = 65536.0; | |
447 v3.vWorldPosition.y = 0.0; | |
448 v3.vWorldPosition.z = 0.0; | |
449 memcpy(&v1, &v3, sizeof(v1)); | |
450 v3.flt_2C = 0.0; | |
451 v3.vWorldPosition.x = 0.0; | |
452 v3.vWorldPosition.y = 65536.0; | |
453 v3.vWorldPosition.z = 0.0; | |
454 memcpy(&v2, &v4, sizeof(v2)); | |
455 v4.flt_2C = 0.0; | |
456 v4.vWorldPosition.x = 65536.0; | |
457 v4.vWorldPosition.y = 0.0; | |
458 v4.vWorldPosition.z = 0.0; | |
459 memcpy(&this->stru_200C, &v1, 0x60u); | |
460 memcpy(&v1, &v4, sizeof(v1)); | |
461 memcpy(&v2, &v3, sizeof(v2)); | |
462 memcpy(&this->stru_206C, &v1, 0x60u); | |
463 } | |
464 | |
465 //----- (004C1ABA) -------------------------------------------------------- | |
466 bool Vis::SortVectors_x(RenderVertexSoft *a2, int a3, int a4) | |
467 { | |
468 bool result; // eax@1 | |
469 RenderVertexSoft *v5; // edx@2 | |
470 int v6; // ebx@2 | |
471 int i; // ecx@2 | |
472 int v8; // esi@3 | |
473 int v9; // esi@5 | |
474 RenderVertexSoft *v10; // eax@8 | |
475 RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 | |
476 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 | |
477 int v13; // [sp+64h] [bp-Ch]@7 | |
478 Vis *thisa; // [sp+68h] [bp-8h]@1 | |
479 RenderVertexSoft *v15; // [sp+6Ch] [bp-4h]@2 | |
480 | |
481 result = a4; | |
482 thisa = this; | |
483 if ( a4 > a3 ) | |
484 { | |
485 v5 = a2; | |
486 v15 = &a2[a4]; | |
487 v6 = a3 - 1; | |
488 memcpy(&v12, &a2[a4], sizeof(v12)); | |
489 for ( i = a4; ; i = v13 ) | |
490 { | |
491 v8 = (int)&v5[v6].vWorldViewPosition; | |
492 do | |
493 { | |
494 v8 += 48; | |
495 ++v6; | |
496 } | |
497 while ( *(float *)v8 < (double)v12.vWorldViewPosition.x ); | |
498 v9 = (int)&v5[i].vWorldViewPosition; | |
499 do | |
500 { | |
501 v9 -= 48; | |
502 --i; | |
503 } | |
504 while ( *(float *)v9 > (double)v12.vWorldViewPosition.x ); | |
505 v13 = i; | |
506 if ( v6 >= i ) | |
507 break; | |
508 v10 = &v5[i]; | |
509 memcpy(&v11, &a2[v6], sizeof(v11)); | |
510 v5 = a2; | |
511 memcpy(&a2[v6], v10, sizeof(a2[v6])); | |
512 memcpy(v10, &v11, 0x30u); | |
513 } | |
514 memcpy(&v11, &v5[v6], sizeof(v11)); | |
515 memcpy(&v5[v6], v15, sizeof(v5[v6])); | |
516 memcpy(v15, &v11, 0x30u); | |
517 SortVectors_x(v5, a3, v6 - 1); | |
518 SortVectors_x(a2, v6 + 1, a4); | |
519 } | |
520 return true; | |
521 } | |
522 | |
523 //----- (004C1BAA) -------------------------------------------------------- | |
194 | 524 int Vis::get_object_zbuf_val(Vis_ObjectInfo *info) |
0 | 525 { |
194 | 526 switch (info->object_type) |
527 { | |
528 case VisObjectType_Sprite: | |
529 case VisObjectType_Face: | |
530 return info->sZValue; | |
0 | 531 |
194 | 532 default: |
533 MessageBoxW(nullptr, L"Undefined type requested for: CVis::get_object_zbuf_val()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1037", 0); | |
534 return -1; | |
0 | 535 } |
536 } | |
537 | |
538 //----- (004C1BF1) -------------------------------------------------------- | |
539 int Vis::get_picked_object_zbuf_val() | |
540 { | |
194 | 541 if (!default_list.uNumPointers) |
542 return -1; | |
0 | 543 |
998 | 544 return get_object_zbuf_val(default_list.object_pointers[0]); |
0 | 545 } |
546 | |
547 //----- (004C1C0C) -------------------------------------------------------- | |
1025 | 548 bool Vis::Intersect_Ray_Face(RenderVertexSoft *pRayStart, RenderVertexSoft *pRayEnd, float *pDepth, RenderVertexSoft *Intersection, BLVFace *pFace, unsigned int pBModelID) |
0 | 549 { |
323 | 550 //BLVFace *v7; // ebx@1 |
551 //bool result; // eax@1 | |
0 | 552 double v9; // st7@3 |
323 | 553 //__int16 v10; // fps@3 |
554 //char v11; // c0@3 | |
555 //char v12; // c2@3 | |
556 //char v13; // c3@3 | |
557 //__int16 v14; // fps@5 | |
558 //char v15; // c0@5 | |
559 //char v16; // c2@5 | |
560 //char v17; // c3@5 | |
1025 | 561 double c1; // st5@6 |
323 | 562 //__int16 v19; // fps@6 |
563 //char v20; // c0@6 | |
564 //char v21; // c2@6 | |
565 //char v22; // c3@6 | |
566 //unsigned __int8 v23; // c0@6 | |
567 //char v24; // c2@6 | |
568 //unsigned __int8 v25; // c3@6 | |
569 //char v26; // zf@6 | |
0 | 570 double v27; // st6@10 |
323 | 571 //__int16 v28; // fps@10 |
572 //unsigned __int8 v29; // c0@10 | |
573 //char v30; // c2@10 | |
574 //unsigned __int8 v31; // c3@10 | |
1025 | 575 double c2; // st7@11 |
576 //Vec2_short_ v33; // ST1E_4@11 | |
0 | 577 Vec3_short_ v34; // ST04_6@11 |
323 | 578 //float a5a; // [sp+30h] [bp+18h]@10 |
579 //float a5b; // [sp+30h] [bp+18h]@13 | |
580 | |
1025 | 581 if (pFace->Portal() || pFace->Invisible()) |
323 | 582 return false; |
583 | |
1025 | 584 int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x,//dir_x y z ýòî âåêòîð íàïðàâëåíèÿ |
585 ray_dir_y = pRayEnd->vWorldPosition.y - pRayStart->vWorldPosition.y,//òî÷êà  - òî÷êà À = âåêòîð èç À â  | |
323 | 586 ray_dir_z = pRayEnd->vWorldPosition.z - pRayStart->vWorldPosition.z; |
587 | |
1025 | 588 /*v9 = ray_dir_z * pFace->pFacePlane.vNormal.z |
589 + ray_dir_y * pFace->pFacePlane.vNormal.y//ñêàëÿðíîå ïðîèçâåäåíèå íàïðàâëåíèÿ ëó÷à è íîðìàëè ê ïîëèãîíó | |
590 + ray_dir_x * pFace->pFacePlane.vNormal.x;//= êîñèíóñ óãëà ìåæäó äâóìÿ âåêòîðàìè | |
323 | 591 if (v9 >= 0) // ray faces face's normal ( > 0) or parallel ( == 0) |
1025 | 592 return false;*/ |
323 | 593 |
594 //ray = t dir + start | |
595 //plane = (p - vertex) normal = -d | |
596 // | |
597 // | |
598 //(t dir + start - vertex) normal = -d | |
599 // | |
600 // -d - (start - vertex) norm | |
601 //t = -------------------- | |
602 // dir norm | |
603 | |
604 | |
1025 | 605 /*float dir_mag = sqrtf(ray_dir_x * ray_dir_x + ray_dir_y * ray_dir_y + ray_dir_z * ray_dir_z);//ìîäóëü âåêòîðà |
606 float ndir_x = ray_dir_x / dir_mag,//ndir - íîðìàëèçîâàííîå íàïðàâëåíèå | |
607 ndir_y = ray_dir_y / dir_mag,// ðåçóëüòàòå íîðìàëèçàöèè ïîëó÷àåòñÿ âåêòîð, íàïðàâëåíèå êîòîðîãî ñîâïàäàåò ñ èñõîäíûì, à ìîäóëü ðàâåí åäèíèöå (åäèíè÷íûé âåêòîð). | |
608 ndir_z = ray_dir_z / dir_mag;//×òîáû íîðìàëèçîâàòü ïðîèçâîëüíûé âåêòîð, äîñòàòî÷íî ðàçäåëèòü êàæäûé êîìïîíåíò âåêòîðà íà ìîäóëü âåêòîðà | |
323 | 609 |
1025 | 610 int face_center_x = (pFace->pBounding.x1 + pFace->pBounding.x2) / 2,//óñðåäí¸ííûå êîîðäèíàòû áàóíäèíãà |
611 face_center_y = (pFace->pBounding.y1 + pFace->pBounding.y2) / 2, | |
612 face_center_z = (pFace->pBounding.z1 + pFace->pBounding.z2) / 2; | |
0 | 613 |
1025 | 614 int to_plane_x = pRayStart->vWorldPosition.x - face_center_x,//âåêòîð èç ãëàñ ê ñåðåäèíå ôåéñà |
323 | 615 to_plane_y = pRayStart->vWorldPosition.y - face_center_y, |
1025 | 616 to_plane_z = pRayStart->vWorldPosition.z - face_center_z;*/ |
323 | 617 |
1025 | 618 //float t = /*-pFace->pFacePlane.dist*/ - (to_plane_x * pFace->pFacePlane.vNormal.x + to_plane_y * pFace->pFacePlane.vNormal.y + to_plane_y * pFace->pFacePlane.vNormal.z) / |
619 // (ndir_x * pFace->pFacePlane.vNormal.x + ndir_y * pFace->pFacePlane.vNormal.y + ndir_z * pFace->pFacePlane.vNormal.z);//íàñêîëüêî ñèëüíî ëó÷ èç êàìåðû îòêëîíÿåòñÿ îò ëó÷à äî öåíòðà ôåéñà | |
620 /* if (t <= *pDepth) | |
323 | 621 { |
622 int intersection_x = pRayStart->vWorldPosition.x + ndir_x * t, | |
623 intersection_y = pRayStart->vWorldPosition.y + ndir_y * t, | |
624 intersection_z = pRayStart->vWorldPosition.z + ndir_z * t; | |
625 | |
1025 | 626 if (intersection_x < pFace->pBounding.x1 || intersection_x > pFace->pBounding.x2 || |
627 intersection_y < pFace->pBounding.y1 || intersection_y > pFace->pBounding.y2 || | |
628 intersection_z < pFace->pBounding.z1 || intersection_z > pFace->pBounding.z2) | |
323 | 629 return false; |
630 | |
1025 | 631 pFace->uAttributes |= 0x80000000; |
323 | 632 return true; |
633 } | |
634 | |
1025 | 635 return false;*/ |
323 | 636 |
637 | |
1025 | 638 //c1 = -d-(n*p0) |
639 c1 = -pFace->pFacePlane.dist -(pFace->pFacePlane.vNormal.x * pRayStart->vWorldPosition.x | |
640 + pFace->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y | |
641 + pFace->pFacePlane.vNormal.z * pRayStart->vWorldPosition.z); | |
642 //if (c1 > 0) | |
643 //return false; | |
644 #define EPSILON 0.000001 | |
645 //c2 = n*u | |
646 c2 = pFace->pFacePlane.vNormal.x * ray_dir_y | |
647 + pFace->pFacePlane.vNormal.y * ray_dir_x | |
648 + pFace->pFacePlane.vNormal.z * ray_dir_z; | |
649 if (c2 > -EPSILON && c2 < EPSILON) // ray faces face's normal ( > 0) or parallel ( == 0) | |
323 | 650 return false; |
651 | |
1025 | 652 //t = -d-(n*p0)/n*u |
653 double t = c1 / c2;//òî÷êà ñîïðèêîñíîâåíèÿ | |
654 | |
655 //if (t < 0 || t > 1) | |
656 //return false; | |
323 | 657 |
1025 | 658 // p(t) = p0 + tu; |
659 // p(t) - âåêòîð óêàçûâàþùèé â òî÷êó íà ïëîñêîñòè | |
660 // p0 - íà÷àëî âåêòîðà, òî÷êà íàáëþäàòåëÿ, êàìåðû | |
661 // t - | |
662 // u - âåêòîð íàïðàâëåíèÿ | |
663 Intersection->vWorldPosition.x = pRayStart->vWorldPosition.x + t * ray_dir_y;//12432 < X < 12656 | |
664 Intersection->vWorldPosition.y = pRayStart->vWorldPosition.y + t * ray_dir_x;//-96 < Y < 1088 | |
665 Intersection->vWorldPosition.z = pRayStart->vWorldPosition.z + t * ray_dir_z;//Z == 192 | |
666 | |
667 v34.x = (signed __int64)Intersection->vWorldPosition.x; | |
668 v34.y = (signed __int64)Intersection->vWorldPosition.y; | |
669 v34.z = (signed __int64)Intersection->vWorldPosition.z; | |
323 | 670 |
1025 | 671 if ( !_4C1D2B(pFace, v34, pBModelID) ) |
323 | 672 return false; |
673 | |
674 //a5b = v27; | |
1025 | 675 //*pDepth = t; |
323 | 676 return true; |
0 | 677 } |
678 | |
679 //----- (004C1D2B) -------------------------------------------------------- | |
1025 | 680 bool Vis::_4C1D2B(BLVFace *pFace, Vec3_short_ a2, unsigned int uModelID) |
0 | 681 { |
1025 | 682 //BLVFace *v4; // esi@1 |
0 | 683 int v5; // esi@10 |
684 bool v6; // edi@10 | |
685 int v7; // ecx@12 | |
686 signed int v8; // edx@12 | |
687 signed int v9; // eax@13 | |
688 signed int v10; // ebx@14 | |
689 int v11; // edi@16 | |
690 signed int v12; // ST28_4@18 | |
691 signed __int64 v13; // qtt@18 | |
692 signed int result; // eax@21 | |
693 int v15; // [sp+10h] [bp-Ch]@10 | |
694 signed int v16; // [sp+18h] [bp-4h]@10 | |
695 | |
1025 | 696 //v4 = pFace; |
697 if (a2.x < pFace->pBounding.x1 || a2.x > pFace->pBounding.x2 || | |
698 a2.y < pFace->pBounding.y1 || a2.y > pFace->pBounding.y2 || | |
699 a2.z < pFace->pBounding.z1 || a2.z > pFace->pBounding.z2 ) | |
323 | 700 return false; |
701 | |
1025 | 702 pFace->uAttributes |= 0x80000000; |
703 return true; | |
323 | 704 if (uModelID != -1) |
1025 | 705 _4C2186_BLV_IntersectBModel(pFace, uModelID, |
323 | 706 word_F8BC48_displaced_face_intersect_plane_coords_a, |
707 word_F8BD18_displaced_face_intersect_plane_coords_b, | |
708 &a2, pFace, uModelID); | |
709 else | |
710 _4C1EE5_BLV_IntersectBModel_2((int *)&pFace, (int *)&uModelID, | |
711 word_F8BC48_displaced_face_intersect_plane_coords_a, | |
712 word_F8BD18_displaced_face_intersect_plane_coords_b, | |
713 &a2, pFace); | |
714 | |
1025 | 715 v5 = 2 * pFace->uNumVertices; |
323 | 716 v16 = 0; |
717 word_F8BC48_displaced_face_intersect_plane_coords_a[v5] = word_F8BC48_displaced_face_intersect_plane_coords_a[0]; | |
718 word_F8BD18_displaced_face_intersect_plane_coords_b[v5] = word_F8BD18_displaced_face_intersect_plane_coords_b[0]; | |
719 v15 = 0; | |
720 v6 = word_F8BD18_displaced_face_intersect_plane_coords_b[0] >= (signed int)uModelID; | |
721 if (v5 <= 0) | |
722 return false; | |
723 | |
0 | 724 do |
725 { | |
726 if ( v16 >= 2 ) | |
727 break; | |
728 v7 = 2 * v15; | |
323 | 729 v8 = word_F8BD18_displaced_face_intersect_plane_coords_b[ + v15 + 1]; |
0 | 730 if ( v6 ^ v8 >= (signed int)uModelID ) |
731 { | |
323 | 732 v9 = word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2 + 1]; |
0 | 733 if ( v9 >= (signed int)pFace ) |
734 v10 = 0; | |
735 else | |
736 v10 = 2; | |
323 | 737 v11 = v10 | word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2] < (signed int)pFace; |
0 | 738 if ( v11 != 3 ) |
739 { | |
740 if ( !v11 | |
323 | 741 || (v12 = v9 - word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2], |
0 | 742 LODWORD(v13) = v12 << 16, |
743 HIDWORD(v13) = v12 >> 16, | |
323 | 744 word_F8BC48_displaced_face_intersect_plane_coords_a[v7/2] |
745 + ((signed int)(((unsigned __int64)(v13 / (v8 - word_F8BD18_displaced_face_intersect_plane_coords_b[v7/2]) | |
746 * (signed int)((uModelID - word_F8BD18_displaced_face_intersect_plane_coords_b[v7/2]) << 16)) >> 16) + 32768) >> 16) >= (signed int)pFace) ) | |
0 | 747 ++v16; |
748 } | |
749 } | |
750 ++v15; | |
751 v6 = v8 >= (signed int)uModelID; | |
752 } | |
753 while ( v15 < v5 ); | |
754 result = 1; | |
755 if ( v16 != 1 ) | |
756 LABEL_25: | |
757 result = 0; | |
758 return result; | |
759 } | |
760 | |
761 //----- (004C1EE5) -------------------------------------------------------- | |
762 bool Vis::_4C1EE5_BLV_IntersectBModel_2(int *a1, int *a2, __int16 *a3, __int16 *a4, Vec3_short_ *a5, BLVFace *pFace) | |
763 { | |
1035 | 764 if (pFace->uAttributes & FACE_XY_PLANE) |
765 { | |
766 *a1 = a5->x; | |
767 *a2 = a5->y; | |
768 | |
769 for (uint i = 0; i < pFace->uNumVertices; ++i) | |
770 { | |
771 a3[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; | |
772 a3[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; | |
773 | |
774 a4[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; | |
775 a4[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; | |
776 } | |
777 } | |
778 else if (pFace->uAttributes & FACE_XZ_PLANE) | |
779 { | |
780 *a1 = a5->x; | |
781 *a2 = a5->z; | |
0 | 782 |
1035 | 783 for (uint i = 0; i < pFace->uNumVertices; ++i) |
0 | 784 { |
1035 | 785 a3[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; |
786 a3[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; | |
787 | |
788 a4[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; | |
789 a4[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; | |
790 } | |
791 } | |
792 else if (pFace->uAttributes & FACE_YZ_PLANE) | |
793 { | |
794 *a1 = a5->y; | |
795 *a2 = a5->z; | |
796 | |
797 for (uint i = 0; i < pFace->uNumVertices; ++i) | |
798 { | |
799 a3[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; | |
800 a3[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; | |
801 | |
802 a4[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; | |
803 a4[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; | |
0 | 804 } |
805 } | |
806 else | |
807 { | |
1035 | 808 assert(false); |
809 return false; | |
0 | 810 } |
1035 | 811 |
812 return true; | |
0 | 813 } |
814 | |
815 //----- (004C2186) -------------------------------------------------------- | |
1025 | 816 bool Vis::_4C2186_BLV_IntersectBModel(BLVFace *pFace, unsigned int ModelID, __int16 *displaced_face_intersect_plane_coords_a, __int16 *displaced_face_intersect_plane_coords_b, Vec3_short_ *a5, BLVFace *face, unsigned int uModelID) |
0 | 817 { |
818 bool result; // eax@1 | |
1025 | 819 //int *v9; // esi@1 |
820 //unsigned int v10; // ecx@1 | |
821 //unsigned int v11; // edx@3 | |
822 //signed int v12; // ecx@4 | |
0 | 823 __int16 v13; // si@4 |
824 __int16 *v14; // ecx@4 | |
825 unsigned int v15; // edx@8 | |
1025 | 826 //signed int v16; // ecx@9 |
0 | 827 __int16 v17; // si@9 |
828 __int16 *v18; // ecx@9 | |
829 unsigned int v19; // edx@12 | |
1025 | 830 //signed int v20; // ecx@13 |
0 | 831 __int16 v21; // si@13 |
832 __int16 *v22; // ecx@13 | |
1025 | 833 //signed int a1a; // [sp+14h] [bp+8h]@1 |
0 | 834 __int16 *a5a; // [sp+24h] [bp+18h]@3 |
835 __int16 *a5b; // [sp+24h] [bp+18h]@8 | |
836 __int16 *a5c; // [sp+24h] [bp+18h]@12 | |
837 | |
1025 | 838 //result = (bool)a6; |
839 //v9 = pFace; | |
840 //v10 = pFace->uAttributes; | |
841 //a1a = 0; | |
842 if ( BYTE1(pFace->uAttributes) & 1 ) | |
0 | 843 { |
1025 | 844 pFace->pFacePlane.vNormal.x = a5->x; |
845 pFace->pFacePlane.vNormal.y = a5->y; | |
846 if ( pFace->uNumVertices ) | |
0 | 847 { |
1025 | 848 //v11 = 188 * ModelID + 72; |
849 a5a = displaced_face_intersect_plane_coords_b + 1; | |
850 for ( uint i = 0; i < pFace->uNumVertices; ++i ) | |
0 | 851 { |
1025 | 852 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[ModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; |
853 displaced_face_intersect_plane_coords_b[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[ModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; | |
854 *(__int16 *)((char *)a5a + (int)(char *)displaced_face_intersect_plane_coords_a - (char *)displaced_face_intersect_plane_coords_b) = | |
855 pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[ModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; | |
856 v13 = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[ModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; | |
0 | 857 v14 = a5a; |
858 a5a += 2; | |
859 *v14 = v13; | |
860 } | |
861 } | |
862 } | |
863 else | |
864 { | |
1025 | 865 if ( BYTE1(pFace->uAttributes) & 2 ) |
0 | 866 { |
1025 | 867 pFace->pFacePlane.vNormal.x = a5->x; |
868 pFace->pFacePlane.vNormal.z = a5->z; | |
869 if ( pFace->uNumVertices ) | |
0 | 870 { |
871 v15 = 188 * uModelID + 72; | |
1025 | 872 a5b = displaced_face_intersect_plane_coords_b + 1; |
873 for ( uint i = 0; i < pFace->uNumVertices; ++i ) | |
0 | 874 { |
1025 | 875 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; |
876 *(a5b - 1) = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; | |
877 *(__int16 *)((char *)a5b + (int)displaced_face_intersect_plane_coords_a - (int)displaced_face_intersect_plane_coords_b) = pFace->pXInterceptDisplacements[i + 1] | |
878 + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; | |
879 v17 = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; | |
0 | 880 v18 = a5b; |
881 a5b += 2; | |
882 *v18 = v17; | |
883 } | |
884 } | |
885 } | |
886 else | |
887 { | |
1025 | 888 pFace->pFacePlane.vNormal.y = a5->y; |
889 pFace->pFacePlane.vNormal.z = a5->z; | |
890 if ( pFace->uNumVertices ) | |
0 | 891 { |
892 v19 = 188 * uModelID + 72; | |
1025 | 893 a5c = displaced_face_intersect_plane_coords_b + 1; |
894 for ( uint i = 0; i < pFace->uNumVertices; ++i ) | |
0 | 895 { |
1025 | 896 displaced_face_intersect_plane_coords_a[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; |
897 *(a5c - 1) = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z; | |
898 *(__int16 *)((char *)a5c + (int)(char *)displaced_face_intersect_plane_coords_a - (char *)displaced_face_intersect_plane_coords_b) = pFace->pYInterceptDisplacements[i + 1] | |
899 + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; | |
900 v21 = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; | |
0 | 901 v22 = a5c; |
902 a5c += 2; | |
903 *v22 = v21; | |
904 } | |
905 } | |
906 } | |
907 } | |
1025 | 908 return true; |
0 | 909 } |
910 | |
911 //----- (004C248E) -------------------------------------------------------- | |
912 void Vis::CastPickRay(RenderVertexSoft *pRay, float fMouseX, float fMouseY, float fPickDepth) | |
913 { | |
1025 | 914 int pRotY; // esi@1 |
915 Vec3_int_ pStartR; // ST08_12@1 | |
916 int pRotX; // ST04_4@1 | |
917 int pDepth; // eax@1 | |
0 | 918 RenderVertexSoft v11[2]; // [sp+2Ch] [bp-74h]@1 |
1025 | 919 int outx; |
0 | 920 int outz; // [sp+94h] [bp-Ch]@1 |
921 int outy; // [sp+98h] [bp-8h]@1 | |
922 | |
1025 | 923 pRotY = pIndoorCamera->sRotationY + UnprojectX((signed __int64)fMouseX); |
924 pStartR.z = pIndoorCamera->pos.z; | |
925 pStartR.x = pIndoorCamera->pos.x; | |
926 pStartR.y = pIndoorCamera->pos.y; | |
927 pRotX = pIndoorCamera->sRotationX + UnprojectY((signed __int64)fMouseY); | |
1029 | 928 pDepth = fixpoint_from_float(fPickDepth); |
1025 | 929 Vec3_int_::Rotate(pDepth, pRotY, pRotX, pStartR, &outx, &outy, &outz); |
930 | |
0 | 931 v11[0].flt_2C = 0.0; |
1025 | 932 v11[0].vWorldPosition.x = (double)outx; |
0 | 933 v11[0].vWorldPosition.y = (double)outy; |
934 v11[0].vWorldPosition.z = (double)outz; | |
1025 | 935 |
0 | 936 v11[1].flt_2C = 0.0; |
1025 | 937 v11[1].vWorldPosition.x = (double)pIndoorCamera->pos.x; |
938 v11[1].vWorldPosition.y = (double)pIndoorCamera->pos.y; | |
939 v11[1].vWorldPosition.z = (double)pIndoorCamera->pos.z; | |
940 | |
0 | 941 memcpy(pRay, &v11[1], 0x30u); |
942 memcpy(&pRay[1], v11, sizeof(pRay[1])); | |
943 } | |
944 | |
945 //----- (004C2551) -------------------------------------------------------- | |
194 | 946 Vis_ObjectInfo *Vis_SelectionList::sub_4C2551(int a2, int a3) |
0 | 947 { |
948 unsigned int v3; // esi@1 | |
949 signed int v4; // edx@1 | |
950 char *v5; // eax@2 | |
194 | 951 Vis_ObjectInfo *result; // eax@6 |
0 | 952 |
953 v3 = this->uNumPointers; | |
954 v4 = 0; | |
955 if ( (signed int)v3 <= 0 ) | |
956 { | |
957 LABEL_6: | |
958 result = 0; | |
959 } | |
960 else | |
961 { | |
194 | 962 v5 = (char *)&this->object_pool[0].sZValue; |
0 | 963 while ( *((int *)v5 + 1) != a2 || (*(int *)v5 & 0xFFFF) != a3 ) |
964 { | |
965 ++v4; | |
966 v5 += 12; | |
967 if ( v4 >= (signed int)v3 ) | |
968 goto LABEL_6; | |
969 } | |
194 | 970 result = &this->object_pool[v4]; |
0 | 971 } |
972 return result; | |
973 } | |
974 | |
975 //----- (004C2591) -------------------------------------------------------- | |
194 | 976 void Vis_SelectionList::create_object_pointers(PointerCreationType type) |
0 | 977 { |
194 | 978 switch (type) |
979 { | |
980 case All: | |
981 { | |
982 for (uint i = 0; i < uNumPointers; ++i) | |
983 object_pointers[i] = &object_pool[i]; | |
984 } | |
985 break; | |
0 | 986 |
194 | 987 case Unique: // seems quite retarted; the inner if condition will never trigger, since we compare pointers, not values. pointers will always be unique |
988 { // but it may be decompilation error thou | |
989 bool create = true; | |
990 | |
991 for (uint i = 0; i < uNumPointers; ++i) | |
0 | 992 { |
194 | 993 for (uint j = 0; j < i; ++j) |
0 | 994 { |
194 | 995 if (object_pointers[j] == &object_pool[i]) |
0 | 996 { |
194 | 997 create = false; |
998 break; | |
0 | 999 } |
1000 } | |
194 | 1001 |
1002 if (create) | |
1003 object_pointers[i] = &object_pool[i]; | |
0 | 1004 } |
1005 } | |
196 | 1006 break; |
194 | 1007 |
1008 default: | |
0 | 1009 MessageBoxW(nullptr, L"Unknown pointer creation flag passed to ::create_object_pointers()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1358", 0); |
1010 } | |
1011 } | |
1012 | |
1013 //----- (004C264A) -------------------------------------------------------- | |
194 | 1014 void Vis::sort_object_pointers(Vis_ObjectInfo **pPointers, int left, int right) |
0 | 1015 { |
1016 int v4; // edx@1 | |
1017 int v5; // ebx@1 | |
1018 int v6; // esi@2 | |
1019 signed int i; // ecx@2 | |
1020 int v8; // eax@3 | |
1021 int v9; // ebx@4 | |
1022 int v10; // ebx@6 | |
194 | 1023 Vis_ObjectInfo *v11; // eax@7 |
0 | 1024 Vis *thisa; // [sp+4h] [bp-4h]@1 |
194 | 1025 Vis_ObjectInfo *a3a; // [sp+14h] [bp+Ch]@2 |
0 | 1026 |
1027 v4 = left; | |
1028 v5 = right; | |
1029 thisa = this; | |
1030 if ( right > left ) | |
1031 { | |
1032 do | |
1033 { | |
1034 v6 = v4 - 1; | |
1035 a3a = pPointers[v5]; | |
1036 for ( i = v5; ; pPointers[i] = v11 ) | |
1037 { | |
1038 v8 = a3a->sZValue; | |
1039 LOWORD(v8) = 0; | |
1040 do | |
1041 { | |
1042 ++v6; | |
1043 v9 = pPointers[v6]->sZValue; | |
1044 LOWORD(v9) = 0; | |
1045 } | |
1046 while ( v9 < (unsigned int)v8 ); | |
1047 do | |
1048 { | |
1049 if ( i < 1 ) | |
1050 break; | |
1051 --i; | |
1052 v10 = pPointers[i]->sZValue; | |
1053 LOWORD(v10) = 0; | |
1054 } | |
1055 while ( v10 > (unsigned int)v8 ); | |
1056 v11 = pPointers[v6]; | |
1057 if ( v6 >= i ) | |
1058 break; | |
1059 pPointers[v6] = pPointers[i]; | |
1060 } | |
1061 v5 = right; | |
1062 pPointers[v6] = pPointers[right]; | |
1063 pPointers[right] = v11; | |
1064 sort_object_pointers(pPointers, v4, v6 - 1); | |
1065 v4 = v6 + 1; | |
1066 } | |
1067 while ( right > v6 + 1 ); | |
1068 } | |
1069 } | |
1070 | |
1071 //----- (004C26D0) -------------------------------------------------------- | |
1072 bool Vis::SortVerticesByX(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) | |
1073 { | |
1074 bool result; // eax@1 | |
1075 RenderVertexD3D3 *v5; // edx@2 | |
1076 RenderVertexD3D3 *v6; // esi@2 | |
1077 void *v7; // edi@2 | |
1078 unsigned int v8; // ebx@2 | |
1079 RenderVertexD3D3 *v9; // ecx@3 | |
1080 RenderVertexD3D3 *v10; // ecx@5 | |
1081 RenderVertexD3D3 *v11; // eax@8 | |
1082 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 | |
1083 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 | |
1084 Vis *thisa; // [sp+44h] [bp-Ch]@1 | |
1085 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 | |
1086 unsigned int v16; // [sp+4Ch] [bp-4h]@2 | |
1087 | |
1088 result = uEnd; | |
1089 thisa = this; | |
1090 if ( (signed int)uEnd > (signed int)uStart ) | |
1091 { | |
1092 v5 = a2; | |
1093 v6 = &a2[uEnd]; | |
1094 v7 = &v13; | |
1095 v15 = &a2[uEnd]; | |
1096 v8 = uStart - 1; | |
1097 v16 = uEnd; | |
1098 while ( 1 ) | |
1099 { | |
1100 memcpy(v7, v6, 0x20u); | |
1101 v9 = &v5[v8]; | |
1102 do | |
1103 { | |
1104 ++v9; | |
1105 ++v8; | |
1106 } | |
1107 while ( v9->pos.x < (double)v13.pos.x ); | |
1108 v10 = &v5[v16]; | |
1109 do | |
1110 { | |
1111 --v10; | |
1112 --v16; | |
1113 } | |
1114 while ( v10->pos.x > (double)v13.pos.x ); | |
1115 if ( (signed int)v8 >= (signed int)v16 ) | |
1116 break; | |
1117 v11 = &v5[v16]; | |
1118 memcpy(&v12, &a2[v8], sizeof(v12)); | |
1119 v5 = a2; | |
1120 memcpy(&a2[v8], v11, sizeof(a2[v8])); | |
1121 v6 = &v12; | |
1122 v7 = v11; | |
1123 } | |
1124 memcpy(&v12, &v5[v8], sizeof(v12)); | |
1125 memcpy(&v5[v8], v15, sizeof(v5[v8])); | |
1126 memcpy(v15, &v12, 0x20u); | |
1127 SortVerticesByX(v5, uStart, v8 - 1); | |
1128 SortVerticesByX(a2, v8 + 1, uEnd); | |
1129 } | |
1130 return true; | |
1131 } | |
1132 | |
1133 //----- (004C27AD) -------------------------------------------------------- | |
1134 bool Vis::SortVerticesByY(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) | |
1135 { | |
1136 bool result; // eax@1 | |
1137 RenderVertexD3D3 *v5; // edx@2 | |
1138 RenderVertexD3D3 *v6; // esi@2 | |
30 | 1139 void *v7; // edi@2 |
0 | 1140 unsigned int v8; // ebx@2 |
30 | 1141 float *v9; // ecx@3 |
1142 float *v10; // ecx@5 | |
1143 RenderVertexD3D3 *v11; // eax@8 | |
0 | 1144 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 |
30 | 1145 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 |
0 | 1146 Vis *thisa; // [sp+44h] [bp-Ch]@1 |
30 | 1147 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 |
1148 unsigned int v16; // [sp+4Ch] [bp-4h]@2 | |
0 | 1149 |
1150 result = uEnd; | |
1151 thisa = this; | |
1152 if ( (signed int)uEnd > (signed int)uStart ) | |
1153 { | |
1154 v5 = a2; | |
1155 v6 = &a2[uEnd]; | |
30 | 1156 v7 = &v13; |
1157 v15 = &a2[uEnd]; | |
0 | 1158 v8 = uStart - 1; |
30 | 1159 v16 = uEnd; |
0 | 1160 while ( 1 ) |
1161 { | |
30 | 1162 memcpy(v7, v6, 0x20u); |
1163 v9 = &v5[v8].pos.y; | |
0 | 1164 do |
1165 { | |
30 | 1166 v9+=8; |
0 | 1167 ++v8; |
1168 } | |
30 | 1169 while ( *v9 < (double)v13.pos.y ); |
1170 v10 = &v5[v16].pos.y; | |
0 | 1171 do |
1172 { | |
30 | 1173 v10-=8; |
1174 --v16; | |
0 | 1175 } |
30 | 1176 while ( *v10 > (double)v13.pos.y ); |
1177 if ( (signed int)v8 >= (signed int)v16 ) | |
0 | 1178 break; |
30 | 1179 v11 = &v5[v16]; |
0 | 1180 memcpy(&v12, &a2[v8], sizeof(v12)); |
1181 v5 = a2; | |
30 | 1182 memcpy(&a2[v8], v11, sizeof(a2[v8])); |
0 | 1183 v6 = &v12; |
30 | 1184 v7 = v11; |
0 | 1185 } |
1186 memcpy(&v12, &v5[v8], sizeof(v12)); | |
30 | 1187 memcpy(&v5[v8], v15, sizeof(v5[v8])); |
1188 memcpy(v15, &v12, 0x20u); | |
194 | 1189 SortVerticesByY(v5, uStart, v8 - 1); |
1190 SortVerticesByY(a2, v8 + 1, uEnd); | |
0 | 1191 } |
1192 return true; | |
1193 } | |
1194 | |
1195 //----- (004C288E) -------------------------------------------------------- | |
196 | 1196 bool Vis::SortByScreenSpaceX(RenderVertexSoft *pArray, int sLeft, int sRight) |
0 | 1197 { |
1198 bool result; // eax@1 | |
1199 RenderVertexSoft *v5; // edx@2 | |
1200 int v6; // ebx@2 | |
1201 int i; // ecx@2 | |
1202 int v8; // esi@3 | |
1203 int v9; // esi@5 | |
159 | 1204 //RenderVertexSoft *v10; // eax@8 |
1205 const void *v10; | |
0 | 1206 RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 |
1207 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 | |
159 | 1208 //float v13; // [sp+4Ch] [bp-24h]@4 |
0 | 1209 int v14; // [sp+64h] [bp-Ch]@7 |
159 | 1210 //Vis *thisa; // [sp+68h] [bp-8h]@1 |
196 | 1211 //void *thisa; |
159 | 1212 //RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 |
1213 const void *v16; | |
0 | 1214 |
196 | 1215 //thisa = this; |
159 | 1216 if (sRight <= sLeft) |
1217 return true; | |
1218 v5 = pArray; | |
1219 v16 = &pArray[sRight]; | |
1220 v6 = sLeft - 1; | |
1221 memcpy(&v12, &pArray[sRight], sizeof(v12)); | |
1222 for ( i = sRight; ; i = v14 ) | |
0 | 1223 { |
159 | 1224 v8 = (int)&v5[v6].vWorldViewProjX; |
1225 do | |
0 | 1226 { |
159 | 1227 v8 += 48; |
1228 ++v6; | |
1229 } | |
1230 while ( *(float *)v8 < v12.vWorldViewProjX); | |
1231 v9 = (int)&v5[i].vWorldViewProjX; | |
1232 do | |
1233 { | |
1234 v9 -= 48; | |
1235 --i; | |
0 | 1236 } |
159 | 1237 while ( *(float *)v9 > v12.vWorldViewProjX); |
1238 v14 = i; | |
1239 if ( v6 >= i ) | |
1240 break; | |
1241 v10 = &v5[i]; | |
1242 memcpy(&v11, &pArray[v6], sizeof(v11)); | |
1243 v5 = pArray; | |
1244 memcpy(&pArray[v6], v10, sizeof(pArray[v6])); | |
1245 memcpy((void *)v10, &v11, sizeof(0x30u)); | |
0 | 1246 } |
159 | 1247 memcpy(&v11, &v5[v6], sizeof(v11)); |
1248 memcpy(&v5[v6], v16, sizeof(v5[v6])); | |
1249 memcpy((void *)v16, &v11, sizeof(0x30u)); | |
196 | 1250 SortByScreenSpaceX(v5, sLeft, v6 - 1); |
1251 SortByScreenSpaceX(pArray, v6 + 1, sRight); | |
0 | 1252 return true; |
1253 } | |
1254 | |
1255 //----- (004C297E) -------------------------------------------------------- | |
196 | 1256 bool Vis::SortByScreenSpaceY(RenderVertexSoft *pArray, int sLeft, int sRight) |
0 | 1257 { |
159 | 1258 //bool result; // eax@1 |
0 | 1259 RenderVertexSoft *v5; // edx@2 |
1260 int v6; // ebx@2 | |
1261 int i; // ecx@2 | |
1262 int v8; // esi@3 | |
1263 int v9; // esi@5 | |
159 | 1264 //RenderVertexSoft *v10; // eax@8 |
1265 const void *v10; | |
1266 //char v11; // [sp+4h] [bp-6Ch]@8 | |
1267 RenderVertexSoft v11; | |
0 | 1268 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 |
159 | 1269 //float v13; // [sp+50h] [bp-20h]@4 |
0 | 1270 int v14; // [sp+64h] [bp-Ch]@7 |
159 | 1271 //Vis *thisa; // [sp+68h] [bp-8h]@1 |
0 | 1272 RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 |
1273 | |
159 | 1274 if (sRight <= sLeft) |
1275 return true; | |
1276 v5 = pArray; | |
1277 v16 = &pArray[sRight]; | |
1278 v6 = sLeft - 1; | |
1279 memcpy(&v12, &pArray[sRight], sizeof(v12)); | |
1280 for ( i = sRight; ; i = v14 ) | |
0 | 1281 { |
159 | 1282 v8 = (int)&v5[v6].vWorldViewProjY; |
1283 do | |
1284 { | |
1285 v8 += 48; | |
1286 ++v6; | |
1287 } | |
1288 while ( *(float *)v8 < v12.vWorldViewProjY); | |
1289 v9 = (int)&v5[v6].vWorldViewProjY; | |
1290 do | |
0 | 1291 { |
159 | 1292 v9 -= 48; |
1293 --i; | |
0 | 1294 } |
159 | 1295 while ( *(float *)v9 > v12.vWorldViewProjY); |
1296 v14 = i; | |
1297 if ( v6 >= i ) | |
1298 break; | |
1299 v10 = &v5[i]; | |
1300 memcpy(&v11, &pArray[v6], sizeof(0x30)); | |
1301 v5 = pArray; | |
1302 memcpy(&pArray[v6], v10, sizeof(pArray[v6])); | |
1303 memcpy((void *)v10, &v11, sizeof(0x30)); | |
0 | 1304 } |
159 | 1305 memcpy(&v11, &v5[v6], sizeof(0x30)); |
1306 memcpy(&v5[v6], v16, sizeof(v5[v6])); | |
1307 memcpy((void *)v16, &v11, sizeof(0x30)); | |
196 | 1308 SortByScreenSpaceY(v5, sLeft, v6 - 1); |
1309 SortByScreenSpaceY(pArray, v6 + 1, sRight); | |
0 | 1310 return true; |
1311 } | |
1312 | |
1313 | |
1314 //----- (004C04AF) -------------------------------------------------------- | |
1315 Vis::Vis() | |
1316 { | |
1317 RenderVertexSoft v3; // [sp+Ch] [bp-60h]@1 | |
1318 RenderVertexSoft v4; // [sp+3Ch] [bp-30h]@1 | |
1319 | |
1320 v3.flt_2C = 0.0; | |
1321 v3.vWorldPosition.x = 0.0; | |
1322 v3.vWorldPosition.y = 65536.0; | |
1323 v3.vWorldPosition.z = 0.0; | |
1324 v4.flt_2C = 0.0; | |
1325 v4.vWorldPosition.x = 65536.0; | |
1326 v4.vWorldPosition.y = 0.0; | |
1327 v4.vWorldPosition.z = 0.0; | |
196 | 1328 memcpy(&stru_200C, &v4, sizeof(stru_200C)); |
1329 | |
0 | 1330 v4.flt_2C = 0.0; |
1331 v4.vWorldPosition.x = 0.0; | |
1332 v4.vWorldPosition.y = 65536.0; | |
1333 v4.vWorldPosition.z = 0.0; | |
196 | 1334 memcpy(&stru_203C, &v3, sizeof(stru_203C)); |
1335 | |
0 | 1336 v3.flt_2C = 0.0; |
1337 v3.vWorldPosition.x = 65536.0; | |
1338 v3.vWorldPosition.y = 0.0; | |
1339 v3.vWorldPosition.z = 0.0; | |
196 | 1340 memcpy(&stru_206C, &v3, sizeof(stru_206C)); |
1341 memcpy(&stru_209C, &v4, sizeof(stru_209C)); | |
1342 | |
1343 keyboard_pick_depth = 512; | |
0 | 1344 } |
1345 | |
1346 //----- (004C055C) -------------------------------------------------------- | |
194 | 1347 Vis_SelectionList::Vis_SelectionList() |
0 | 1348 { |
1349 for (uint i = 0; i < 512; ++i) | |
1350 { | |
194 | 1351 object_pool[i].object = nullptr; |
1352 object_pool[i].sZValue = -1; | |
1353 object_pool[i].object_type = VisObjectType_Any; | |
0 | 1354 } |
1355 uNumPointers = 0; | |
1356 } | |
1357 | |
1358 //----- (004C05CC) -------------------------------------------------------- | |
194 | 1359 bool Vis::PickKeyboard(Vis_SelectionList *list, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) |
0 | 1360 { |
194 | 1361 if (!list) |
1362 list = &default_list; | |
1363 list->uNumPointers = 0; | |
0 | 1364 |
196 | 1365 PickBillboards_Keyboard(keyboard_pick_depth, list, sprite_filter); |
194 | 1366 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
196 | 1367 PickIndoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); |
194 | 1368 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) |
196 | 1369 PickOutdoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); |
0 | 1370 else |
194 | 1371 assert(false); |
1372 | |
1373 list->create_object_pointers(Vis_SelectionList::Unique); | |
1374 sort_object_pointers(list->object_pointers, 0, list->uNumPointers - 1); | |
1375 | |
0 | 1376 return true; |
1377 } | |
1378 | |
1379 //----- (004C0646) -------------------------------------------------------- | |
194 | 1380 bool Vis::PickMouse(float fDepth, float fMouseX, float fMouseY, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) |
0 | 1381 { |
1382 RenderVertexSoft pMouseRay[2]; // [sp+1Ch] [bp-60h]@1 | |
1383 | |
194 | 1384 default_list.uNumPointers = 0; |
0 | 1385 CastPickRay(pMouseRay, fMouseX, fMouseY, fDepth); |
194 | 1386 PickBillboards_Mouse(fDepth, fMouseX, fMouseY, &default_list, sprite_filter); |
0 | 1387 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
196 | 1388 PickIndoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter); |
227 | 1389 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) |
1390 PickOutdoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter, false); | |
0 | 1391 else |
227 | 1392 { |
323 | 1393 Log::Warning(L"Picking mouse in undefined level"); // picking in main menu is default (buggy) game behaviour. should've returned false in Game::PickMouse |
227 | 1394 return false; |
1395 } | |
194 | 1396 default_list.create_object_pointers(Vis_SelectionList::All); |
1397 sort_object_pointers(default_list.object_pointers, 0, default_list.uNumPointers - 1); | |
1398 | |
0 | 1399 return true; |
1400 } | |
1401 | |
1402 //----- (004C06F8) -------------------------------------------------------- | |
196 | 1403 void Vis::PickBillboards_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1404 { |
194 | 1405 for (int i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) |
1406 { | |
1407 auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; | |
0 | 1408 |
194 | 1409 if (is_part_of_selection((void *)i, filter)) |
0 | 1410 { |
194 | 1411 if (DoesRayIntersectBillboard(pick_depth, i)) |
0 | 1412 { |
194 | 1413 auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; |
1414 | |
1415 list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); | |
0 | 1416 } |
1417 } | |
1418 } | |
1419 } | |
1420 | |
194 | 1421 |
1422 // tests the object against selection filter to determine whether it can be picked or not | |
0 | 1423 //----- (004C0791) -------------------------------------------------------- |
194 | 1424 bool Vis::is_part_of_selection(void *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, Vis_SelectionFilter *filter) |
0 | 1425 { |
194 | 1426 //stru157 *v3; // esi@1 |
1427 //int result; // eax@1 | |
0 | 1428 int v5; // edx@2 |
194 | 1429 //int v6; // ecx@2 |
1430 //char v7; // zf@3 | |
0 | 1431 int v8; // esi@5 |
1432 std::string *v9; // ecx@7 | |
1433 Actor *v10; // edi@18 | |
194 | 1434 //const char *v12; // [sp-20h] [bp-2Ch]@7 |
0 | 1435 int v13; // [sp-1Ch] [bp-28h]@7 |
194 | 1436 //std::string v14; // [sp-18h] [bp-24h]@7 |
1437 //const char *v15; // [sp-8h] [bp-14h]@7 | |
0 | 1438 int v16; // [sp-4h] [bp-10h]@7 |
1439 | |
194 | 1440 switch (filter->object_type) |
0 | 1441 { |
194 | 1442 case VisObjectType_Any: |
1443 return true; | |
1444 | |
1445 case VisObjectType_Sprite: | |
0 | 1446 { |
194 | 1447 v5 = filter->field_10; |
848 | 1448 int object_idx = PID_ID(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid); |
1449 int object_type = PID_TYPE(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid); | |
194 | 1450 if ( v5 & 2 ) |
1451 { | |
1452 if (object_type == filter->object_id) | |
1453 return false; | |
1454 return true; | |
1455 } | |
1456 if ( v5 & 4 ) | |
1457 { | |
1458 v8 = filter->object_id; | |
1459 if ( object_type != filter->object_id) | |
1460 return true; | |
1461 if (v8 != OBJECT_Decoration) | |
1462 { | |
1463 MessageBoxA(nullptr, "Unsupported \"exclusion if no event\" type in CVis::is_part_of_selection", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:207", 0); | |
1464 return true; | |
1465 } | |
1466 if (pLevelDecorations[object_idx].uCog || pLevelDecorations[object_idx].field_16_event_id) | |
1467 return true; | |
1468 return pLevelDecorations[object_idx].IsInteractive(); | |
1469 } | |
1470 if (object_type == filter->object_id) | |
1471 { | |
1472 if (object_type != OBJECT_Actor) | |
1473 { | |
1474 MessageBoxA(nullptr, "Default case reached in VIS", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:245", 0); | |
1475 return true; | |
1476 } | |
1477 | |
1478 v10 = &pActors[object_idx]; | |
1479 int result = 1 << LOBYTE(v10->uAIState); | |
1480 if ( result & filter->field_C | |
1481 || !(result & filter->field_8) | |
1482 || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 ) | |
1483 return false; | |
1484 if ( !(filter->field_10 & 1) ) | |
1485 return true; | |
1486 | |
1487 result = v10->GetActorsRelation(nullptr); | |
1488 if (result == 0) | |
1489 return false; | |
1490 return true; | |
1491 } | |
1492 return false; | |
0 | 1493 } |
194 | 1494 |
1495 case VisObjectType_Face: | |
0 | 1496 { |
194 | 1497 uint face_attrib = 0; |
1498 bool no_event = true; | |
1499 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
1500 { | |
1501 auto face = (ODMFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; | |
1502 no_event = face->sCogTriggeredID == 0; | |
1503 face_attrib = face->uAttributes; | |
1504 } | |
1505 else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
1506 { | |
1507 auto face = (BLVFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; | |
1508 no_event = pIndoor->pFaceExtras[face->uFaceExtraID].uEventID == 0; | |
1509 face_attrib = face->uAttributes; | |
1510 } | |
1511 else | |
1512 assert(false); | |
1513 | |
1514 if (filter->object_id != OBJECT_BLVDoor) | |
1515 return true; | |
1516 if (no_event || face_attrib & filter->field_C) | |
1517 return false; | |
1518 return (face_attrib & filter->field_8) != 0; | |
0 | 1519 } |
194 | 1520 |
1521 default: | |
1522 assert(false); | |
0 | 1523 } |
1524 } | |
1525 | |
1526 //----- (004C091D) -------------------------------------------------------- | |
1527 bool Vis::DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) | |
1528 { | |
159 | 1529 int v3; // eax@3 |
1530 //signed int v5; // ecx@4 | |
1531 //float v6; // ST04_4@6 | |
1532 //float v7; // ST00_4@7 | |
194 | 1533 //int v8; // eax@10 |
1534 //unsigned int v9; // eax@12 | |
159 | 1535 int v10; // eax@17 |
1536 double v11; // st6@18 | |
1537 double v12; // st7@18 | |
1538 double v13; // st4@18 | |
1539 float v14; // ST0C_4@22 | |
1540 float v15; // ST08_4@22 | |
1541 //float v16; // ST04_4@23 | |
1542 //float v17; // ST00_4@24 | |
194 | 1543 //signed int v18; // eax@27 |
1544 //unsigned int v19; // eax@29 | |
159 | 1545 double v20; // st6@32 |
1546 double v21; // st7@32 | |
1547 int v22; // eax@32 | |
1548 double v23; // st7@36 | |
1549 //void *v24; // esi@40 | |
1550 float v25; // ST08_4@40 | |
1551 //float v26; // ST04_4@41 | |
1552 //float v27; // ST00_4@42 | |
1553 int v28; // eax@45 | |
1554 unsigned int v29; // eax@47 | |
1555 char result; // al@48 | |
1556 struct RenderVertexSoft pPickingRay[2]; | |
1557 //int v31; // [sp+20h] [bp-DCh]@5 | |
1558 struct RenderVertexSoft local_80[2]; | |
1559 //int v32; // [sp+80h] [bp-7Ch]@22 | |
1560 float v33; // [sp+E0h] [bp-1Ch]@33 | |
1561 float v34; // [sp+E4h] [bp-18h]@32 | |
1562 int v35; // [sp+E8h] [bp-14h]@5 | |
1563 int v36; // [sp+ECh] [bp-10h]@5 | |
194 | 1564 int v37; // [sp+F0h] [bp-Ch]@5 |
159 | 1565 float v38; // [sp+F4h] [bp-8h]@17 |
1566 //void *v39; // [sp+F8h] [bp-4h]@1 | |
1567 signed int v40; // [sp+108h] [bp+Ch]@17 | |
1568 float v41; // [sp+108h] [bp+Ch]@32 | |
0 | 1569 |
194 | 1570 static Vis_SelectionList Vis_static_stru_F91E10; |
0 | 1571 Vis_static_stru_F91E10.uNumPointers = 0; |
159 | 1572 v3 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID; |
1573 if (v3 == -1) | |
1574 return false; | |
1575 if (pBillboardRenderList[v3].GetFloatZ() > fDepth) | |
0 | 1576 { |
159 | 1577 LABEL_49: |
1578 return false; | |
1579 } | |
194 | 1580 |
159 | 1581 v37 = pBillboardRenderList[v3].sZValue & 0xFFFF0000; |
1582 GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuards, 4, (float *)&v35, (float *)&v36); | |
194 | 1583 CastPickRay(pPickingRay, *(float *)&v35, *(float *)&v36, fDepth); |
1584 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
196 | 1585 PickIndoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter); |
0 | 1586 else |
196 | 1587 PickOutdoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter, false); |
194 | 1588 Vis_static_stru_F91E10.create_object_pointers(); |
1589 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); | |
159 | 1590 if (Vis_static_stru_F91E10.uNumPointers) |
0 | 1591 { |
194 | 1592 if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) |
1593 return 1; | |
159 | 1594 } |
692 | 1595 else if ((double)(pViewport->uScreen_TL_X) <= *(float *)&v35 && |
1596 (double)pViewport->uScreen_BR_X >= *(float *)&v35 && | |
1597 (double)pViewport->uScreen_TL_Y <= *(float *)&v36 && | |
1598 (double)pViewport->uScreen_BR_Y >= *(float *)&v36) | |
159 | 1599 return 1; |
1600 v40 = 0; | |
1601 v10 = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y; | |
1602 LODWORD(v38) = (int)&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y; | |
0 | 1603 while ( 1 ) |
1604 { | |
159 | 1605 v12 = *(float *)(v10 - 4); |
1606 v11 = *(float *)v10; | |
1607 v13 = *(float *)(v10 - 4); | |
0 | 1608 Vis_static_stru_F91E10.uNumPointers = 0; |
692 | 1609 if ( v13 >= (double)(pViewport->uScreen_TL_X)) |
0 | 1610 { |
692 | 1611 if ( v12 <= (double)pViewport->uScreen_BR_X ) |
0 | 1612 { |
692 | 1613 if ( v11 >= (double)pViewport->uScreen_TL_Y ) |
159 | 1614 { |
692 | 1615 if ( v11 <= (double)pViewport->uScreen_BR_Y ) |
159 | 1616 { |
1617 v14 = v11; | |
1618 v15 = v12; | |
1619 CastPickRay(local_80, SLODWORD(v15), v14, fDepth); | |
1620 if ( uCurrentlyLoadedLevelType == 1 ) | |
196 | 1621 PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter); |
159 | 1622 else |
196 | 1623 PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false); |
194 | 1624 Vis_static_stru_F91E10.create_object_pointers(); |
1625 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); | |
159 | 1626 if ( !Vis_static_stru_F91E10.uNumPointers ) |
1627 break; | |
194 | 1628 else |
1629 { | |
1630 //v18 = Vis_static_stru_F91E10.uNumPointers <= 0 ? 0 : (int); | |
1631 //v19 = *(_DWORD *)(v18 + 4); | |
1632 //LOWORD(v19) = 0; | |
1633 if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) | |
159 | 1634 break; |
194 | 1635 } |
159 | 1636 } |
1637 } | |
0 | 1638 } |
1639 } | |
159 | 1640 ++v40; |
1641 v10 = LODWORD(v38) + 32; | |
1642 LODWORD(v38) += 32; | |
1643 if ( v40 >= 4 ) | |
0 | 1644 { |
159 | 1645 if ( uCurrentlyLoadedLevelType != 2 ) |
1646 return false; | |
1647 v21 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.x; | |
1648 v20 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x; | |
1649 v22 = *(int *)(&pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[0].pos.y); | |
1650 v34 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[3].pos.x; | |
1651 LODWORD(v38) = v22; | |
1652 v41 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuards[1].pos.y; | |
1653 if ( v21 > v20 ) | |
0 | 1654 { |
159 | 1655 v33 = v21; |
1656 v21 = v34; | |
1657 v20 = v33; | |
0 | 1658 } |
159 | 1659 if ( v38 > (double)v41 ) |
1660 v41 = v38; | |
1661 Vis_static_stru_F91E10.uNumPointers = 0; | |
1662 v23 = (v20 - v21) * 0.5; | |
692 | 1663 if ( v23 < (double)(pViewport->uScreen_TL_X) |
1664 || v23 > (double)pViewport->uScreen_BR_X | |
1665 || (double)pViewport->uScreen_TL_Y > v41 | |
1666 || (double)pViewport->uScreen_BR_Y < v41 | |
159 | 1667 || ((v25 = v23, CastPickRay(local_80, SLODWORD(v25), v41, fDepth), uCurrentlyLoadedLevelType != 1) ? |
196 | 1668 (PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false)) : |
1669 (PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter)), | |
194 | 1670 (Vis_static_stru_F91E10.create_object_pointers(), |
1671 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1), | |
159 | 1672 Vis_static_stru_F91E10.uNumPointers) |
194 | 1673 && (Vis_static_stru_F91E10.uNumPointers <= 0 ? (v28 = 0) : (v28 = (int)Vis_static_stru_F91E10.object_pointers), |
159 | 1674 v29 = *(_DWORD *)(v28 + 4), |
1675 LOWORD(v29) = 0, | |
1676 v29 <= v37)) ) | |
1677 return false; | |
0 | 1678 break; |
1679 } | |
1680 } | |
194 | 1681 return true; |
0 | 1682 } |
1683 // F93E18: using guessed type char static_byte_F93E18_init; | |
1684 | |
1685 //----- (004C0D32) -------------------------------------------------------- | |
196 | 1686 void Vis::PickIndoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1687 { |
1688 int result; // eax@1 | |
742 | 1689 signed int pFaceID; // esi@2 |
1690 BLVFace *pFace; // edi@4 | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
1691 //unsigned int v7; // eax@6 |
194 | 1692 Vis_ObjectInfo *v8; // eax@6 |
0 | 1693 signed int i; // [sp+18h] [bp-8h]@1 |
1694 | |
1695 result = 0; | |
676
ecfb1b3c9a39
BLV: when standing right on the portal (orange wall) everything looks fine
Nomad
parents:
618
diff
changeset
|
1696 for ( i = 0; i < (signed int)pBspRenderer->num_faces; ++i ) |
0 | 1697 { |
742 | 1698 pFaceID = pBspRenderer->faces[result].uFaceID; |
1699 if ( pFaceID >= 0 ) | |
0 | 1700 { |
742 | 1701 if ( pFaceID < (signed int)pIndoor->uNumFaces ) |
0 | 1702 { |
742 | 1703 pFace = &pIndoor->pFaces[pFaceID]; |
1704 if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) ) | |
0 | 1705 { |
742 | 1706 if ( is_part_of_selection(pFace, filter) ) |
0 | 1707 { |
916 | 1708 v8 = DetermineFacetIntersection(pFace, PID(OBJECT_BModel, pFaceID), pick_depth); |
0 | 1709 if ( v8 ) |
194 | 1710 list->AddObject(v8->object, v8->object_type, v8->sZValue); |
0 | 1711 } |
1712 } | |
1713 } | |
1714 } | |
1715 result = i + 1; | |
1716 } | |
1717 } | |
1718 | |
1719 //----- (004C0DEA) -------------------------------------------------------- | |
196 | 1720 void Vis::PickOutdoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1721 { |
196 | 1722 for (uint i = 0; i < pOutdoor->uNumBModels; ++i) |
1723 { | |
1724 int v17; | |
1725 if (!IsBModelVisible(i, &v17)) | |
1726 continue; | |
1727 if (!v17) | |
1728 continue; | |
0 | 1729 |
196 | 1730 auto bmodel = pOutdoor->pBModels + i; |
1731 for (uint j = 0; j < bmodel->uNumFaces; ++j) | |
0 | 1732 { |
916 | 1733 auto face = &bmodel->pFaces[j]; |
196 | 1734 |
1735 if (is_part_of_selection(face, filter) ) | |
0 | 1736 { |
196 | 1737 BLVFace blv_face; |
1738 blv_face.FromODM(face); | |
1739 | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
1740 int pid = PID(OBJECT_BModel, j | (i << 6)); |
916 | 1741 if (auto object_info = DetermineFacetIntersection(&blv_face, pid, pick_depth)) |
196 | 1742 list->AddObject(object_info->object, object_info->object_type, object_info->sZValue); |
0 | 1743 } |
1744 } | |
1745 } | |
1746 } |