public Vector3D DetectEntitiesInBox(MyObjectBuilder_CubeGrid grid, Vector3D spawnOrigin) { BoundingBoxD box = CalculateBoundingBox(grid); box.Translate(spawnOrigin); List <MyEntity> pruneList; do { pruneList = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref box, pruneList, MyEntityQueryType.Both); if (pruneList.Count <= 0) { continue; } foreach (MyEntity entity in pruneList) { Core.GeneralLog.WriteToLog("DetectEntitiesInBox", $"{entity}"); } //box = box.Translate(new Vector3D(10, 0, 0)); //box = box.Translate(new Vector3D(.5, .5, .5)); box = box.Translate(Vector3D.Up + .25); } while (pruneList.Count > 0); //MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref pruneSphere, pruneList, MyEntityQueryType.Dynamic); return(box.Center); }
public unsafe void PrepareVoxelTriangleTests(BoundingBoxD cellBoundingBox, List <MyCubeGrid> gridsToTestOutput) { m_tmpEntityList.Clear(); float cubeSize = MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large); cellBoundingBox.Inflate((double)cubeSize); if (MyPerGameSettings.NavmeshPresumesDownwardGravity) { Vector3D min = cellBoundingBox.Min; double * numPtr1 = (double *)ref min.Y; numPtr1[0] -= cubeSize; cellBoundingBox.Min = min; } MyGamePruningStructure.GetAllEntitiesInBox(ref cellBoundingBox, m_tmpEntityList, MyEntityQueryType.Both); foreach (MyCubeGrid grid in m_tmpEntityList) { if (grid == null) { continue; } if (MyGridPathfinding.GridCanHaveNavmesh(grid)) { gridsToTestOutput.Add(grid); } } m_tmpEntityList.Clear(); }
private void KillEveryoneAround() { if (MySession.Static.LocalCharacter == null || !Sync.IsServer || !MySession.Static.IsAdmin || !MySession.Static.IsAdminMenuEnabled) { return; } Vector3D myPosition = MySession.Static.LocalCharacter.PositionComp.GetPosition(); Vector3D offset = new Vector3D(25, 25, 25); BoundingBoxD bb = new BoundingBoxD(myPosition - offset, myPosition + offset); List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref bb, entities); foreach (var entity in entities) { var character = entity as MyCharacter; if (character != null && entity != MySession.Static.LocalCharacter) { character.DoDamage(1000000, MyDamageType.Unknown, true); } } MyRenderProxy.DebugDrawAABB(bb, Color.Red, 0.5f, 1f, true, true); }
private void GetCharactersInBoundingBox(BoundingBoxD boundingBox, List <MyCharacter> characters) { MyGamePruningStructure.GetAllEntitiesInBox(ref boundingBox, m_entitiesInRange); foreach (var entity in m_entitiesInRange) { var character = entity as MyCharacter; if (character != null) { characters.Add(character); } } m_entitiesInRange.Clear(); }
public static void ActivateInBox(ref BoundingBoxD box) { using (m_tmpEntityResults.GetClearToken()) { MyGamePruningStructure.GetAllEntitiesInBox(ref box, m_tmpEntityResults); foreach (var entity in m_tmpEntityResults) { if (entity.Physics != null && entity.Physics.Enabled && entity.Physics.RigidBody != null) { entity.Physics.RigidBody.Activate(); } } } }
public void SetPathfindingDebugTarget(Vector3D?target) { MyExternalPathfinding pathfinding = this.m_pathfinding as MyExternalPathfinding; if (pathfinding != null) { pathfinding.SetTarget(target); } else if (target != null) { this.m_debugTargetAABB = new MyOrientedBoundingBoxD(target.Value, new Vector3D(5.0, 5.0, 5.0), Quaternion.Identity).GetAABB(); List <MyEntity> result = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref this.m_debugTargetAABB, result, MyEntityQueryType.Both); } this.DebugTarget = target; }
public void SetPathfindingDebugTarget(Vector3D? target) { MyExternalPathfinding pf = m_pathfinding as MyExternalPathfinding; if (pf != null) pf.SetTarget(target); else { if (target.HasValue) { //TODO: Just for debug purpose... Anything can be implemented m_debugTargetAABB = new MyOrientedBoundingBoxD(target.Value, new Vector3D(5, 5, 5), Quaternion.Identity).GetAABB(); List<VRage.Game.Entity.MyEntity> entities = new List<VRage.Game.Entity.MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref m_debugTargetAABB, entities); } } DebugTarget = target; }
private unsafe void DisableOtherItemsInVMap(MyVoxelBase voxelMap) { MyOrientedBoundingBoxD obb = MyOrientedBoundingBoxD.Create((BoundingBoxD)voxelMap.PositionComp.LocalAABB, voxelMap.PositionComp.WorldMatrix); var center = obb.Center; var box = voxelMap.PositionComp.WorldAABB; m_entities.Clear(); MyGamePruningStructure.GetAllEntitiesInBox(ref box, m_entities, MyEntityQueryType.Static); for (int eIndex = 0; eIndex < m_entities.Count; ++eIndex) { var sector = m_entities[eIndex] as MyEnvironmentSector; if (sector == null || sector.DataView == null) { continue; } obb.Center = center - sector.SectorCenter; for (int sectorInd = 0; sectorInd < sector.DataView.LogicalSectors.Count; sectorInd++) { var logicalSector = sector.DataView.LogicalSectors[sectorInd]; var logicalItems = logicalSector.Items; var cnt = logicalItems.Count; fixed(ItemInfo *items = logicalItems.GetInternalArray()) for (int i = 0; i < cnt; ++i) { var point = items[i].Position + sector.SectorCenter; if (items[i].DefinitionIndex >= 0 && obb.Contains(ref items[i].Position) && voxelMap.CountPointsInside(&point, 1) > 0 && !IsVoxelItem(sector, items[i].DefinitionIndex)) { logicalSector.EnableItem(i, false); } } } } }
public void PrepareVoxelTriangleTests(BoundingBoxD cellBoundingBox, List <MyCubeGrid> gridsToTestOutput) { ProfilerShort.Begin("PrepareVoxelTriangleTests"); m_tmpEntityList.Clear(); // Each triangle will be tested with grids up to one largest cube further away from them, so we have to reflect this in the bounding box. float largeCubeSize = MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large); cellBoundingBox.Inflate(largeCubeSize); // Furthermore, a triangle cannot lie in a cube under existing block, so we have to extend the bbox even further if (MyPerGameSettings.NavmeshPresumesDownwardGravity) { var min = cellBoundingBox.Min; min.Y -= largeCubeSize; cellBoundingBox.Min = min; } MyGamePruningStructure.GetAllEntitiesInBox(ref cellBoundingBox, m_tmpEntityList); foreach (var entity in m_tmpEntityList) { var grid = entity as MyCubeGrid; if (grid == null) { continue; } if (!MyGridPathfinding.GridCanHaveNavmesh(grid)) { continue; } gridsToTestOutput.Add(grid); } m_tmpEntityList.Clear(); ProfilerShort.End(); }
private void AddEntities(float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List <BoundingBoxD> boundingBoxes, List <MyVoxelMap> trackedEntities) { obb.HalfExtent += new Vector3D(border, 0, border); var aabb = obb.GetAABB(); List <MyEntity> entities = new List <MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref aabb, entities); //TODO: remove this? Just for Debug... if (entities.Count(e => e is MyCubeGrid) > 0) { m_lastGridsInfo.Clear(); m_lastIntersectedGridsInfoCubes.Clear(); } foreach (var entity in entities) { var grid = entity as MyCubeGrid; //TODO: let the static be here? if (grid != null && grid.IsStatic) { ProfilerShort.Begin("AddEntities.AddGridVerticesInsideOBB"); AddGridVerticesInsideOBB(grid, obb); ProfilerShort.End(); return; } var voxelMap = entity as MyVoxelMap; if (voxelMap != null) { trackedEntities.Add(voxelMap); ProfilerShort.Begin("AddEntities.AddVoxelVertices"); AddVoxelVertices(voxelMap, border, originPosition, obb, boundingBoxes); ProfilerShort.End(); return; } } }
private unsafe void AddEntities(float border, Vector3D originPosition, MyOrientedBoundingBoxD obb, List <BoundingBoxD> boundingBoxes, List <MyVoxelMap> trackedEntities) { Vector3D *vectordPtr1 = (Vector3D *)ref obb.HalfExtent; vectordPtr1[0] += new Vector3D((double)border, 0.0, (double)border); BoundingBoxD aABB = obb.GetAABB(); List <VRage.Game.Entity.MyEntity> result = new List <VRage.Game.Entity.MyEntity>(); MyGamePruningStructure.GetAllEntitiesInBox(ref aABB, result, MyEntityQueryType.Both); if (result.Count <VRage.Game.Entity.MyEntity>(e => (e is MyCubeGrid)) > 0) { this.m_lastGridsInfo.Clear(); this.m_lastIntersectedGridsInfoCubes.Clear(); } foreach (VRage.Game.Entity.MyEntity entity in result) { using (entity.Pin()) { if (entity.MarkedForClose) { continue; } MyCubeGrid grid = entity as MyCubeGrid; if (grid != null) { bool isStatic = grid.IsStatic; } MyVoxelMap item = entity as MyVoxelMap; if (item != null) { trackedEntities.Add(item); this.AddVoxelVertices(item, border, originPosition, obb, boundingBoxes); } } } }