Пример #1
0
        public static bool CanAddBlocks(MyCubeBlockDefinition definition, MyBlockOrientation orientation, MyCubeBlockDefinition otherDefinition, MyBlockOrientation otherOrientation)
        {
            Debug.Assert(MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES);

            if (!IsCompoundEnabled(definition) || !IsCompoundEnabled(otherDefinition))
            {
                return(false);
            }

            if (MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES)
            {
                Matrix thisRotation;
                orientation.GetMatrix(out thisRotation);

                m_tmpDummies.Clear();
                GetCompoundCollisionDummies(definition, m_tmpDummies);

                Matrix otherRotation;
                otherOrientation.GetMatrix(out otherRotation);

                m_tmpOtherDummies.Clear();
                GetCompoundCollisionDummies(otherDefinition, m_tmpOtherDummies);

                bool intersect = CompoundDummiesIntersect(ref thisRotation, ref otherRotation, m_tmpDummies, m_tmpOtherDummies);
                m_tmpDummies.Clear();
                m_tmpOtherDummies.Clear();
                return(!intersect);
            }

            // Note that this part (compound templates) is not implemented, because it will not be used in future (only dummies).
            return(true);
        }
Пример #2
0
        public static bool CanAddBlocks(MyCubeBlockDefinition definition, MyBlockOrientation orientation, MyCubeBlockDefinition otherDefinition, MyBlockOrientation otherOrientation)
        {
            Matrix matrix;
            Matrix matrix2;

            if (!IsCompoundEnabled(definition) || !IsCompoundEnabled(otherDefinition))
            {
                return(false);
            }
            if (!MyFakes.ENABLE_COMPOUND_BLOCK_COLLISION_DUMMIES)
            {
                return(true);
            }
            orientation.GetMatrix(out matrix);
            m_tmpDummies.Clear();
            GetCompoundCollisionDummies(definition, m_tmpDummies);
            otherOrientation.GetMatrix(out matrix2);
            m_tmpOtherDummies.Clear();
            GetCompoundCollisionDummies(otherDefinition, m_tmpOtherDummies);
            m_tmpDummies.Clear();
            m_tmpOtherDummies.Clear();
            return(!CompoundDummiesIntersect(ref matrix, ref matrix2, m_tmpDummies, m_tmpOtherDummies));
        }
        private bool CanBuildBlock(MyObjectBuilder_CubeBlock block, MyCubeGrid blockGrid, MyCubeBlock projector, MyCubeGrid projectorGrid, MyObjectBuilder_ProjectorBase projectorBuilder)
        {
            MyBlockOrientation blockOrientation = block.BlockOrientation;

            Matrix local;

            blockOrientation.GetMatrix(out local);
            var gridOrientation = GetGridOrientation(projectorBuilder);

            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;

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

            MyCubeBlockDefinition blockDefinition;

            MyDefinitionManager.Static.TryGetCubeBlockDefinition(block.GetId(), out blockDefinition);

            // Get real block max
            Vector3I blockMax = Vector3I.Zero;
            Vector3I blockMin = block.Min;

            ComputeMax(blockDefinition, block.BlockOrientation, ref blockMin, out blockMax);
            var position = ComputePositionInGrid(new MatrixI(block.BlockOrientation), blockDefinition, blockMin);

            Vector3I projectedMin = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(block.Min));
            Vector3I projectedMax = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(blockMax));
            Vector3I blockPos     = projectorGrid.WorldToGridInteger(blockGrid.GridIntegerToWorld(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 (!projectorGrid.CanAddCubes(projectedMin, projectedMax))
            {
                IMySlimBlock slimBlock = (IMySlimBlock)blockGrid.GetCubeBlock(block.Min);
                if (slimBlock == null || slimBlock.FatBlock == null)
                {
                    return(false);
                }

                Logging.Instance.WriteLine(string.Format("Can not add block: {0}: {1} - {2} {3} {4} {5}", slimBlock.FatBlock.EntityId, blockDefinition.Id, projectedMin, projectedMax, blockMin, blockMax)); //, slimBlock.FatBlock.EntityId));
                return(false);
            }

            var  mountPoints = blockDefinition.GetBuildProgressModelMountPoints(1.0f);
            bool isConnected = MyCubeGrid.CheckConnectivity(projectorGrid, blockDefinition, mountPoints, ref blockOrientationQuat, ref blockPos);

            if (isConnected)
            {
                if (projectorGrid.GetCubeBlock(blockPos) == null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Пример #4
0
        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;

            var  mountPoints = projectedBlock.BlockDefinition.GetBuildProgressModelMountPoints(1.0f);
            bool isConnected = MyCubeGrid.CheckConnectivity(this.CubeGrid, projectedBlock.BlockDefinition, mountPoints,
                                                            ref blockOrientationQuat, ref blockPos);

            if (isConnected)
            {
                if (CubeGrid.GetCubeBlock(blockPos) == null)
                {
                    if (checkHavokIntersections)
                    {
                        if (MyCubeGrid.TestPlacementAreaCube(CubeGrid, ref settings, projectedMin, projectedMax, blockOrientation, projectedBlock.BlockDefinition, CubeGrid))
                        {
                            return(BuildCheckResult.OK);
                        }
                        else
                        {
                            return(BuildCheckResult.IntersectedWithSomethingElse);
                        }
                    }
                    else
                    {
                        return(BuildCheckResult.OK);
                    }
                }
                else
                {
                    return(BuildCheckResult.AlreadyBuilt);
                }
            }
            else
            {
                return(BuildCheckResult.NotConnected);
            }
        }