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);
        }
        void Main()
        {
            HashSet <GyroAction> actions = GyroAction.GetElements();

            HashSet <GyroAction> .Enumerator enumerator = actions.GetEnumerator();
            while (enumerator.MoveNext())
            {
                debug.Append(enumerator.Current).AppendLine();
            }

            debug.Append(XUtils.Identity.Backward.Equals(XUtils.Identity.Backward)).AppendLine();

            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Backward)).AppendLine();
            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Forward)).AppendLine();
            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Up)).AppendLine();
            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Down)).AppendLine();
            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Right)).AppendLine();
            debug.Append(GyroAction.getActionAroundAxis(XUtils.Identity.Left)).AppendLine();

            Debug(debug.ToString());
            debug.Clear();
        }
示例#3
0
            /// <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>
            public void Rotate(VRageMath.Vector3 axis, float value)
            {
                if (value < gyroRotateMin || value > gyroRotateMax)
                {
                    throw new Exception("Value out of range [" + gyroRotateMin + ", " + gyroRotateMax + "].");
                }

                VRageMath.Matrix local = new VRageMath.Matrix();
                referenceBlock.Orientation.GetMatrix(out local);
                axis = VRageMath.Vector3.Transform(axis, local);

                for (int i = 0; i < gyros.Count; ++i)
                {
                    IMyGyro gyro = gyros[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 = gyroActions[transformedAxis];
                    gyro.SetValue(action.GetName(), action.Reversed ? -value : value);
                }
            }
        /// <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);
            }
        }