当前位置: 首页>>代码示例>>C#>>正文


C# BoundingSphereD类代码示例

本文整理汇总了C#中BoundingSphereD的典型用法代码示例。如果您正苦于以下问题:C# BoundingSphereD类的具体用法?C# BoundingSphereD怎么用?C# BoundingSphereD使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BoundingSphereD类属于命名空间,在下文中一共展示了BoundingSphereD类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateBeforeSimulation

        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();
                        }
                    }
                }
                foreach (var key in m_emitterLibraryToRemove)
                {
                    if (m_emitterLibrary.ContainsKey(key))
                    {
                        m_emitterLibrary[key].StopSound(true);
                        m_emitterLibrary.Remove(key);
                    }
                }
                m_emitterLibraryToRemove.Clear();
                foreach (var emitter in m_emitterLibrary.Values)
                    emitter.Update();
            }
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:35,代码来源:MyAudioComponent.cs

示例2: Intersects

 public static bool Intersects(this MyPlanet planet, BoundingSphereD sphere)
 {
     Vector3D centre = sphere.Center;
     Vector3D closestPoint = planet.GetClosestSurfacePointGlobal(ref centre);
     double minDistance = sphere.Radius; minDistance *= minDistance;
     return Vector3D.DistanceSquared(centre, closestPoint) <= minDistance;
 }
开发者ID:deimosx6,项目名称:Autopilot,代码行数:7,代码来源:MyPlanetExtensions.cs

示例3: FindNearbyStuff

        private void FindNearbyStuff()
        {
            var bs = new BoundingSphereD(Ship.GetPosition(), ConquestMod.MaxEngagementRange);
            var ents = MyAPIGateway.Entities.GetEntitiesInSphere(ref bs);
            var closeBy = ents;
            //entitiesFiltered.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList();

            //var closeAsteroids = asteroids.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList();

            ClearNearbyObjects();
            foreach (var closeItem in closeBy)
            {
                try
                {
                    if (closeItem is Sandbox.ModAPI.IMyCubeGrid)
                        AddNearbyFloatingItem(closeItem);

                    if (closeItem is IMyVoxelBase)
                    {
                        //_entitiesNearDcDrones.Add(closeItem)
                        AddNearbyAsteroid((IMyVoxelBase) closeItem);
                    }
                }
                catch
                {
                    //This catches duplicate key entries being put in KnownEntities.
                }
            }
        }
开发者ID:ESearcy,项目名称:PVE-AI-Drones-Drone-Conquest,代码行数:29,代码来源:MothershipDrone.cs

示例4: FindClosestTreeInRadius

        public static bool FindClosestTreeInRadius(Vector3D fromPosition, float radius, out ItemInfo result)
        {
            result = default(ItemInfo);

            BoundingSphereD sphere = new BoundingSphereD(fromPosition, (double)radius);
            var entities = MyEntities.GetEntitiesInSphere(ref sphere);

            double closestDistanceSq = double.MaxValue;

            foreach (MyEntity entity in entities)
            {
                MyTrees trees = entity as MyTrees;
                if (trees == null) continue;

                trees.GetPhysicalItemsInRadius(fromPosition, radius, m_tmpEnvItemList);

                foreach (var tree in m_tmpEnvItemList)
                {
                    double distanceSq = Vector3D.DistanceSquared(fromPosition, tree.Transform.Position);
                    if (distanceSq < closestDistanceSq)
                    {
                        result.ItemsEntityId = entity.EntityId;
                        result.ItemId = tree.LocalId;
                        result.Target = tree.Transform.Position;
                        closestDistanceSq = distanceSq;
                    }
                }
            }

			entities.Clear();

            return closestDistanceSq != double.MaxValue;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:33,代码来源:MyItemsCollector.cs

示例5: FindNearbyStuff

        private void FindNearbyStuff()
        {
            var bs = new BoundingSphereD(Ship.GetPosition(), ConquestMod.MaxEngagementRange);
            var ents = MyAPIGateway.Entities.GetEntitiesInSphere(ref bs);
            var closeBy = ents;//entitiesFiltered.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList();

            //var closeAsteroids = asteroids.Where(z => (z.GetPosition() - drone.GetPosition()).Length() < MaxEngagementRange).ToList();

            ClearNearbyObjects();
            foreach (var closeItem in closeBy)
            {
                try
                {
                    if (closeItem is IMyCubeGrid && !closeItem.Transparent && closeItem.Physics.Mass > 2000)
                        AddNearbyFloatingItem(closeItem);

                    if (closeItem is IMyVoxelBase)
                    {
                        ConquestDroneManager.GetInstance().AddDiscoveredAsteroid(closeItem as IMyVoxelBase);
                        AddNearbyAsteroid((IMyVoxelBase)closeItem);
                    }
                }
                catch
                {
                    //This catches duplicate key entries being put in KnownEntities.
                }
            }
        }
开发者ID:ESearcy,项目名称:PVE-AI-Drones-Drone-Conquest,代码行数:28,代码来源:ConquestDrone.cs

示例6: UpdateLcds

        public static void UpdateLcds()
        {
            if (!EconomyScript.Instance.ServerConfig.EnableLcds)
                return;

            var players = new List<IMyPlayer>();
            MyAPIGateway.Players.GetPlayers(players, p => p != null);
            var updatelist = new HashSet<IMyTextPanel>();

            foreach (var player in players)
            {
                // Establish a visual range of the LCD.
                // if there are no players closer than this, don't bother updating it.
                var sphere = new BoundingSphereD(player.GetPosition(), 75);
                var list = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
                foreach (var block in list)
                {
                    // TODO: projected ship check?
                    var textPanel = block as IMyTextPanel;
                    if (textPanel != null
                        && textPanel.IsFunctional
                        && textPanel.IsWorking
                        && EconomyConsts.LCDTags.Any(tag => textPanel.CustomName.IndexOf(tag, StringComparison.InvariantCultureIgnoreCase) >= 0))
                    {
                        updatelist.Add((IMyTextPanel)block);
                    }
                }
            }

            foreach (var textPanel in updatelist)
                ProcessLcdBlock(textPanel);
        }
开发者ID:jpcsupplies,项目名称:Economy_mod,代码行数:32,代码来源:LcdManager.cs

示例7: MySphereDensityFunction

 public MySphereDensityFunction(Vector3D center, double radius, double additionalFalloff)
 {
     m_center = center;
     m_sphereMax = new BoundingSphereD(center, radius + additionalFalloff);
     m_innerRadius = radius;
     m_halfFalloff = additionalFalloff / 2.0;
     m_middleRadius = radius + m_halfFalloff;
     m_outerRadius = radius + additionalFalloff;
 }
开发者ID:ChristianHeinz71,项目名称:SpaceEngineers,代码行数:9,代码来源:MySphereDensityFunction.cs

示例8: CollectObjects

        public static void CollectObjects(ulong steamId, Vector3D destination, double range)
        {
            var sphere = new BoundingSphereD(destination, range);
            var floatingList = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
            //floatingList = floatingList.Where(e => (e is Sandbox.ModAPI.IMyFloatingObject) || (e is Sandbox.ModAPI.IMyCharacter)).ToList();
            floatingList = floatingList.Where(e => (e is Sandbox.ModAPI.IMyFloatingObject) || (e is Sandbox.Game.Entities.MyReplicableEntity)).ToList();

            _instance._timer100.Stop();
            _instance._workQueue.Clear();
            for (var i = 0; i < floatingList.Count; i++)
            {
                var item = floatingList[i];

                // Check for null physics and IsPhantom, to prevent picking up primitives.
                if (item.Physics != null && !item.Physics.IsPhantom)
                {
                    if (item is Sandbox.ModAPI.IMyCharacter)
                    {
                        var character = item.GetObjectBuilder() as MyObjectBuilder_Character;
                        if (!character.Health.HasValue || character.Health.Value > 0) // ignore living players
                        {
                            // TODO: not working currently. It causes body duplicates?

                            //item.Physics.ClearSpeed();
                            //_workQueue.Enqueue(delegate() { item.SetPosition(destination); });
                        }
                    }
                    else if (item is IMyFloatingObject || item is Sandbox.Game.Entities.MyReplicableEntity)
                    {
                        // Need to queue the objects, and relocate them over a number of frames, otherwise if they
                        // are all moved simultaneously to the same point in space, they will become stuck.

                        _instance._workQueue.Enqueue(delegate()
                        {
                            //item.SyncObject.UpdatePosition(); // causes Null exception.

                            if (item.Physics != null)
                            {
                                if (MyAPIGateway.Multiplayer.MultiplayerActive)
                                {
                                    item.Physics.ClearSpeed();
                                    item.SetPosition(destination); // Doesn't sync to the server.
                                    ConnectionHelper.SendMessageToAllPlayers(new MessageSyncEntityPosition() {EntityId = item.EntityId, Position = destination});
                                }
                                else if (item.Physics != null)
                                {
                                    item.Physics.ClearSpeed();
                                    item.SetPosition(destination); // Doesn't sync to the server.
                                }
                            }
                        });
                    }
                }
            }
            if (_instance._workQueue.Count > 0)
                _instance._timer100.Start();
        }
开发者ID:DigTron,项目名称:Space-Engineers-Admin-script-mod,代码行数:57,代码来源:CommandObjectsCollect.cs

示例9: Init

        public void Init(BoundingSphereD explosion, float explosionDamage)
        {
            m_explosion = explosion;
            m_explosionDamage = explosionDamage;

            AffectedCubeBlocks.Clear();
            AffectedCubeGrids.Clear();
            m_damageRemaining.Clear();
            m_damagedBlocks.Clear();
            m_castBlocks.Clear();
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:11,代码来源:MyGridExplosion.cs

示例10: HandleCommand

        // admin scan x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() != 8 && words.Count() != 0)
                return false;

            if (words.Count() != 8)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return true;
            }

            // Test Input
            float test = 0;
            for(int r = 0; r < 8; r++)
            {
                if(!float.TryParse(words[r], out test))
                {
                    Communication.SendPrivateInformation(userId, string.Format("The value at position {0} - '{1}' is invalid.  Please try the command again.", r + 1, words[r]));
                    return true;
                }
            }

            Vector3D startPosition = new Vector3D(float.Parse(words[0]), float.Parse(words[1]), float.Parse(words[2]));
            Vector3D targetPosition = new Vector3D(float.Parse(words[3]), float.Parse(words[4]), float.Parse(words[5]));
            float distance = float.Parse(words[6]);
            float radius = float.Parse(words[7]);

            Vector3D targetMovement = targetPosition - startPosition;
            targetMovement.Normalize();
            Vector3D finalPosition = targetMovement * distance;
            finalPosition += startPosition;

            List<MyObjectBuilder_CubeGrid> gridsToMove = new List<MyObjectBuilder_CubeGrid>();
            BoundingSphereD sphere = new BoundingSphereD(finalPosition, radius);
            List<IMyEntity> entities = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
            int count = 0;

            Communication.SendPrivateInformation(userId, string.Format("Scanning {0} meters around {1}", radius, General.Vector3DToString(finalPosition)));
            Wrapper.GameAction(() =>
            {
                foreach (IMyEntity entity in entities)
                {
                    if (!(entity is IMyCubeGrid))
                        continue;

                    Communication.SendPrivateInformation(userId, string.Format("Found ship {0} at {1}", entity.DisplayName, General.Vector3DToString(entity.GetPosition())));
                    count++;
                }
            });

            Communication.SendPrivateInformation(userId, string.Format("Total ships found: {0}", count));
            return true;
        }
开发者ID:afinegan,项目名称:EssentialsPlugin,代码行数:54,代码来源:HandleAdminScanAreaTowards.cs

示例11: GetAllBroadcastersInSphere

 public static void GetAllBroadcastersInSphere(BoundingSphereD sphere, List<MyDataBroadcaster> result)
 {
     m_aabbTree.OverlapAllBoundingSphere<MyDataBroadcaster>(ref sphere, result, false);
     for(int i = result.Count -1; i >= 0; i--)
     {
         var x = result[i];
         var dst = (sphere.Radius + ((MyRadioBroadcaster)x).BroadcastRadius);
         dst*=dst;
         if (Vector3D.DistanceSquared(sphere.Center, x.BroadcastPosition) > dst)
             result.RemoveAtFast(i);
     }
 }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:12,代码来源:MyRadioBroadcasters.cs

示例12: HandleCommand

        public override bool HandleCommand( ulong userId, string[] words )
        {
            Essentials.Log.Info( "Asteroid cleanup" );
            HashSet<IMyEntity> entities = new HashSet<IMyEntity>( );
            Wrapper.GameAction( ( ) =>
                                {
                                    MyAPIGateway.Entities.GetEntities( entities );
                                    foreach ( IMyEntity entity in entities )
                                    {
                                        if ( entity == null )
                                            continue;

                                        if ( entity is IMyVoxelMap )
                                            asteroidPositions.Add( entity.PositionComp.GetPosition( ), (IMyVoxelMap)entity );
                                        else
                                            entityPositions.Add( entity.PositionComp.GetPosition( ) );
                                    }
                                } );
            //TODO: Use a thread pool to speed this up?
            DateTime profile = DateTime.Now;
            Communication.SendPrivateInformation( userId, $"Found {asteroidPositions.Count} asteroids." );
            foreach ( var asteroid in asteroidPositions )
            {
                bool found = false;
                BoundingSphereD bound = new BoundingSphereD( asteroid.Key, 1000 );
                foreach ( Vector3D checkPosition in entityPositions )
                {
                    if ( bound.Contains( checkPosition ) == ContainmentType.Contains )
                    {
                        found = true;
                        break;
                    }
                }

                if ( !found )
                    toRemove.Add( asteroid.Value );
            }
            Communication.SendPrivateInformation( userId, $"Found {toRemove.Count} asteroids to remove." );
            int count = 0;
            foreach ( IMyVoxelMap asteroid in toRemove )
            {
                if ( asteroid == null || asteroid.Closed )
                    continue;

                count++;

                Wrapper.GameAction( ( ) => asteroid.Close( ) );
            }
            Communication.SendPrivateInformation( userId, $"Removed {count} asteroids." );
            Essentials.Log.Info( "Asteroid cleanup elapsed time: " + (DateTime.Now - profile) );
            return true;
        }
开发者ID:rexxar-tc,项目名称:EssentialsPlugin,代码行数:52,代码来源:HandleAdminAsteroidCleanup.cs

示例13: HideTrianglesAfterExplosion

        //  Blends-out triangles affected by explosion (radius + some safe delta). Triangles there have zero alpha are flaged to not-draw at all.
        public static void HideTrianglesAfterExplosion(MyVoxelBase voxelMap, ref BoundingSphereD explosionSphere)
        {
            VRageRender.MyRenderProxy.GetRenderProfiler().StartProfilingBlock("MyDecals::HideTrianglesAfterExplosion");
            //MyMwcVector3Int renderCellCoord = voxelMap.GetVoxelRenderCellCoordinateFromMeters(ref explosionSphere.Center);
            //m_decalsForVoxels.HideTrianglesAfterExplosion(voxelMap.VoxelMapId, ref renderCellCoord, ref explosionSphere);

            foreach (uint id in voxelMap.Render.RenderObjectIDs)
            {
                VRageRender.MyRenderProxy.HideDecals(id, explosionSphere.Center, (float)explosionSphere.Radius);
            }

            VRageRender.MyRenderProxy.GetRenderProfiler().EndProfilingBlock();
        }
开发者ID:leandro1129,项目名称:SpaceEngineers,代码行数:14,代码来源:MyDecals.cs

示例14: Contains

        public bool Contains(IMyEntity entity)
        {
            switch (Shape)
            {
                case ProtectionAreaShape.Cube:
                    var boundingBox = new BoundingBoxD(new Vector3D(Center.X - Size, Center.Y - Size, Center.Z - Size), new Vector3D(Center.X + Size, Center.Y + Size, Center.Z + Size));
                    return boundingBox.Intersects(entity.WorldAABB);
                case ProtectionAreaShape.Sphere:
                    var boundingSphere = new BoundingSphereD(Center, Size);
                    return boundingSphere.Intersects(entity.WorldAABB);
            }

            return false;
        }
开发者ID:Intueor,项目名称:Space-Engineers-Admin-script-mod,代码行数:14,代码来源:ProtectionArea.cs

示例15: HandleCommand

        // /admin movefrom x y z x y z radius
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (words.Count() != 7 && words.Count() != 0)
                return false;

            if (words.Count() != 7)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return true;
            }

            // Test Input
            float test = 0;
            for(int r = 0; r < 7; r++)
            {
                if(!float.TryParse(words[r], out test))
                {
                    Communication.SendPrivateInformation(userId, string.Format("The value at position {0} - '{1}' is invalid.  Please try the command again.", r + 1, words[r]));
                    return true;
                }
            }

            Vector3D startPosition = new Vector3(float.Parse(words[0]), float.Parse(words[1]), float.Parse(words[2]));
            Vector3D movePosition = new Vector3(float.Parse(words[3]), float.Parse(words[4]), float.Parse(words[5]));
            Vector3D difference = startPosition - movePosition;
            float radius = float.Parse(words[6]);

            Communication.SendPrivateInformation(userId, $"Moving all grids in a radius of {radius} near {startPosition} to {movePosition}" );

            BoundingSphereD sphere = new BoundingSphereD(startPosition, radius);
            List<IMyEntity> entitiesToMove = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);
            int moveCount = 0;
            foreach ( IMyEntity entity in entitiesToMove )
            {
                if ( !( entity is IMyCubeGrid ) )
                    continue;

                Vector3D target = entity.GetPosition( ) + difference;

                Communication.SendPrivateInformation( userId, $"Moving '{entity.DisplayName}' from {entity.GetPosition( )} to {target}" );

                //position can be set directly on the server
                Wrapper.GameAction( ( ) => entity.SetPosition( target ) );
                moveCount++;
            }

            Communication.SendPrivateInformation(userId, $"Moved {moveCount} grids" );

            return true;
        }
开发者ID:rexxar-tc,项目名称:EssentialsPlugin,代码行数:51,代码来源:HandleAdminMoveAreaToPosition.cs


注:本文中的BoundingSphereD类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。