DayZ 1.29
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено

◆ FilterObstructedObjectsByGrouping()

static void FilterObstructedObjectsByGrouping ( vector origin,
float range,
float distanceDelta,
array< Object > objects,
array< Object > obstructingObjects,
out array< Object > filteredObjects,
bool doDistanceCheck = false,
bool checkIfDistanceCanBeIgnored = false,
float maxDist = 0 )
staticprotected

group objects that are close to each other together

См. определение в файле MiscGameplayFunctions.c строка 1303

1304 {
1305 array<Object> vicinityObjects= new array<Object>;
1306 vicinityObjects.Copy(objects);
1307
1308 int i = 0;
1309 int j = 0;
1310 int k = 0;
1311 int mCount = vicinityObjects.Count();
1312
1313 if (!filteredObjects)
1314 filteredObjects = new array<Object>();
1315
1316 // Remove objects that are too far from the player anyways
1317 if ( doDistanceCheck )
1318 {
1319 for ( i = vicinityObjects.Count() - 1; i >= 0; --i )
1320 {
1321 Object obj = vicinityObjects[i];
1322 if ( obj && !CanIgnoreDistanceCheck( obj ) && vector.DistanceSq(origin, obj.GetPosition()) > maxDist * maxDist )
1323 vicinityObjects.Remove(i);
1324 }
1325 }
1326
1327 // Sort obstructingObjects to have the furthest one first
1328 array<Object> sortedObstructingObjects = new array<Object>();
1329 array<float> distanceHelper = new array<float>();
1330 array<float> distanceHelperUnsorted = new array<float>();
1331 float distance, dist1, dist2;
1332
1333 for ( i = 0; i < obstructingObjects.Count(); ++i )
1334 {
1335 distance = vector.DistanceSq(obstructingObjects[i].GetWorldPosition(), origin);
1336 distanceHelper.Insert(distance);
1337 }
1338
1339 distanceHelperUnsorted.Copy(distanceHelper);
1340 distanceHelper.Sort();
1341
1342 for ( i = distanceHelper.Count() - 1; i >= 0; --i )
1343 sortedObstructingObjects.Insert(obstructingObjects[distanceHelperUnsorted.Find(distanceHelper[i])]);
1344
1346 array<ref array<Object>> objectGroups = new array<ref array<Object>>();
1347 array<Object> group;
1348
1349 float cos = Math.Cos(90);
1350 float sin = Math.Sin(90);
1351
1352 // Iterate through sorted obstructingObjects
1353 for ( i = 0; i < sortedObstructingObjects.Count(); ++i )
1354 {
1355 Object obstrObj = sortedObstructingObjects[i];
1356 vector worldPos = obstrObj.GetWorldPosition();
1357 vector min, max;
1358 vector minMax[2];
1359 if ( obstrObj.GetCollisionBox(minMax) )
1360 {
1361 min = minMax[0];
1362 max = minMax[1];
1363 max = max * (obstrObj.GetOrientation() * range);
1364
1365 vector center, dx, dy, dz, half;
1366 center = (min + max) * 0.5;
1367 dz = obstrObj.GetOrientation();
1368 dx = vector.RotateAroundZero(dz, vector.Up, cos, sin);
1369 dy = vector.RotateAroundZero(dz, vector.Aside, cos, sin);
1370 half = (max - min) * 0.5;
1371 half = Vector(Math.AbsFloat(half[0]), Math.AbsFloat(half[1]), Math.AbsFloat(half[2]));
1372
1373 group = new array<Object>();
1374
1375 // Group objects within the above box
1376 for ( j = vicinityObjects.Count() - 1; j >= 0; --j )
1377 {
1378 Object vicObj = vicinityObjects[j];
1379 if ( vicObj )
1380 {
1381 vector d = vicObj.GetWorldPosition() - worldPos + center;
1382 if ( Math.AbsFloat(vector.Dot(d, dx)) <= half[0] && Math.AbsFloat(vector.Dot(d, dy)) <= half[1] && Math.AbsFloat(vector.Dot(d, dz)) <= half[2] )
1383 {
1384 group.Insert(vicObj);
1385 vicinityObjects.Remove(j);
1386 }
1387 }
1388 }
1389
1390 if ( group.Count() > 0 )
1391 tempGroups.Insert(group);
1392 }
1393 }
1394
1395 // Go through the objects grouped by obstruction to split them by distance too
1396 for ( i = 0; i < tempGroups.Count(); ++i )
1397 SplitArrayIntoGroupsByDistance(tempGroups[i], objectGroups, distanceDelta);
1398
1399 // Split initial groups by distance
1400 SplitArrayIntoGroupsByDistance(vicinityObjects, objectGroups, distanceDelta);
1401
1402 // Raycast items in groups (previously sample item in group which is not enough, sadly)
1403 IsObjectObstructedCache cache = new IsObjectObstructedCache(origin, mCount);
1404 foreach (array<Object> objectGroup : objectGroups)
1405 {
1406 foreach (Object filteredObject : objectGroup)
1407 {
1408 if (!IsObjectObstructedEx(filteredObject, cache))
1409 filteredObjects.Insert(filteredObject);
1410 }
1411
1412 }
1413
1414 cache.ClearCache();
1415 }
static bool CanIgnoreDistanceCheck(Object obj)
Определения MiscGameplayFunctions.c:1297
void IsObjectObstructedCache(vector rayCastStart, int totalObjects)
Определения MiscGameplayFunctions.c:1950
static bool IsObjectObstructedEx(Object object, IsObjectObstructedCache cache, bool doDistanceCheck=false, vector distanceCheckPos="0 0 0", float maxDist=0)
Определения MiscGameplayFunctions.c:1460
static void SplitArrayIntoGroupsByDistance(array< Object > objects, array< ref array< Object > > objectGroups, float squaredDistanceDelta)
Определения MiscGameplayFunctions.c:1417
Определения EnMath.c:7
Определения ObjectTyped.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto native float DistanceSq(vector v1, vector v2)
Returns the square distance between tips of two 3D vectors.
static const vector Aside
Определения EnConvert.c:121
static float Dot(vector v1, vector v2)
Returns Dot product of vector v1 and vector v2.
Определения EnConvert.c:284
static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
Rotate a vector around 0,0,0.
Определения EnConvert.c:490
static const vector Up
Определения EnConvert.c:120
Определения EnConvert.c:119
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Cos(float angle)
Returns cosinus of angle in radians.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto float AbsFloat(float f)
Returns absolute value.

Перекрестные ссылки Math::AbsFloat(), vector::Aside, CanIgnoreDistanceCheck(), Math::Cos(), vector::DistanceSq(), vector::Dot(), IsObjectObstructedCache(), IsObjectObstructedEx(), vector::RotateAroundZero(), Math::Sin(), SplitArrayIntoGroupsByDistance(), vector::Up и Vector().