private static bool FindClosestFracturedTreeInternal(Vector3D fromPosition, Vector3D searchCenter, double searchRadius, MyPlaceArea area, out EntityInfo result) { result = default(EntityInfo); double closestDistanceSq = double.MaxValue; MyFracturedPiece closestTarget = null; Vector3D closestPoint = default(Vector3D); BoundingSphereD searchSphere = new BoundingSphereD(searchCenter, searchRadius); m_tmpFracturePieceList.Clear(); MyFracturedPiecesManager.Static.GetFracturesInSphere(ref searchSphere, ref m_tmpFracturePieceList); for (int i = 0; i < m_tmpFracturePieceList.Count; ++i) { var fracture = m_tmpFracturePieceList[i]; // Skip non-tree fractures if (!MyTrees.IsEntityFracturedTree(fracture)) { continue; } if (IsFracturedTreeStump(fracture)) { continue; } Vector3D positionInTrunkLocal = Vector3D.Transform(fromPosition, fracture.PositionComp.WorldMatrixNormalizedInv); Vector3D closestPointOnTrunk; if (!FindClosestPointOnFracturedTree(positionInTrunkLocal, fracture, out closestPointOnTrunk)) { continue; } if (area == null || area.TestPoint(closestPointOnTrunk)) { double distanceSq = Vector3D.DistanceSquared(closestPointOnTrunk, fromPosition); if (distanceSq < closestDistanceSq) { closestDistanceSq = distanceSq; closestTarget = fracture; closestPoint = closestPointOnTrunk; } } } m_tmpFracturePieceList.Clear(); if (closestTarget == null) { return(false); } result.EntityId = closestTarget.EntityId; result.Target = closestPoint; return(true); }
private static void FindFracturedTreesInternal(Vector3D fromPosition, MyPlaceArea area, BoundingSphereD sphere) { Debug.Assert(m_tmpFracturePieceList.Count == 0, "m_tmpFracturePieceList was not cleared after last use!"); MyFracturedPiecesManager.Static.GetFracturesInSphere(ref sphere, ref m_tmpFracturePieceList); for (int i = m_tmpFracturePieceList.Count - 1; i >= 0; i--) { MyFracturedPiece fracture = m_tmpFracturePieceList[i]; if (!MyTrees.IsEntityFracturedTree(fracture)) { m_tmpFracturePieceList.RemoveAtFast(i); continue; } if (IsFracturedTreeStump(fracture)) { m_tmpFracturePieceList.RemoveAtFast(i); continue; } Vector3D positionInTrunkLocal = Vector3D.Transform(fromPosition, fracture.PositionComp.WorldMatrixNormalizedInv); Vector3D closestPointOnTrunk; if (!FindClosestPointOnFracturedTree(positionInTrunkLocal, fracture, out closestPointOnTrunk)) { m_tmpFracturePieceList.RemoveAtFast(i); continue; } if (!area.TestPoint(closestPointOnTrunk)) { m_tmpFracturePieceList.RemoveAtFast(i); continue; } } }