• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Cube.MyGridPlacementSettings类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: TestPlacementAreaCube

        /// <summary>
        /// Test cube block placement area in grid.
        /// </summary>
        public static bool TestPlacementAreaCube(
            MyCubeGrid targetGrid,
            ref MyGridPlacementSettings settings,
            Vector3I min,
            Vector3I max,
            MyBlockOrientation blockOrientation,
            MyCubeBlockDefinition blockDefinition,
            out MyCubeGrid touchingGrid,
            MyEntity ignoredEntity = null,
            bool ignoreFracturedPieces = false)
        {
            touchingGrid = null;

            ProfilerShort.Begin("Math");
            var worldMatrix = targetGrid != null ? targetGrid.WorldMatrix : MatrixD.Identity;
            var gridSize = targetGrid != null ? targetGrid.GridSize : MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large);

            Vector3 halfExtents = ((max - min) * gridSize + gridSize) / 2;
            if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
                halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
            else
                halfExtents -= new Vector3(0.03f, 0.03f, 0.03f); //allows touching blocks like wheels
            var matrix = MatrixD.CreateTranslation((max + min) * 0.5f * gridSize) * worldMatrix;
            var localAabb = BoundingBoxD.CreateInvalid();
            localAabb.Include(min * gridSize - gridSize / 2);
            localAabb.Include(max * gridSize + gridSize / 2);

            Vector3D translation = matrix.Translation;
            Quaternion rotation = Quaternion.CreateFromRotationMatrix(matrix);

            ProfilerShort.BeginNextBlock("TestBlockPlacementArea");
            bool result = TestBlockPlacementArea(targetGrid, ref settings, blockOrientation, blockDefinition, ref translation, ref rotation, ref halfExtents, ref localAabb, out touchingGrid, ignoredEntity: ignoredEntity, 
                ignoreFracturedPieces: ignoreFracturedPieces);

            ProfilerShort.End();

            return result;
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:41,代码来源:MyCubeGrid.Static.cs


示例2: TrySnapToSurface

        protected bool TrySnapToSurface(MyGridPlacementSettings.SnapMode snapMode)
        {
            if (m_closestHitDistSq < float.MaxValue)
            {
                Vector3 newDragPointPosition = m_hitPos;

                bool isAnyStatic = AnyCopiedGridIsStatic;
                if (isAnyStatic)
                {
                    m_pasteDirForward = Vector3.Forward;
                    m_pasteDirUp = Vector3.Up;
                }
                else if (m_hitNormal.Length() > 0.5)
                {
                    if (snapMode == MyGridPlacementSettings.SnapMode.OneFreeAxis)
                    {
                        m_pasteDirUp = m_hitNormal;

                        float dotUp = m_pasteDirUp.Dot(m_hitEntity.WorldMatrix.Up);
                        float dotFwd = m_pasteDirUp.Dot(m_hitEntity.WorldMatrix.Forward);
                        float dotRt = m_pasteDirUp.Dot(m_hitEntity.WorldMatrix.Right);
                        if (Math.Abs(dotUp) > Math.Abs(dotFwd))
                        {
                            if (Math.Abs(dotUp) > Math.Abs(dotRt))
                            {
                                m_pasteDirForward = Vector3.Normalize(m_hitEntity.WorldMatrix.Right - (dotRt * m_pasteDirUp));
                            }
                            else
                            {
                                m_pasteDirForward = Vector3.Normalize(m_hitEntity.WorldMatrix.Forward - (dotFwd * m_pasteDirUp));
                            }
                        }
                        else
                        {
                            if (Math.Abs(dotFwd) > Math.Abs(dotRt))
                            {
                                m_pasteDirForward = Vector3.Normalize(m_hitEntity.WorldMatrix.Up - (dotUp * m_pasteDirUp));
                            }
                            else
                            {
                                m_pasteDirForward = Vector3.Normalize(m_hitEntity.WorldMatrix.Forward - (dotFwd * m_pasteDirUp));
                            }
                        }
                    }
                    else if (snapMode == MyGridPlacementSettings.SnapMode.Base6Directions)
                    {
                        var hitGrid = m_hitEntity as MyCubeGrid;
                        if (hitGrid != null)
                        {
                            Matrix hitGridRotation = hitGrid.WorldMatrix.GetOrientation();
                            Matrix firstRotation = GetFirstGridOrientationMatrix();
                            Matrix newFirstRotation = Matrix.AlignRotationToAxes(ref firstRotation, ref hitGridRotation);
                            Matrix rotationDelta = Matrix.Invert(firstRotation) * newFirstRotation;

                            m_pasteDirForward = newFirstRotation.Forward;
                            m_pasteDirUp = newFirstRotation.Up;
                            m_pasteOrientationAngle = 0.0f;
                        }
                    }
                }

                Matrix newOrientation = GetFirstGridOrientationMatrix();
                Vector3 globalCenterDelta = Vector3.TransformNormal(m_dragPointToPositionLocal, newOrientation);

                m_pastePosition = newDragPointPosition + globalCenterDelta;

                if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE)
                {
                    MyRenderProxy.DebugDrawSphere(newDragPointPosition, 0.08f, Color.Red.ToVector3(), 1.0f, false);
                    MyRenderProxy.DebugDrawSphere(m_pastePosition, 0.08f, Color.Red.ToVector3(), 1.0f, false);
                }

                IsSnapped = true;
                return true;
            }
            IsSnapped = false;
            return false;
        }
开发者ID:Krulac,项目名称:SpaceEngineers,代码行数:78,代码来源:MyGridClipboard.cs


示例3: TestPlacementAreaInternal

        private static bool TestPlacementAreaInternal(MyCubeGrid targetGrid,
           bool targetGridIsStatic,
           ref MyGridPlacementSettings settings,
           MyCubeBlockDefinition blockDefinition,
           MyBlockOrientation? blockOrientation,
           ref BoundingBoxD localAabb,
           MyEntity ignoredEntity,
           ref MatrixD worldMatrix,
           out MyCubeGrid touchingGrid,
           bool dynamicBuildMode = false,
           bool ignoreFracturedPieces = false,
           bool testVoxels = true)
        {
            ProfilerShort.Begin("TestPlacementAreaInternal");

            touchingGrid = null;

            float gridSize = targetGrid != null ? targetGrid.GridSize : (blockDefinition != null ? MyDefinitionManager.Static.GetCubeSize(blockDefinition.CubeSize) : MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large));
            bool isStatic = targetGridIsStatic;

            var worldAabb = localAabb.Transform(ref worldMatrix);

            bool entityOverlap = false;
            MyVoxelBase overlappedVoxelMap = null;
            bool touchingStaticGrid = false;
            foreach (var collison in m_physicsBoxQueryList)
            {
                var entity = collison.Body.GetEntity(0) as MyEntity;
                if (entity == null)
                    continue;

                if (ignoreFracturedPieces && (entity is MyFracturedPiece))
                    continue;

                if (entity.GetPhysicsBody().WeldInfo.Children.Count == 0 && ignoredEntity != null && (entity == ignoredEntity || entity.GetTopMostParent() == ignoredEntity))
                    continue;

                var body = entity.Physics;
                if (body != null && body.IsPhantom)
                    continue;

                var voxelMap = entity as MyVoxelBase;
                if (voxelMap != null)
                {
                    overlappedVoxelMap = voxelMap;
                    continue;
                }

                var grid = entity as MyCubeGrid;
				if (grid == null)
				{
					var subPart = entity as MyEntitySubpart;
					if (subPart != null)
					{
						grid = subPart.GetTopMostParent() as MyCubeGrid;
					}
				}

                if(entity.GetPhysicsBody().WeldInfo.Children.Count > 0)
                {
                    if(entity != ignoredEntity)
                    {
                        //Vector4 min,max;
                        //entity.Physics.GetShape().GetLocalAABB(0.05f, out min, out max);
                        //MyOrientedBoundingBoxD obb = new MyOrientedBoundingBoxD(new BoundingBoxD(new Vector3D(min.X, min.Y, min.Z), new Vector3D(max.X, max.Y, max.Z)), entity.WorldMatrix);
                        //MyRenderProxy.DebugDrawOBB(obb, Color.Green, 0.5f, false, false);
                        //obb = new MyOrientedBoundingBoxD(new BoundingBoxD(-m_lastQueryBox.HalfExtents, m_lastQueryBox.HalfExtents), m_lastQueryTransform);
                        //MyRenderProxy.DebugDrawOBB(obb, Color.Red, 0.5f, false, false);
                        if (TestQueryIntersection(entity.GetPhysicsBody().GetShape(), entity.WorldMatrix))
                        {
                            entityOverlap = true;
                            if(touchingGrid == null)
                                touchingGrid = entity as MyCubeGrid;
                            break;
                        }
                    }

                    foreach(var child in entity.GetPhysicsBody().WeldInfo.Children)
                    {
                        if(child.Entity == ignoredEntity)
                            continue;
                        if(TestQueryIntersection(child.WeldedRigidBody.GetShape(), child.Entity.WorldMatrix))
                        {
                            if (touchingGrid == null)
                                touchingGrid = child.Entity as MyCubeGrid;
                            entityOverlap = true;
                            break;
                        }
                    }
                    if (entityOverlap)
                        break;
                    continue;
                }

                if (grid != null && ((isStatic && grid.IsStatic)
                    || (MyFakes.ENABLE_DYNAMIC_SMALL_GRID_MERGING && !isStatic && !grid.IsStatic && blockDefinition != null && blockDefinition.CubeSize == grid.GridSizeEnum)
                    || (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL && isStatic && grid.IsStatic && blockDefinition != null && blockDefinition.CubeSize == grid.GridSizeEnum)))
                {
                    // Small on large (or large on small) always possible
                    if (isStatic == grid.IsStatic && gridSize != grid.GridSize)
//.........这里部分代码省略.........
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:101,代码来源:MyCubeGrid.Static.cs


示例4: TestPlacementVoxelMapOverlap

        public static bool TestPlacementVoxelMapOverlap(
            MyVoxelBase voxelMap,
            ref MyGridPlacementSettings settings,
            ref BoundingBoxD localAabb,
            ref MatrixD worldMatrix,
            bool touchingStaticGrid = false)
        {
            ProfilerShort.Begin("TestPlacementVoxelMapOverlap");

            var worldAabb = localAabb.Transform(ref worldMatrix);

            const int IntersectsOrInside = 1;
            const int Outside = 2;

            int overlapState = Outside;

            if (voxelMap == null)
                voxelMap = MySession.Static.VoxelMaps.GetVoxelMapWhoseBoundingBoxIntersectsBox(ref worldAabb, null);

            if (voxelMap != null && voxelMap.IsAnyAabbCornerInside(ref worldMatrix, localAabb))
            {
                overlapState = IntersectsOrInside;
            }

            bool testPassed = true;

            switch (overlapState)
            {
                case IntersectsOrInside:
                    testPassed = settings.Penetration.MaxAllowed > 0;
                    break;
                case Outside:
                    testPassed = settings.Penetration.MinAllowed <= 0 || (settings.CanAnchorToStaticGrid && touchingStaticGrid);
                    break;
                default:
                    Debug.Fail("Invalid branch.");
                    break;
            }

            ProfilerShort.End();

            return testPassed;
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:43,代码来源:MyCubeGrid.Static.cs


示例5: TestBlockPlacementArea

        public static bool TestBlockPlacementArea(MyCubeBlockDefinition blockDefinition, MyBlockOrientation? blockOrientation, MatrixD worldMatrix, ref MyGridPlacementSettings settings, BoundingBoxD localAabb, bool dynamicBuildMode,
            MyEntity ignoredEntity = null)
        {
            ProfilerShort.Begin("TestStart");
            Vector3 halfExtents = localAabb.HalfExtents;
            halfExtents += settings.SearchHalfExtentsDeltaAbsolute; //this works for SE
            if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
                halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
            Vector3D translation = localAabb.Transform(ref worldMatrix).Center;
            Quaternion quaternion = Quaternion.CreateFromRotationMatrix(worldMatrix);
            quaternion.Normalize();
            ProfilerShort.End();

            ProfilerShort.Begin("Havok.GetPenetrationsBox");
            Debug.Assert(m_physicsBoxQueryList.Count == 0, "List not cleared");
            MyPhysics.GetPenetrationsBox(ref halfExtents, ref translation, ref quaternion, m_physicsBoxQueryList, MyPhysics.CollisionLayers.CharacterCollisionLayer);
            m_lastQueryBox.HalfExtents = halfExtents;
            m_lastQueryTransform = MatrixD.CreateFromQuaternion(quaternion);
            m_lastQueryTransform.Translation = translation;
            ProfilerShort.End();

            MyCubeGrid touchingGrid;
            return TestPlacementAreaInternal(null, ref settings, blockDefinition, blockOrientation, ref localAabb, ignoredEntity, ref worldMatrix, out touchingGrid, dynamicBuildMode: dynamicBuildMode);
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:24,代码来源:MyCubeGrid.Static.cs


示例6: TestPlacementAreaInternalWithEntities

        private static bool TestPlacementAreaInternalWithEntities(MyCubeGrid targetGrid,
         bool targetGridIsStatic,
         ref MyGridPlacementSettings settings,
         ref BoundingBoxD localAabb,
         MyEntity ignoredEntity,
         ref MatrixD worldMatrix,
         bool dynamicBuildMode = false)
        {
            ProfilerShort.Begin("TestPlacementAreaInternalWithEntities");

            MyCubeGrid touchingGrid = null;

            float gridSize = targetGrid.GridSize;
            bool isStatic = targetGridIsStatic;

            var worldAabb = localAabb.Transform(ref worldMatrix);

            bool entityOverlap = false;
            MyVoxelBase overlappedVoxelMap = null;
            bool touchingStaticGrid = false;
            foreach (var entity in m_tmpResultList)
            {
                if (ignoredEntity != null && (entity == ignoredEntity || entity.GetTopMostParent() == ignoredEntity))
                    continue;

                var body = entity.Physics;
                if (body == null)
                    continue;

                var voxelMap = entity as MyVoxelBase;
                if (voxelMap != null)
                {
                    overlappedVoxelMap = voxelMap;
                    continue;
                }

                var grid = entity as MyCubeGrid;
                if (grid != null)
                {
                    // Small on large (or large on small) always possible
                    if (isStatic == grid.IsStatic && gridSize != grid.GridSize)
                        continue;

                    TestGridPlacement(ref settings, ref worldMatrix, ref touchingGrid, gridSize, isStatic, ref localAabb, null, null, ref entityOverlap, ref touchingStaticGrid, grid);

                    if (entityOverlap)
                    {
                        break;
                    }
                }
                else
                {
                    var character = entity as MyCharacter;
                    if (character != null && character.PositionComp.WorldAABB.Intersects(targetGrid.PositionComp.WorldAABB))
                    {
                        entityOverlap = true;
                        break;
                    }
                }
            }

            m_tmpResultList.Clear();
            ProfilerShort.End();

            if (entityOverlap)
                return false;

            if (targetGrid.IsStatic)
            {
                return true;
            }

            ProfilerShort.Begin("TestVoxelOverlap");
            bool result = TestVoxelOverlap(ref settings, ref localAabb, ref worldMatrix, ref worldAabb, ref overlappedVoxelMap, touchingStaticGrid);
            ProfilerShort.End();

            return result;
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:78,代码来源:MyCubeGrid.Static.cs


示例7: TestBlockPlacementOnGrid

        protected static bool TestBlockPlacementOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            Vector3I positionMin;
            Vector3I.Transform(ref block.Min, ref transform, out positionMin);
            Vector3I positionMax;
            Vector3I.Transform(ref block.Max, ref transform, out positionMax);
            Vector3I min = Vector3I.Min(positionMin, positionMax);
            Vector3I max = Vector3I.Max(positionMin, positionMax);

            Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward));
            Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up));

            MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));

            if (!hitGrid.CanAddCubes(min, max, blockOrientation, block.BlockDefinition))
                return false;

            return MyCubeGrid.TestPlacementAreaCube(hitGrid, ref settings, min, max, blockOrientation, block.BlockDefinition, ignoredEntity: hitGrid);
        }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:19,代码来源:MyGridClipboard2.cs


示例8: TestBlockPlacement

 protected static bool TestBlockPlacement(MySlimBlock block, ref MyGridPlacementSettings settings)
 {
     return MyCubeGrid.TestPlacementAreaCube(block.CubeGrid, ref settings, block.Min, block.Max, block.Orientation, block.BlockDefinition, ignoredEntity: block.CubeGrid);
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:4,代码来源:MyGridClipboard2.cs


示例9: TestGridPlacementOnGrid

        protected bool TestGridPlacementOnGrid(MyCubeGrid previewGrid, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            bool retval = true;

            Vector3I gridOffset = hitGrid.WorldToGridInteger(m_pastePosition);
            MatrixI transform = hitGrid.CalculateMergeTransform(previewGrid, gridOffset);

            if (MyDebugDrawSettings.DEBUG_DRAW_COPY_PASTE)
                MyRenderProxy.DebugDrawText2D(new Vector2(0.0f, 60.0f), "First grid offset: " + gridOffset.ToString(), Color.Red, 1.0f);
            retval = retval && hitGrid.GridSizeEnum == previewGrid.GridSizeEnum && hitGrid.CanMergeCubes(previewGrid, gridOffset);
            retval = retval && MyCubeGrid.CheckMergeConnectivity(hitGrid, previewGrid, gridOffset);

            // Check if any block connects to hit grid
            if (retval)
            {
                bool connected = false;

                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            connected |= CheckConnectivityOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (connected)
                                break;
                        }
                    }
                    else
                    {
                        connected |= CheckConnectivityOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (connected)
                        break;
                }

                retval &= connected;
            }

            if (retval)
            {
                foreach (var block in previewGrid.CubeBlocks)
                {
                    if (block.FatBlock is MyCompoundCubeBlock)
                    {
                        MyCompoundCubeBlock compoundBlock = block.FatBlock as MyCompoundCubeBlock;
                        foreach (var blockInCompound in compoundBlock.GetBlocks())
                        {
                            retval = retval && TestBlockPlacementOnGrid(blockInCompound, ref transform, ref settings, hitGrid);
                            if (!retval)
                                break;
                        }
                    }
                    else
                    {
                        retval = retval && TestBlockPlacementOnGrid(block, ref transform, ref settings, hitGrid);
                    }

                    if (!retval)
                        break;
                }
            }

            return retval;
        }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:67,代码来源:MyGridClipboard2.cs


示例10: CheckConnectivityOnGrid

        protected static bool CheckConnectivityOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            Vector3I position;
            Vector3I.Transform(ref block.Position, ref transform, out position);

            Vector3I forward = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Forward));
            Vector3I up = Base6Directions.GetIntVector(transform.GetDirection(block.Orientation.Up));
            MyBlockOrientation blockOrientation = new MyBlockOrientation(Base6Directions.GetDirection(forward), Base6Directions.GetDirection(up));
            Quaternion rotation;
            blockOrientation.GetQuaternion(out rotation);
			var blockDefinition = block.BlockDefinition;
            return MyCubeGrid.CheckConnectivity(hitGrid, blockDefinition, blockDefinition.GetBuildProgressModelMountPoints(block.BuildLevelRatio), ref rotation, ref position);
        }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:13,代码来源:MyGridClipboard2.cs


示例11: TestBlockPlacementArea

        public static bool TestBlockPlacementArea(
            MyCubeGrid targetGrid,
            ref MyGridPlacementSettings settings,
            MyBlockOrientation blockOrientation,
            MyCubeBlockDefinition blockDefinition,
            ref Vector3D translation,
            ref Quaternion rotation,
            ref Vector3 halfExtents,
            ref BoundingBoxD localAabb,
            out MyCubeGrid touchingGrid,
            MyEntity ignoredEntity = null)
        {
            touchingGrid = null;

            if (blockDefinition != null && blockDefinition.UseModelIntersection)
            {
                var model = MyModels.GetModelOnlyData(blockDefinition.Model);
                if(model != null)
                    model.CheckLoadingErrors(blockDefinition.Context);

                if (model != null && model.HavokCollisionShapes != null)
                {
                    int shapeCount = model.HavokCollisionShapes.Length;
                    HkShape[] shapes = new HkShape[shapeCount];
                    for (int q = 0; q < shapeCount; ++q)
                    {
                        shapes[q] = model.HavokCollisionShapes[q];
                    }

                    var shape = new HkListShape(shapes, shapeCount, HkReferencePolicy.None);

                    Quaternion q2 = Quaternion.CreateFromForwardUp(Base6Directions.GetVector(blockOrientation.Forward), Base6Directions.GetVector(blockOrientation.Up));
                    rotation = rotation * q2;
                    MyPhysics.GetPenetrationsShape(shape, ref translation, ref rotation, m_physicsBoxQueryList, MyPhysics.CharacterCollisionLayer);

                    shape.Base.RemoveReference();
                }
                else
                {
                    Debug.Assert(m_physicsBoxQueryList.Count == 0, "List not cleared");
                    MyPhysics.GetPenetrationsBox(ref halfExtents, ref translation, ref rotation, m_physicsBoxQueryList, MyPhysics.CharacterCollisionLayer);
                }
            }
            else
            {
                Debug.Assert(m_physicsBoxQueryList.Count == 0, "List not cleared");
                MyPhysics.GetPenetrationsBox(ref halfExtents, ref translation, ref rotation, m_physicsBoxQueryList, MyPhysics.CharacterCollisionLayer);
            }
            m_lastQueryBox.HalfExtents = halfExtents;
            m_lastQueryTransform = MatrixD.CreateFromQuaternion(rotation);
            m_lastQueryTransform.Translation = translation;

            var worldMatrix = targetGrid != null ? targetGrid.WorldMatrix : MatrixD.Identity;
            return TestPlacementAreaInternal(targetGrid, ref settings, blockDefinition, blockOrientation, ref localAabb, ignoredEntity, ref worldMatrix, out touchingGrid);
        }
开发者ID:fluxit,项目名称:SpaceEngineers,代码行数:55,代码来源:MyCubeGrid.Static.cs


示例12: TestBlockPlacementOnGrid

        protected static bool TestBlockPlacementOnGrid(MySlimBlock block, ref MatrixI transform, ref MyGridPlacementSettings settings, MyCubeGrid hitGrid)
        {
            Vector3I positionMin;
            Vector3I.Transform(ref block.Min, ref transform, out positionMin);
            Vector3I positionMax;
            Vector3I.Transform(ref block.Max, ref transform, out positionMax);
            Vector3I min = Vector3I.Min(positionMin, positionMax);
            Vector3I max = Vector3I.Max(positionMin, positionMax);

            var forward = transform.GetDirection(block.Orientation.Forward);
            var up = transform.GetDirection(block.Orientation.Up);
            MyBlockOrientation blockOrientation = new MyBlockOrientation(forward, up);
            return hitGrid.CanPlaceBlock(min, max, blockOrientation, block.BlockDefinition, ref settings);
        }
开发者ID:stanhebben,项目名称:SpaceEngineers,代码行数:14,代码来源:MyGridClipboardAdvanced.cs


示例13: TestPlacementAreaInternal

        private static bool TestPlacementAreaInternal(MyCubeGrid targetGrid,
           bool targetGridIsStatic,
           ref MyGridPlacementSettings settings,
           MyCubeBlockDefinition blockDefinition,
           MyBlockOrientation? blockOrientation,
           ref BoundingBoxD localAabb,
           MyEntity ignoredEntity,
           ref MatrixD worldMatrix,
           out MyCubeGrid touchingGrid,
           bool dynamicBuildMode = false)
        {
            ProfilerShort.Begin("TestPlacementAreaInternal");

            touchingGrid = null;

            float gridSize = targetGrid != null ? targetGrid.GridSize : (blockDefinition != null ? MyDefinitionManager.Static.GetCubeSize(blockDefinition.CubeSize) : MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large));
            bool isStatic = targetGridIsStatic;

            var worldAabb = localAabb.Transform(ref worldMatrix);

            bool entityOverlap = false;
            MyVoxelBase overlappedVoxelMap = null;
            bool touchingStaticGrid = false;
            foreach (var rigidBody in m_physicsBoxQueryList)
            {
                var entity = rigidBody.GetEntity();
                if (entity == null)
                    continue;

                if (ignoredEntity != null && (entity == ignoredEntity || entity.GetTopMostParent() == ignoredEntity))
                    continue;

                var body = rigidBody.GetBody();
                if (body != null && body.IsPhantom)
                    continue;

                var voxelMap = entity as MyVoxelBase;
                if (voxelMap != null)
                {
                    overlappedVoxelMap = voxelMap;
                    continue;
                }

                var grid = entity as MyCubeGrid;
                if (grid != null && ((isStatic && grid.IsStatic)
                    || (MyFakes.ENABLE_DYNAMIC_SMALL_GRID_MERGING && !isStatic && !grid.IsStatic && blockDefinition != null && blockDefinition.CubeSize == grid.GridSizeEnum)
                    || (MyFakes.ENABLE_BLOCK_PLACEMENT_ON_VOXEL && isStatic && grid.IsStatic && blockDefinition != null && blockDefinition.CubeSize == grid.GridSizeEnum)))
                {
                    // Small on large (or large on small) always possible
                    if (isStatic == grid.IsStatic && gridSize != grid.GridSize)
                        continue;

                    TestGridPlacement(ref settings, ref worldMatrix, ref touchingGrid, gridSize, isStatic, ref worldAabb, blockDefinition, blockOrientation, ref entityOverlap, ref touchingStaticGrid, grid);
                    if (entityOverlap)
                    {
                        break;
                    }
                    continue;
                }


                entityOverlap = true;
                break;
            }
            m_tmpResultList.Clear();
            m_physicsBoxQueryList.Clear();
            ProfilerShort.End();

            if (entityOverlap)
                return false;

            return TestVoxelOverlap(ref settings, ref localAabb, ref worldMatrix, ref worldAabb, ref overlappedVoxelMap, touchingStaticGrid);
        }
开发者ID:austusross,项目名称:SpaceEngineers,代码行数:73,代码来源:MyCubeGrid.Static.cs


示例14: TestPlacementAreaCubeNoAABBInflate

        public static bool TestPlacementAreaCubeNoAABBInflate(
            MyCubeGrid targetGrid,
            ref MyGridPlacementSettings settings,
            Vector3I min,
            Vector3I max,
            MyBlockOrientation blockOrientation,
            MyCubeBlockDefinition blockDefinition,
            out MyCubeGrid touchingGrid,
            MyEntity ignoredEntity = null)
        {
            touchingGrid = null;

            var worldMatrix = targetGrid != null ? targetGrid.WorldMatrix : MatrixD.Identity;
            var gridSize = targetGrid != null ? targetGrid.GridSize : MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large);

            Vector3 halfExtents = ((max - min) * gridSize + gridSize) / 2;
            var matrix = MatrixD.CreateTranslation((max + min) * 0.5f * gridSize) * worldMatrix;
            var localAabb = BoundingBoxD.CreateInvalid();
            localAabb.Include(min * gridSize - gridSize / 2);
            localAabb.Include(max * gridSize + gridSize / 2);

            Vector3D translation = matrix.Translation;
            Quaternion rotation = Quaternion.CreateFromRotationMatrix(matrix);

            return TestBlockPlacementArea(targetGrid, ref settings, blockOrientation, blockDefinition, ref translation, ref rotation, ref halfExtents, ref localAabb, out touchingGrid, ignoredEntity);
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:26,代码来源:MyCubeGrid.Static.cs


示例15: TestBlockPlacementNoAABBInflate

 protected static bool TestBlockPlacementNoAABBInflate(MySlimBlock block, ref MyGridPlacementSettings settings, out MyCubeGrid touchingGrid)
 {
     return MyCubeGrid.TestPlacementAreaCubeNoAABBInflate(block.CubeGrid, ref settings, block.Min, block.Max, block.Orientation, block.BlockDefinition, out touchingGrid, ignoredEntity: block.CubeGrid);
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:4,代码来源:MyGridClipboard2.cs


示例16: TestPlacementAreaWithEntities

        public static bool TestPlacementAreaWithEntities(MyCubeGrid targetGrid, bool targetGridIsStatic, ref MyGridPlacementSettings settings, BoundingBoxD localAabb, bool dynamicBuildMode, MyEntity ignoredEntity = null)
        {
            ProfilerShort.Begin("Test start with entities");
            var worldMatrix = targetGrid.WorldMatrix;

            Vector3 halfExtents = localAabb.HalfExtents;
            halfExtents += settings.SearchHalfExtentsDeltaAbsolute; //this works for SE
            if (MyFakes.ENABLE_BLOCK_PLACING_IN_OCCUPIED_AREA)
                halfExtents -= new Vector3D(GRID_PLACING_AREA_FIX_VALUE);
            Vector3D translation = localAabb.Transform(ref worldMatrix).Center;
            Quaternion quaternion = Quaternion.CreateFromRotationMatrix(worldMatrix);
            quaternion.Normalize();
            ProfilerShort.End();

            ProfilerShort.Begin("get top most entities");

            m_tmpResultList.Clear();
            BoundingBoxD box = targetGrid.PositionComp.WorldAABB;
            MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, m_tmpResultList);
            ProfilerShort.End();

            return TestPlacementAreaInternalWithEntities(targetGrid, targetGridIsStatic, ref settings, ref localAabb, ignoredEntity, ref worldMatrix, dynamicBuildMode: dynamicBuildMode);
        }
开发者ID:ales-vilchytski,项目名称:SpaceEngineers,代码行数:23,代码来源:MyCubeGrid.Static.cs


示例17: TestBlockPlacementArea

 protected static bool TestBlockPlacementArea(MySlimBlock block, ref MyGridPlacementSettings settings, bool dynamicMode)
 {
     var localAabb = BoundingBoxD.CreateInvalid();
     localAabb.Include(block.Min * block.CubeGrid.GridSize - block.CubeGrid.GridSize / 2);
     localAabb.Include(block.Max * block.CubeGrid.GridSize + block.CubeGrid.GridSize / 2);
     return MyCubeGrid.TestBlockPlacementArea(block.BlockDefinition, block.Orientation, block.CubeGrid.WorldMatrix, ref settings, localAabb, dynamicMode, ignoredEntity: block.CubeGrid);
 }
开发者ID:notten,项目名称:SpaceEngineers,代码行数:7,代码来源:MyGridClipboard2.cs


示例18: CanBuild

        public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections)
        {
            MyBlockOrientation blockOrientation = projectedBlock.Orientation;
            
            Matrix local;
            blockOrientation.GetMatrix(out local);
            var gridOrientation = (m_clipboard as MyGridClipboard).GetFirstGridOrientationMatrix();
            if (gridOrientation != Matrix.Identity)
            {
                var afterRotation = Matrix.Multiply(local, gridOrientation);
                blockOrientation = new MyBlockOrientation(ref afterRotation);
            }
            
            Quaternion blockOrientationQuat;
            blockOrientation.GetQuaternion(out blockOrientationQuat);

            Quaternion projQuat = Quaternion.Identity;
            Orientation.GetQuaternion(out projQuat);
            blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat);

            Vector3I projectedMin = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Min));
            Vector3I projectedMax = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Max));
            Vector3I blockPos = CubeGrid.WorldToGridInteger(projectedBlock.CubeGrid.GridIntegerToWorld(projectedBlock.Position));

            Vector3I min = new Vector3I(Math.Min(projectedMin.X, projectedMax.X), Math.Min(projectedMin.Y, projectedMax.Y), Math.Min(projectedMin.Z, projectedMax.Z));
            Vector3I max = new Vector3I(Math.Max(projectedMin.X, projectedMax.X), Math.Max(projectedMin.Y, projectedMax.Y), Math.Max(projectedMin.Z, projectedMax.Z));

            projectedMin = min;
            projectedMax = max;

            if (!CubeGrid.CanAddCubes(projectedMin, projectedMax))
            {
                return BuildCheckResult.IntersectedWithGrid;
            }

            MyGridPlacementSettings settings = new MyGridPlacementSettings();
            settings.Mode = MyGridPlacementSettings.SnapMode.OneFreeAxis;

            bool canBuild = true;
            if (checkHavokIntersections)
            {
                canBuild = MyCubeGrid.TestPlacementAreaCube(CubeGrid, ref settings, projectedMin, projectedMax, blockOrientation, projectedBlock.BlockDefinition, CubeGrid);
            }

            bool isConnected = MyCubeGrid.CheckConnectivity(this.CubeGrid, projectedBlock.BlockDefinition, ref blockOrientationQuat, ref blockPos);

            if (!canBuild)
            {
                return BuildCheckResult.IntersectedWithSomethingElse;
            }
            else
            {
                if (isConnected)
                {
                    if (CubeGrid.GetCubeBlock(blockPos) == null)
                    {
                        return BuildCheckResult.OK;
                    }
                    else
                    {
                        return BuildCheckResult.AlreadyBuilt;
                    }
                }
            }

            return BuildCheckResult.NotConnected;
        }
开发者ID:caomw,项目名称:SpaceEngineers,代码行数:67,代码来源:MyProjector.cs


示例19: TestGridPlacement

        private static void TestGridPlacement(ref MyGridPlacementSettings settings, ref MatrixD worldMatrix, ref MyCubeGrid touchingGrid, float gridSize, bool isStatic, ref BoundingBoxD localAABB, MyCubeBlockDefinition blockDefinition,
           MyBlockOrientation? blockOrientation, ref bool entityOverlap, ref bool touchingStaticGrid, MyCubeGrid grid)
        {
            var worldAabb = localAABB.Transform(ref worldMatrix);
            var invWorldMatrix = grid.PositionComp.WorldMatrixNormalizedInv;
            var otherLocalAabb = worldAabb.Transform(ref invWorldMatrix);

            Vector3D minToWorld = Vector3D.Transform(localAABB.Min, worldMatrix);
            Vector3D maxToWorld = Vector3D.Transform(localAABB.Max, worldMatrix);
            Vector3D tempMinLocal = Vector3D.Transform(minToWorld, invWorldMatrix);
            Vector3D tempMaxLocal = Vector3D.Transform(maxToWorld, invWorldMatrix);

            Vector3D otherMinLocal = Vector3D.Min(tempMinLocal, tempMaxLocal);
            Vector3D otherMaxLocal = Vector3D.Max(tempMinLocal, tempMaxLocal);

            var scaledMin = (otherMinLocal + gridSize / 2) / grid.GridSize;
            var scaledMax = (otherMaxLocal - gridSize / 2) / grid.GridSize;
            var tempMin = Vector3I.Round(scaledMin);
            var tempMax = Vector3I.Round(scaledMax);
            var min = Vector3I.Min(tempMin, tempMax);
            var max = Vector3I.Max(tempMin, tempMax);

            MyBlockOrientation? gridBlockOrientation = null;
            if (MyFakes.ENABLE_COMPOUND_BLOCKS && isStatic && grid.IsStatic && blockOrientation != null)
            {
                Matrix blockRotation;
                blockOrientation.Value.GetMatrix(out blockRotation);
                Matrix rotationInGrid = blockRotation * worldMatrix;
                rotationInGrid = rotationInGrid * invWorldMatrix;
                rotationInGrid.Translation = Vector3.Zero;

                Base6Directions.Direction forwardDir = Base6Directions.GetForward(ref rotationInGrid);
           

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Cube.MySlimBlock类代码示例发布时间:2022-05-26
下一篇:
C# Character.MyCharacter类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap