Exemplo n.º 1
0
        /// <summary>
        /// I only made this public so I could hook a tester to it
        /// </summary>
        public static void OrthonormalizeOrientation(MyMatrix3 orientation)
        {
            // Do some crazy math (something about constraining 9 degrees of freedom of a matrix down to 3)
            MyVector x = new MyVector(orientation.M11, orientation.M21, orientation.M31);

            x.BecomeUnitVector();

            MyVector y = new MyVector(orientation.M12, orientation.M22, orientation.M32);               // just store a temp variable into y (until I calculate z)

            MyVector z = MyVector.Cross(x, y);

            z.BecomeUnitVector();

            y = MyVector.Cross(z, x);
            y.BecomeUnitVector();

            // Overwrite the matrix passed in
            orientation.M11 = x.X;
            orientation.M12 = y.X;
            orientation.M13 = z.X;

            orientation.M21 = x.Y;
            orientation.M22 = y.Y;
            orientation.M23 = z.Y;

            orientation.M31 = x.Z;
            orientation.M32 = y.Z;
            orientation.M33 = z.Z;
        }
Exemplo n.º 2
0
        /// <summary>
        /// This creates a new vector that is the vector with a length of one
        /// </summary>
        public static MyVector BecomeUnitVector(MyVector vector)
        {
            MyVector retVal = vector.Clone();

            retVal.BecomeUnitVector();

            return(retVal);
        }
Exemplo n.º 3
0
        /// <summary>
        /// I will internally rotate the vectors around, get the Z component to drop out, and only return Theta.  I will not change the values
        /// of the vectors passed in
        /// </summary>
        public static double GetAngleBetweenVectors(MyVector v1, MyVector v2)
        {
            // Get the dot product of the two vectors (I use retVal, just because it makes a convenient temp variable)
            double retVal = Dot(MyVector.BecomeUnitVector(v1), MyVector.BecomeUnitVector(v2));

            // Now pull the arccos of the dot product
            retVal = Math.Acos(retVal);

            // Exit Function
            return(retVal);
        }
Exemplo n.º 4
0
        /// <summary>
        /// This constructs a unit quaternion that represents the rotation
        /// </summary>
        public MyQuaternion(MyVector rotationAxis, double radians)
        {
            double   halfAngle        = radians / 2d;
            double   sinHalfAngle     = Math.Sin(halfAngle);
            MyVector rotateAroundUnit = MyVector.BecomeUnitVector(rotationAxis);

            // Set my values
            this.X = rotateAroundUnit.X * sinHalfAngle;
            this.Y = rotateAroundUnit.Y * sinHalfAngle;
            this.Z = rotateAroundUnit.Z * sinHalfAngle;
            this.W = Math.Cos(halfAngle);
        }
Exemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            MyVector v1 = new MyVector(3, 4, 5);

            v1.Add(1, 2, 3);

            v1.BecomeUnitVector();

            MyVector v2 = v1.Clone();

            v2.Multiply(3);

            v1.Divide(3);
        }
Exemplo n.º 6
0
        /// <summary>
        /// This gives the dot product between the two vectors passed in.  This overload allows for the
        /// vectors to be normalized first.
        /// </summary>
        /// <param name="becomeUnitVectors">
        /// This tells the funtion to make them unit vectors first (forces the output to -1 to 1)
        /// NOTE:  If you're going to pass false, then use the simpler overload.  It will avoid the if statement.
        /// </param>
        public static double Dot(MyVector v1, MyVector v2, bool becomeUnitVectors)
        {
            // See if they need to become unit vectors first
            if (becomeUnitVectors)
            {
                // Turn the vectors passed in into unit vectors first
                MyVector working1 = MyVector.BecomeUnitVector(v1);
                MyVector working2 = MyVector.BecomeUnitVector(v2);

                // Exit Function
                return((working1.X * working2.X) +
                       (working1.Y * working2.Y) +
                       (working1.Z * working2.Z));
            }
            else
            {
                return((v1.X * v2.X) +
                       (v1.Y * v2.Y) +
                       (v1.Z * v2.Z));
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// I only made this public so I could hook a tester to it
        /// </summary>
        public static void OrthonormalizeOrientation(MyMatrix3 orientation)
        {
            // Do some crazy math (something about constraining 9 degrees of freedom of a matrix down to 3)
            MyVector x = new MyVector(orientation.M11, orientation.M21, orientation.M31);
            x.BecomeUnitVector();

            MyVector y = new MyVector(orientation.M12, orientation.M22, orientation.M32);		// just store a temp variable into y (until I calculate z)

            MyVector z = MyVector.Cross(x, y);
            z.BecomeUnitVector();

            y = MyVector.Cross(z, x);
            y.BecomeUnitVector();

            // Overwrite the matrix passed in
            orientation.M11 = x.X;
            orientation.M12 = y.X;
            orientation.M13 = z.X;

            orientation.M21 = x.Y;
            orientation.M22 = y.Y;
            orientation.M23 = z.Y;

            orientation.M31 = x.Z;
            orientation.M32 = y.Z;
            orientation.M33 = z.Z;
        }
Exemplo n.º 8
0
        private MyVector GetSpinVelocityAtPoint(ref AngularVelocityInfo angularInfo, out MyVector dirToCenterLine, MyVector dirFacingWorld, MyVector lineBetween, MyVector blipPosition)
        {
            // Get a line that's orthogonal to lineBetween, and always points toward the dirFacingWorld vector
            dirToCenterLine = MyVector.Cross(MyVector.Cross(lineBetween, dirFacingWorld), lineBetween);
            dirToCenterLine.BecomeUnitVector();

            if (angularInfo == null)
            {
                #region Cache Angular Velocity

                angularInfo = new AngularVelocityInfo();

                if (_ship.TorqueBall != null)
                {
                    angularInfo.AngularVelocity = _ship.TorqueBall.AngularVelocity.GetMagnitude();

                    angularInfo.SpinDirection = MyVector.Cross(_ship.TorqueBall.AngularVelocity, _ship.TorqueBall.DirectionFacing.Standard);
                    angularInfo.SpinDirection.BecomeUnitVector();

                    angularInfo.CenterMass = _ship.TorqueBall.Rotation.GetRotatedVector(_ship.TorqueBall.CenterOfMass, true);
                    angularInfo.CenterMass.Add(_ship.TorqueBall.Position);
                }
                else
                {
                    angularInfo.SpinDirection = dirToCenterLine.Clone();
                    angularInfo.AngularVelocity = 0d;
                    angularInfo.CenterMass = _ship.Ball.Position.Clone();
                }

                #endregion
            }

            // Get the line between the blip and the center of mass
            MyVector lineBetweenCM = blipPosition - angularInfo.CenterMass;

            // Figure out my velocity of spin where the blip is
            return angularInfo.SpinDirection * (angularInfo.AngularVelocity * lineBetweenCM.GetMagnitude());
        }
Exemplo n.º 9
0
        private void StoreMouseMove(int x, int y)
        {
            MyVector safe = new MyVector();
            safe.X = UtilityCore.GetScaledValue(_multiplier * -1d, _multiplier, 0, this.Width, x);
            safe.Y = UtilityCore.GetScaledValue(_multiplier * -1d, _multiplier, 0, this.Height, y);

            double safeMultiplier = _multiplier * SAFEPERCENT;		// I don't want to butt up against the multiplier, or store value will increase it on me
            if (safe.GetMagnitudeSquared() > safeMultiplier * safeMultiplier)
            {
                safe.BecomeUnitVector();
                safe.Multiply(safeMultiplier);
            }

            StoreNewValue(safe.X, safe.Y, 0d);
        }