/// <summary> /// Prefetches planetary voxel physics along a ray /// </summary> /// <param name="ray">ray to prefetch</param> /// <param name="force">force a new prefetch task</param> public static void PrefetchRay(ref LineD ray, bool force = false) { // Force is second so we still update the cache for forced if (!_raycastPrefetchCache.IsItemPresent(ray.GetHash(), (int)MyAPIGateway.Session.ElapsedPlayTime.TotalSeconds) || force) { var voxelHits = _voxelCache.Get(); try { MyGamePruningStructure.GetVoxelMapsOverlappingRay(ref ray, voxelHits); foreach (var e in voxelHits) { var planet = (e.Element?.RootVoxel ?? e.Element) as MyPlanet; // This needs to be done for all voxel maps. To bad we can't. planet?.PrefetchShapeOnRay(ref ray); } } finally { voxelHits.Clear(); if (_voxelCache.Count <= 1) { _voxelCache.Return(voxelHits); } } } }
private void UpdatePhysics() { ProfilerShort.Begin("Update Physics Sectors"); BoundingBoxD box = Planet.PositionComp.WorldAABB; box.Min -= MyPlanet.PHYSICS_SECTOR_SIZE_METERS; box.Max += MyPlanet.PHYSICS_SECTOR_SIZE_METERS; m_sectorBoxes.Clear(); MyGamePruningStructure.GetAproximateDynamicClustersForSize(ref box, EnvironmentDefinition.SectorSize / 2, m_sectorBoxes); foreach (var cell in m_sectorBoxes) { var c = cell; c.Translate(-PlanetTranslation); c.Inflate(EnvironmentDefinition.SectorSize / 2); var position = c.Center; double distance = position.Length(); double inflate = c.Size.Length() / 2; if (distance >= Planet.MinimumRadius - inflate && distance <= Planet.MaximumRadius + inflate) { RasterSectorsForPhysics(c); } } ProfilerShort.End(); }
public static MatrixD GetPlanetRandomSpawnMatrix(Vector3D coords, double minDist, double maxDist, double minAltitude, double maxAltitude, bool inheritAltitude = false) { MatrixD result = MatrixD.Identity; var planet = MyGamePruningStructure.GetClosestPlanet(coords); var upDir = GetPlanetUpDirection(coords); if (planet == null) { return(result); } double inheritedAltitude = 0; if (inheritAltitude) { var npcSurface = GetPlanetSurfaceCoordsAtPosition(coords, planet); inheritedAltitude = Vector3D.Distance(npcSurface, coords); } var perpDir = RandomPerpendicular(upDir); var roughArea = perpDir * RandomDistance(minDist, maxDist) + coords; var surfaceCoords = GetPlanetSurfaceCoordsAtPosition(roughArea, planet); var upAtSurface = Vector3D.Normalize(surfaceCoords - planet.PositionComp.WorldAABB.Center); var spawnCoords = upAtSurface * (RandomDistance(minAltitude, maxAltitude) + inheritedAltitude) + surfaceCoords; var perpSurfaceDir = RandomPerpendicular(upAtSurface); result = MatrixD.CreateWorld(spawnCoords, perpSurfaceDir, upAtSurface); return(result); }
private MyPlanet GetPlanet(Vector3D position) { int num = 100; BoundingBoxD box = new BoundingBoxD(position - (num * 0.5f), position + (num * 0.5f)); return(MyGamePruningStructure.GetClosestPlanet(ref box)); }
public override void CloseObject(MyObjectSeed obj) { List <MyVoxelBase> voxelMaps = new List <MyVoxelBase>(); var bounds = obj.BoundingVolume; MyGamePruningStructure.GetAllVoxelMapsInBox(ref bounds, voxelMaps); string storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", obj.CellId.X, obj.CellId.Y, obj.CellId.Z, obj.Params.Index, obj.Params.Seed); foreach (MyVoxelBase map in voxelMaps) { if (map.StorageName == storageName) { if (m_NotSavedMaps.Contains(map)) { Action <MyEntity> onClose = null; onClose = delegate { obj.Params.Generated = false; map.OnClose -= onClose; }; map.Save = false; map.Close(); map.OnClose += onClose; m_NotSavedMaps.Remove(map); } break; } } voxelMaps.Clear(); }
protected void GatherDetectorsInArea(Vector3D from) { Debug.Assert(m_detectableEntities.Count == 0, "Detected entities weren't cleared"); var boundingSphere = new BoundingSphereD(from, MyConstants.DEFAULT_INTERACTIVE_DISTANCE); MyGamePruningStructure.GetAllEntitiesInSphere(ref boundingSphere, m_detectableEntities); }
private void PerformCellMarking(List <Vector3D> updatePositions) { ProfilerShort.Begin("Cell marking"); Vector3D offset = new Vector3D(1.0f); foreach (var pos in updatePositions) { BoundingBoxD box = new BoundingBoxD(pos - offset, pos + offset); ProfilerShort.Begin("GetVoxelMaps"); m_tmpVoxelMaps.Clear(); MyGamePruningStructure.GetAllVoxelMapsInBox(ref box, m_tmpVoxelMaps); ProfilerShort.End(); foreach (var map in m_tmpVoxelMaps) { MyVoxelNavigationMesh mesh = null; m_navigationMeshes.TryGetValue(map, out mesh); if (mesh == null) { continue; } mesh.MarkBoxForAddition(box); } } m_tmpVoxelMaps.Clear(); ProfilerShort.End(); }
void OnPickPlanet(MyGuiControlButton button) { var results = new List <MyLineSegmentOverlapResult <MyEntity> >(); var ray = new LineD(MySector.MainCamera.Position, MySector.MainCamera.ForwardVector); MyGamePruningStructure.GetAllEntitiesInRay(ref ray, results); float closestPlanetDistance = float.MaxValue; MyPlanet closestPlanet = null; foreach (var result in results) { var planet = result.Element as MyPlanet; if (planet != null && planet.EntityId != m_selectedPlanetEntityID) { if (result.Distance < closestPlanetDistance) { closestPlanet = planet; } } } if (closestPlanet != null) { m_selectedPlanetEntityID = closestPlanet.EntityId; m_atmosphereSettings = closestPlanet.AtmosphereSettings; m_originalAtmosphereSettings = m_atmosphereSettings; RecreateControls(false); } }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); m_waitForUpdate--; if (m_waitForUpdate > 0) { return; } m_waitForUpdate = UPDATE_DELAY; Vector3D position = MySector.MainCamera.Position; MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(position); if (planet != null) { var distanceFromPlanet = Vector3D.Distance(planet.PositionComp.GetPosition(), position); if (distanceFromPlanet > planet.MaximumRadius + Math.Max(100, planet.MaximumRadius)) { ; } planet = null; //too far planet } if (m_closestPlanet != planet) { m_closestPlanet = planet; if (m_closestPlanet != null) { MyStringId category = MyStringId.GetOrCompute(m_closestPlanet.Generator.Id.SubtypeId.ToString()); MyStringId transition = MyStringId.GetOrCompute(m_closestPlanet.Generator.Id.SubtypeId.ToString()); if (!MyAudio.Static.IsValidTransitionCategory(transition, category)) { category = MyStringId.GetOrCompute("OtherPlanet"); transition = MyStringId.GetOrCompute("OtherPlanet"); } MyMusicTrack mt = new MyMusicTrack() { MusicCategory = category, TransitionCategory = transition }; MyAudio.Static.PlayMusic(mt); } else { //random MyMusicTrack mt = new MyMusicTrack() { }; MyAudio.Static.PlayMusic(mt, 1); } } }
public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); m_updateCounter++; if (m_updateCounter % 100 == 0 && MySession.Static.LocalCharacter != null) { m_detectedGrids.Clear(); BoundingSphereD playerSphere = new BoundingSphereD(MySession.Static.LocalCharacter.PositionComp.GetPosition(), 500f); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref playerSphere, m_detectedGrids); for (int i = 0; i < m_detectedGrids.Count; i++) { MyCubeGrid grid = m_detectedGrids[i] as MyCubeGrid; if (grid != null) { foreach (var block in grid.CubeBlocks) { if (block.FatBlock is MyFunctionalBlock) { (block.FatBlock as MyFunctionalBlock).UpdateSoundEmitters(); } } } } } }
void GenerateEntityList(bool DetectVoxels, out HashSet <IMyCubeGrid> Grids, out HashSet <IMyCharacter> Characters, out HashSet <IMyFloatingObject> Flobjes, out HashSet <IMyVoxelBase> Voxels) { Grids = new HashSet <IMyCubeGrid>(); Characters = new HashSet <IMyCharacter>(); Flobjes = new HashSet <IMyFloatingObject>(); Voxels = new HashSet <IMyVoxelBase>(); LineD WorkingRay = new LineD(MyKernel.BeamDrawer.BeamStart, MyKernel.BeamDrawer.BeamEnd); List <MyLineSegmentOverlapResult <MyEntity> > Overlaps = new List <MyLineSegmentOverlapResult <MyEntity> >(50); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref WorkingRay, Overlaps); if (Overlaps.Count == 0) { return; } if (DetectVoxels) { Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes, Voxels); } else { Overlaps.Select(x => x.Element as IMyEntity).SortByType(Grids, Characters, Flobjes); } }
public IEnumerable <OffenderProximityInfo> ScanProximity(IEnumerable <DefenderGridInfo> defenders) { var tmpNearEntities = new List <MyEntity>(); foreach (var defender in defenders) { var lookout = _config.MaxProximity * 10; var sphere = new BoundingSphereD(defender.Position, lookout); var bb = BoundingBoxD.CreateFromSphere(sphere); var obb = MyOrientedBoundingBoxD.CreateFromBoundingBox(bb); MyGamePruningStructure.GetAllEntitiesInOBB(ref obb, tmpNearEntities); foreach (var entity in tmpNearEntities) { Log.Trace($"near entity: \"{entity.DisplayName}\""); if (TryGetOffender(entity, defender, out var offender)) { yield return(offender); } } tmpNearEntities.Clear(); } }
private void QueryTrigger() { m_queryResult.Clear(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref m_triggerAABB, m_queryResult); for (int i = m_queryResult.Count - 1; i >= 0; i--) { var e = m_queryResult[i]; if (e.Physics == null || e.Physics.IsStatic) { m_queryResult.RemoveAtFast(i); continue; } if (e is MyFloatingObject || e is MyDebrisBase) { m_queryResult.RemoveAtFast(i); continue; } if (e == Entity.GetTopMostParent()) { m_queryResult.RemoveAtFast(i); continue; } //if (e.Physics.RigidBody != null && e.Physics.RigidBody.IsActive) // activeCounter++; //e.Physics.RigidBody.Activated += RBActivated; //e.Physics.RigidBody.Deactivated += RBDeactivated; } }
protected override void CloseObjectSeed(MyObjectSeed objectSeed) { switch (objectSeed.Params.Type) { case MyObjectSeedType.Asteroid: case MyObjectSeedType.AsteroidCluster: var bbox = objectSeed.BoundingVolume; MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList); String storageName = string.Format("Asteroid_{0}_{1}_{2}_{3}_{4}", objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed); foreach (var voxelBase in m_tmpVoxelMapsList) { if (voxelBase.StorageName == storageName) { if (!voxelBase.Save) { voxelBase.Close(); } break; } } m_tmpVoxelMapsList.Clear(); break; case MyObjectSeedType.EncounterAlone: case MyObjectSeedType.EncounterSingle: MyEncounterGenerator.RemoveEncounter(objectSeed.BoundingVolume, objectSeed.Params.Seed); break; default: throw new InvalidBranchException(); break; } }
private List <MyEntity> EntitiesInLargeAABB(BoundingBoxD start, BoundingBoxD end) { Vector3D[] pathPoints = new Vector3D[4]; pathPoints[0] = start.Min; pathPoints[1] = start.Max; pathPoints[2] = end.Min; pathPoints[3] = end.Max; BoundingBoxD PathAABB = BoundingBoxD.CreateFromPoints(pathPoints); //m_logger.debugLog("Path AABB = " + PathAABB, "EntitiesInLargeAABB()"); m_offenders.Clear(); MyGamePruningStructure.GetTopMostEntitiesInBox(ref PathAABB, m_offenders); m_offRemove.Clear(); for (int i = 0; i < m_offenders.Count; i++) { if (!collect_Entity(m_grid, m_offenders[i]) || (m_ignoreEntity != null && m_ignoreEntity == m_offenders[i])) { //m_logger.debugLog("discarding: " + m_offenders[i].getBestName(), "EntitiesInLargeAABB()"); m_offRemove.Add(m_offenders[i]); } } for (int i = 0; i < m_offRemove.Count; i++) { m_offenders.Remove(m_offRemove[i]); } return(m_offenders); }
protected override void CloseObjectSeed(MyObjectSeed objectSeed) { IMyAsteroidFieldDensityFunction func = objectSeed.UserData as IMyAsteroidFieldDensityFunction; if (func != null) { ChildrenRemoveDensityFunctionRemoved(func); } var bbox = objectSeed.BoundingVolume; MyGamePruningStructure.GetAllVoxelMapsInBox(ref bbox, m_tmpVoxelMapsList); String storageName = string.Format("{0}_{1}_{2}_{3}_{4}_{5}", objectSeed.Params.Type, objectSeed.CellId.X, objectSeed.CellId.Y, objectSeed.CellId.Z, objectSeed.Params.Index, objectSeed.Params.Seed); foreach (var voxelBase in m_tmpVoxelMapsList) { if (voxelBase.StorageName == storageName) { if (!voxelBase.Save) { voxelBase.Close(); } break; } } m_tmpVoxelMapsList.Clear(); }
public static bool IsInSpace(Vector3D pos) { var closestPlanet = MyGamePruningStructure.GetClosestPlanet(pos); return(closestPlanet == null || !closestPlanet.HasAtmosphere || closestPlanet.GetAirDensity(pos) <= 0.5); }
/// <summary> /// Destroys missiles in blast radius. /// </summary> private void DestroyAllNearbyMissiles() { if (myCluster != null || m_destroyedNearbyMissiles) { return; } m_destroyedNearbyMissiles = true; BoundingSphereD explosion = new BoundingSphereD(MyEntity.GetPosition(), myAmmo.MissileDefinition.MissileExplosionRadius); Log.DebugLog("Explosion: " + explosion); List <MyEntity> entitiesInExplosion = new List <MyEntity>(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref explosion, entitiesInExplosion, MyEntityQueryType.Dynamic); foreach (MyEntity entity in entitiesInExplosion) { if (!entity.Closed && entity.IsMissile() && entity != MyEntity) { Log.DebugLog("Explode: " + entity + ", position: " + entity.PositionComp.GetPosition()); ((MyAmmoBase)entity).Explode(); } } explosion.Radius *= 10f; entitiesInExplosion.Clear(); MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref explosion, entitiesInExplosion, MyEntityQueryType.Dynamic); foreach (MyEntity entity in entitiesInExplosion) { if (!entity.Closed && entity.IsMissile() && entity != MyEntity) { Log.DebugLog("nearby: " + entity + ", position: " + entity.PositionComp.GetPosition()); } } }
public MyPlanet GetClosestContainingPlanet(Vector3D point) { m_voxels.Clear(); BoundingBoxD b = new BoundingBoxD(point, point); MyGamePruningStructure.GetAllVoxelMapsInBox(ref b, m_voxels); double dist = double.PositiveInfinity; MyPlanet p = null; foreach (var v in m_voxels) { if (v is MyPlanet) { var d = Vector3.Distance(v.WorldMatrix.Translation, point); if (d < dist) { dist = d; p = (MyPlanet)v; } } } return(p); }
public static void ScorePlanetFlatness(Vector3D startPos, double radius, out double score, out Vector3D groundPos) { var planet = MyGamePruningStructure.GetClosestPlanet(startPos); groundPos = planet.GetClosestSurfacePointGlobal(ref startPos); var center = planet.PositionComp.WorldVolume.Center; var normal = groundPos - center; normal.Normalize(); // Sample two points _radius_ away perp. to normal var otherDir = Vector3D.CalculatePerpendicularVector(normal); otherDir.Normalize(); var otherWorld = groundPos + otherDir * radius; var other1Surf = planet.GetClosestSurfacePointGlobal(ref otherWorld); Vector3D.Cross(ref normal, ref otherDir, out otherDir); otherDir.Normalize(); otherWorld = groundPos + otherDir * radius; var other2Surf = planet.GetClosestSurfacePointGlobal(ref otherWorld); var surfNorm = Vector3D.Cross(other2Surf - groundPos, other1Surf - groundPos); surfNorm.Normalize(); score = Math.Abs(Vector3D.Dot(surfNorm, normal)); }
public void Update(Vector3D position, bool checkControl = true) { Clear(); if (!SetRelayedRequest && checkControl && !OnCheckControl()) { m_depositGroupsByEntity.Clear(); return; } SetRelayedRequest = false; var sphere = new BoundingSphereD(position, DetectionRadius); MyGamePruningStructure.GetAllVoxelMapsInSphere(ref sphere, m_inRangeCache); { // Find voxel maps which went out of range and then remove them. foreach (var voxelMap in m_depositGroupsByEntity.Keys) { if (!m_inRangeCache.Contains(voxelMap)) { m_notInRangeCache.Add(voxelMap); } } foreach (var notInRange in m_notInRangeCache) { m_depositGroupsByEntity.Remove(notInRange); } m_notInRangeCache.Clear(); } { // Add voxel maps which came into range. foreach (var voxelMap in m_inRangeCache) { if (!m_depositGroupsByEntity.ContainsKey(voxelMap)) { m_depositGroupsByEntity.Add(voxelMap, new MyOreDepositGroup(voxelMap)); } } m_inRangeCache.Clear(); } // Update deposit queries using current detection sphere. foreach (var entry in m_depositGroupsByEntity) { var voxelMap = entry.Key; var group = entry.Value; group.UpdateDeposits(ref sphere); foreach (var deposit in group.Deposits) { if (deposit != null) { MyHud.OreMarkers.RegisterMarker(deposit); } } } m_inRangeCache.Clear(); }
internal bool GetAimedAtBlock(out MyCubeBlock cube) { cube = null; if (UiInput.AimRay.Length > 0) { AimRayEnts.Clear(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref UiInput.AimRay, AimRayEnts); foreach (var ent in AimRayEnts) { var grid = ent.Element as MyCubeGrid; if (grid?.Physics != null && grid.Physics.Enabled && !grid.Physics.IsPhantom && grid.InScene && !grid.IsPreview) { MyCube myCube; var hitV3I = grid.RayCastBlocks(UiInput.AimRay.From, UiInput.AimRay.To); if (hitV3I.HasValue && grid.TryGetCube(hitV3I.Value, out myCube)) { var slim = (IMySlimBlock)myCube.CubeBlock; if (slim.FatBlock != null) { cube = (MyCubeBlock)slim.FatBlock; return(true); } } } } } return(false); }
public override void Draw() { base.Draw(); if (MySession.Static == null) { return; } const float raycastDist = 200; var ray = new LineD(MySector.MainCamera.Position, MySector.MainCamera.Position + raycastDist * MySector.MainCamera.ForwardVector); var entities = new List <MyLineSegmentOverlapResult <MyEntity> >(); MyGamePruningStructure.GetTopmostEntitiesOverlappingRay(ref ray, entities, MyEntityQueryType.Static); double closest = double.PositiveInfinity; foreach (var e in entities) { var voxel = e.Element as MyVoxelBase; if (voxel != null && e.Distance < closest) { m_selectedVoxel = voxel; } } if (m_selectedVoxel != null) { Text(Color.DarkOrange, 1.5f, "Selected Voxel: {0}:{1}", m_selectedVoxel.StorageName, m_selectedVoxel.EntityId); } }
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(); }
/// <summary> /// Returns the planet closest to the given position /// </summary> /// <param name="position">3D Point from where the search is started</param> /// <returns>The closest planet</returns> private MyPlanet GetPlanet(Vector3D position) { int voxelDistance = 200; BoundingBoxD box = new BoundingBoxD(position - voxelDistance * 0.5f, position + voxelDistance * 0.5f); return(MyGamePruningStructure.GetClosestPlanet(ref box)); }
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); }
public static Vector3D GetRandomDespawnCoords(Vector3D coords, double distance = 8000, double altitude = 1500) { Vector3D result = Vector3D.Zero; var planet = MyGamePruningStructure.GetClosestPlanet(coords); var planetEntity = planet as IMyEntity; var gravityProvider = planetEntity?.Components?.Get <MyGravityProviderComponent>(); if (gravityProvider != null && gravityProvider.IsPositionInRange(coords)) { var up = Vector3D.Normalize(coords - planetEntity.GetPosition()); Vector3D randDirection = MyUtils.GetRandomPerpendicularVector(up); var surfaceCoords = planet.GetClosestSurfacePointGlobal(randDirection * distance + coords); result = Vector3D.Normalize(surfaceCoords - planetEntity.GetPosition()) * altitude + surfaceCoords; } else if (planet != null) { var up = Vector3D.Normalize(coords - planetEntity.GetPosition()); Vector3D randDirection = MyUtils.GetRandomPerpendicularVector(up); result = randDirection * distance + coords; } else { Vector3D randDirection = Vector3D.Normalize(MyUtils.GetRandomVector3D()); return(randDirection * distance + coords); } return(result); }
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); }
//alter position based on altitude private void HoverMechanic(ref Vector3D pos) { m_hoverMin = 5; m_hoverMax = 25; Vector3 gravity = MyGravityProviderSystem.CalculateNaturalGravityInPoint(pos); if (gravity.LengthSquared() > 0f) { MyPlanet planet = MyGamePruningStructure.GetClosestPlanet(pos); if (planet != null) { Vector3D closestPoint = planet.GetClosestSurfacePointGlobal(ref pos); float altitude = (float)Vector3D.Distance(closestPoint, pos); if (Vector3D.DistanceSquared(planet.PositionComp.GetPosition(), closestPoint) > Vector3D.DistanceSquared(planet.PositionComp.GetPosition(), pos)) { altitude *= -1; } if (altitude < m_hoverMin) { pos = closestPoint - Vector3D.Normalize(gravity) * m_hoverMin; } else if (altitude > m_hoverMax) { pos = closestPoint - Vector3D.Normalize(gravity) * m_hoverMax; } } } }
private void RevealEntity(IMyEntity entity) { if (entity != entity.GetTopMostParent()) { return; } entity.GetStorage().SetValue(Id, "False"); MyGamePruningStructure.Add((MyEntity)entity); entity.Physics?.Activate(); RegisterRecursive(entity); void RegisterRecursive(IMyEntity e) { MyEntities.RegisterForUpdate((MyEntity)e); if (e.Hierarchy == null) { return; } foreach (var child in e.Hierarchy.Children) { RegisterRecursive(child.Container.Entity); } } }