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