private void DebugDrawOBB(MyOrientedBoundingBox obb, Matrix localMatrix) { Matrix matrix = (Matrix.CreateFromTransformScale(obb.Orientation, obb.Center, (Vector3)(2f * obb.HalfExtent)) * localMatrix) * base.PositionComp.WorldMatrix; MyRenderProxy.DebugDrawAxis(MatrixD.Normalize(matrix), 0.1f, false, false, false); MyRenderProxy.DebugDrawOBB(matrix, Vector3.One, 0.1f, false, false, true, false); }
private void CreateHalfExtents() { _oldGridHalfExtents = DsState.State.GridHalfExtents; var myAabb = MyGrid.PositionComp.LocalAABB; var shieldGrid = MyGrid; var expandedAabb = myAabb; if (ShieldComp.GetSubGrids.Count > 1) { foreach (var grid in ShieldComp.GetSubGrids) { if (grid == null || grid == shieldGrid) { continue; } var shieldMatrix = shieldGrid.PositionComp.WorldMatrixNormalizedInv; var gQuaternion = Quaternion.CreateFromRotationMatrix(grid.WorldMatrix); var gOriBBoxD = new MyOrientedBoundingBox(grid.PositionComp.WorldAABB.Center, grid.PositionComp.LocalAABB.HalfExtents, gQuaternion); gOriBBoxD.Transform(shieldMatrix); expandedAabb.Include(gOriBBoxD.GetAABB()); } } if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) { var extend = DsSet.Settings.ExtendFit ? 2 : 1; var fortify = DsSet.Settings.FortifyShield ? 3 : 1; var size = expandedAabb.HalfExtents.Max() * fortify; var scaler = 4; if (shieldGrid.GridSizeEnum == MyCubeSize.Small && !DsSet.Settings.ExtendFit) { scaler = 5; } var vectorSize = new Vector3D(size, size, size); var fudge = shieldGrid.GridSize * scaler * extend; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - vectorSize.LengthSquared(); if (extentsDiff < -1 || extentsDiff > 1 || DsState.State.GridHalfExtents == Vector3D.Zero || !fudge.Equals(DsState.State.ShieldFudge)) { DsState.State.GridHalfExtents = vectorSize; } DsState.State.ShieldFudge = fudge; } else { var blockHalfSize = MyGrid.GridSize * 0.5; DsState.State.ShieldFudge = 0f; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - expandedAabb.HalfExtents.LengthSquared(); var overThreshold = extentsDiff <-blockHalfSize || extentsDiff> blockHalfSize; if (overThreshold || DsState.State.GridHalfExtents == Vector3D.Zero) { DsState.State.GridHalfExtents = expandedAabb.HalfExtents; } } _halfExtentsChanged = !DsState.State.GridHalfExtents.Equals(_oldGridHalfExtents); if (_halfExtentsChanged) { _adjustShape = true; } }
public override bool IsPositionInRange(Vector3D worldPoint) { Vector3 halfExtents = m_fieldSize.Value * 0.5f; MyOrientedBoundingBox obb = new MyOrientedBoundingBox((Vector3)WorldMatrix.Translation, halfExtents, Quaternion.CreateFromRotationMatrix(WorldMatrix)); Vector3 conv = (Vector3)worldPoint; return(obb.Contains(ref conv)); }
private static bool CompoundDummiesIntersect(ref Matrix thisRotation, ref Matrix otherRotation, List <MyModelDummy> thisDummies, List <MyModelDummy> otherDummies) { using (List <MyModelDummy> .Enumerator enumerator = thisDummies.GetEnumerator()) { bool flag; while (true) { if (enumerator.MoveNext()) { Matrix matrix2; MyModelDummy current = enumerator.Current; Vector3 forward = current.Matrix.Forward; Vector3 max = new Vector3(current.Matrix.Right.Length(), current.Matrix.Up.Length(), forward.Length()) * 0.5f; BoundingBox box = new BoundingBox(-max, max); Matrix matrix = Matrix.Normalize(current.Matrix); Matrix.Multiply(ref matrix, ref thisRotation, out matrix2); Matrix.Invert(ref matrix2, out matrix); List <MyModelDummy> .Enumerator enumerator2 = otherDummies.GetEnumerator(); try { while (true) { Matrix matrix4; if (!enumerator2.MoveNext()) { break; } MyModelDummy dummy2 = enumerator2.Current; forward = dummy2.Matrix.Forward; Vector3 vector3 = new Vector3(dummy2.Matrix.Right.Length(), dummy2.Matrix.Up.Length(), forward.Length()) * 0.5f; Matrix matrix3 = Matrix.Normalize(dummy2.Matrix); Matrix.Multiply(ref matrix3, ref otherRotation, out matrix4); Matrix.Multiply(ref matrix4, ref matrix, out matrix3); MyOrientedBoundingBox box2 = MyOrientedBoundingBox.Create(new BoundingBox(-vector3, vector3), matrix3); if (box2.Intersects(ref box)) { return(true); } } continue; } finally { enumerator2.Dispose(); continue; } } else { goto TR_0000; } break; } return(flag); } TR_0000: return(false); }
private void DebugDrawOBB(MyOrientedBoundingBox obb, Matrix localMatrix) { Matrix obbTransform = Matrix.CreateFromTransformScale(obb.Orientation, obb.Center, 2 * obb.HalfExtent); MatrixD worldMatrix = obbTransform * (MatrixD)localMatrix; worldMatrix *= PositionComp.WorldMatrix; VRageRender.MyRenderProxy.DebugDrawAxis(MatrixD.Normalize(worldMatrix), 0.1f, false); VRageRender.MyRenderProxy.DebugDrawOBB(worldMatrix, Vector3.One, 0.1f, false, false); }
public override void DoWork() { MyBoxSensorElement seBoxElement = (MyBoxSensorElement)m_SensorElement; Matrix seBoxMatrix = seBoxElement.GetGlobalTransformation(); BoundingBox oeAABB = m_RBElement.GetWorldSpaceAABB(); BoundingBox seBB = new BoundingBox(-seBoxElement.Extent, seBoxElement.Extent); MyOrientedBoundingBox seBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(seBB).Transform(seBoxMatrix); m_IsInside = seBoxOriented.Intersects(ref oeAABB); }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); MyOrientedBoundingBox bbox = new MyOrientedBoundingBox(Center, m_halfExtents, m_orientation); var aabb = bbox.GetAABB(); var res = MyEntities.GetEntitiesInAABB(ref aabb); for (int i = 0; i < res.Count; ++i) { var rootEntity = res[i].GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, FrontPoint); } res.Clear(); }
public override void DoWork() { MyRBBoxElement rbBoxElement = (MyRBBoxElement)m_RBElement; MyBoxSensorElement seBoxElement = (MyBoxSensorElement)m_SensorElement; Matrix rbBoxMatrix = rbBoxElement.GetGlobalTransformation(); Matrix seBoxMatrix = seBoxElement.GetGlobalTransformation(); BoundingBox rbBB = new BoundingBox(-rbBoxElement.Size / 2f, rbBoxElement.Size / 2f); BoundingBox seBB = new BoundingBox(-seBoxElement.Extent, seBoxElement.Extent); MyOrientedBoundingBox rbBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(rbBB).Transform(rbBoxMatrix); MyOrientedBoundingBox seBoxOriented = MyOrientedBoundingBox.CreateFromBoundingBox(seBB).Transform(seBoxMatrix); m_IsInside = rbBoxOriented.Intersects(ref seBoxOriented); }
private static bool CompoundDummiesIntersect(ref Matrix thisRotation, ref Matrix otherRotation, List <MyModelDummy> thisDummies, List <MyModelDummy> otherDummies) { foreach (var dummy in thisDummies) { //TODO: thisBoxHalfExtends should be dummy.Matrix.Scale * 0.5 but Scale in Matrix is bad. Vector3 thisBoxHalfExtends = new Vector3(dummy.Matrix.Right.Length(), dummy.Matrix.Up.Length(), dummy.Matrix.Forward.Length()) * 0.5f; BoundingBox thisAABB = new BoundingBox(-thisBoxHalfExtends, thisBoxHalfExtends); // Normalize this dummy, use inverse matrix as temporary. Matrix thisDummyMatrixInv = Matrix.Normalize(dummy.Matrix); // Rotate this dummy Matrix thisDummyMatrix; Matrix.Multiply(ref thisDummyMatrixInv, ref thisRotation, out thisDummyMatrix); // Create trasform to this dummy (inverse). Matrix.Invert(ref thisDummyMatrix, out thisDummyMatrixInv); //DebugDrawAABB(thisAABB, thisDummyMatrix); foreach (var otherDummy in otherDummies) { //TODO: otherBoxHalfExtends should be otherDummy.Matrix.Scale * 0.5 but Scale in Matrix is bad. Vector3 otherBoxHalfExtends = new Vector3(otherDummy.Matrix.Right.Length(), otherDummy.Matrix.Up.Length(), otherDummy.Matrix.Forward.Length()) * 0.5f; BoundingBox otherAABB = new BoundingBox(-otherBoxHalfExtends, otherBoxHalfExtends); // Store normalized dummy matrix as temporary Matrix otherDummyMatrixInThis = Matrix.Normalize(otherDummy.Matrix); // Rotate other dummy Matrix otherDummyMatrix; Matrix.Multiply(ref otherDummyMatrixInThis, ref otherRotation, out otherDummyMatrix); // Transform other dummy to this dummy Matrix.Multiply(ref otherDummyMatrix, ref thisDummyMatrixInv, out otherDummyMatrixInThis); MyOrientedBoundingBox obb = MyOrientedBoundingBox.Create(otherAABB, otherDummyMatrixInThis); //DebugDrawOBB(obb, thisDummyMatrix); if (obb.Intersects(ref thisAABB)) { return(true); } } } return(false); }
protected override void ReadEntitiesInRange() { m_entitiesInRange.Clear(); MyOrientedBoundingBox bbox = new MyOrientedBoundingBox(Center, m_halfExtents, m_orientation); var aabb = bbox.GetAABB(); var res = MyEntities.GetEntitiesInAABB(ref aabb); for (int i = 0; i < res.Count; ++i) { var rootEntity = res[i].GetTopMostParent(); if (!IgnoredEntities.Contains(rootEntity)) { m_entitiesInRange[rootEntity.EntityId] = new DetectionInfo(rootEntity, FrontPoint); } } res.Clear(); }
private void GetEnlargedBoundingBoxes(out MyOrientedBoundingBox largerOBB, out BoundingBox largerAABBHr) { // compute larger OBB var obb = MyOrientedBoundingBox.CreateFromBoundingBox(GetModelLod0().BoundingBox).Transform(WorldMatrix); var averageHalfExtent = (obb.HalfExtent.X + obb.HalfExtent.Y + obb.HalfExtent.Z) / 3f; float explosionDeleteMultiplier = MathHelper.Clamp(MyPrefabConstants.EXPLOSION_DELETE_MULTIPLIER_BY_SIZE * averageHalfExtent, 1.0f, 1.6f); var obbHalfExtentIncrease = obb.HalfExtent * explosionDeleteMultiplier; var obbHalfExtentIncreaseClamped = Vector3.Clamp(obbHalfExtentIncrease, MyPrefabConstants.MIN_SIZE_INCREASE_FOR_EXPLOSION, obbHalfExtentIncrease); largerOBB = obb; largerOBB.HalfExtent += obbHalfExtentIncreaseClamped; // compute larger AABB var minToMax = WorldAABBHr.Max - WorldAABBHr.Min; minToMax *= explosionDeleteMultiplier; minToMax += MyPrefabConstants.MIN_SIZE_INCREASE_FOR_EXPLOSION; largerAABBHr = new BoundingBox(WorldAABBHr.Min - minToMax, WorldAABBHr.Max + minToMax); }
public void CalculateRotationHints(MatrixD drawMatrix, BoundingBoxD worldBox, bool draw, bool fixedAxes = false, bool hideForwardAndUpArrows = false) { drawMatrix.Translation = Vector3D.Zero; MatrixD drawInverse = MatrixD.Invert(drawMatrix); drawInverse *= drawMatrix.GetOrientation(); drawInverse *= MySector.MainCamera.ViewMatrixAtZero; MatrixD camWorld = MatrixD.Invert(drawInverse); m_viewProjection.ViewAtZero = MatrixD.CreateLookAt(Vector3D.Zero, camWorld.Forward, camWorld.Up); m_viewProjection.ViewAtZero.Translation = new Vector3D(0, 0, -6); m_viewProjection.View = drawInverse; m_viewProjection.View.Translation += new Vector3D(0, 0, -10); m_viewProjection.CameraPosition = camWorld.Translation; Vector2 screenSize = MyGuiManager.GetScreenSizeFromNormalizedSize(Vector2.One); float previewRatio = 2.5f; int hintsWidth = (int)(screenSize.X / previewRatio), hintsHeight = (int)(screenSize.Y / previewRatio), hintsXOffset = 0, hintsYOffset = 0; m_viewProjection.Viewport = new MyViewport( (int)MySector.MainCamera.Viewport.Width - hintsWidth - hintsXOffset, hintsYOffset, hintsWidth, hintsHeight); m_viewProjection.DepthRead = false; m_viewProjection.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)hintsHeight / hintsWidth, 0.1f, 10); worldBox = new BoundingBoxD(-new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large) * 0.5f), new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large)) * 0.5f); //m_rotationHintsViewProjection.Projection = MySector.MainCamera.ProjectionMatrix; int projectionId = 0; VRageRender.MyRenderProxy.AddBillboardViewProjection(projectionId, m_viewProjection); //MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, // ref worldBox, ref Vector4.One, MySimpleObjectRasterizer.Wireframe, 1, 0.04f, null, null, false, 0); if (draw) { var white = Color.White; MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref worldBox, ref white, MySimpleObjectRasterizer.Solid, 1, 0.04f, "SquareFullColor", null, false, projectionId, 100); } MyOrientedBoundingBoxD rotateHintsBox = new MyOrientedBoundingBoxD(Vector3D.Transform(worldBox.Center, drawMatrix), worldBox.HalfExtents, Quaternion.CreateFromRotationMatrix(drawMatrix)); //VRageRender.MyRenderProxy.DebugDrawOBB(rotateHintsBox, Vector3.One, 1, false, false); rotateHintsBox.GetCorners(m_cubeVertices, 0); //for (int vi = 0; vi < 8; vi++) //{ // VRageRender.MyRenderProxy.DebugDrawText3D(m_cubeVertices[vi], vi.ToString(), Color.White, 0.7f, false); //} //for (int vi = 0; vi < 4; vi++) //{ // VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartXVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndXVertices[vi]]) * 0.5f, vi.ToString(), Color.Red, 0.7f, false); // VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartYVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndYVertices[vi]]) * 0.5f, vi.ToString(), Color.Green, 0.7f, false); // VRageRender.MyRenderProxy.DebugDrawText3D((m_cubeVertices[MyOrientedBoundingBox.StartZVertices[vi]] + m_cubeVertices[MyOrientedBoundingBox.EndZVertices[vi]]) * 0.5f, vi.ToString(), Color.Blue, 0.7f, false); //} int closestXAxis, closestXAxis2; GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartXVertices, MyOrientedBoundingBox.EndXVertices, out closestXAxis, out closestXAxis2); Vector3D startXVertex = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis]]; Vector3D endXVertex = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis]]; Vector3D startXVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartXVertices[closestXAxis2]]; Vector3D endXVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndXVertices[closestXAxis2]]; int closestYAxis, closestYAxis2; GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartYVertices, MyOrientedBoundingBox.EndYVertices, out closestYAxis, out closestYAxis2); Vector3D startYVertex = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis]]; Vector3D endYVertex = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis]]; Vector3D startYVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartYVertices[closestYAxis2]]; Vector3D endYVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndYVertices[closestYAxis2]]; int closestZAxis, closestZAxis2; GetClosestCubeEdge(m_cubeVertices, MyOrientedBoundingBox.StartZVertices, MyOrientedBoundingBox.EndZVertices, out closestZAxis, out closestZAxis2); Vector3D startZVertex = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis]]; Vector3D endZVertex = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis]]; Vector3D startZVertex2 = m_cubeVertices[MyOrientedBoundingBox.StartZVertices[closestZAxis2]]; Vector3D endZVertex2 = m_cubeVertices[MyOrientedBoundingBox.EndZVertices[closestZAxis2]]; m_cubeEdges.Clear(); m_cubeEdges.Add(new BoxEdge() { Axis = 0, Edge = new LineD(startXVertex, endXVertex) }); m_cubeEdges.Add(new BoxEdge() { Axis = 1, Edge = new LineD(startYVertex, endYVertex) }); m_cubeEdges.Add(new BoxEdge() { Axis = 2, Edge = new LineD(startZVertex, endZVertex) }); if (!fixedAxes) { int rotDirection; RotationRightAxis = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Right, out rotDirection); RotationRightDirection = rotDirection; RotationUpAxis = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Up, out rotDirection); RotationUpDirection = rotDirection; RotationForwardAxis = GetBestAxis(m_cubeEdges, MySector.MainCamera.WorldMatrix.Forward, out rotDirection); RotationForwardDirection = rotDirection; } string rightControlName1 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); string rightControlName2 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); string upControlName1 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); string upControlName2 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); string forwControlName1 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); string forwControlName2 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard).ToString(); if (MyInput.Static.IsJoystickConnected()) { rightControlName1 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).ToString(); rightControlName2 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).ToString(); upControlName1 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).ToString(); upControlName2 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).ToString(); forwControlName1 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).ToString(); forwControlName2 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).ToString(); } Vector3D rightStart = Vector3D.Zero; Vector3D rightEnd = Vector3D.Zero; Vector3D upStart = Vector3D.Zero; Vector3D upEnd = Vector3D.Zero; Vector3D forwStart = Vector3D.Zero; Vector3D forwEnd = Vector3D.Zero; Vector3D rightStart2 = Vector3D.Zero; Vector3D rightEnd2 = Vector3D.Zero; Vector3D upStart2 = Vector3D.Zero; Vector3D upEnd2 = Vector3D.Zero; Vector3D forwStart2 = Vector3D.Zero; Vector3D forwEnd2 = Vector3D.Zero; int rightAxis = -1, upAxis = -1, forwAxis = -1; int closestRightEdge = -1, closestUpEdge = -1, closestForwEdge = -1; int closestRightEdge2 = -1, closestUpEdge2 = -1, closestForwEdge2 = -1; if (RotationRightAxis == 0) { rightStart = startXVertex; rightEnd = endXVertex; rightStart2 = startXVertex2; rightEnd2 = endXVertex2; rightAxis = 0; closestRightEdge = closestXAxis; closestRightEdge2 = closestXAxis2; } else if (RotationRightAxis == 1) { rightStart = startYVertex; rightEnd = endYVertex; rightStart2 = startYVertex2; rightEnd2 = endYVertex2; rightAxis = 1; closestRightEdge = closestYAxis; closestRightEdge2 = closestYAxis2; } else if (RotationRightAxis == 2) { rightStart = startZVertex; rightEnd = endZVertex; rightStart2 = startZVertex2; rightEnd2 = endZVertex2; rightAxis = 2; closestRightEdge = closestZAxis; closestRightEdge2 = closestZAxis2; } else { System.Diagnostics.Debug.Assert(false, "Not defined axis"); } if (RotationUpAxis == 0) { upStart = startXVertex; upEnd = endXVertex; upStart2 = startXVertex2; upEnd2 = endXVertex2; upAxis = 0; closestUpEdge = closestXAxis; closestUpEdge2 = closestXAxis2; } else if (RotationUpAxis == 1) { upStart = startYVertex; upEnd = endYVertex; upStart2 = startYVertex2; upEnd2 = endYVertex2; upAxis = 1; closestUpEdge = closestYAxis; closestUpEdge2 = closestYAxis2; } else if (RotationUpAxis == 2) { upStart = startZVertex; upEnd = endZVertex; upStart2 = startZVertex2; upEnd2 = endZVertex2; upAxis = 2; closestUpEdge = closestZAxis; closestUpEdge2 = closestZAxis2; } if (RotationForwardAxis == 0) { forwStart = startXVertex; forwEnd = endXVertex; forwStart2 = startXVertex2; forwEnd2 = endXVertex2; forwAxis = 0; closestForwEdge = closestXAxis; closestForwEdge2 = closestXAxis2; } else if (RotationForwardAxis == 1) { forwStart = startYVertex; forwEnd = endYVertex; forwStart2 = startYVertex2; forwEnd2 = endYVertex2; forwAxis = 1; closestForwEdge = closestYAxis; closestForwEdge2 = closestYAxis2; } else if (RotationForwardAxis == 2) { forwStart = startZVertex; forwEnd = endZVertex; forwStart2 = startZVertex2; forwEnd2 = endZVertex2; forwAxis = 2; closestForwEdge = closestZAxis; closestForwEdge2 = closestZAxis2; } float textScale = 0.7f; //Closest axis //VRageRender.MyRenderProxy.DebugDrawLine3D(rightStart, rightEnd, Color.Red, Color.Red, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(upStart, upEnd, Color.Green, Color.Green, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(forwStart, forwEnd, Color.Blue, Color.Blue, false); if (draw) { //if all axis are visible, all are shown on edges //if 1 axis is not visible, other 2 must be shown on faces //if 2 are not visible, they are shown on faces and the one is shown on face center //Vector3 camVector = Vector3.Normalize(rotateHintsBox.Center - MySector.MainCamera.Position); Vector3D camVector = MySector.MainCamera.ForwardVector; Vector3D rightDirection = Vector3.Normalize(rightEnd - rightStart); Vector3D upDirection = Vector3.Normalize(upEnd - upStart); Vector3D forwDirection = Vector3.Normalize(forwEnd - forwStart); float dotRight = Math.Abs(Vector3.Dot(camVector, rightDirection)); float dotUp = Math.Abs(Vector3.Dot(camVector, upDirection)); float dotForw = Math.Abs(Vector3.Dot(camVector, forwDirection)); bool drawRightOnFace = false, drawUpOnFace = false, drawForwOnFace = false; bool drawRightOnFaceCenter = false, drawUpOnFaceCenter = false, drawForwOnFaceCenter = false; float dotAngle = 0.4f; if (dotRight < dotAngle) { if (dotUp < dotAngle) { drawForwOnFaceCenter = true; drawRightOnFace = true; drawUpOnFace = true; System.Diagnostics.Debug.Assert(dotForw >= dotAngle); } else if (dotForw < dotAngle) { drawUpOnFaceCenter = true; drawRightOnFace = true; drawForwOnFace = true; System.Diagnostics.Debug.Assert(dotUp >= dotAngle); } else { drawUpOnFace = true; drawForwOnFace = true; } } else if (dotUp < dotAngle) { if (dotRight < dotAngle) { drawForwOnFaceCenter = true; drawRightOnFace = true; drawUpOnFace = true; System.Diagnostics.Debug.Assert(dotForw >= dotAngle); } else if (dotForw < dotAngle) { drawRightOnFaceCenter = true; drawUpOnFace = true; drawForwOnFace = true; System.Diagnostics.Debug.Assert(dotRight >= dotAngle); } else { drawRightOnFace = true; drawForwOnFace = true; } } else if (dotForw < dotAngle) { if (dotRight < dotAngle) { drawUpOnFaceCenter = true; drawRightOnFace = true; drawForwOnFace = true; System.Diagnostics.Debug.Assert(dotUp >= dotAngle); } else if (dotUp < dotAngle) { drawUpOnFaceCenter = true; drawRightOnFace = true; drawForwOnFace = true; System.Diagnostics.Debug.Assert(dotRight >= dotAngle); } else { drawUpOnFace = true; drawRightOnFace = true; } } //Draw according to cube visual appearance if (!(hideForwardAndUpArrows && RotationRightAxis != 1)) { if (drawRightOnFaceCenter) { // VRageRender.MyRenderProxy.DebugDrawSphere((forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f, 0.2f, Vector3.Right, 1.0f, false, false); Vector3D faceCenter = (forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f; MyTransparentGeometry.AddBillboardOriented( "ArrowLeftGreen", Vector4.One, faceCenter - RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, -RotationForwardDirection * forwDirection, -RotationUpDirection * upDirection, 0.2f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowRightGreen", Vector4.One, faceCenter + RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, RotationForwardDirection * forwDirection, RotationUpDirection * upDirection, 0.2f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationForwardDirection * forwDirection * 0.2f - RotationRightDirection * rightDirection * 0.01f, rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } else if (drawRightOnFace) { //VRageRender.MyRenderProxy.DebugDrawLine3D(rightStart2, rightEnd2, Color.Red, Color.Red, false); Vector3 normalRightBack, normalRightForw; MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge2, out normalRightForw); Vector3D rightCenter = (rightStart + rightEnd) * 0.5f; Vector3D rightNormalForwWorld = Vector3D.TransformNormal(normalRightForw, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge2, closestRightEdge, out normalRightBack); Vector3D rightCenter2 = (rightStart2 + rightEnd2) * 0.5f; Vector3D rightNormalBackWorld = Vector3D.TransformNormal(normalRightBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalForwWorld, Color.Red, Color.Red, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter2, rightCenter2 + rightNormalBackWorld, Color.Red, Color.Red, false); int normalEdge = -1; bool opposite = false; if (closestRightEdge == 0 && closestRightEdge2 == 3) { normalEdge = closestRightEdge + 1; } else if ((closestRightEdge < closestRightEdge2) || (closestRightEdge == 3 && closestRightEdge2 == 0)) { normalEdge = closestRightEdge - 1; opposite = true; } else { normalEdge = closestRightEdge + 1; } if (RotationRightDirection < 0) { opposite = !opposite; } Vector3 rightOffset; MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, normalEdge, out rightOffset); Vector3D rightOffsetWorld = Vector3D.TransformNormal(rightOffset, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.6f - rightOffsetWorld * 0.01f, opposite ? rightControlName2 : rightControlName1, Color.White, textScale, false); //VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter2 + rightNormalBackWorld * 0.6f - rightOffsetWorld * 0.01f, opposite ? rightControlName1 : rightControlName2, Color.White, textScale, false); MyTransparentGeometry.AddBillboardOriented( "ArrowGreen", Vector4.One, rightCenter + rightNormalForwWorld * 0.4f - rightOffsetWorld * 0.01f, rightNormalBackWorld, rightDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowGreen", Vector4.One, rightCenter2 + rightNormalBackWorld * 0.4f - rightOffsetWorld * 0.01f, rightNormalForwWorld, rightDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.3f - rightOffsetWorld * 0.01f, opposite ? rightControlName1 : rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter2 + rightNormalBackWorld * 0.3f - rightOffsetWorld * 0.01f, opposite ? rightControlName2 : rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } else //draw on edge { Vector3 normalRightBack, normalRightForw; MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge + 1, out normalRightForw); MyOrientedBoundingBox.GetNormalBetweenEdges(rightAxis, closestRightEdge, closestRightEdge - 1, out normalRightBack); Vector3D rightCenter = (rightStart + rightEnd) * 0.5f; Vector3D rightNormalForwWorld = Vector3D.TransformNormal(normalRightForw, drawMatrix); Vector3D rightNormalBackWorld = Vector3D.TransformNormal(normalRightBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalForwWorld, Color.Red, Color.Red, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(rightCenter, rightCenter + rightNormalBackWorld, Color.Red, Color.Red, false); MyTransparentGeometry.AddBillboardOriented( "ArrowGreen", Vector4.One, rightCenter + rightNormalForwWorld * 0.3f - rightNormalBackWorld * 0.01f, rightNormalForwWorld, rightDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowGreen", Vector4.One, rightCenter + rightNormalBackWorld * 0.3f - rightNormalForwWorld * 0.01f, rightNormalBackWorld, rightDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalForwWorld * 0.3f - rightNormalBackWorld * 0.01f, RotationRightDirection < 0 ? rightControlName1 : rightControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(rightCenter + rightNormalBackWorld * 0.3f - rightNormalForwWorld * 0.01f, RotationRightDirection < 0 ? rightControlName2 : rightControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } } if (!(hideForwardAndUpArrows && RotationUpAxis != 1)) { if (drawUpOnFaceCenter) { //VRageRender.MyRenderProxy.DebugDrawSphere((forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f, 0.2f, Vector3.Up, 1.0f, false, false); Vector3D faceCenter = (forwStart + forwEnd + forwStart2 + forwEnd2) * 0.25f; MyTransparentGeometry.AddBillboardOriented( "ArrowLeftRed", Vector4.One, faceCenter - RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, -RotationRightDirection * rightDirection, -RotationForwardDirection * forwDirection, 0.2f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowRightRed", Vector4.One, faceCenter + RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, RotationRightDirection * rightDirection, RotationForwardDirection * forwDirection, 0.2f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationRightDirection * rightDirection * 0.2f - RotationUpDirection * upDirection * 0.01f, upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } else if (drawUpOnFace) { //VRageRender.MyRenderProxy.DebugDrawLine3D(upStart2, upEnd2, Color.Green, Color.Green, false); Vector3 normalUpBack, normalUpForw; MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge2, out normalUpForw); Vector3D upCenter = (upStart + upEnd) * 0.5f; Vector3 upNormalForwWorld = Vector3.TransformNormal(normalUpForw, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge2, closestUpEdge, out normalUpBack); Vector3D upCenter2 = (upStart2 + upEnd2) * 0.5f; Vector3 upNormalBackWorld = Vector3.TransformNormal(normalUpBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalForwWorld, Color.Green, Color.Green, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter2, upCenter2 + upNormalBackWorld, Color.Green, Color.Green, false); int normalEdge = -1; bool opposite = false; if (closestUpEdge == 0 && closestUpEdge2 == 3) { normalEdge = closestUpEdge + 1; } else if ((closestUpEdge < closestUpEdge2) || (closestUpEdge == 3 && closestUpEdge2 == 0)) { normalEdge = closestUpEdge - 1; opposite = true; } else { normalEdge = closestUpEdge + 1; } if (RotationUpDirection < 0) { opposite = !opposite; } Vector3 upOffset; MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, normalEdge, out upOffset); Vector3 upOffsetWorld = Vector3.TransformNormal(upOffset, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.6f - upOffsetWorld * 0.01f, opposite ? upControlName1 : upControlName2, Color.White, textScale, false); //VRageRender.MyRenderProxy.DebugDrawText3D(upCenter2 + upNormalBackWorld * 0.6f - upOffsetWorld * 0.01f, opposite ? upControlName2 : upControlName1, Color.White, textScale, false); MyTransparentGeometry.AddBillboardOriented( "ArrowRed", Vector4.One, upCenter + upNormalForwWorld * 0.4f - upOffsetWorld * 0.01f, upNormalBackWorld, upDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowRed", Vector4.One, upCenter2 + upNormalBackWorld * 0.4f - upOffsetWorld * 0.01f, upNormalForwWorld, upDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.3f - upOffsetWorld * 0.01f, opposite ? upControlName2 : upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(upCenter2 + upNormalBackWorld * 0.3f - upOffsetWorld * 0.01f, opposite ? upControlName1 : upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } else //draw on edge { Vector3 normalUpBack, normalUpForw; MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge + 1, out normalUpForw); MyOrientedBoundingBox.GetNormalBetweenEdges(upAxis, closestUpEdge, closestUpEdge - 1, out normalUpBack); Vector3D upCenter = (upStart + upEnd) * 0.5f; Vector3 upNormalForwWorld = Vector3.TransformNormal(normalUpForw, drawMatrix); Vector3 upNormalBackWorld = Vector3.TransformNormal(normalUpBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalForwWorld, Color.Green, Color.Green, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(upCenter, upCenter + upNormalBackWorld, Color.Green, Color.Green, false); MyTransparentGeometry.AddBillboardOriented( "ArrowRed", Vector4.One, upCenter + upNormalForwWorld * 0.3f - upNormalBackWorld * 0.01f, upNormalForwWorld, upDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowRed", Vector4.One, upCenter + upNormalBackWorld * 0.3f - upNormalForwWorld * 0.01f, upNormalBackWorld, upDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalForwWorld * 0.6f - upNormalBackWorld * 0.01f, RotationUpDirection > 0 ? upControlName1 : upControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(upCenter + upNormalBackWorld * 0.6f - upNormalForwWorld * 0.01f, RotationUpDirection > 0 ? upControlName2 : upControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } } if (!(hideForwardAndUpArrows && RotationForwardAxis != 1)) { if (drawForwOnFaceCenter) { //VRageRender.MyRenderProxy.DebugDrawSphere((rightStart + rightEnd + rightStart2 + rightEnd2) * 0.25f, 0.2f, Vector3.Backward, 1.0f, false, false); Vector3D faceCenter = (rightStart + rightEnd + rightStart2 + rightEnd2) * 0.25f; MyTransparentGeometry.AddBillboardOriented( "ArrowLeftBlue", Vector4.One, faceCenter + RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, RotationUpDirection * upDirection, -RotationRightDirection * rightDirection, 0.2f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowRightBlue", Vector4.One, faceCenter - RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, -RotationUpDirection * upDirection, RotationRightDirection * rightDirection, 0.2f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter + RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(faceCenter - RotationUpDirection * upDirection * 0.2f - RotationForwardDirection * forwDirection * 0.01f, forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, projectionId); } else if (drawForwOnFace) { //VRageRender.MyRenderProxy.DebugDrawLine3D(forwStart2, forwEnd2, Color.Blue, Color.Blue, false); Vector3 normalForwBack, normalForwForw; MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge2, out normalForwForw); Vector3D forwCenter = (forwStart + forwEnd) * 0.5f; Vector3 forwNormalForwWorld = Vector3.TransformNormal(normalForwForw, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge2, closestForwEdge, out normalForwBack); Vector3D forwCenter2 = (forwStart2 + forwEnd2) * 0.5f; Vector3 forwNormalBackWorld = Vector3.TransformNormal(normalForwBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalForwWorld, Color.Blue, Color.Blue, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter2, forwCenter2 + forwNormalBackWorld, Color.Blue, Color.Blue, false); int normalEdge = -1; bool opposite = false; if (closestForwEdge == 0 && closestForwEdge2 == 3) { normalEdge = closestForwEdge + 1; } else if ((closestForwEdge < closestForwEdge2) || (closestForwEdge == 3 && closestForwEdge2 == 0)) { normalEdge = closestForwEdge - 1; opposite = true; } else { normalEdge = closestForwEdge + 1; } if (RotationForwardDirection < 0) { opposite = !opposite; } Vector3 forwOffset; MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, normalEdge, out forwOffset); Vector3 forwOffsetWorld = Vector3.TransformNormal(forwOffset, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.6f - forwOffsetWorld * 0.01f, opposite ? forwControlName2 : forwControlName1, Color.White, textScale, false); //VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter2 + forwNormalBackWorld * 0.6f - forwOffsetWorld * 0.01f, opposite ? forwControlName1 : forwControlName2, Color.White, textScale, false); MyTransparentGeometry.AddBillboardOriented( "ArrowBlue", Vector4.One, forwCenter + forwNormalForwWorld * 0.4f - forwOffsetWorld * 0.01f, forwNormalBackWorld, forwDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowBlue", Vector4.One, forwCenter2 + forwNormalBackWorld * 0.4f - forwOffsetWorld * 0.01f, forwNormalForwWorld, forwDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.3f - forwOffsetWorld * 0.01f, opposite ? forwControlName1 : forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter2 + forwNormalBackWorld * 0.3f - forwOffsetWorld * 0.01f, opposite ? forwControlName2 : forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } else //draw on edge { Vector3 normalForwBack, normalForwForw; MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge + 1, out normalForwForw); MyOrientedBoundingBox.GetNormalBetweenEdges(forwAxis, closestForwEdge, closestForwEdge - 1, out normalForwBack); Vector3D forwCenter = (forwStart + forwEnd) * 0.5f; Vector3 forwNormalForwWorld = Vector3.TransformNormal(normalForwForw, drawMatrix); Vector3 forwNormalBackWorld = Vector3.TransformNormal(normalForwBack, drawMatrix); //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalForwWorld, Color.Blue, Color.Blue, false); //VRageRender.MyRenderProxy.DebugDrawLine3D(forwCenter, forwCenter + forwNormalBackWorld, Color.Blue, Color.Blue, false); MyTransparentGeometry.AddBillboardOriented( "ArrowBlue", Vector4.One, forwCenter + forwNormalForwWorld * 0.3f - forwNormalBackWorld * 0.01f, forwNormalForwWorld, forwDirection, 0.5f, 110, false, projectionId); MyTransparentGeometry.AddBillboardOriented( "ArrowBlue", Vector4.One, forwCenter + forwNormalBackWorld * 0.3f - forwNormalForwWorld * 0.01f, forwNormalBackWorld, forwDirection, 0.5f, 110, false, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalForwWorld * 0.3f - forwNormalBackWorld * 0.01f, RotationForwardDirection < 0 ? forwControlName1 : forwControlName2, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); VRageRender.MyRenderProxy.DebugDrawText3D(forwCenter + forwNormalBackWorld * 0.3f - forwNormalForwWorld * 0.01f, RotationForwardDirection < 0 ? forwControlName2 : forwControlName1, Color.White, textScale, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, projectionId); } } } }
//public List<object> m_debugBones = new List<object>(); /// <summary> /// Applies deformation, returns true when block was destroyed (explosion should be generated) /// </summary> /// <param name="deformationOffset">Amount of deformation in the localPos</param> /// <param name="offsetThreshold">When deformation offset for bone is lower then threshold, it won't move the bone at all or do damage</param> public int ApplyDeformation(float deformationOffset, float softAreaPlanar, float softAreaVertical, Vector3 localPos, Vector3 localNormal, MyStringHash damageType, float offsetThreshold = 0, float lowerRatioLimit = 0, long attackerId = 0) { if (!m_grid.BlocksDestructionEnabled) return 0; int blocksDeformed = 0; offsetThreshold /= m_grid.GridSizeEnum == MyCubeSize.Large ? 1 : 5; float roundSize = m_grid.GridSize / MyGridSkeleton.BoneDensity; Vector3I roundedPos = Vector3I.Round((localPos + new Vector3(m_grid.GridSize / 2)) / roundSize); Vector3I gridPos = Vector3I.Round((localPos + new Vector3(m_grid.GridSize / 2)) / m_grid.GridSize); Vector3I gridOffset = roundedPos - gridPos * MyGridSkeleton.BoneDensity; float breakOffset = m_grid.GridSize * 0.7f; float breakOffsetDestruction = breakOffset; Vector3I min = Vector3I.MaxValue; Vector3I max = Vector3I.MinValue; bool isDirty = false; bool destructionDone = false; Vector3 absNormal = Vector3.Abs(localNormal); float maxNorm = Math.Max(Math.Max(absNormal.X, absNormal.Y), absNormal.Z); float maxDef = maxNorm * deformationOffset; float destructionPotencial = (1 - breakOffsetDestruction / maxDef); float minDeformationRatio = 1; var softAreaPlanarR = 1.0f / softAreaPlanar; var softAreaVerticalR = 1.0f / softAreaVertical; var gridSizeR = 1.0f / m_grid.GridSize; Vector3D forward = localNormal; var up = MyUtils.GetRandomPerpendicularVector(ref forward); float minLength = Math.Min(m_grid.GridSize / 256.0f, deformationOffset * 0.06f); // When we're sure that there will be destroyed blocks, it's not necessary to do deformations, just do destruction MyDamageInformation damageInfo = new MyDamageInformation(true, 1f, MyDamageType.Deformation, attackerId); if (destructionPotencial > 0) { float critVertical = destructionPotencial * softAreaVertical; float critPlanar = destructionPotencial * softAreaPlanar; var he = new Vector3(critPlanar, critPlanar, critVertical); MyOrientedBoundingBox obb = new MyOrientedBoundingBox(gridPos,he, Quaternion.CreateFromForwardUp(forward, up)); var aabb = obb.GetAABB(); //float maxCritDist = Math.Max(critPlanar, critVertical); //Vector3I distCubes = new Vector3I((int)Math.Ceiling(maxCritDist / m_grid.GridSize)); //Vector3I minOffset = gridPos - distCubes; //Vector3I maxOffset = gridPos + distCubes; var minOffset = Vector3I.Floor(aabb.Min); var maxOffset = Vector3I.Ceiling(aabb.Max); minOffset = Vector3I.Max(minOffset, m_grid.Min); maxOffset = Vector3I.Min(maxOffset, m_grid.Max); ProfilerShort.Begin("Update destruction"); Vector3I offset; for (offset.X = minOffset.X; offset.X <= maxOffset.X; offset.X++) { for (offset.Y = minOffset.Y; offset.Y <= maxOffset.Y; offset.Y++) { for (offset.Z = minOffset.Z; offset.Z <= maxOffset.Z; offset.Z++) { Vector3 closestCorner = m_grid.GetClosestCorner(offset, localPos); float soften = 1.0f; if (offset != gridPos) { soften = CalculateSoften(softAreaPlanarR, softAreaVerticalR, ref localNormal, closestCorner - localPos); } float deformation = maxDef * soften; if (deformation > breakOffsetDestruction) { var block = m_grid.GetCubeBlock(offset); if (block != null) { if (block.UseDamageSystem) { damageInfo.Amount = 1; MyDamageSystem.Static.RaiseBeforeDamageApplied(block, ref damageInfo); if (damageInfo.Amount == 0f) continue; } minDeformationRatio = Math.Min(minDeformationRatio, block.DeformationRatio); if (Math.Max(lowerRatioLimit, block.DeformationRatio) * deformation > breakOffsetDestruction) { ProfilerShort.Begin("Remove destroyed blocks"); min = Vector3I.Min(min, block.Min - Vector3I.One); max = Vector3I.Max(max, block.Max + Vector3I.One); isDirty = true; m_grid.RemoveDestroyedBlock(block); ProfilerShort.End(); destructionDone = true; blocksDeformed++; } } } } } } ProfilerShort.End(); // When there was no destruction, reduce area and do deformation minDeformationRatio = Math.Max(minDeformationRatio, 0.2f); softAreaPlanar *= minDeformationRatio; softAreaVertical *= minDeformationRatio; } if (!destructionDone) { //m_debugBones.Clear(); var boneDensity = MyGridSkeleton.BoneDensity; ProfilerShort.Begin("Update deformation"); MyOrientedBoundingBox obb = new MyOrientedBoundingBox( gridPos * boneDensity + gridOffset, new Vector3(softAreaPlanar * gridSizeR * boneDensity, softAreaPlanar * gridSizeR * boneDensity , softAreaVertical * gridSizeR * boneDensity), Quaternion.CreateFromForwardUp(forward, up)); var aabb = obb.GetAABB(); //float softArea = Math.Max(softAreaPlanar, softAreaVertical); //var distBones = new Vector3I((int)Math.Ceiling(softArea / m_grid.GridSize * m_grid.Skeleton.BoneDensity)); //Vector3I minOffset = gridPos * m_grid.Skeleton.BoneDensity + gridOffset - distBones; //Vector3I maxOffset = gridPos * m_grid.Skeleton.BoneDensity + gridOffset + distBones; var minOffset = Vector3I.Floor(aabb.Min); var maxOffset = Vector3I.Ceiling(aabb.Max); minOffset = Vector3I.Max(minOffset, m_grid.Min * MyGridSkeleton.BoneDensity); maxOffset = Vector3I.Min(maxOffset, m_grid.Max * MyGridSkeleton.BoneDensity); Vector3I minDirtyBone = Vector3I.MaxValue; Vector3I maxDirtyBone = Vector3I.MinValue; ProfilerShort.Begin("Get bones"); Debug.Assert(m_tmpBoneList.Count == 0, "Temporary dictionary not cleared properly"); m_grid.GetExistingBones(minOffset, maxOffset, m_tmpBoneList, damageInfo); ProfilerShort.End(); ProfilerShort.Begin("Deform bones"); Vector3 bone; Vector3I baseOffset = gridPos * MyGridSkeleton.BoneDensity; float boneDensityR = 1.0f / MyGridSkeleton.BoneDensity; var halfGridSize = new Vector3(m_grid.GridSize * 0.5f); ProfilerShort.CustomValue("Bone Count", m_tmpBoneList.Count, 0); foreach (var b in m_tmpBoneList) { var boneIndex = b.Key; var baseBonePos = boneIndex * m_grid.GridSize * boneDensityR - halfGridSize; m_grid.Skeleton.GetBone(ref boneIndex, out bone); var bonePos = bone + baseBonePos; float soften = CalculateSoften(softAreaPlanarR, softAreaVerticalR, ref localNormal, bonePos - localPos); if (soften == 0) continue; min = Vector3I.Min(min, Vector3I.Floor(bonePos * gridSizeR - Vector3.One * boneDensityR)); max = Vector3I.Max(max, Vector3I.Ceiling(bonePos *gridSizeR + Vector3.One * boneDensityR)); isDirty = true; float deformationRatio = 1.0f; bool doDeformation = true; var block2 = b.Value; { Debug.Assert(block2 != null, "Block cannot be null"); deformationRatio = Math.Max(lowerRatioLimit, block2.DeformationRatio); // + some deformation coeficient based on integrity float maxAxisDeformation = maxNorm * deformationOffset * soften; doDeformation = block2.UsesDeformation; if (block2.IsDestroyed) // || block2.DoDamage(maxAxisDeformation / m_grid.GridSize, damageType, addDirtyParts: false)) { destructionDone = true; } } if (deformationOffset * deformationRatio < offsetThreshold) continue; float deformationLength = deformationOffset * soften * deformationRatio; var deformation = localNormal * deformationLength; bool canDeform = damageType != MyDamageType.Bullet || (Math.Abs(bone.X + deformation.X) < breakOffset && Math.Abs(bone.Y + deformation.Y) < breakOffset && Math.Abs(bone.Z + deformation.Z) < breakOffset); if (canDeform && deformationLength > minLength) { bone += deformation; //m_debugBones.Add(new Tuple<Vector3, float>(bonePos, deformationRatio)); var offset = boneIndex - baseOffset; if (Math.Abs(bone.X) > breakOffset || Math.Abs(bone.Y) > breakOffset || Math.Abs(bone.Z) > breakOffset) { m_tmpCubeList.Clear(); Vector3I wrappedBoneOffset = offset; Vector3I wrappedGridPos = gridPos; m_grid.Skeleton.Wrap(ref wrappedGridPos, ref wrappedBoneOffset); m_grid.Skeleton.GetAffectedCubes(wrappedGridPos, wrappedBoneOffset, m_tmpCubeList, m_grid); foreach (var c in m_tmpCubeList) { var block = m_grid.GetCubeBlock(c); if (block != null) { ProfilerShort.Begin("Remove destroyed blocks"); m_grid.RemoveDestroyedBlock(block); AddDirtyBlock(block); ProfilerShort.End(); destructionDone = true; blocksDeformed++; } } } else if (doDeformation && Sync.IsServer) { minDirtyBone = Vector3I.Min(minDirtyBone, boneIndex); maxDirtyBone = Vector3I.Max(maxDirtyBone, boneIndex); m_grid.Skeleton.SetBone(ref boneIndex, ref bone); m_grid.AddDirtyBone(gridPos, offset); m_grid.BonesToSend.AddInput(boneIndex); } } } m_tmpBoneList.Clear(); ProfilerShort.End(); ProfilerShort.End(); } if (isDirty) { m_dirtyCubesInfo.DirtyParts.Add(new BoundingBoxI() { Min = min, Max = max }); } return blocksDeformed; }
public void CreateHalfExtents(bool forceUpdate = false, bool growOnly = false) { _oldGridHalfExtents = DsState.State.GridHalfExtents; var myAabb = MyGrid.PositionComp.LocalAABB; var shieldGrid = MyGrid; var expandedAabb = myAabb; if (ShieldComp.SubGrids.Count > 1) { foreach (var grid in ShieldComp.SubGrids.Keys) { using (grid.Pin()) { if (grid == shieldGrid || grid.MarkedForClose) { continue; } var shieldMatrix = shieldGrid.PositionComp.WorldMatrixNormalizedInv; var gQuaternion = Quaternion.CreateFromRotationMatrix(grid.WorldMatrix); var gOriBBoxD = new MyOrientedBoundingBox(grid.PositionComp.WorldAABB.Center, grid.PositionComp.LocalAABB.HalfExtents, gQuaternion); gOriBBoxD.Transform(shieldMatrix); expandedAabb.Include(gOriBBoxD.GetAABB()); } } } if (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) { var fortify = DsSet.Settings.FortifyShield ? 3 : 1; var fit = (float)UtilsStatic.GetFit(DsSet.Settings.Fit) * 0.5f; var scaler = 4f; if (shieldGrid.GridSizeEnum == MyCubeSize.Small && DsSet.Settings.Fit < 15) { scaler = 5; } var size = (expandedAabb.HalfExtents.Max() * fortify) * fit; var vectorSize = new Vector3D(size, size, size); var fudge = shieldGrid.GridSize * scaler; var extentsDiff = DsState.State.GridHalfExtents.LengthSquared() - vectorSize.LengthSquared(); if (extentsDiff < -1 || extentsDiff > 1 || DsState.State.GridHalfExtents == Vector3D.Zero || !fudge.Equals(DsState.State.ShieldFudge)) { DsState.State.GridHalfExtents = vectorSize; } DsState.State.ShieldFudge = fudge; } else { var offset = MyGrid.GridSize * 0.01; DsState.State.ShieldFudge = 0f; var extentsDiff = DsState.State.GridHalfExtents.Length() - expandedAabb.HalfExtents.Length(); var overThreshold = extentsDiff <-offset || extentsDiff> offset || forceUpdate; //first grow, second shrink if (overThreshold || DsState.State.GridHalfExtents == Vector3D.Zero) { DsState.State.GridHalfExtents = expandedAabb.HalfExtents; } } _halfExtentsChanged = !DsState.State.GridHalfExtents.Equals(_oldGridHalfExtents) || (DsSet.Settings.SphereFit || DsSet.Settings.FortifyShield) && SettingsUpdated; if (_halfExtentsChanged || SettingsUpdated) { _adjustShape = true; } }
public unsafe void CalculateRotationHints(MatrixD drawMatrix, bool draw, bool fixedAxes = false, bool hideForwardAndUpArrows = false) { int num6; string controlButtonName; string str2; string str3; string str4; string str5; string str6; Vector3D zero; Vector3D vectord14; Vector3D vectord15; Vector3D vectord16; Vector3D vectord17; Vector3D vectord18; Vector3D vectord19; Vector3D vectord20; Vector3D vectord21; Vector3D vectord22; Vector3D vectord23; Vector3D vectord24; int num13; int num14; int num15; int num16; int num17; int num18; int num20; int num21; float num22; Vector3D vectord25; Vector3D vectord26; Vector3D vectord27; bool flag2; bool flag3; bool flag5; bool flag6; Vector3D vectord29; Vector3D vectord30; Vector3D vectord31; Vector3D vectord32; int num28; bool flag7; Vector3 vector3; Vector3D vectord38; Vector3 vector8; Vector3D vectord39; Vector3 vector9; int num29; bool flag8; Vector3 vector10; Matrix viewMatrix = (Matrix)MySector.MainCamera.ViewMatrix; MatrixD matrix = MatrixD.Invert(viewMatrix); if (!drawMatrix.IsValid()) { return; } else { if (viewMatrix.IsValid()) { int num7; int num8; int num9; int num10; int num11; int num12; MatrixD *xdPtr1 = (MatrixD *)ref matrix; xdPtr1.Translation = ((drawMatrix.Translation - (7.0 * matrix.Forward)) + (1.0 * matrix.Left)) - (0.60000002384185791 * matrix.Up); MatrixD *xdPtr2 = (MatrixD *)ref drawMatrix; xdPtr2.Translation -= matrix.Translation; this.m_viewProjection.CameraPosition = matrix.Translation; matrix.Translation = Vector3D.Zero; Matrix matrix2 = (Matrix)MatrixD.Transpose(matrix); this.m_viewProjection.ViewAtZero = matrix2; float num = 2.75f; Vector2 screenSizeFromNormalizedSize = MyGuiManager.GetScreenSizeFromNormalizedSize(Vector2.One, false); int num2 = (int)(screenSizeFromNormalizedSize.X / num); int num3 = (int)(screenSizeFromNormalizedSize.Y / num); int num4 = 0; int num5 = 0; this.m_viewProjection.Viewport = new MyViewport((float)((((int)MySector.MainCamera.Viewport.Width) - num2) - num4), (float)num5, (float)num2, (float)num3); this.m_viewProjection.Projection = Matrix.CreatePerspectiveFieldOfView(0.7853982f, ((float)num2) / ((float)num3), 0.1f, 10f); BoundingBoxD localbox = new BoundingBoxD(-new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large) * 0.5f), new Vector3(MyDefinitionManager.Static.GetCubeSize(MyCubeSize.Large)) * 0.5f); num6 = 0; MyRenderProxy.AddBillboardViewProjection(num6, this.m_viewProjection); if (draw) { Color red = Color.Red; Color green = Color.Green; Color blue = Color.Blue; Color white = Color.White; Color color5 = Color.White; Color color6 = Color.White; Color wire = Color.White; MyStringId?lineMaterial = null; MySimpleObjectDraw.DrawTransparentBox(ref drawMatrix, ref localbox, ref red, ref green, ref blue, ref white, ref color5, ref color6, ref wire, MySimpleObjectRasterizer.Solid, 1, 0.04f, new MyStringId?(ID_SQUARE_FULL_COLOR), lineMaterial, false, num6, MyBillboard.BlendTypeEnum.LDR, 1f, null); } new MyOrientedBoundingBoxD(Vector3D.Transform(localbox.Center, drawMatrix), localbox.HalfExtents, Quaternion.CreateFromRotationMatrix(drawMatrix)).GetCorners(this.m_cubeVertices, 0); GetClosestCubeEdge(this.m_cubeVertices, Vector3D.Zero, MyOrientedBoundingBox.StartXVertices, MyOrientedBoundingBox.EndXVertices, out num7, out num8); Vector3D from = this.m_cubeVertices[MyOrientedBoundingBox.StartXVertices[num7]]; Vector3D to = this.m_cubeVertices[MyOrientedBoundingBox.EndXVertices[num7]]; Vector3D vectord3 = this.m_cubeVertices[MyOrientedBoundingBox.StartXVertices[num8]]; Vector3D vectord4 = this.m_cubeVertices[MyOrientedBoundingBox.EndXVertices[num8]]; GetClosestCubeEdge(this.m_cubeVertices, Vector3D.Zero, MyOrientedBoundingBox.StartYVertices, MyOrientedBoundingBox.EndYVertices, out num9, out num10); Vector3D vectord5 = this.m_cubeVertices[MyOrientedBoundingBox.StartYVertices[num9]]; Vector3D vectord6 = this.m_cubeVertices[MyOrientedBoundingBox.EndYVertices[num9]]; Vector3D vectord7 = this.m_cubeVertices[MyOrientedBoundingBox.StartYVertices[num10]]; Vector3D vectord8 = this.m_cubeVertices[MyOrientedBoundingBox.EndYVertices[num10]]; GetClosestCubeEdge(this.m_cubeVertices, Vector3D.Zero, MyOrientedBoundingBox.StartZVertices, MyOrientedBoundingBox.EndZVertices, out num11, out num12); Vector3D vectord9 = this.m_cubeVertices[MyOrientedBoundingBox.StartZVertices[num11]]; Vector3D vectord10 = this.m_cubeVertices[MyOrientedBoundingBox.EndZVertices[num11]]; Vector3D vectord11 = this.m_cubeVertices[MyOrientedBoundingBox.StartZVertices[num12]]; Vector3D vectord12 = this.m_cubeVertices[MyOrientedBoundingBox.EndZVertices[num12]]; this.m_cubeEdges.Clear(); BoxEdge item = new BoxEdge { Axis = 0, Edge = new LineD(from, to) }; this.m_cubeEdges.Add(item); item = new BoxEdge { Axis = 1, Edge = new LineD(vectord5, vectord6) }; this.m_cubeEdges.Add(item); item = new BoxEdge { Axis = 2, Edge = new LineD(vectord9, vectord10) }; this.m_cubeEdges.Add(item); if (!fixedAxes) { int num23; this.RotationRightAxis = GetBestAxis(this.m_cubeEdges, MySector.MainCamera.WorldMatrix.Right, out num23); this.RotationRightDirection = num23; this.RotationUpAxis = GetBestAxis(this.m_cubeEdges, MySector.MainCamera.WorldMatrix.Up, out num23); this.RotationUpDirection = num23; this.RotationForwardAxis = GetBestAxis(this.m_cubeEdges, MySector.MainCamera.WorldMatrix.Forward, out num23); this.RotationForwardDirection = num23; } controlButtonName = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); str2 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); str3 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); str4 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); str5 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); str6 = MyInput.Static.GetGameControl(MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).GetControlButtonName(MyGuiInputDeviceEnum.Keyboard); if (MyInput.Static.IsJoystickConnected() && MyInput.Static.IsJoystickLastUsed) { controlButtonName = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_POSITIVE).ToString(); str2 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_HORISONTAL_NEGATIVE).ToString(); str3 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_POSITIVE).ToString(); str4 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_VERTICAL_NEGATIVE).ToString(); str5 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_POSITIVE).ToString(); str6 = MyControllerHelper.GetCodeForControl(MySpaceBindingCreator.CX_BUILD_MODE, MyControlsSpace.CUBE_ROTATE_ROLL_NEGATIVE).ToString(); } zero = Vector3D.Zero; vectord14 = Vector3D.Zero; vectord15 = Vector3D.Zero; vectord16 = Vector3D.Zero; vectord17 = Vector3D.Zero; vectord18 = Vector3D.Zero; vectord19 = Vector3D.Zero; vectord20 = Vector3D.Zero; vectord21 = Vector3D.Zero; vectord22 = Vector3D.Zero; vectord23 = Vector3D.Zero; vectord24 = Vector3D.Zero; num13 = -1; num14 = -1; num15 = -1; num16 = -1; num17 = -1; num18 = -1; int num19 = -1; num20 = -1; num21 = -1; if (this.RotationRightAxis == 0) { zero = from; vectord14 = to; vectord19 = vectord3; vectord20 = vectord4; num13 = 0; num16 = num7; num19 = num8; } else if (this.RotationRightAxis == 1) { zero = vectord5; vectord14 = vectord6; vectord19 = vectord7; vectord20 = vectord8; num13 = 1; num16 = num9; num19 = num10; } else if (this.RotationRightAxis == 2) { zero = vectord9; vectord14 = vectord10; vectord19 = vectord11; vectord20 = vectord12; num13 = 2; num16 = num11; num19 = num12; } if (this.RotationUpAxis == 0) { vectord15 = from; vectord16 = to; vectord21 = vectord3; vectord22 = vectord4; num14 = 0; num17 = num7; num20 = num8; } else if (this.RotationUpAxis == 1) { vectord15 = vectord5; vectord16 = vectord6; vectord21 = vectord7; vectord22 = vectord8; num14 = 1; num17 = num9; num20 = num10; } else if (this.RotationUpAxis == 2) { vectord15 = vectord9; vectord16 = vectord10; vectord21 = vectord11; vectord22 = vectord12; num14 = 2; num17 = num11; num20 = num12; } if (this.RotationForwardAxis == 0) { vectord17 = from; vectord18 = to; vectord23 = vectord3; vectord24 = vectord4; num15 = 0; num18 = num7; num21 = num8; } else if (this.RotationForwardAxis == 1) { vectord17 = vectord5; vectord18 = vectord6; vectord23 = vectord7; vectord24 = vectord8; num15 = 1; num18 = num9; num21 = num10; } else if (this.RotationForwardAxis == 2) { vectord17 = vectord9; vectord18 = vectord10; vectord23 = vectord11; vectord24 = vectord12; num15 = 2; num18 = num11; num21 = num12; } num22 = 0.5448648f; if (!draw) { return; } else { vectord25 = Vector3.Normalize(vectord14 - zero); vectord26 = Vector3.Normalize(vectord16 - vectord15); vectord27 = Vector3.Normalize(vectord18 - vectord17); Vector3D forwardVector = MySector.MainCamera.ForwardVector; float num24 = Math.Abs(Vector3.Dot((Vector3)forwardVector, (Vector3)vectord25)); float num25 = Math.Abs(Vector3.Dot((Vector3)forwardVector, (Vector3)vectord26)); float num26 = Math.Abs(Vector3.Dot((Vector3)forwardVector, (Vector3)vectord27)); bool flag = false; flag2 = false; flag3 = false; bool flag4 = false; flag5 = false; flag6 = false; float num27 = 0.4f; if (num24 < num27) { if (num25 < num27) { flag6 = true; flag = true; flag2 = true; } else if (num26 >= num27) { flag2 = true; flag3 = true; } else { flag5 = true; flag = true; flag3 = true; } } else if (num25 < num27) { if (num24 < num27) { flag6 = true; flag = true; flag2 = true; } else if (num26 >= num27) { flag = true; flag3 = true; } else { flag4 = true; flag2 = true; flag3 = true; } } else if (num26 < num27) { if (num24 < num27) { flag5 = true; flag = true; flag3 = true; } else if (num25 >= num27) { flag2 = true; flag = true; } else { flag5 = true; flag = true; flag3 = true; } } if (hideForwardAndUpArrows && (this.RotationRightAxis != 1)) { goto TR_0025; } if (!flag4) { if (!flag) { Vector3 vector4; Vector3 vector5; MyOrientedBoundingBox.GetNormalBetweenEdges(num13, num16, num16 + 1, out vector5); MyOrientedBoundingBox.GetNormalBetweenEdges(num13, num16, num16 - 1, out vector4); Vector3D vectord34 = (zero + vectord14) * 0.5; Vector3D vectord35 = Vector3D.TransformNormal(vector5, drawMatrix); Vector3D vectord36 = Vector3D.TransformNormal(vector4, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_GREEN, Vector4.One, (vectord34 + (vectord35 * 0.30000001192092896)) - (vectord36 * 0.0099999997764825821), (Vector3)vectord25, (Vector3)vectord35, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_GREEN, Vector4.One, (vectord34 + (vectord36 * 0.30000001192092896)) - (vectord35 * 0.0099999997764825821), (Vector3)vectord25, (Vector3)vectord36, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord34 + (vectord35 * 0.30000001192092896)) - (vectord36 * 0.0099999997764825821), (this.RotationRightDirection < 0) ? controlButtonName : str2, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord34 + (vectord36 * 0.30000001192092896)) - (vectord35 * 0.0099999997764825821), (this.RotationRightDirection < 0) ? str2 : controlButtonName, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0025; } else { Vector3 vector; Vector3 vector2; MyOrientedBoundingBox.GetNormalBetweenEdges(num13, num16, num19, out vector2); vectord29 = (zero + vectord14) * 0.5; vectord30 = Vector3D.TransformNormal(vector2, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(num13, num19, num16, out vector); vectord31 = (vectord19 + vectord20) * 0.5; vectord32 = Vector3D.TransformNormal(vector, drawMatrix); flag7 = false; if ((num16 == 0) && (num19 == 3)) { num28 = num16 + 1; goto TR_0029; } if ((num16 >= num19) && ((num16 != 3) || (num19 != 0))) { num28 = num16 + 1; goto TR_0029; } } } else { Vector3D vectord28 = (((vectord17 + vectord18) + vectord23) + vectord24) * 0.25; MyTransparentGeometry.AddBillboardOriented(ID_ARROW_LEFT_GREEN, Vector4.One, (vectord28 - ((this.RotationForwardDirection * vectord27) * 0.20000000298023224)) - ((this.RotationRightDirection * vectord25) * 0.0099999997764825821), (Vector3)(-this.RotationUpDirection * vectord26), (Vector3)(-this.RotationForwardDirection * vectord27), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RIGHT_GREEN, Vector4.One, (vectord28 + ((this.RotationForwardDirection * vectord27) * 0.20000000298023224)) - ((this.RotationRightDirection * vectord25) * 0.0099999997764825821), (Vector3)(this.RotationUpDirection * vectord26), (Vector3)(this.RotationForwardDirection * vectord27), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord28 - ((this.RotationForwardDirection * vectord27) * 0.20000000298023224)) - ((this.RotationRightDirection * vectord25) * 0.0099999997764825821), str2, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord28 + ((this.RotationForwardDirection * vectord27) * 0.20000000298023224)) - ((this.RotationRightDirection * vectord25) * 0.0099999997764825821), controlButtonName, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0025; } goto TR_002B; } goto TR_0029; } else { return; } goto TR_002B; } goto TR_0029; TR_0013: if (!hideForwardAndUpArrows || (this.RotationForwardAxis == 1)) { if (flag6) { Vector3D vectord41 = (((zero + vectord14) + vectord19) + vectord20) * 0.25; MyTransparentGeometry.AddBillboardOriented(ID_ARROW_LEFT_BLUE, Vector4.One, (vectord41 + ((this.RotationUpDirection * vectord26) * 0.20000000298023224)) - ((this.RotationForwardDirection * vectord27) * 0.0099999997764825821), (Vector3)(-this.RotationRightDirection * vectord25), (Vector3)(this.RotationUpDirection * vectord26), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RIGHT_BLUE, Vector4.One, (vectord41 - ((this.RotationUpDirection * vectord26) * 0.20000000298023224)) - ((this.RotationForwardDirection * vectord27) * 0.0099999997764825821), (Vector3)(this.RotationRightDirection * vectord25), (Vector3)(-this.RotationUpDirection * vectord26), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord41 + ((this.RotationUpDirection * vectord26) * 0.20000000298023224)) - ((this.RotationForwardDirection * vectord27) * 0.0099999997764825821), str5, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord41 - ((this.RotationUpDirection * vectord26) * 0.20000000298023224)) - ((this.RotationForwardDirection * vectord27) * 0.0099999997764825821), str6, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_CENTER, num6, false); return; } if (!flag3) { Vector3 vector22; Vector3 vector23; MyOrientedBoundingBox.GetNormalBetweenEdges(num15, num18, num18 + 1, out vector23); MyOrientedBoundingBox.GetNormalBetweenEdges(num15, num18, num18 - 1, out vector22); Vector3D vectord44 = (vectord17 + vectord18) * 0.5; Vector3 upVector = Vector3.TransformNormal(vector23, drawMatrix); Vector3 vector25 = Vector3.TransformNormal(vector22, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_BLUE, Vector4.One, (vectord44 + (upVector * 0.3f)) - (vector25 * 0.01f), (Vector3)vectord27, upVector, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_BLUE, Vector4.One, (vectord44 + (vector25 * 0.3f)) - (upVector * 0.01f), (Vector3)vectord27, vector25, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord44 + (upVector * 0.3f)) - (vector25 * 0.01f), (this.RotationForwardDirection < 0) ? str5 : str6, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord44 + (vector25 * 0.3f)) - (upVector * 0.01f), (this.RotationForwardDirection < 0) ? str6 : str5, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); } else { Vector3 vector16; Vector3 vector17; int num30; Vector3 vector20; MyOrientedBoundingBox.GetNormalBetweenEdges(num15, num18, num21, out vector17); Vector3D vectord42 = (vectord17 + vectord18) * 0.5; Vector3 upVector = Vector3.TransformNormal(vector17, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(num15, num21, num18, out vector16); Vector3D vectord43 = (vectord23 + vectord24) * 0.5; Vector3 vector19 = Vector3.TransformNormal(vector16, drawMatrix); bool flag9 = false; if ((num18 == 0) && (num21 == 3)) { num30 = num18 + 1; } else if ((num18 >= num21) && ((num18 != 3) || (num21 != 0))) { num30 = num18 + 1; } else { num30 = num18 - 1; flag9 = true; } if (this.RotationForwardDirection < 0) { flag9 = !flag9; } MyOrientedBoundingBox.GetNormalBetweenEdges(num15, num18, num30, out vector20); Vector3 vector21 = Vector3.TransformNormal(vector20, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_BLUE, Vector4.One, (vectord42 + (upVector * 0.4f)) - (vector21 * 0.01f), (Vector3)vectord27, vector19, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_BLUE, Vector4.One, (vectord43 + (vector19 * 0.4f)) - (vector21 * 0.01f), (Vector3)vectord27, upVector, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord42 + (upVector * 0.3f)) - (vector21 * 0.01f), flag9 ? str5 : str6, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord43 + (vector19 * 0.3f)) - (vector21 * 0.01f), flag9 ? str6 : str5, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); return; } } return; TR_0017: if (this.RotationUpDirection < 0) { flag8 = !flag8; } MyOrientedBoundingBox.GetNormalBetweenEdges(num14, num17, num29, out vector10); Vector3 vector11 = Vector3.TransformNormal(vector10, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RED, Vector4.One, (vectord38 + (vector8 * 0.4f)) - (vector11 * 0.01f), (Vector3)vectord26, vector9, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RED, Vector4.One, (vectord39 + (vector9 * 0.4f)) - (vector11 * 0.01f), (Vector3)vectord26, vector8, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord38 + (vector8 * 0.3f)) - (vector11 * 0.01f), flag8 ? str4 : str3, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord39 + (vector9 * 0.3f)) - (vector11 * 0.01f), flag8 ? str3 : str4, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0013; TR_0025: if (hideForwardAndUpArrows && (this.RotationUpAxis != 1)) { goto TR_0013; } if (!flag5) { if (!flag2) { Vector3 vector12; Vector3 vector13; MyOrientedBoundingBox.GetNormalBetweenEdges(num14, num17, num17 + 1, out vector13); MyOrientedBoundingBox.GetNormalBetweenEdges(num14, num17, num17 - 1, out vector12); Vector3D vectord40 = (vectord15 + vectord16) * 0.5; Vector3 upVector = Vector3.TransformNormal(vector13, drawMatrix); Vector3 vector15 = Vector3.TransformNormal(vector12, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RED, Vector4.One, (vectord40 + (upVector * 0.3f)) - (vector15 * 0.01f), (Vector3)vectord26, upVector, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RED, Vector4.One, (vectord40 + (vector15 * 0.3f)) - (upVector * 0.01f), (Vector3)vectord26, vector15, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord40 + (upVector * 0.6f)) - (vector15 * 0.01f), (this.RotationUpDirection > 0) ? str3 : str4, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord40 + (vector15 * 0.6f)) - (upVector * 0.01f), (this.RotationUpDirection > 0) ? str4 : str3, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0013; } else { Vector3 vector6; Vector3 vector7; MyOrientedBoundingBox.GetNormalBetweenEdges(num14, num17, num20, out vector7); vectord38 = (vectord15 + vectord16) * 0.5; vector8 = Vector3.TransformNormal(vector7, drawMatrix); MyOrientedBoundingBox.GetNormalBetweenEdges(num14, num20, num17, out vector6); vectord39 = (vectord21 + vectord22) * 0.5; vector9 = Vector3.TransformNormal(vector6, drawMatrix); flag8 = false; if ((num17 == 0) && (num20 == 3)) { num29 = num17 + 1; goto TR_0017; } if ((num17 >= num20) && ((num17 != 3) || (num20 != 0))) { num29 = num17 + 1; goto TR_0017; } } } else { Vector3D vectord37 = (((vectord17 + vectord18) + vectord23) + vectord24) * 0.25; MyTransparentGeometry.AddBillboardOriented(ID_ARROW_LEFT_RED, Vector4.One, (vectord37 - ((this.RotationRightDirection * vectord25) * 0.20000000298023224)) - ((this.RotationUpDirection * vectord26) * 0.0099999997764825821), (Vector3)(-this.RotationForwardDirection * vectord27), (Vector3)(-this.RotationRightDirection * vectord25), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_RIGHT_RED, Vector4.One, (vectord37 + ((this.RotationRightDirection * vectord25) * 0.20000000298023224)) - ((this.RotationUpDirection * vectord26) * 0.0099999997764825821), (Vector3)(this.RotationForwardDirection * vectord27), (Vector3)(this.RotationRightDirection * vectord25), 0.2f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord37 - ((this.RotationRightDirection * vectord25) * 0.20000000298023224)) - ((this.RotationUpDirection * vectord26) * 0.0099999997764825821), str3, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord37 + ((this.RotationRightDirection * vectord25) * 0.20000000298023224)) - ((this.RotationUpDirection * vectord26) * 0.0099999997764825821), str4, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0013; } num29 = num17 - 1; flag8 = true; goto TR_0017; TR_0029: if (this.RotationRightDirection < 0) { flag7 = !flag7; } MyOrientedBoundingBox.GetNormalBetweenEdges(num13, num16, num28, out vector3); Vector3D vectord33 = Vector3D.TransformNormal(vector3, drawMatrix); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_GREEN, Vector4.One, (vectord29 + (vectord30 * 0.40000000596046448)) - (vectord33 * 0.0099999997764825821), (Vector3)vectord25, (Vector3)vectord32, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyTransparentGeometry.AddBillboardOriented(ID_ARROW_GREEN, Vector4.One, (vectord31 + (vectord32 * 0.40000000596046448)) - (vectord33 * 0.0099999997764825821), (Vector3)vectord25, (Vector3)vectord30, 0.5f, num6, MyBillboard.BlendTypeEnum.LDR); MyRenderProxy.DebugDrawText3D((vectord29 + (vectord30 * 0.30000001192092896)) - (vectord33 * 0.0099999997764825821), flag7 ? controlButtonName : str2, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); MyRenderProxy.DebugDrawText3D((vectord31 + (vectord32 * 0.30000001192092896)) - (vectord33 * 0.0099999997764825821), flag7 ? str2 : controlButtonName, Color.White, num22, false, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, num6, false); goto TR_0025; TR_002B: num28 = num16 - 1; flag7 = true; goto TR_0029; }
public static void CutOutOrientedBox(MyVoxelMap voxelMap, MyOrientedBoundingBox box, ref bool changed) { BoundingBox aabb = box.GetAABB(); MyMwcVector3Int minCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Min - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); MyMwcVector3Int maxCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Max + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); voxelMap.FixVoxelCoord(ref minCorner); voxelMap.FixVoxelCoord(ref maxCorner); System.Threading.Tasks.Parallel.For(minCorner.X, maxCorner.X, i => { System.Threading.Tasks.Parallel.For(minCorner.Y, maxCorner.Y, j => { System.Threading.Tasks.Parallel.For(minCorner.Z, maxCorner.Z, k => { MyMwcVector3Int tempVoxelCoord = new MyMwcVector3Int(i, j, k); Vector3 position = voxelMap.GetVoxelCenterPositionAbsolute(ref tempVoxelCoord); BoundingBox voxelAABB = new BoundingBox(position - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF), position + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)); byte newContent = 0; ContainmentType ct = box.Contains(ref voxelAABB); if (ct == ContainmentType.Contains) { newContent = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (ct == ContainmentType.Disjoint) { newContent = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // Transform the point into box-local space and check against // our extents. Quaternion qinv = Quaternion.Conjugate(box.Orientation); Vector3 plocal = Vector3.Transform(position - box.Center, qinv); //MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF float distX = 0; float distY = 0; float distZ = 0; int sX = System.Math.Sign(plocal.X); int sY = System.Math.Sign(plocal.Y); int sZ = System.Math.Sign(plocal.Z); if (sX > 0) { distX = plocal.X - box.HalfExtent.X; } else { distX = plocal.X + box.HalfExtent.X; } if (sY > 0) { distY = plocal.Y - box.HalfExtent.Y; } else { distY = plocal.Y + box.HalfExtent.Y; } if (sZ > 0) { distZ = plocal.Z - box.HalfExtent.Z; } else { distZ = plocal.Z + box.HalfExtent.Z; } //float diff = (distX + distY + distZ) / 3; //float diff = (sX*sY*sZ) * System.Math.Min(System.Math.Min(distX,distY), distZ); int contentX; int contentY; int contentZ; if (sX < 0) { if (distX > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentX = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distX < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentX = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentX = MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distX / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } else { if (distX < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentX = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distX > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentX = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentX = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distX / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } if (sY < 0) { if (distY > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distY < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentY = MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } else { if (distY < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distY > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentY = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } if (sZ < 0) { if (distZ > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentZ = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distZ < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentZ = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentZ = MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distZ / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } else { if (distZ < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentZ = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else if (distZ > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentZ = MyVoxelConstants.VOXEL_CONTENT_FULL; } else { // This formula will work even if diff is positive or negative contentZ = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distZ / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } //voxelMap.SetVoxelContent( (byte)((contentX + contentY + contentZ)/3.0f), ref tempVoxelCoord); newContent = (byte)(System.Math.Min(System.Math.Min(contentX, contentY), contentZ)); } byte originalContent = voxelMap.GetVoxelContent(ref tempVoxelCoord); if (newContent < originalContent) { voxelMap.SetVoxelContent(newContent, ref tempVoxelCoord, true); //changed = true; } }); }); }); /* for (tempVoxelCoord.X = minCorner.X; tempVoxelCoord.X <= maxCorner.X; tempVoxelCoord.X++) { for (tempVoxelCoord.Y = minCorner.Y; tempVoxelCoord.Y <= maxCorner.Y; tempVoxelCoord.Y++) { for (tempVoxelCoord.Z = minCorner.Z; tempVoxelCoord.Z <= maxCorner.Z; tempVoxelCoord.Z++) { } } }*/ changed = true; voxelMap.InvalidateCache(minCorner, maxCorner); voxelMap.CalcAverageDataCellMaterials(); }
public override bool IsPositionInRange(Vector3D worldPoint) { Vector3 halfExtents = m_fieldSize.Value * 0.5f; MyOrientedBoundingBox obb = new MyOrientedBoundingBox((Vector3)WorldMatrix.Translation, halfExtents, Quaternion.CreateFromRotationMatrix(WorldMatrix)); Vector3 conv = (Vector3)worldPoint; return obb.Contains(ref conv); }
private void DisableContainedDummyParticles(MyOrientedBoundingBox largerOBB, BoundingBox largerAABB) { MyRender.GetEntitiesFromPrunningStructure(ref largerAABB, m_destroyHelper); foreach (var elem in m_destroyHelper) { var entity = ((MyRenderObject)elem).Entity; var dummyPoint = entity as MyDummyPoint; if (dummyPoint != null && !dummyPoint.CanSurvivePrefabDestruction()) { var position = dummyPoint.GetPosition(); // if contained entity can be destroyed, is smaller than me and has center inside me, close it if (largerOBB.Contains(ref position)) { m_particlesToStop.Add(dummyPoint); } continue; } } m_destroyHelper.Clear(); }
private void RemoveContainedPrefabs(MyOrientedBoundingBox largerOBB, BoundingBox largerAABB) { var intersectingElements = MyEntities.GetElementsInBox(ref largerAABB); using (var intersectingElements2 = PoolList<MyRBElement>.Get()) { intersectingElements2.AddRange(intersectingElements); intersectingElements.Clear(); foreach (var rbElement in intersectingElements2) { var rigidBody = rbElement.GetRigidBody(); if (rigidBody == null) continue; var containedEntity = ((MyPhysicsBody)rigidBody.m_UserData).Entity; var candidateToDestroy = containedEntity.GetTopMostParent(typeof(MyPrefabBase)) as MyPrefabBase; if (candidateToDestroy != null && candidateToDestroy != this) { var position = candidateToDestroy.WorldVolumeHr.Center; // if contained entity can be destroyed, is smaller than me and has center inside me, close it if (WorldVolumeHr.Radius > candidateToDestroy.WorldVolumeHr.Radius && largerOBB.Contains(ref position) && candidateToDestroy.IsDestructible) { if (candidateToDestroy.m_isExploded) continue; candidateToDestroy.m_isExploded = true; m_prefabsToDestroy.Add(candidateToDestroy); candidateToDestroy.DestroyPrefabsInsideHr(); } continue; } } } intersectingElements.Clear(); }
} //CreateCylinder public static void CutOutCylinder(MyVoxelMap voxelMap, float radius1, float radius2, MyOrientedBoundingBox box, MyMwcVoxelMaterialsEnum? material, ref bool changed) { //box.HalfExtent x = radius1 //box.HalfExtent y = length/2 //box.HalfExtent z = radius2 BoundingBox aabb = box.GetAABB(); MyMwcVector3Int minCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Min - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); MyMwcVector3Int maxCorner = voxelMap.GetVoxelCoordinateFromMeters(aabb.Max + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES)); voxelMap.FixVoxelCoord(ref minCorner); voxelMap.FixVoxelCoord(ref maxCorner); MyMwcVector3Int tempVoxelCoord; for (tempVoxelCoord.X = minCorner.X; tempVoxelCoord.X <= maxCorner.X; tempVoxelCoord.X++) { for (tempVoxelCoord.Y = minCorner.Y; tempVoxelCoord.Y <= maxCorner.Y; tempVoxelCoord.Y++) { for (tempVoxelCoord.Z = minCorner.Z; tempVoxelCoord.Z <= maxCorner.Z; tempVoxelCoord.Z++) { Vector3 position = voxelMap.GetVoxelCenterPositionAbsolute(ref tempVoxelCoord); //BoundingBox voxelAABB = new BoundingBox(position - new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF), position + new Vector3(MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF)); byte newContent = 0; // Transform the point into box-local space and check against // our extents. Quaternion qinv = Quaternion.Conjugate(box.Orientation); Vector3 plocal = Vector3.Transform(position - box.Center, qinv); //MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF float distY = 0; int sY = System.Math.Sign(plocal.Y); if (sY > 0) { distY = plocal.Y - box.HalfExtent.Y; } else { distY = plocal.Y + box.HalfExtent.Y; } float distRatio = 1; distRatio = MathHelper.Clamp((plocal.Y + box.HalfExtent.Y) / (2 * box.HalfExtent.Y), 0, 1); int contentY = -1; if (sY > 0) { if (distY > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_FULL; } else if (distY < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else { // This formula will work even if diff is positive or negative //contentY = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); contentY = MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } else { if (distY < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_FULL; } else if (distY > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { contentY = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else { // This formula will work even if diff is positive or negative //contentY = MyVoxelConstants.VOXEL_CONTENT_FULL - (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); contentY = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - distY / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); } } Matrix boxMatrix = Matrix.CreateFromQuaternion(box.Orientation); Vector3 hY1 = box.Center + boxMatrix.Up * box.HalfExtent.Y; Vector3 hY2 = box.Center + boxMatrix.Down * box.HalfExtent.Y; float dist = MyUtils.GetPointLineDistance(ref hY1, ref hY2, ref position); float diff = dist - MathHelper.Lerp(radius2, radius1, distRatio); //float diff = dist - box.HalfExtent.Z; byte newContent2; if (diff > MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { newContent2 = MyVoxelConstants.VOXEL_CONTENT_FULL; } else if (diff < -MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF) { newContent2 = MyVoxelConstants.VOXEL_CONTENT_EMPTY; } else { // This formula will work even if diff is positive or negative //newContent2 = (byte)(MyVoxelConstants.VOXEL_ISO_LEVEL - diff / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL); newContent2 = (byte)(MyVoxelConstants.VOXEL_CONTENT_FULL - (int)(MyVoxelConstants.VOXEL_ISO_LEVEL - diff / MyVoxelConstants.VOXEL_SIZE_IN_METRES_HALF * MyVoxelConstants.VOXEL_ISO_LEVEL)); } newContent = (byte)System.Math.Max(contentY, newContent2); //newContent = (byte)contentY; byte originalContent = voxelMap.GetVoxelContent(ref tempVoxelCoord); if (newContent < originalContent) { voxelMap.SetVoxelContent(newContent, ref tempVoxelCoord); if (material.HasValue) voxelMap.SetVoxelMaterialAndIndestructibleContent(material.Value, 0, ref tempVoxelCoord); } } } } voxelMap.InvalidateCache(minCorner, maxCorner); voxelMap.CalcAverageDataCellMaterials(); } //CutoutCylinder