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