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


C# MySlimBlock.GetWorldBoundingBox方法代码示例

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


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

示例1: IsInVoxels

        public static bool IsInVoxels(MySlimBlock block,bool checkForPhysics = true)
        {
            if (block.CubeGrid.Physics == null && checkForPhysics)
               return false;

            if (MyPerGameSettings.Destruction && block.CubeGrid.GridSizeEnum == MyCubeSize.Large)
                return block.CubeGrid.Physics.Shape.BlocksConnectedToWorld.Contains(block.Position);

            BoundingBoxD blockWorldAABB;
            block.GetWorldBoundingBox(out blockWorldAABB);

            m_tmpVoxelList.Clear();
            MyGamePruningStructure.GetAllVoxelMapsInBox(ref blockWorldAABB, m_tmpVoxelList);
            var cubeSize = block.CubeGrid.GridSize;
            BoundingBoxD localAAABB = new BoundingBoxD(cubeSize * ((Vector3D)block.Min - 0.5), cubeSize * ((Vector3D)block.Max + 0.5));
            var gridWorldMatrix = block.CubeGrid.WorldMatrix;
            foreach(var map in m_tmpVoxelList)
            {
                if (map.IsAnyAabbCornerInside(ref gridWorldMatrix, localAAABB))
                {
                    return true;
                }
            }
            return false;
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:25,代码来源:MyCubeGrid.Static.cs

示例2: IsInVoxels

        public static bool IsInVoxels(MySlimBlock block,bool checkForPhysics = true)
        {
            if (block.CubeGrid.Physics == null && checkForPhysics)
               return false;

            if (MyPerGameSettings.Destruction && block.CubeGrid.GridSizeEnum == Common.ObjectBuilders.MyCubeSize.Large)
                return block.CubeGrid.Physics.Shape.BlocksConnectedToWorld.Contains(block.Position);

            BoundingBoxD blockWorldAABB;
            block.GetWorldBoundingBox(out blockWorldAABB);

            var voxelMap = MySession.Static.VoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref blockWorldAABB, null);
            if (voxelMap == null)
                return false;

            var cubeSize = block.CubeGrid.GridSize;
            BoundingBoxD localAAABB = new BoundingBoxD(cubeSize * ((Vector3D)block.Min - 0.5), cubeSize * ((Vector3D)block.Max + 0.5));
            var gridWorldMatrix = block.CubeGrid.WorldMatrix;

            return voxelMap.IsAnyAabbCornerInside(ref gridWorldMatrix, localAAABB);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:21,代码来源:MyCubeGrid.Static.cs

示例3: DetectTouchingGrid

        private MyCubeGrid DetectTouchingGrid(MySlimBlock block)
        {
            if (MyCubeBuilder.Static.DynamicMode)
                return null;

            if (block == null)
                return null;

            if (block.FatBlock is MyCompoundCubeBlock)
            {
                foreach (var blockInCompound in (block.FatBlock as MyCompoundCubeBlock).GetBlocks())
                {
                    MyCubeGrid touchingGrid = DetectTouchingGrid(blockInCompound);
                    if (touchingGrid != null)
                        return touchingGrid;
                }

                return null;
            }

            ProfilerShort.Begin("MultiBlockClipboard: DetectMerge");

            float gridSize = block.CubeGrid.GridSize;
            BoundingBoxD aabb;
            block.GetWorldBoundingBox(out aabb);
            // Inflate by half cube, so it will intersect for sure when there's anything
            aabb.Inflate(gridSize / 2);

            m_tmpNearEntities.Clear();
            MyEntities.GetElementsInBox(ref aabb, m_tmpNearEntities);

            var mountPoints = block.BlockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio);

            try
            {
                for (int i = 0; i < m_tmpNearEntities.Count; i++)
                {
                    var grid = m_tmpNearEntities[i] as MyCubeGrid;
                    if (grid != null && grid != block.CubeGrid && grid.Physics != null && grid.Physics.Enabled && grid.IsStatic && grid.GridSizeEnum == block.CubeGrid.GridSizeEnum)
                    {
                        Vector3I gridOffset = grid.WorldToGridInteger(m_pastePosition);
                        if (!grid.CanMergeCubes(block.CubeGrid, gridOffset))
                            continue;

                        MatrixI transform = grid.CalculateMergeTransform(block.CubeGrid, gridOffset);
                        Base6Directions.Direction forward = transform.GetDirection(block.Orientation.Forward);
                        Base6Directions.Direction up = transform.GetDirection(block.Orientation.Up);
                        MyBlockOrientation newOrientation = new MyBlockOrientation(forward, up);
                        Quaternion newRotation;
                        newOrientation.GetQuaternion(out newRotation);
                        Vector3I newPosition = Vector3I.Transform(block.Position, transform);

                        if (!MyCubeGrid.CheckConnectivity(grid, block.BlockDefinition, mountPoints, ref newRotation, ref newPosition))
                            continue;

                        return grid;
                    }
                }
            }
            finally
            {
                m_tmpNearEntities.Clear();
                ProfilerShort.End();
            }

            return null;
        }
开发者ID:rem02,项目名称:SpaceEngineers,代码行数:67,代码来源:MyMultiBlockClipboard.cs

示例4: MyCubeGridsOnBlockBuilt

        private void MyCubeGridsOnBlockBuilt(MyCubeGrid myCubeGrid, MySlimBlock mySlimBlock)
        {
            if (mySlimBlock == null || !myCubeGrid.IsStatic) return;

            // Avoid multiple queues for compound block additions.
            var compound = myCubeGrid.GetCubeBlock(mySlimBlock.Min).FatBlock as MyCompoundCubeBlock;
            if (compound != null && mySlimBlock.FatBlock != compound) return;

            BoundingBoxD blockAabb;
            mySlimBlock.GetWorldBoundingBox(out blockAabb, true);
            m_cubeBlocksPending.Add(myCubeGrid, blockAabb);

            //Debug.Print("CubeGrid {0}: Block added at {1}.", myCubeGrid, mySlimBlock.Position);
        }
开发者ID:2asoft,项目名称:SpaceEngineers,代码行数:14,代码来源:MyPlanetEnvironmentSessionComponent.cs

示例5: grid_OnBlockRemoved

        private void grid_OnBlockRemoved(MySlimBlock block)
        {
            bool ignore = true;
            bool noEntry = false;
            bool meshFound = false;

            var existingBlock = m_grid.GetCubeBlock(block.Position);
            var compound = existingBlock == null ? null : existingBlock.FatBlock as MyCompoundCubeBlock;

            if (!(block.FatBlock is MyCompoundCubeBlock) && block.BlockDefinition.NavigationDefinition == null) return;

            // Ignore blocks without navigation info (i.e. decorations and such)
            if (compound == null)
            {
                Debug.Assert(existingBlock == null, "Removed a block from position, but there still is another block and it's not a compound!");

                ignore = false;
                if (existingBlock != null)
                {
                    if (block.BlockDefinition.NavigationDefinition.NoEntry)
                        noEntry = true;
                    else
                        meshFound = true;
                }
            }
            else
            {
                var blocks = compound.GetBlocks();

                if (blocks.Count != 0)
                {
                    foreach (var subBlock in blocks)
                    {
                        if (subBlock.BlockDefinition.NavigationDefinition == null) continue;
                        if (subBlock.BlockDefinition.NavigationDefinition.NoEntry || meshFound)
                        {
                            ignore = false;
                            noEntry = true;
                            break;
                        }
                        else
                        {
                            ignore = false;
                            meshFound = true;
                            block = subBlock;
                        }
                    }
                }
            }

            BoundingBoxD bbox;
            block.GetWorldBoundingBox(out bbox);
            bbox.Inflate(5.1f);

            //m_coordinator.RemoveGridNavmeshLinks(m_grid);
            m_coordinator.InvalidateVoxelsBBox(ref bbox);

            MarkBlockChanged(block);
            MyAIComponent.Static.Pathfinding.GridPathfinding.MarkHighLevelDirty();

            if (ignore)
            {
                RemoveBlock(block.Min, block.Max, eraseCubeSet: true);
                FixBlockFaces(block);
            }
            else if (noEntry)
            {
                RemoveBlock(block.Min, block.Max, eraseCubeSet: false);
            }
            else if (meshFound)
            {
                RemoveBlock(block.Min, block.Max, eraseCubeSet: true);
                AddBlock(block);
            }
            else
            {
                if (m_cubeSet.Contains(block.Position))
                {
                    RemoveBlock(block.Min, block.Max, eraseCubeSet: true);
                    FixBlockFaces(block);
                }
            }
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:83,代码来源:MyGridNavigationMesh.cs

示例6: OnBlockAddedInternal


//.........这里部分代码省略.........
            }
            else
            {
                if (block.BlockDefinition.NavigationDefinition != null)
                {
                    if (block.BlockDefinition.NavigationDefinition.NoEntry)
                    {
                        meshFound = false;
                        noEntry = true;
                    }
                    else
                    {
                        meshFound = true;
                    }
                }
            }

            // Ignore compounds with blocks without navigation info
            if (!noEntry && !meshFound) return;

            if (noEntry)
            {
                if (m_cubeSet.Contains(block.Position))
                    RemoveBlock(block.Min, block.Max, true);

                Vector3I pos = default(Vector3I);
                for (pos.X = block.Min.X; pos.X <= block.Max.X; ++pos.X)
                {
                    for (pos.Y = block.Min.Y; pos.Y <= block.Max.Y; ++pos.Y)
                    {
                        pos.Z = block.Min.Z - 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Backward);
                        }

                        pos.Z = block.Max.Z + 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Forward);
                        }
                    }

                    for (pos.Z = block.Min.Z; pos.Z <= block.Max.Z; ++pos.Z)
                    {
                        pos.Y = block.Min.Y - 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Up);
                        }

                        pos.Y = block.Max.Y + 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Down);
                        }
                    }
                }

                for (pos.Y = block.Min.Y; pos.Y <= block.Max.Y; ++pos.Y)
                {
                    for (pos.Z = block.Min.Z; pos.Z <= block.Max.Z; ++pos.Z)
                    {
                        pos.X = block.Min.X - 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Right);
                        }

                        pos.X = block.Max.X + 1;
                        if (m_cubeSet.Contains(ref pos))
                        {
                            EraseFaceTriangles(pos, Base6Directions.Direction.Left);
                        }
                    }
                }

                pos = block.Min;
                for (var it = new Vector3I.RangeIterator(ref pos, ref block.Max); it.IsValid(); it.GetNext(out pos))
                {
                    m_cubeSet.Add(pos);
                }
            }
            else
            {
                if (m_cubeSet.Contains(block.Position))
                {
                    RemoveBlock(block.Min, block.Max, eraseCubeSet: true);
                }
                AddBlock(block);
            }

            BoundingBoxD bbox;
            block.GetWorldBoundingBox(out bbox);
            bbox.Inflate(5.1f);

            m_coordinator.InvalidateVoxelsBBox(ref bbox);

            MarkBlockChanged(block);
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:101,代码来源:MyGridNavigationMesh.cs


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