protected override unsafe MyEntity DestroyItem(int itemInstanceId) { int num; MyEntity entity; if (!base.m_localIdToPhysicsShapeInstanceId.TryGetValue(itemInstanceId, out num)) { num = -1; } MyEnvironmentItems.MyEnvironmentItemData data = base.m_itemsData[itemInstanceId]; base.RemoveItem(itemInstanceId, num, false, true); Vector3D position = data.Transform.Position; string modelAsset = data.Model.AssetName.Insert(data.Model.AssetName.Length - 4, "_broken"); bool flag = false; if (MyModels.GetModelOnlyData(modelAsset) == null) { entity = MyDebris.Static.CreateDebris(data.Model.AssetName); } else { flag = true; entity = MyDebris.Static.CreateDebris(modelAsset); } MyDebrisBase.MyDebrisBaseLogic gameLogic = entity.GameLogic as MyDebrisBase.MyDebrisBaseLogic; gameLogic.LifespanInMiliseconds = 0x4e20; MatrixD xd = MatrixD.CreateFromQuaternion(data.Transform.Rotation); MatrixD *xdPtr1 = (MatrixD *)ref xd; xdPtr1.Translation = position + (xd.Up * (flag ? ((double)0) : ((double)5))); gameLogic.Start(xd, Vector3.Zero, false); return(entity); }
public unsafe MatrixD GetHeadMatrix(bool includeY, bool includeX = true, bool forceHeadAnim = false, bool forceHeadBone = false) { MatrixD worldMatrix = base.WorldMatrix; MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation -= 4.0 * base.WorldMatrix.Forward; return(worldMatrix); }
public unsafe void Apply() { MatrixD worldMatrix = this.m_character.WorldMatrix; MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation += this.m_delta; this.m_character.PositionComp.SetWorldMatrix(worldMatrix, null, true, true, true, false, false, false); }
internal override unsafe void DebugDraw(ref MatrixD worldTranslation, Color color) { MatrixD xd2; MatrixD xd = MatrixD.CreateTranslation(this.m_translation) * worldTranslation; float num = (this.m_primaryRadius + this.m_secondaryRadius) * 2f; float num2 = this.m_secondaryRadius * 2f; MatrixD.CreateFromQuaternion(ref this.m_invRotation, out xd2); MatrixD *xdPtr1 = (MatrixD *)ref xd2; MatrixD.Transpose(ref (MatrixD) ref xdPtr1, out xd2); MyRenderProxy.DebugDrawCylinder((MatrixD.CreateScale((double)num, (double)num2, (double)num) * xd2) * xd, color.ToVector3(), 0.5f, true, false, false); }
private unsafe long SpawnInventoryContainer(MyDefinitionId bagDefinition, MyInventory inventory, bool spawnAboveCharacter = true, long ownerIdentityId = 0L) { MyContainerDefinition definition; if ((MySession.Static == null) || !MySession.Static.Ready) { return(0L); } MyEntity character = base.Character; MatrixD worldMatrix = base.Character.WorldMatrix; if (spawnAboveCharacter) { MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation += worldMatrix.Up + worldMatrix.Forward; } else { MatrixD *xdPtr2 = (MatrixD *)ref worldMatrix; xdPtr2.Translation = base.Character.PositionComp.WorldAABB.Center + (worldMatrix.Backward * 0.40000000596046448); } if (!MyComponentContainerExtension.TryGetContainerDefinition(bagDefinition.TypeId, bagDefinition.SubtypeId, out definition)) { return(0L); } MyEntity entity2 = MyEntities.CreateFromComponentContainerDefinitionAndAdd(definition.Id, false, true); if (entity2 == null) { return(0L); } MyInventoryBagEntity entity3 = entity2 as MyInventoryBagEntity; if (entity3 != null) { entity3.OwnerIdentityId = ownerIdentityId; } entity2.PositionComp.SetWorldMatrix(worldMatrix, null, false, true, true, false, false, false); entity2.Physics.LinearVelocity = character.Physics.LinearVelocity; entity2.Physics.AngularVelocity = character.Physics.AngularVelocity; entity2.Render.EnableColorMaskHsv = true; entity2.Render.ColorMaskHsv = base.Character.Render.ColorMaskHsv; inventory.RemoveEntityOnEmpty = true; entity2.Components.Add <MyInventoryBase>(inventory); return(entity2.EntityId); }
private unsafe void DebugDrawFrozen(MatrixD *cascadesMatrices) { Vector3D *verticesWS = stackalloc Vector3D[8]; Color[] cascadeColor = null; cascadeColor = new[] { Color.Red, Color.Green, Color.Blue, Color.Yellow, Color.Gray, Color.Orange }; var lineBatch = MyLinesRenderer.CreateBatch(); Vector3 *tmpFloatVertices = stackalloc Vector3[8]; for (int c = 0; c < m_initializedShadowCascadesCount; c++) { if (MyRenderProxy.Settings.ShadowCascadeFrozen[c]) { var inverseViewProj = MatrixD.Invert(cascadesMatrices[c]); Vector3D.Transform(m_cornersCS, ref inverseViewProj, verticesWS); for (int vertexIndex = 0; vertexIndex < 8; ++vertexIndex) { verticesWS[vertexIndex] += MyEnvironment.CameraPosition; } for (int vertexIndex = 0; vertexIndex < 8; ++vertexIndex) { tmpFloatVertices[vertexIndex] = verticesWS[vertexIndex]; } MyPrimitivesRenderer.Draw6FacedConvexZ(tmpFloatVertices, cascadeColor[c], 0.2f); lineBatch.Add6FacedConvex(tmpFloatVertices, Color.Pink); } } lineBatch.Commit(); }
private unsafe void AddGridVerticesInsideOBB(MyCubeGrid grid, MyOrientedBoundingBoxD obb) { BoundingBoxD aABB = obb.GetAABB(); using (HashSet <MyGroups <MyCubeGrid, MyGridLogicalGroupData> .Node> .Enumerator enumerator = MyCubeGridGroups.Static.Logical.GetGroup(grid).Nodes.GetEnumerator()) { while (enumerator.MoveNext()) { MyCubeGrid nodeData = enumerator.Current.NodeData; this.m_rdPathfinding.AddToTrackedGrids(nodeData); MatrixD worldMatrix = nodeData.WorldMatrix; MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation -= this.m_center; MatrixD xd3 = MatrixD.Transform(worldMatrix, this.rdWorldQuaternion); if (MyPerGameSettings.Game == GameEnum.SE_GAME) { BoundingBoxD xd4 = aABB.TransformFast(nodeData.PositionComp.WorldMatrixNormalizedInv); Vector3I vectori = new Vector3I((int)Math.Round(xd4.Min.X), (int)Math.Round(xd4.Min.Y), (int)Math.Round(xd4.Min.Z)); Vector3I vectori2 = new Vector3I((int)Math.Round(xd4.Max.X), (int)Math.Round(xd4.Max.Y), (int)Math.Round(xd4.Max.Z)); vectori = Vector3I.Min(vectori, vectori2); vectori2 = Vector3I.Max(vectori, vectori2); if (nodeData.Physics != null) { using (MyUtils.ReuseCollection <HkShape>(ref m_tmpShapes)) { MyGridShape shape = nodeData.Physics.Shape; using (MyGridShape.NativeShapeLock.AcquireSharedUsing()) { shape.GetShapesInInterval(vectori, vectori2, m_tmpShapes); foreach (HkShape shape2 in m_tmpShapes) { this.AddPhysicalShape(shape2, (Matrix)xd3); } } } } } } } }
public static unsafe bool CutOutSphereFast(MyVoxelBase voxelMap, ref Vector3D center, float radius, out Vector3I cacheMin, out Vector3I cacheMax, bool notifyChanged) { Vector3I vectori; Vector3I vectori2; MatrixD worldMatrixInvScaled = voxelMap.PositionComp.WorldMatrixInvScaled; MatrixD *xdPtr1 = (MatrixD *)ref worldMatrixInvScaled; xdPtr1.Translation += voxelMap.SizeInMetresHalf; BoundingBoxD shapeAabb = BoundingBoxD.CreateFromSphere(new BoundingSphereD(center, (double)radius)).TransformFast(worldMatrixInvScaled); ComputeShapeBounds(voxelMap, ref shapeAabb, Vector3.Zero, voxelMap.Storage.Size, out vectori, out vectori2); cacheMin = vectori - 1; cacheMax = (Vector3I)(vectori2 + 1); voxelMap.Storage.ClampVoxelCoord(ref cacheMin, 1); voxelMap.Storage.ClampVoxelCoord(ref cacheMax, 1); CutOutSphere voxelOperator = new CutOutSphere { RadSq = radius * radius, Center = Vector3D.Transform(center, worldMatrixInvScaled) - (cacheMin - voxelMap.StorageMin) }; voxelMap.Storage.ExecuteOperationFast <CutOutSphere>(ref voxelOperator, MyStorageDataTypeFlags.Content, ref cacheMin, ref cacheMax, notifyChanged); return(voxelOperator.Changed); }
protected override unsafe void UpdateGridTransformations() { MatrixD worldMatrix = this.m_projector.WorldMatrix; if ((this.m_firstUpdateAfterNewBlueprint || ((this.m_oldProjectorRotation != this.m_projector.ProjectionRotation) || ((this.m_oldProjectorOffset != this.m_projector.ProjectionOffset) || !this.m_oldProjectorMatrix.EqualsFast(ref worldMatrix, 0.0001)))) || (this.m_projector.Scale != this.m_oldScale)) { this.m_firstUpdateAfterNewBlueprint = false; this.m_oldProjectorRotation = this.m_projector.ProjectionRotation; this.m_oldProjectorMatrix = worldMatrix; this.m_oldProjectorOffset = this.m_projector.ProjectionOffset; this.m_oldScale = this.m_projector.Scale; worldMatrix = Matrix.Multiply(Matrix.CreateFromQuaternion(this.m_projector.ProjectionRotationQuaternion), (Matrix)worldMatrix); float scale = this.m_projector.Scale; for (int i = 0; i < base.PreviewGrids.Count; i++) { Vector3D zero = Vector3D.Zero; if (!this.m_projector.AllowScaling) { Vector3D translation; if (base.PreviewGrids[i].CubeBlocks.Count <= 0) { translation = worldMatrix.Translation; } else { MySlimBlock block = base.PreviewGrids[i].CubeBlocks.First <MySlimBlock>(); translation = MyCubeGrid.GridIntegerToWorld(base.PreviewGrids[i].GridSize, block.Position, worldMatrix); } zero = (translation - this.m_projector.WorldMatrix.Translation) * scale; } MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation -= zero + Vector3D.Transform((Vector3D)this.m_projector.GetProjectionTranslationOffset(), this.m_projector.WorldMatrix.GetOrientation()); base.PreviewGrids[i].PositionComp.Scale = new float?(scale); base.PreviewGrids[i].PositionComp.SetWorldMatrix(worldMatrix, null, false, true, true, true, false, false); } } }
public static unsafe void DrawCollisionShape(HkShape shape, MatrixD worldMatrix, float alpha, ref int shapeIndex, string customText = null, bool isPhantom = false) { Color color = GetShapeColor(shape.ShapeType, ref shapeIndex, isPhantom); if (isPhantom) { alpha *= alpha; } color.A = (byte)(alpha * 255f); bool smooth = true; float num = 0.02f; float num2 = 1.035f; bool flag2 = false; HkShapeType shapeType = shape.ShapeType; switch (shapeType) { case HkShapeType.Sphere: { float radius = ((HkSphereShape)shape).Radius; MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, alpha, true, smooth, true, false); if (isPhantom) { MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1f, true, false, true, false); MyRenderProxy.DebugDrawSphere(worldMatrix.Translation, radius, color, 1f, true, false, false, false); } flag2 = true; goto TR_0003; } case HkShapeType.Cylinder: { HkCylinderShape shape4 = (HkCylinderShape)shape; MyRenderProxy.DebugDrawCylinder(worldMatrix, shape4.VertexA, shape4.VertexB, shape4.Radius, color, alpha, true, smooth, false); flag2 = true; goto TR_0003; } case HkShapeType.Triangle: { HkTriangleShape shape12 = (HkTriangleShape)shape; MyRenderProxy.DebugDrawTriangle(shape12.Pt0, shape12.Pt1, shape12.Pt2, Color.Green, false, false, false); goto TR_0003; } case HkShapeType.Box: { HkBoxShape shape5 = (HkBoxShape)shape; MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, alpha, true, smooth, true, false); if (isPhantom) { MyRenderProxy.DebugDrawOBB(Matrix.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, 1f, true, false, true, false); MyRenderProxy.DebugDrawOBB(Matrix.CreateScale((shape5.HalfExtents * 2f) + new Vector3(num)) * worldMatrix, color, 1f, true, false, false, false); } flag2 = true; goto TR_0003; } case HkShapeType.Capsule: { HkCapsuleShape shape3 = (HkCapsuleShape)shape; MyRenderProxy.DebugDrawCapsule(Vector3.Transform(shape3.VertexA, worldMatrix), Vector3.Transform(shape3.VertexB, worldMatrix), shape3.Radius, color, true, smooth, false); flag2 = true; goto TR_0003; } case HkShapeType.ConvexVertices: { Vector3 vector; ((HkConvexVerticesShape)shape).GetGeometry(DebugGeometry, out vector); Vector3D vectord2 = Vector3D.Transform(vector, worldMatrix.GetOrientation()); MatrixD xd = worldMatrix; xd = MatrixD.CreateScale((double)num2) * xd; MatrixD *xdPtr1 = (MatrixD *)ref xd; xdPtr1.Translation -= vectord2 * (num2 - 1f); DrawGeometry(DebugGeometry, xd, color, true, true); flag2 = true; goto TR_0003; } case HkShapeType.TriSampledHeightFieldCollection: case HkShapeType.TriSampledHeightFieldBvTree: case HkShapeType.SampledHeightField: case HkShapeType.ExtendedMesh: case HkShapeType.Transform: case HkShapeType.CompressedMesh: case HkShapeType.Collection: case HkShapeType.User0: case HkShapeType.User1: case HkShapeType.User2: goto TR_0003; case HkShapeType.List: { HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator(); while (iterator.IsValid) { DrawCollisionShape(iterator.CurrentValue, worldMatrix, alpha, ref shapeIndex, customText, false); iterator.Next(); } goto TR_0003; } case HkShapeType.Mopp: DrawCollisionShape((HkShape)((HkMoppBvTreeShape)shape).ShapeCollection, worldMatrix, alpha, ref shapeIndex, customText, false); goto TR_0003; case HkShapeType.ConvexTranslate: { HkConvexTranslateShape shape7 = (HkConvexTranslateShape)shape; DrawCollisionShape((HkShape)shape7.ChildShape, Matrix.CreateTranslation(shape7.Translation) * worldMatrix, alpha, ref shapeIndex, customText, false); goto TR_0003; } case HkShapeType.ConvexTransform: { HkConvexTransformShape shape8 = (HkConvexTransformShape)shape; DrawCollisionShape((HkShape)shape8.ChildShape, shape8.Transform * worldMatrix, alpha, ref shapeIndex, customText, false); goto TR_0003; } case HkShapeType.StaticCompound: { HkStaticCompoundShape shape11 = (HkStaticCompoundShape)shape; if (DebugDrawFlattenHierarchy) { HkShapeContainerIterator iterator2 = shape11.GetIterator(); while (iterator2.IsValid) { if (shape11.IsShapeKeyEnabled(iterator2.CurrentShapeKey)) { object[] objArray1 = new object[4]; object[] objArray2 = new object[4]; objArray2[0] = customText ?? string.Empty; object[] local2 = objArray2; local2[1] = "-"; local2[2] = iterator2.CurrentShapeKey; local2[3] = "-"; string str = string.Concat(local2); DrawCollisionShape(iterator2.CurrentValue, worldMatrix, alpha, ref shapeIndex, str, false); } iterator2.Next(); } } else { for (int i = 0; i < shape11.InstanceCount; i++) { string str2; bool flag3 = shape11.IsInstanceEnabled(i); if (flag3) { object[] objArray3 = new object[4]; object[] objArray4 = new object[4]; objArray4[0] = customText ?? string.Empty; object[] local4 = objArray4; local4[1] = "<"; local4[2] = i; local4[3] = ">"; str2 = string.Concat(local4); } else { object[] objArray5 = new object[4]; object[] objArray6 = new object[4]; objArray6[0] = customText ?? string.Empty; object[] local6 = objArray6; local6[1] = "("; local6[2] = i; local6[3] = ")"; str2 = string.Concat(local6); } if (flag3) { DrawCollisionShape(shape11.GetInstance(i), shape11.GetInstanceTransform(i) * worldMatrix, alpha, ref shapeIndex, str2, false); } } } goto TR_0003; } case HkShapeType.BvCompressedMesh: break; case HkShapeType.BvTree: { HkGridShape shape13 = (HkGridShape)shape; if (HkGridShapeCellDebugDraw && !shape13.Base.IsZero) { float cellSize = shape13.CellSize; int shapeInfoCount = shape13.GetShapeInfoCount(); for (int i = 0; i < shapeInfoCount; i++) { try { Vector3S vectors; Vector3S vectors2; shape13.GetShapeInfo(i, out vectors, out vectors2, m_tmpShapeList); Vector3 position = (Vector3)(((vectors2 * cellSize) + (vectors * cellSize)) / 2f); Color color2 = color; if (vectors == vectors2) { color2 = new Color(1f, 0.2f, 0.1f); } MyRenderProxy.DebugDrawOBB((Matrix.CreateScale((((vectors2 * cellSize) - (vectors * cellSize)) + (Vector3.One * cellSize)) + new Vector3(num)) * Matrix.CreateTranslation(position)) * worldMatrix, color2, alpha, true, smooth, true, false); } finally { m_tmpShapeList.Clear(); } } } else { MyRenderMessageDebugDrawTriangles msgInterface = MyRenderProxy.PrepareDebugDrawTriangles(); try { using (HkShapeBuffer buffer = new HkShapeBuffer()) { HkShapeContainerIterator iterator3 = ((HkBvTreeShape)shape).GetIterator(buffer); while (iterator3.IsValid) { HkShape currentValue = iterator3.CurrentValue; if (currentValue.ShapeType != HkShapeType.Triangle) { DrawCollisionShape(currentValue, worldMatrix, alpha, ref shapeIndex, null, false); } else { HkTriangleShape shape17 = (HkTriangleShape)currentValue; msgInterface.AddTriangle(shape17.Pt0, shape17.Pt1, shape17.Pt2); } iterator3.Next(); } goto TR_0003; } } finally { msgInterface.Color = color; MyRenderProxy.DebugDrawTriangles(msgInterface, new MatrixD?(worldMatrix), false, false, false, false); } break; } goto TR_0003; } default: if (shapeType == HkShapeType.Bv) { HkBvShape shape19 = (HkBvShape)shape; DrawCollisionShape(shape19.BoundingVolumeShape, worldMatrix, alpha, ref shapeIndex, null, true); DrawCollisionShape(shape19.ChildShape, worldMatrix, alpha, ref shapeIndex, null, false); } else if (shapeType == HkShapeType.PhantomCallback) { MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, "Phantom", Color.Green, 0.75f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false); } goto TR_0003; } if (MyDebugDrawSettings.DEBUG_DRAW_TRIANGLE_PHYSICS) { ((HkBvCompressedMeshShape)shape).GetGeometry(DebugGeometry); DrawGeometry(DebugGeometry, worldMatrix, Color.Green, false, false); flag2 = true; } TR_0003: if (flag2 && (customText != null)) { color.A = 0xff; MyRenderProxy.DebugDrawText3D(worldMatrix.Translation, customText, color, 0.8f, false, MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_TOP, -1, false); } }
private unsafe void DebugDrawShape(string blockName, HkShape shape, MatrixD worldMatrix) { float num = 1.05f; float num2 = 0.02f; if (MyPerGameSettings.Game == GameEnum.SE_GAME) { num2 = 0.1f; } switch (shape.ShapeType) { case HkShapeType.Box: MyRenderProxy.DebugDrawOBB(MatrixD.CreateScale((((HkBoxShape)shape).HalfExtents * 2f) + new Vector3(num2)) * worldMatrix, Color.Red, 0f, true, false, true, false); return; case HkShapeType.Capsule: case HkShapeType.TriSampledHeightFieldCollection: case HkShapeType.TriSampledHeightFieldBvTree: break; case HkShapeType.ConvexVertices: { GeometryCenterPair pair; HkConvexVerticesShape shape7 = (HkConvexVerticesShape)shape; if (!this.m_cachedGeometry.TryGetValue(blockName, out pair)) { Vector3 vector; HkGeometry geometry = new HkGeometry(); shape7.GetGeometry(geometry, out vector); GeometryCenterPair pair1 = new GeometryCenterPair(); pair1.Geometry = geometry; pair1.Center = vector; pair = pair1; if (!string.IsNullOrEmpty(blockName)) { this.m_cachedGeometry.Add(blockName, pair); } } Vector3D vectord = Vector3D.Transform(pair.Center, worldMatrix.GetOrientation()); MatrixD xd = worldMatrix; xd = MatrixD.CreateScale((double)num) * xd; MatrixD *xdPtr1 = (MatrixD *)ref xd; xdPtr1.Translation -= vectord * (num - 1f); this.DrawGeometry(pair.Geometry, xd, Color.Olive, false, false); break; } case HkShapeType.List: { HkShapeContainerIterator iterator = ((HkListShape)shape).GetIterator(); int num3 = 0; while (iterator.IsValid) { num3++; this.DebugDrawShape(blockName + num3, iterator.CurrentValue, worldMatrix); iterator.Next(); } return; } case HkShapeType.Mopp: { HkMoppBvTreeShape shape4 = (HkMoppBvTreeShape)shape; this.DebugDrawShape(blockName, (HkShape)shape4.ShapeCollection, worldMatrix); return; } case HkShapeType.ConvexTranslate: { HkConvexTranslateShape shape6 = (HkConvexTranslateShape)shape; this.DebugDrawShape(blockName, (HkShape)shape6.ChildShape, Matrix.CreateTranslation(shape6.Translation) * worldMatrix); return; } case HkShapeType.ConvexTransform: { HkConvexTransformShape shape5 = (HkConvexTransformShape)shape; this.DebugDrawShape(blockName, (HkShape)shape5.ChildShape, shape5.Transform * worldMatrix); return; } default: return; } }
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; }
/// <summary> /// Creates shadowmap queries and appends them to the provided list /// </summary> internal unsafe void PrepareQueries(List <MyShadowmapQuery> appendShadowmapQueries) { Debug.Assert(appendShadowmapQueries != null, "Shadowmap query list cannot be null!"); if (!MyRenderProxy.Settings.EnableShadows || !MyRender11.DebugOverrides.Shadows) { return; } MyImmediateRC.RC.BeginProfilingBlock("PrepareCascades"); MyImmediateRC.RC.DeviceContext.CopyResource(m_cascadeShadowmapArray.Resource, m_cascadeShadowmapBackup.Resource); bool stabilize = true; const float DirectionDifferenceThreshold = 0.0175f; float shadowChangeDelayMultiplier = 180; for (int cascadeIndex = 0; cascadeIndex < m_initializedShadowCascadesCount; ++cascadeIndex) { ++m_shadowCascadeFramesSinceLightUpdate[cascadeIndex]; if (m_shadowCascadeFramesSinceLightUpdate[cascadeIndex] > cascadeIndex * shadowChangeDelayMultiplier || MyRender11.Environment.DirectionalLightDir.Dot(m_shadowCascadeLightDirections[cascadeIndex]) < (1 - DirectionDifferenceThreshold)) { m_shadowCascadeLightDirections[cascadeIndex] = MyRender11.Environment.DirectionalLightDir; m_shadowCascadeFramesSinceLightUpdate[cascadeIndex] = 0; } } var globalMatrix = CreateGlobalMatrix(); float cascadesNearClip = 1f; float backOffset = MyRender11.RenderSettings.ShadowQuality.BackOffset(); float shadowmapSize = MyRender11.RenderSettings.ShadowQuality.ShadowCascadeResolution(); for (int cascadeIndex = 0; cascadeIndex < ShadowCascadeSplitDepths.Length; ++cascadeIndex) { ShadowCascadeSplitDepths[cascadeIndex] = MyRender11.RenderSettings.ShadowQuality.ShadowCascadeSplit(cascadeIndex); } double unitWidth = 1.0 / MyRender11.Environment.Projection.M11; double unitHeight = 1.0 / MyRender11.Environment.Projection.M22; Vector3D *untransformedVertices = stackalloc Vector3D[4]; untransformedVertices[0] = new Vector3D(-unitWidth, -unitHeight, -1); untransformedVertices[1] = new Vector3D(-unitWidth, unitHeight, -1); untransformedVertices[2] = new Vector3D(unitWidth, unitHeight, -1); untransformedVertices[3] = new Vector3D(unitWidth, -unitHeight, -1); MatrixD *cascadesMatrices = stackalloc MatrixD[MaxShadowCascades]; for (int cascadeIndex = 0; cascadeIndex < m_initializedShadowCascadesCount; ++cascadeIndex) { for (int vertexIndex = 0; vertexIndex < 4; ++vertexIndex) { m_frustumVerticesWS[vertexIndex] = untransformedVertices[vertexIndex] * ShadowCascadeSplitDepths[cascadeIndex]; m_frustumVerticesWS[vertexIndex + 4] = untransformedVertices[vertexIndex] * ShadowCascadeSplitDepths[cascadeIndex + 1]; } bool skipCascade = MyCommon.FrameCounter % (ulong)m_shadowCascadeUpdateIntervals[cascadeIndex].Item1 != (ulong)m_shadowCascadeUpdateIntervals[cascadeIndex].Item2; bool forceUpdate = ShadowCascadeSplitDepths[cascadeIndex] > 1000f && Vector3D.DistanceSquared(m_shadowCascadeUpdatePositions[cascadeIndex], MyRender11.Environment.CameraPosition) > Math.Pow(1000, 2); // if (!forceUpdate && skipCascade && !MyRenderProxy.Settings.UpdateCascadesEveryFrame) { continue; } if (MyRenderProxy.Settings.ShadowCascadeFrozen[cascadeIndex]) { continue; } m_shadowCascadeUpdatePositions[cascadeIndex] = MyRender11.Environment.CameraPosition; MatrixD invView = MyRender11.Environment.InvView; Vector3D.Transform(m_frustumVerticesWS, ref invView, m_frustumVerticesWS); var bSphere = BoundingSphereD.CreateFromPoints(m_frustumVerticesWS); if (stabilize) { bSphere.Center = bSphere.Center.Round(); bSphere.Radius = Math.Ceiling(bSphere.Radius); } var shadowCameraPosWS = bSphere.Center + m_shadowCascadeLightDirections[cascadeIndex] * (bSphere.Radius + cascadesNearClip); var lightView = VRageMath.MatrixD.CreateLookAt(shadowCameraPosWS, shadowCameraPosWS - m_shadowCascadeLightDirections[cascadeIndex], Math.Abs(Vector3.UnitY.Dot(m_shadowCascadeLightDirections[cascadeIndex])) < 0.99f ? Vector3.UnitY : Vector3.UnitX); var offset = bSphere.Radius + cascadesNearClip + backOffset; Vector3D vMin = new Vector3D(-bSphere.Radius, -bSphere.Radius, cascadesNearClip); Vector3D vMax = new Vector3D(bSphere.Radius, bSphere.Radius, offset + bSphere.Radius); var cascadeProjection = MatrixD.CreateOrthographicOffCenter(vMin.X, vMax.X, vMin.Y, vMax.Y, vMax.Z, vMin.Z); cascadesMatrices[cascadeIndex] = lightView * cascadeProjection; var transformed = Vector3D.Transform(Vector3D.Zero, cascadesMatrices[cascadeIndex]) * shadowmapSize / 2; var smOffset = (transformed.Round() - transformed) * 2 / shadowmapSize; // stabilize 1st cascade only if (stabilize) { cascadeProjection.M41 += smOffset.X; cascadeProjection.M42 += smOffset.Y; cascadesMatrices[cascadeIndex] = lightView * cascadeProjection; } var inverseCascadeMatrix = MatrixD.Invert(cascadesMatrices[cascadeIndex]); var corner0 = Vector3D.Transform(Vector3D.Transform(new Vector3D(-1, -1, 0), inverseCascadeMatrix), globalMatrix); var corner1 = Vector3D.Transform(Vector3D.Transform(new Vector3D(1, 1, 1), inverseCascadeMatrix), globalMatrix); var diameter = corner1 - corner0; var cascadeScale = 1f / diameter; ShadowCascadeScales[cascadeIndex] = new Vector4D(cascadeScale, 0); var query = new MyShadowmapQuery(); query.DepthBuffer = m_cascadeShadowmapArray.SubresourceDsv(cascadeIndex); query.Viewport = new MyViewport(shadowmapSize, shadowmapSize); m_cascadeInfo[cascadeIndex].WorldCameraOffsetPosition = MyRender11.Environment.CameraPosition; m_cascadeInfo[cascadeIndex].WorldToProjection = cascadesMatrices[cascadeIndex]; // todo: skip translation, recalculate matrix in local space, keep world space matrix only for bounding frustum m_cascadeInfo[cascadeIndex].LocalToProjection = Matrix.CreateTranslation(MyRender11.Environment.CameraPosition) * cascadesMatrices[cascadeIndex]; query.ProjectionInfo = m_cascadeInfo[cascadeIndex]; query.ProjectionDir = m_shadowCascadeLightDirections[cascadeIndex]; query.ProjectionFactor = (float)(shadowmapSize * shadowmapSize / (bSphere.Radius * bSphere.Radius * 4)); query.QueryType = MyFrustumEnum.ShadowCascade; query.CascadeIndex = cascadeIndex; appendShadowmapQueries.Add(query); } DebugProcessFrustrums(); FillConstantBuffer(m_csmConstants); MyImmediateRC.RC.EndProfilingBlock(); }
public unsafe void UpdateRagdollPosition() { MatrixD worldMatrix; if (this.Ragdoll == null) { return; } if (!this.m_inicialized) { return; } else if (this.IsActive) { if (this.IsPartiallySimulated || this.IsKeyFramed) { if (!this.m_character.IsDead) { worldMatrix = this.m_character.Physics.GetWorldMatrix(); MatrixD *xdPtr2 = (MatrixD *)ref worldMatrix; xdPtr2.Translation = this.m_character.Physics.WorldToCluster(worldMatrix.Translation); } else { worldMatrix = this.m_character.WorldMatrix; MatrixD *xdPtr1 = (MatrixD *)ref worldMatrix; xdPtr1.Translation = this.m_character.Physics.WorldToCluster(worldMatrix.Translation); if (MyFakes.ENABLE_RAGDOLL_DEBUG) { } } if (worldMatrix.IsValid() && (worldMatrix != MatrixD.Zero)) { int num1; double num = (worldMatrix.Translation - this.Ragdoll.WorldMatrix.Translation).LengthSquared(); double num2 = (worldMatrix.Forward - this.Ragdoll.WorldMatrix.Forward).LengthSquared(); double num3 = (worldMatrix.Up - this.Ragdoll.WorldMatrix.Up).LengthSquared(); if ((num > 1.0000000116860974E-07) || (num2 > 1.0000000116860974E-07)) { num1 = 1; } else { num1 = (int)(num3 > 1.0000000116860974E-07); } this.m_changed = (bool)num1; if (num > 10.0) { goto TR_0005; } else if (!this.m_character.m_positionResetFromServer) { if (this.m_changed) { if (MyFakes.ENABLE_RAGDOLL_DEBUG) { MyLog.Default.WriteLine("MyRagdollMapper.UpdateRagdollPosition"); } this.Ragdoll.SetWorldMatrix(worldMatrix, true, false); } } else { goto TR_0005; } } } return; } else { return; } TR_0005: this.m_character.m_positionResetFromServer = false; if (MyFakes.ENABLE_RAGDOLL_DEBUG) { MyLog.Default.WriteLine("MyRagdollMapper.UpdateRagdollPosition"); } this.Ragdoll.SetWorldMatrix(worldMatrix); bool flag1 = MyFakes.ENABLE_RAGDOLL_DEBUG; }
public static unsafe void CutOutShapeWithProperties(MyVoxelBase voxelMap, MyShape shape, out float voxelsCountInPercent, out MyVoxelMaterialDefinition voxelMaterial, Dictionary <MyVoxelMaterialDefinition, int> exactCutOutMaterials = null, bool updateSync = false, bool onlyCheck = false, bool applyDamageMaterial = false, bool onlyApplyMaterial = false, bool skipCache = false) { if ((!MySession.Static.EnableVoxelDestruction || ((voxelMap == null) || (voxelMap.Storage == null))) || (shape == null)) { voxelsCountInPercent = 0f; voxelMaterial = null; } else { Vector3I vectori3; Vector3I vectori4; Vector3I maxCorner; Vector3I minCorner; int num = 0; int num2 = 0; MatrixD transformation = shape.Transformation; MatrixD xd2 = transformation * voxelMap.PositionComp.WorldMatrixInvScaled; MatrixD *xdPtr1 = (MatrixD *)ref xd2; xdPtr1.Translation += voxelMap.SizeInMetresHalf; shape.Transformation = xd2; BoundingBoxD worldBoundaries = shape.GetWorldBoundaries(); ComputeShapeBounds(voxelMap, ref worldBoundaries, Vector3.Zero, voxelMap.Storage.Size, out minCorner, out maxCorner); bool flag = (exactCutOutMaterials != null) | applyDamageMaterial; Vector3I voxelCoord = minCorner - 1; Vector3I vectori2 = (Vector3I)(maxCorner + 1); voxelMap.Storage.ClampVoxelCoord(ref voxelCoord, 1); voxelMap.Storage.ClampVoxelCoord(ref vectori2, 1); if (m_cache == null) { m_cache = new MyStorageData(MyStorageDataTypeFlags.All); } m_cache.Resize(voxelCoord, vectori2); MyVoxelRequestFlags requestFlags = (skipCache ? ((MyVoxelRequestFlags)0) : MyVoxelRequestFlags.AdviseCache) | (flag ? MyVoxelRequestFlags.ConsiderContent : ((MyVoxelRequestFlags)0)); voxelMap.Storage.ReadRange(m_cache, flag ? MyStorageDataTypeFlags.All : MyStorageDataTypeFlags.Content, 0, voxelCoord, vectori2, ref requestFlags); if (exactCutOutMaterials != null) { vectori3 = (Vector3I)(m_cache.Size3D / 2); voxelMaterial = MyDefinitionManager.Static.GetVoxelMaterialDefinition(m_cache.Material(ref vectori3)); } else { vectori3 = (Vector3I)((voxelCoord + vectori2) / 2); voxelMaterial = voxelMap.Storage.GetMaterialAt(ref vectori3); } MyVoxelMaterialDefinition key = null; vectori4.X = minCorner.X; while (vectori4.X <= maxCorner.X) { vectori4.Y = minCorner.Y; while (true) { if (vectori4.Y > maxCorner.Y) { int *numPtr3 = (int *)ref vectori4.X; numPtr3[0]++; break; } vectori4.Z = minCorner.Z; while (true) { if (vectori4.Z > maxCorner.Z) { int *numPtr2 = (int *)ref vectori4.Y; numPtr2[0]++; break; } Vector3I p = vectori4 - voxelCoord; int linearIdx = m_cache.ComputeLinear(ref p); byte num4 = m_cache.Content(linearIdx); if (num4 != 0) { Vector3D voxelPosition = (Vector3D)((vectori4 - voxelMap.StorageMin) * 1.0); float volume = shape.GetVolume(ref voxelPosition); if (volume != 0f) { int num7 = Math.Max(num4 - ((int)(volume * 255f)), 0); int num8 = num4 - num7; if ((num4 / 10) != (num7 / 10)) { if (!onlyCheck && !onlyApplyMaterial) { m_cache.Content(linearIdx, (byte)num7); } num += num4; num2 += num8; byte materialIndex = m_cache.Material(linearIdx); if (num7 == 0) { m_cache.Material(linearIdx, 0xff); } if (materialIndex != 0xff) { if (flag) { key = MyDefinitionManager.Static.GetVoxelMaterialDefinition(materialIndex); } if (exactCutOutMaterials != null) { int num10; exactCutOutMaterials.TryGetValue(key, out num10); exactCutOutMaterials[key] = num10 + (MyFakes.ENABLE_REMOVED_VOXEL_CONTENT_HACK ? ((int)(num8 * 3.9f)) : num8); } } } } } int *numPtr1 = (int *)ref vectori4.Z; numPtr1[0]++; } } } if ((((num2 > 0) & updateSync) && Sync.IsServer) && !onlyCheck) { shape.SendDrillCutOutRequest(voxelMap, applyDamageMaterial); } if ((num2 > 0) && !onlyCheck) { RemoveSmallVoxelsUsingChachedVoxels(); MyStorageDataTypeFlags all = MyStorageDataTypeFlags.All; if (MyFakes.LOG_NAVMESH_GENERATION && (MyAIComponent.Static.Pathfinding != null)) { MyAIComponent.Static.Pathfinding.GetPathfindingLog().LogStorageWrite(voxelMap, m_cache, all, voxelCoord, vectori2); } voxelMap.Storage.WriteRange(m_cache, all, voxelCoord, vectori2, false, skipCache); } voxelsCountInPercent = (num > 0f) ? (((float)num2) / ((float)num)) : 0f; if (num2 > 0) { BoundingBoxD cutOutBox = shape.GetWorldBoundaries(); MySandboxGame.Static.Invoke(delegate { if (voxelMap.Storage != null) { voxelMap.Storage.NotifyChanged(minCorner, maxCorner, MyStorageDataTypeFlags.All); NotifyVoxelChanged(MyVoxelBase.OperationType.Cut, voxelMap, ref cutOutBox); } }, "CutOutShapeWithProperties notify"); } shape.Transformation = transformation; } }
public unsafe void Update(MyShadowVolume[] volumes, ref MyShadowsSettings settings, float shadowmapResolution) { bool stabilize = true; float cascadesNearClip = 1f; float shadowChangeDelayMultiplier = 180; const float directionDifferenceThreshold = 0.0175f; float backOffset = MyRender11.RenderSettings.ShadowQuality.BackOffset(); float shadowmapSize = MyRender11.RenderSettings.ShadowQuality.ShadowCascadeResolution(); Array.Resize(ref m_shadowCascadeSplitDepths, volumes.Length + 1); Array.Resize(ref m_shadowCascadeUpdatePositions, volumes.Length); Array.Resize(ref m_shadowCascadeFramesSinceLightUpdate, volumes.Length); Array.Resize(ref m_shadowCascadeLightDirections, volumes.Length); for (int cascadeIndex = 0; cascadeIndex < volumes.Length; ++cascadeIndex) { m_shadowCascadeSplitDepths[cascadeIndex] = MyRender11.RenderSettings.ShadowQuality.ShadowCascadeSplit(cascadeIndex); } double unitWidth = 1.0 / MyRender11.Environment.Matrices.Projection.M11; double unitHeight = 1.0 / MyRender11.Environment.Matrices.Projection.M22; Vector3D *untransformedVertices = stackalloc Vector3D[4]; untransformedVertices[0] = new Vector3D(-unitWidth, -unitHeight, -1); untransformedVertices[1] = new Vector3D(-unitWidth, unitHeight, -1); untransformedVertices[2] = new Vector3D(unitWidth, unitHeight, -1); untransformedVertices[3] = new Vector3D(unitWidth, -unitHeight, -1); MatrixD *cascadesMatrices = stackalloc MatrixD[volumes.Length]; for (int cascadeIndex = 0; cascadeIndex < volumes.Length; ++cascadeIndex) { ++m_shadowCascadeFramesSinceLightUpdate[cascadeIndex]; if (m_shadowCascadeFramesSinceLightUpdate[cascadeIndex] > cascadeIndex * shadowChangeDelayMultiplier || MyRender11.Environment.Data.EnvironmentLight.SunLightDirection.Dot(m_shadowCascadeLightDirections[cascadeIndex]) < (1 - directionDifferenceThreshold)) { m_shadowCascadeLightDirections[cascadeIndex] = MyRender11.Environment.Data.EnvironmentLight.SunLightDirection; m_shadowCascadeFramesSinceLightUpdate[cascadeIndex] = 0; } } for (int cascadeIndex = 0; cascadeIndex < volumes.Length; ++cascadeIndex) { for (int vertexIndex = 0; vertexIndex < 4; ++vertexIndex) { m_frustumVerticesWS[vertexIndex] = untransformedVertices[vertexIndex] * m_shadowCascadeSplitDepths[cascadeIndex]; m_frustumVerticesWS[vertexIndex + 4] = untransformedVertices[vertexIndex] * m_shadowCascadeSplitDepths[cascadeIndex + 1]; } bool skipCascade = MyCommon.FrameCounter % (ulong)m_shadowCascadeUpdateIntervals[cascadeIndex].Item1 != (ulong)m_shadowCascadeUpdateIntervals[cascadeIndex].Item2; bool forceUpdate = m_shadowCascadeSplitDepths[cascadeIndex] > 1000f && Vector3D.DistanceSquared(m_shadowCascadeUpdatePositions[cascadeIndex], MyRender11.Environment.Matrices.CameraPosition) > Math.Pow(1000, 2); // if (!forceUpdate && skipCascade && !settings.Data.UpdateCascadesEveryFrame) { continue; } //if (settings.ShadowCascadeFrozen[cascadeIndex]) // continue; m_shadowCascadeUpdatePositions[cascadeIndex] = MyRender11.Environment.Matrices.CameraPosition; MatrixD invView = MyRender11.Environment.Matrices.InvView; Vector3D.Transform(m_frustumVerticesWS, ref invView, m_frustumVerticesWS); var bSphere = BoundingSphereD.CreateFromPoints(m_frustumVerticesWS); if (stabilize) { bSphere.Center = bSphere.Center.Round(); bSphere.Radius = Math.Ceiling(bSphere.Radius); } var shadowCameraPosWS = bSphere.Center + m_shadowCascadeLightDirections[cascadeIndex] * (bSphere.Radius + cascadesNearClip); var lightView = VRageMath.MatrixD.CreateLookAt(shadowCameraPosWS, shadowCameraPosWS - m_shadowCascadeLightDirections[cascadeIndex], Math.Abs(Vector3.UnitY.Dot(m_shadowCascadeLightDirections[cascadeIndex])) < 0.99f ? Vector3.UnitY : Vector3.UnitX); var offset = bSphere.Radius + cascadesNearClip + backOffset; Vector3D vMin = new Vector3D(-bSphere.Radius, -bSphere.Radius, cascadesNearClip); Vector3D vMax = new Vector3D(bSphere.Radius, bSphere.Radius, offset + bSphere.Radius); var cascadeProjection = MatrixD.CreateOrthographicOffCenter(vMin.X, vMax.X, vMin.Y, vMax.Y, vMax.Z, vMin.Z); cascadesMatrices[cascadeIndex] = lightView * cascadeProjection; var transformed = Vector3D.Transform(Vector3D.Zero, cascadesMatrices[cascadeIndex]) * shadowmapSize / 2; var smOffset = (transformed.Round() - transformed) * 2 / shadowmapSize; // stabilize 1st cascade only if (stabilize) { cascadeProjection.M41 += smOffset.X; cascadeProjection.M42 += smOffset.Y; cascadesMatrices[cascadeIndex] = lightView * cascadeProjection; } Matrix matrixTranslation = Matrix.CreateTranslation(MyRender11.Environment.Matrices.CameraPosition); cascadesMatrices[cascadeIndex] = matrixTranslation * cascadesMatrices[cascadeIndex]; volumes[cascadeIndex].SetMatrixWorldAt0ToShadow(cascadesMatrices[cascadeIndex]); } }
public unsafe void MoveAndRotate(ref Vector3 moveIndicator, ref Vector2 rotationIndicator, float roll, bool canRotate) { MyCharacterProxy characterProxy = base.Character.Physics.CharacterProxy; this.ThrustComp.ControlThrust = Vector3.Zero; base.Character.SwitchAnimation(MyCharacterMovementEnum.Flying, true); base.Character.SetCurrentMovementState(MyCharacterMovementEnum.Flying); MyCharacterMovementFlags movementFlags = base.Character.MovementFlags; MyCharacterMovementFlags flags2 = base.Character.MovementFlags; this.IsFlying = !(moveIndicator.LengthSquared() == 0f); HkCharacterStateType type = (characterProxy != null) ? characterProxy.GetState() : HkCharacterStateType.HK_CHARACTER_ON_GROUND; if ((type == HkCharacterStateType.HK_CHARACTER_IN_AIR) || (type == ((HkCharacterStateType)5))) { base.Character.PlayCharacterAnimation("Jetpack", MyBlendOption.Immediate, MyFrameOption.Loop, 0.2f, 1f, false, null, false); base.Character.CanJump = true; } MatrixD worldMatrix = base.Character.WorldMatrix; if (canRotate) { MatrixD identity = MatrixD.Identity; MatrixD xd3 = MatrixD.Identity; MatrixD xd4 = MatrixD.Identity; if (Math.Abs(rotationIndicator.X) > float.Epsilon) { if (base.Character.Definition.VerticalPositionFlyingOnly) { base.Character.SetHeadLocalXAngle(base.Character.HeadLocalXAngle - (rotationIndicator.X * base.Character.RotationSpeed)); } else { identity = MatrixD.CreateFromAxisAngle(worldMatrix.Right, (double)((-rotationIndicator.X * base.Character.RotationSpeed) * 0.02f)); } } if (Math.Abs(rotationIndicator.Y) > float.Epsilon) { xd3 = MatrixD.CreateFromAxisAngle(worldMatrix.Up, (double)((-rotationIndicator.Y * base.Character.RotationSpeed) * 0.02f)); } if (!base.Character.Definition.VerticalPositionFlyingOnly && (Math.Abs(roll) > float.Epsilon)) { xd4 = MatrixD.CreateFromAxisAngle(worldMatrix.Forward, (double)(roll * 0.02f)); } float y = base.Character.ModelCollision.BoundingBoxSizeHalf.Y; MatrixD xd7 = worldMatrix.GetOrientation() * ((identity * xd3) * xd4); MatrixD *xdPtr1 = (MatrixD *)ref xd7; xdPtr1.Translation = (base.Character.Physics.GetWorldMatrix().Translation + (worldMatrix.Up * y)) - (xd7.Up * y); base.Character.WorldMatrix = xd7; base.Character.ClearShapeContactPoints(); } Vector3 position = moveIndicator; if (base.Character.Definition.VerticalPositionFlyingOnly) { float num2 = Math.Sign(base.Character.HeadLocalXAngle); double x = Math.Abs(MathHelper.ToRadians(base.Character.HeadLocalXAngle)); double y = 1.95; double num5 = Math.Pow(x, y) * (x / Math.Pow((double)MathHelper.ToRadians((float)89f), y)); position = (Vector3)Vector3D.Transform(position, MatrixD.CreateFromAxisAngle(Vector3D.Right, num2 * num5)); } if (!Vector3.IsZero(position)) { position.Normalize(); } MyJetpackThrustComponent thrustComp = this.ThrustComp; thrustComp.ControlThrust += position * this.ForceMagnitude; }
public static unsafe void ChangeMaterialsInShape(MyVoxelBase voxelMap, MyShape shape, byte materialIdx, bool[] materialsToChange) { if ((voxelMap != null) && (shape != null)) { using (voxelMap.Pin()) { if (!voxelMap.MarkedForClose) { Vector3I vectori; Vector3I vectori2; Vector3I vectori5; MatrixD xd = shape.Transformation * voxelMap.PositionComp.WorldMatrixInvScaled; MatrixD *xdPtr1 = (MatrixD *)ref xd; xdPtr1.Translation += voxelMap.SizeInMetresHalf; shape.Transformation = xd; BoundingBoxD worldBoundaries = shape.GetWorldBoundaries(); ComputeShapeBounds(voxelMap, ref worldBoundaries, Vector3.Zero, voxelMap.Storage.Size, out vectori, out vectori2); Vector3I voxelCoord = vectori - 1; Vector3I vectori4 = (Vector3I)(vectori2 + 1); voxelMap.Storage.ClampVoxelCoord(ref voxelCoord, 1); voxelMap.Storage.ClampVoxelCoord(ref vectori4, 1); if (m_cache == null) { m_cache = new MyStorageData(MyStorageDataTypeFlags.All); } m_cache.Resize(voxelCoord, vectori4); MyVoxelRequestFlags requestFlags = MyVoxelRequestFlags.AdviseCache | MyVoxelRequestFlags.ConsiderContent; voxelMap.Storage.ReadRange(m_cache, MyStorageDataTypeFlags.Material, 0, voxelCoord, vectori4, ref requestFlags); vectori5.X = vectori.X; while (vectori5.X <= vectori2.X) { vectori5.Y = vectori.Y; while (true) { if (vectori5.Y > vectori2.Y) { int *numPtr3 = (int *)ref vectori5.X; numPtr3[0]++; break; } vectori5.Z = vectori.Z; while (true) { if (vectori5.Z > vectori2.Z) { int *numPtr2 = (int *)ref vectori5.Y; numPtr2[0]++; break; } Vector3I p = vectori5 - vectori; int linearIdx = m_cache.ComputeLinear(ref p); byte index = m_cache.Material(linearIdx); if (materialsToChange[index]) { Vector3D vectord; MyVoxelCoordSystems.VoxelCoordToWorldPosition(voxelMap.PositionLeftBottomCorner, ref vectori5, out vectord); if ((shape.GetVolume(ref vectord) > 0.5f) && (m_cache.Material(ref p) != 0xff)) { m_cache.Material(ref p, materialIdx); } } int *numPtr1 = (int *)ref vectori5.Z; numPtr1[0]++; } } } } } } }