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