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