void GetAxisAndDir(Base6Directions.Direction RefDir, out string Axis, out float sign) { Axis = "Yaw"; sign = -1.0f; if (Base6Directions.GetAxis(YawAxisDir) == Base6Directions.GetAxis(RefDir)) { if (YawAxisDir == RefDir) { sign = 1.0f; } } if (Base6Directions.GetAxis(PitchAxisDir) == Base6Directions.GetAxis(RefDir)) { Axis = "Pitch"; if (PitchAxisDir == RefDir) { sign = 1.0f; } } if (Base6Directions.GetAxis(RollAxisDir) == Base6Directions.GetAxis(RefDir)) { Axis = "Roll"; if (RollAxisDir == RefDir) { } else { sign = 1.0f; } } }
private Vector3I CalculateCornerPosition() { Vector3I posDist = ConnectingPosition2.LocalGridPosition - ConnectingPosition1.LocalGridPosition; Debug.Assert(posDist.AbsMin() == 0); switch (Base6Directions.GetAxis(ConnectingPosition1.Direction)) { case Base6Directions.Axis.ForwardBackward: return(new Vector3I(ConnectingPosition1.LocalGridPosition + new Vector3I(0, 0, posDist.Z))); case Base6Directions.Axis.LeftRight: return(new Vector3I(ConnectingPosition1.LocalGridPosition + new Vector3I(posDist.X, 0, 0))); case Base6Directions.Axis.UpDown: return(new Vector3I(ConnectingPosition1.LocalGridPosition + new Vector3I(0, posDist.Y, 0))); } Debug.Fail("Should not get here"); return(Vector3I.Zero); }
//recommended but not necessary, third to call if used (gyro system is set up then) //passing OrientBlock=null will use the grid as reference public void SetRefBlock(IMyTerminalBlock OrientBlock, Base6Directions.Direction DirForward = Forward, Base6Directions.Direction DirUp = Up) { if (Base6Directions.GetAxis(DirForward) == Base6Directions.GetAxis(DirUp)) { DirUp = Base6Directions.GetPerpendicular(DirForward); } if (OrientBlock == null) { } else { Vector3 RotatedVector = Base6Directions.GetVector(DirForward); Vector3.TransformNormal(ref RotatedVector, OrientBlock.Orientation, out RotatedVector); DirForward = Base6Directions.GetDirection(ref RotatedVector); RotatedVector = Base6Directions.GetVector(DirUp); Vector3.TransformNormal(ref RotatedVector, OrientBlock.Orientation, out RotatedVector); DirUp = Base6Directions.GetDirection(ref RotatedVector); } RefUp = DirUp; RefForward = DirForward; RefLeft = Base6Directions.GetLeft(RefUp, RefForward); }
public static void CreateDefaultTriangles(MyObjectBuilder_BlockNavigationDefinition ob) { Vector3I size = ob.Size; Vector3I center = ob.Center; int triCount = 4 * ((size.X * size.Y) + (size.X * size.Z) + (size.Y * size.Z)); ob.Triangles = new MyObjectBuilder_BlockNavigationDefinition.Triangle[triCount]; int i = 0; // Coords of the block's real center (i.e. origin) relative to blockDef.Center Vector3 origin = (size * 0.5f) - center - Vector3.Half; for (int d = 0; d < 6; ++d) { Base6Directions.Direction faceDirection = Base6Directions.EnumDirections[d]; Base6Directions.Direction rightDir, upDir; Vector3 faceOrigin = origin; switch (faceDirection) { case Base6Directions.Direction.Right: rightDir = Base6Directions.Direction.Forward; upDir = Base6Directions.Direction.Up; faceOrigin += new Vector3(0.5f, -0.5f, 0.5f) * size; break; case Base6Directions.Direction.Left: rightDir = Base6Directions.Direction.Backward; upDir = Base6Directions.Direction.Up; faceOrigin += new Vector3(-0.5f, -0.5f, -0.5f) * size; break; case Base6Directions.Direction.Up: rightDir = Base6Directions.Direction.Right; upDir = Base6Directions.Direction.Forward; faceOrigin += new Vector3(-0.5f, 0.5f, 0.5f) * size; break; case Base6Directions.Direction.Down: rightDir = Base6Directions.Direction.Right; upDir = Base6Directions.Direction.Backward; faceOrigin += new Vector3(-0.5f, -0.5f, -0.5f) * size; break; case Base6Directions.Direction.Backward: rightDir = Base6Directions.Direction.Right; upDir = Base6Directions.Direction.Up; faceOrigin += new Vector3(-0.5f, -0.5f, 0.5f) * size; break; case Base6Directions.Direction.Forward: default: rightDir = Base6Directions.Direction.Left; upDir = Base6Directions.Direction.Up; faceOrigin += new Vector3(0.5f, -0.5f, -0.5f) * size; break; } Vector3 rightVec = Base6Directions.GetVector(rightDir); Vector3 upVec = Base6Directions.GetVector(upDir); int uMax = size.AxisValue(Base6Directions.GetAxis(upDir)); int rMax = size.AxisValue(Base6Directions.GetAxis(rightDir)); for (int u = 0; u < uMax; ++u) { for (int r = 0; r < rMax; ++r) { var triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle(); triangle.Points = new SerializableVector3[3]; triangle.Points[0] = faceOrigin; triangle.Points[1] = faceOrigin + rightVec; triangle.Points[2] = faceOrigin + upVec; ob.Triangles[i++] = triangle; triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle(); triangle.Points = new SerializableVector3[3]; triangle.Points[0] = faceOrigin + rightVec; triangle.Points[1] = faceOrigin + rightVec + upVec; triangle.Points[2] = faceOrigin + upVec; ob.Triangles[i++] = triangle; faceOrigin += rightVec; } faceOrigin -= rightVec * rMax; faceOrigin += upVec; } } }
public static void CreateDefaultTriangles(MyObjectBuilder_BlockNavigationDefinition ob) { Vector3I size = (Vector3I)ob.Size; Vector3I center = (Vector3I)ob.Center; int num = 4 * (((size.X * size.Y) + (size.X * size.Z)) + (size.Y * size.Z)); ob.Triangles = new MyObjectBuilder_BlockNavigationDefinition.Triangle[num]; int index = 0; Vector3 vector = ((Vector3)((size * 0.5f) - center)) - Vector3.Half; int num3 = 0; while (num3 < 6) { Base6Directions.Direction right; Base6Directions.Direction up; Base6Directions.Direction direction = Base6Directions.EnumDirections[num3]; Vector3 vector2 = vector; switch (direction) { case Base6Directions.Direction.Backward: right = Base6Directions.Direction.Right; up = Base6Directions.Direction.Up; vector2 += new Vector3(-0.5f, -0.5f, 0.5f) * size; break; case Base6Directions.Direction.Left: right = Base6Directions.Direction.Backward; up = Base6Directions.Direction.Up; vector2 += new Vector3(-0.5f, -0.5f, -0.5f) * size; break; case Base6Directions.Direction.Right: right = Base6Directions.Direction.Forward; up = Base6Directions.Direction.Up; vector2 += new Vector3(0.5f, -0.5f, 0.5f) * size; break; case Base6Directions.Direction.Up: right = Base6Directions.Direction.Right; up = Base6Directions.Direction.Forward; vector2 += new Vector3(-0.5f, 0.5f, 0.5f) * size; break; case Base6Directions.Direction.Down: right = Base6Directions.Direction.Right; up = Base6Directions.Direction.Backward; vector2 += new Vector3(-0.5f, -0.5f, -0.5f) * size; break; default: right = Base6Directions.Direction.Left; up = Base6Directions.Direction.Up; vector2 += new Vector3(0.5f, -0.5f, -0.5f) * size; break; } Vector3 vector3 = Base6Directions.GetVector(right); Vector3 vector4 = Base6Directions.GetVector(up); int num4 = size.AxisValue(Base6Directions.GetAxis(up)); int num5 = size.AxisValue(Base6Directions.GetAxis(right)); int num6 = 0; while (true) { if (num6 >= num4) { num3++; break; } int num7 = 0; while (true) { if (num7 >= num5) { vector2 = (vector2 - (vector3 * num5)) + vector4; num6++; break; } MyObjectBuilder_BlockNavigationDefinition.Triangle triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle { Points = new SerializableVector3[] { vector2, vector2 + vector3, vector2 + vector4 } }; index++; ob.Triangles[index] = triangle; triangle = new MyObjectBuilder_BlockNavigationDefinition.Triangle { Points = new SerializableVector3[3] }; triangle.Points[0] = vector2 + vector3; triangle.Points[1] = (vector2 + vector3) + vector4; triangle.Points[2] = vector2 + vector4; index++; ob.Triangles[index] = triangle; vector2 += vector3; num7++; } } } }