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


C# BoundingSphereD.Include方法代码示例

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


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

示例1: MarkForExplosion

        void MarkForExplosion()
        {
            m_marked = true;
            //Large grid = 12.5m radius of block
            //Small grid = 2.5m radius
            float radiusMultiplier = 4; //reduced by 20%
            float warheadBlockRadius = CubeGrid.GridSize * radiusMultiplier;
           
            float shrink = 0.85f;
            m_explosionShrinkenSphere = new BoundingSphereD(PositionComp.GetPosition(), (double)warheadBlockRadius * shrink);

            m_explosionParticleSphere = new BoundingSphereD(PositionComp.GetPosition(), double.MinValue);

            MyGamePruningStructure.GetAllEntitiesInSphere(ref m_explosionShrinkenSphere, m_entitiesInShrinkenSphere);
            m_warheadsInsideCount = 0;
            foreach (var entity in m_entitiesInShrinkenSphere)
            {
                if (Vector3D.DistanceSquared(PositionComp.GetPosition(), entity.PositionComp.GetPosition()) < warheadBlockRadius * shrink * warheadBlockRadius * shrink)
                {
                    MyWarhead warhead = entity as MyWarhead;
                    if (warhead != null)
                    {
                        m_warheadsInsideCount++;

                        if (!warhead.MarkedToExplode)
                            m_explosionParticleSphere = m_explosionParticleSphere.Include(new BoundingSphereD(warhead.PositionComp.GetPosition(), CubeGrid.GridSize * radiusMultiplier + warhead.CubeGrid.GridSize));
                    }
                    var block = entity as MyCubeBlock;
                    if (block != null)
                    {
                        block.MarkedToExplode = true;
                    }
                }
            }
            m_entitiesInShrinkenSphere.Clear();

            //m_radius += m_warheadsInsideCount * 0.1f;
            //Explosion radius is based on linear function where 1 warhead has explosion radius :
            //Large: 22.4415f
            // Small: 4.4883f
            //each warhead contribute 0.26 % of radius
            //explosion is clamped to maxExplosionRadius
            float fullExplosionRadius = Math.Min(m_maxExplosionRadius,(1 + 0.024f * m_warheadsInsideCount) * m_warheadDefinition.ExplosionRadius);
            //fullExplosionRadius = fullExplosionRadius;
            m_explosionFullSphere = new BoundingSphere(m_explosionParticleSphere.Center, (float)Math.Max(fullExplosionRadius, m_explosionParticleSphere.Radius));

            if (MyExplosion.DEBUG_EXPLOSIONS)
            {
                MyWarheads.DebugWarheadShrinks.Add(m_explosionShrinkenSphere);
                MyWarheads.DebugWarheadGroupSpheres.Add(m_explosionFullSphere);

                float particleRadius = (float)m_explosionParticleSphere.Radius;
            }
        }
开发者ID:martejj,项目名称:SpaceEngineers,代码行数:54,代码来源:MyWarhead.cs

示例2: GetSafeBoundingBoxForPlayers

        private static void GetSafeBoundingBoxForPlayers(Vector3D start, double spawnDistance, out BoundingBoxD output)
        {
            double tolerance = 10.0f;
            BoundingSphereD sphere = new BoundingSphereD(start, tolerance);

            var players = MySession.Static.Players.GetOnlinePlayers();
            bool tryIncludeOtherPlayers = true;

            // We have to try adding other players until the bounding sphere stays the same
            while (tryIncludeOtherPlayers)
            {
                tryIncludeOtherPlayers = false;
                foreach (var player in players)
                {
                    Vector3D playerPosition = player.GetPosition();
                    double distanceFromSphere = (sphere.Center - playerPosition).Length() - sphere.Radius;

                    if (distanceFromSphere <= 0.0) continue;
                    if (distanceFromSphere > spawnDistance * 2.0f) continue;

                    sphere.Include(new BoundingSphereD(playerPosition, tolerance));
                    tryIncludeOtherPlayers = true;
                }
            }

            sphere.Radius += spawnDistance;
            output = new BoundingBoxD(sphere.Center - new Vector3D(sphere.Radius), sphere.Center + new Vector3D(sphere.Radius));

            var entities = MyEntities.GetEntitiesInAABB(ref output);
            foreach (var entity in entities)
            {
                if (entity is MyCubeGrid)
                {
                    var cubeGrid = entity as MyCubeGrid;
                    if (cubeGrid.IsStatic)
                    {
                        Vector3D gridPosition = cubeGrid.PositionComp.GetPosition();

                        // If grid is close to picked player we need to include it's "safe" bounding box for spawning ships,
                        // so cargo ships don't spawn near it.

                        output.Include(new BoundingBoxD(new Vector3D(gridPosition - spawnDistance), new Vector3D(gridPosition + spawnDistance)));
                    }
                }
            }
            entities.Clear();
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:47,代码来源:MyNeutralShipSpawner.cs


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