DayZ 1.30
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 строка 1436

1437 {
1438 array<Object> vicinityObjects= new array<Object>;
1439 vicinityObjects.Copy(objects);
1440
1441 int i = 0;
1442 int j = 0;
1443 int k = 0;
1444 int mCount = vicinityObjects.Count();
1445
1446 if (!filteredObjects)
1447 filteredObjects = new array<Object>();
1448
1449 // Remove objects that are too far from the player anyways
1450 if ( doDistanceCheck )
1451 {
1452 for ( i = vicinityObjects.Count() - 1; i >= 0; --i )
1453 {
1454 Object obj = vicinityObjects[i];
1455 if ( obj && !CanIgnoreDistanceCheck( obj ) && vector.DistanceSq(origin, obj.GetPosition()) > maxDist * maxDist )
1456 vicinityObjects.Remove(i);
1457 }
1458 }
1459
1460 // Sort obstructingObjects to have the furthest one first
1461 array<Object> sortedObstructingObjects = new array<Object>();
1462 array<float> distanceHelper = new array<float>();
1463 array<float> distanceHelperUnsorted = new array<float>();
1464 float distance, dist1, dist2;
1465
1466 for ( i = 0; i < obstructingObjects.Count(); ++i )
1467 {
1468 distance = vector.DistanceSq(obstructingObjects[i].GetWorldPosition(), origin);
1469 distanceHelper.Insert(distance);
1470 }
1471
1472 distanceHelperUnsorted.Copy(distanceHelper);
1473 distanceHelper.Sort();
1474
1475 for ( i = distanceHelper.Count() - 1; i >= 0; --i )
1476 sortedObstructingObjects.Insert(obstructingObjects[distanceHelperUnsorted.Find(distanceHelper[i])]);
1477
1479 array<ref array<Object>> objectGroups = new array<ref array<Object>>();
1480 array<Object> group;
1481
1482 float cos = Math.Cos(90);
1483 float sin = Math.Sin(90);
1484
1485 // Iterate through sorted obstructingObjects
1486 for ( i = 0; i < sortedObstructingObjects.Count(); ++i )
1487 {
1488 Object obstrObj = sortedObstructingObjects[i];
1489 vector worldPos = obstrObj.GetWorldPosition();
1490 vector min, max;
1491 vector minMax[2];
1492 if ( obstrObj.GetCollisionBox(minMax) )
1493 {
1494 min = minMax[0];
1495 max = minMax[1];
1496 max = max * (obstrObj.GetOrientation() * range);
1497
1498 vector center, dx, dy, dz, half;
1499 center = (min + max) * 0.5;
1500 dz = obstrObj.GetOrientation();
1501 dx = vector.RotateAroundZero(dz, vector.Up, cos, sin);
1502 dy = vector.RotateAroundZero(dz, vector.Aside, cos, sin);
1503 half = (max - min) * 0.5;
1504 half = Vector(Math.AbsFloat(half[0]), Math.AbsFloat(half[1]), Math.AbsFloat(half[2]));
1505
1506 group = new array<Object>();
1507
1508 // Group objects within the above box
1509 for ( j = vicinityObjects.Count() - 1; j >= 0; --j )
1510 {
1511 Object vicObj = vicinityObjects[j];
1512 if ( vicObj )
1513 {
1514 vector d = vicObj.GetWorldPosition() - worldPos + center;
1515 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] )
1516 {
1517 group.Insert(vicObj);
1518 vicinityObjects.Remove(j);
1519 }
1520 }
1521 }
1522
1523 if ( group.Count() > 0 )
1524 tempGroups.Insert(group);
1525 }
1526 }
1527
1528 // Go through the objects grouped by obstruction to split them by distance too
1529 for ( i = 0; i < tempGroups.Count(); ++i )
1530 SplitArrayIntoGroupsByDistance(tempGroups[i], objectGroups, distanceDelta);
1531
1532 // Split initial groups by distance
1533 SplitArrayIntoGroupsByDistance(vicinityObjects, objectGroups, distanceDelta);
1534
1535 // Raycast items in groups (previously sample item in group which is not enough, sadly)
1536 IsObjectObstructedCache cache = new IsObjectObstructedCache(origin, mCount);
1537 foreach (array<Object> objectGroup : objectGroups)
1538 {
1539 foreach (Object filteredObject : objectGroup)
1540 {
1541 if (!IsObjectObstructedEx(filteredObject, cache))
1542 filteredObjects.Insert(filteredObject);
1543 }
1544
1545 }
1546
1547 cache.ClearCache();
1548 }
static bool CanIgnoreDistanceCheck(Object obj)
Определения MiscGameplayFunctions.c:1430
void IsObjectObstructedCache(vector rayCastStart, int totalObjects)
Определения MiscGameplayFunctions.c:2124
static bool IsObjectObstructedEx(Object object, IsObjectObstructedCache cache, bool doDistanceCheck=false, vector distanceCheckPos="0 0 0", float maxDist=0)
Определения MiscGameplayFunctions.c:1593
static void SplitArrayIntoGroupsByDistance(array< Object > objects, array< ref array< Object > > objectGroups, float squaredDistanceDelta)
Определения MiscGameplayFunctions.c:1550
Определения 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:305
static vector RotateAroundZero(vector pos, vector axis, float cosAngle, float sinAngle)
Rotate a vector around 0,0,0.
Определения EnConvert.c:511
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().