Advertisement
plaYer2k

Space Engineers - Helper Methods

Feb 20th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. readonly Vector3D VectorX = new Vector3D(1, 0, 0);
  2. readonly Vector3D VectorY = new Vector3D(0, 1, 0);
  3. readonly Vector3D VectorZ = new Vector3D(0, 0, 1);
  4. readonly Vector3D VectorZero = new Vector3D(0, 0, 0);
  5. void AlignGyroToMatrix(IMyGyro gyro, MatrixD referenceOrientation, MatrixD targetOrientation, double rotationSpeedScale = 19)
  6. {
  7.     if(gyro == null)
  8.         return;
  9.     referenceOrientation.Forward *= -1;
  10.     referenceOrientation.Right *= -1;
  11.     MatrixD gyroOrientation = gyro.WorldMatrix.GetOrientation();
  12.     MatrixD mat = (referenceOrientation * MatrixD.Invert(gyroOrientation)) * MatrixD.Invert(gyroOrientation * MatrixD.Invert(targetOrientation));
  13.     gyro.SetValue<float>("Pitch", (float)(rotationSpeedScale*System.Math.Asin(Vector3D.Dot(mat.Up, VectorZ))));
  14.     gyro.SetValue<float>("Yaw", (float)(rotationSpeedScale*System.Math.Asin(Vector3D.Dot(mat.Backward, VectorX))));
  15.     gyro.SetValue<float>("Roll", (float)(rotationSpeedScale*System.Math.Asin(Vector3D.Dot(mat.Right, VectorY))));
  16. }
  17.  
  18.  
  19. public static IMyTerminalBlock GetRelativeBlock(IMyTerminalBlock reference, Vector3I direction)
  20. {
  21.     if(reference == null)
  22.         return null;
  23.     if(direction = Vector3I.Zero)
  24.         return reference;
  25.     Matrix mat;
  26.     reference.Orientation.GetMatrix(out mat);
  27.     mat.Translation = reference.Position;
  28.     Vector3I.Transform(ref direction, ref mat, out direction);
  29.     IMySlimBlock sb = reference.CubeGrid.GetCubeBlock(direction);
  30.     return sb == null ? null : sb.FatBlock as IMyTerminalBlock;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement