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); } }
public BuildCheckResult CanBuild(MySlimBlock projectedBlock, bool checkHavokIntersections) { MyBlockOrientation blockOrientation = projectedBlock.Orientation; //GR: For rotation take into account: //the projected block orientation Quaternion blockOrientationQuat; blockOrientation.GetQuaternion(out blockOrientationQuat); //GR: The projector block orientation (which is relative to the Cubegrid orientation) Quaternion projQuat = Quaternion.Identity; Orientation.GetQuaternion(out projQuat); blockOrientationQuat = Quaternion.Multiply(projQuat, blockOrientationQuat); //GR: The orienation settings of the projector //Take into account order of multiplication to review! blockOrientationQuat = Quaternion.Multiply(ProjectionRotationQuaternion, 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.SnapMode = 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); } }