private float GetRotate(VRageMath.Vector3 axis) { if (!XUtils.Directions.Contains(axis)) { throw new Exception("Invalid axis vector used: " + axis); } VRageMath.Matrix local = new VRageMath.Matrix(); referenceBlock.Orientation.GetMatrix(out local); axis = VRageMath.Vector3.Transform(axis, local); float totalValue = 0; for (int i = 0; i < gyroscopeBlocks.Count; ++i) { IMyGyro gyro = gyroscopeBlocks[i] as IMyGyro; gyro.Orientation.GetMatrix(out local); VRageMath.Matrix toGyro = VRageMath.Matrix.Transpose(local); VRageMath.Vector3 transformedAxis = VRageMath.Vector3.Transform(axis, toGyro); GyroAction action = GyroAction.getActionAroundAxis(transformedAxis); float value = gyro.GetValue <float>(action.Name); totalValue += action.Reversed ? -value : value; } return(totalValue); }
/// <summary> /// Rotates the ship relative to the reference block. /// A positive Yaw value rotates around the Up vector, such that the Right vector is moved to the Backward vector on the shortest way. /// A positive Pitch value rotates around the Right vector, such that the Up vector is moved to the Backward vector on the shortest way. /// A positive Roll value rotates around the Backward vector, such that the Up vector is moved to the Right vector on the shortest way. /// </summary> /// <param name="axis"></param> /// <param name="value"></param> private void Rotate(VRageMath.Vector3 axis, float value) { if (value < Min || value > Max) { throw new Exception("Value '" + value + "' out of range [" + Min + ", " + Max + "]."); } VRageMath.Matrix local = new VRageMath.Matrix(); referenceBlock.Orientation.GetMatrix(out local); axis = VRageMath.Vector3.Transform(axis, local); for (int i = 0; i < gyroscopeBlocks.Count; ++i) { IMyGyro gyro = gyroscopeBlocks[i] as IMyGyro; gyro.Orientation.GetMatrix(out local); VRageMath.Matrix toGyro = VRageMath.Matrix.Transpose(local); VRageMath.Vector3 transformedAxis = VRageMath.Vector3.Transform(axis, toGyro); GyroAction action = GyroAction.getActionAroundAxis(transformedAxis); gyro.SetValue(action.Name, action.Reversed ? -value : value); } }