コード例 #1
0
        /// <summary>
        /// Adds two vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <returns>The sum of both vectors.</returns>
        #region public static void Add(JVector value1, JVector value2)
        public static FPVector Add(FPVector value1, FPVector value2)
        {
            FPVector result;

            FPVector.Add(ref value1, ref value2, out result);
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Multiplies a vector by a scale factor.
        /// </summary>
        /// <param name="value2">The vector to scale.</param>
        /// <param name="value1">The scale factor.</param>
        /// <returns>Returns the scaled vector.</returns>
        #region public static JVector operator *(FP value1, JVector value2)
        public static FPVector operator *(Fix64 value1, FPVector value2)
        {
            FPVector result;

            FPVector.Multiply(ref value2, value1, out result);
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// Transforms a vector by the given matrix.
        /// </summary>
        /// <param name="position">The vector to transform.</param>
        /// <param name="matrix">The transform matrix.</param>
        /// <returns>The transformed vector.</returns>
        #region public static JVector Transform(JVector position, JMatrix matrix)
        public static FPVector Transform(FPVector position, FPMatrix matrix)
        {
            FPVector result;

            FPVector.Transform(ref position, ref matrix, out result);
            return(result);
        }
コード例 #4
0
        /// <summary>
        /// Divides a vector by a factor.
        /// </summary>
        /// <param name="value1">The vector to divide.</param>
        /// <param name="scaleFactor">The scale factor.</param>
        /// <returns>Returns the scaled vector.</returns>
        public static FPVector Divide(FPVector value1, Fix64 scaleFactor)
        {
            FPVector result;

            FPVector.Divide(ref value1, scaleFactor, out result);
            return(result);
        }
コード例 #5
0
        /// <summary>
        /// The cross product of two vectors.
        /// </summary>
        /// <param name="vector1">The first vector.</param>
        /// <param name="vector2">The second vector.</param>
        /// <returns>The cross product of both vectors.</returns>
        #region public static JVector Cross(JVector vector1, JVector vector2)
        public static FPVector Cross(FPVector vector1, FPVector vector2)
        {
            FPVector result;

            FPVector.Cross(ref vector1, ref vector2, out result);
            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Subtracts two vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <returns>The difference of both vectors.</returns>
        #region public static JVector Subtract(JVector value1, JVector value2)
        public static FPVector Subtract(FPVector value1, FPVector value2)
        {
            FPVector result;

            FPVector.Subtract(ref value1, ref value2, out result);
            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Normalizes the given vector.
        /// </summary>
        /// <param name="value">The vector which should be normalized.</param>
        /// <returns>A normalized vector.</returns>
        #region public static JVector Normalize(JVector value)
        public static FPVector Normalize(FPVector value)
        {
            FPVector result;

            FPVector.Normalize(ref value, out result);
            return(result);
        }
コード例 #8
0
        /// <summary>
        /// Divides a vector by a factor.
        /// </summary>
        /// <param name="value1">The vector to divide.</param>
        /// <param name="scaleFactor">The scale factor.</param>
        /// <returns>Returns the scaled vector.</returns>
        public static FPVector operator /(FPVector value1, Fix64 value2)
        {
            FPVector result;

            FPVector.Divide(ref value1, value2, out result);
            return(result);
        }
コード例 #9
0
        /// <summary>
        /// Multiply a vector with a factor.
        /// </summary>
        /// <param name="value1">The vector to multiply.</param>
        /// <param name="scaleFactor">The scale factor.</param>
        /// <returns>Returns the multiplied vector.</returns>
        #region public static JVector Multiply(JVector value1, FP scaleFactor)
        public static FPVector Multiply(FPVector value1, Fix64 scaleFactor)
        {
            FPVector result;

            FPVector.Multiply(ref value1, scaleFactor, out result);
            return(result);
        }
コード例 #10
0
        /// <summary>
        /// Inverses the direction of a vector.
        /// </summary>
        /// <param name="value">The vector to inverse.</param>
        /// <returns>The negated vector.</returns>
        public static FPVector Negate(FPVector value)
        {
            FPVector result;

            FPVector.Negate(ref value, out result);
            return(result);
        }
コード例 #11
0
        /// <summary>
        /// Normalizes the given vector.
        /// </summary>
        /// <param name="value">The vector which should be normalized.</param>
        /// <param name="result">A normalized vector.</param>
        public static void Normalize(ref FPVector value, out FPVector result)
        {
            Fix64 num2 = ((value.x * value.x) + (value.y * value.y)) + (value.z * value.z);
            Fix64 num  = Fix64.One / Fix64.Sqrt(num2);

            result.x = value.x * num;
            result.y = value.y * num;
            result.z = value.z * num;
        }
コード例 #12
0
        public Fix64 DistanceToPoint(FPVector point)
        {
            Fix64 xMax = this.topRight.x;
            Fix64 xMin = this.topLeft.x;
            Fix64 yMax = this.bottomRight.y;
            Fix64 yMin = this.topRight.y;

            if (point.x < xMin)
            {     // Region I, VIII, or VII
                if (point.y < yMin)
                { // I
                    FPVector diff = point - new FPVector(xMin, yMin, 0);
                    return(diff.magnitude);
                }
                else if (point.y > this.bottomRight.y)
                { // VII
                    FPVector diff = point - new FPVector(xMin, yMax, 0);
                    return(diff.magnitude);
                }
                else
                { // VIII
                    return(xMin - point.x);
                }
            }
            else if (point.x > xMax)
            {     // Region III, IV, or V
                if (point.y < yMin)
                { // III
                    FPVector diff = point - new FPVector(xMax, yMin, 0);
                    return(diff.magnitude);
                }
                else if (point.y > yMax)
                { // V
                    FPVector diff = point - new FPVector(xMax, yMax, 0);
                    return(diff.magnitude);
                }
                else
                { // IV
                    return(point.x - xMax);
                }
            }
            else
            {     // Region II, IX, or VI
                if (point.y < yMin)
                { // II
                    return(yMin - point.y);
                }
                else if (point.y > yMax)
                { // VI
                    return(point.y - yMax);
                }
                else
                { // IX
                    return(0);
                }
            }
        }
コード例 #13
0
 public void RefreshPoints()
 {
     this.xMax        = this.x + this.width;
     this.yMax        = this.y + this.height;
     this.topLeft     = new FPVector(this.x, this.y, 0);
     this.topRight    = new FPVector(this.xMax, this.y, 0);
     this.bottomLeft  = new FPVector(this.x, this.yMax, 0);
     this.bottomRight = new FPVector(this.xMax, this.yMax, 0);
 }
コード例 #14
0
        /// <summary>
        /// Transforms a vector by the transposed of the given Matrix.
        /// </summary>
        /// <param name="position">The vector to transform.</param>
        /// <param name="matrix">The transform matrix.</param>
        /// <param name="result">The transformed vector.</param>
        public static void TransposedTransform(ref FPVector position, ref FPMatrix matrix, out FPVector result)
        {
            Fix64 num0 = ((position.x * matrix.M11) + (position.y * matrix.M12)) + (position.z * matrix.M13);
            Fix64 num1 = ((position.x * matrix.M21) + (position.y * matrix.M22)) + (position.z * matrix.M23);
            Fix64 num2 = ((position.x * matrix.M31) + (position.y * matrix.M32)) + (position.z * matrix.M33);

            result.x = num0;
            result.y = num1;
            result.z = num2;
        }
コード例 #15
0
        /// <summary>
        /// The cross product of two vectors.
        /// </summary>
        /// <param name="vector1">The first vector.</param>
        /// <param name="vector2">The second vector.</param>
        /// <param name="result">The cross product of both vectors.</param>
        public static void Cross(ref FPVector vector1, ref FPVector vector2, out FPVector result)
        {
            Fix64 num3 = (vector1.y * vector2.z) - (vector1.z * vector2.y);
            Fix64 num2 = (vector1.z * vector2.x) - (vector1.x * vector2.z);
            Fix64 num  = (vector1.x * vector2.y) - (vector1.y * vector2.x);

            result.x = num3;
            result.y = num2;
            result.z = num;
        }
コード例 #16
0
        /// <summary>
        /// Tests if an object is equal to this vector.
        /// </summary>
        /// <param name="obj">The object to test.</param>
        /// <returns>Returns true if they are euqal, otherwise false.</returns>
        #region public override bool Equals(object obj)
        public override bool Equals(object obj)
        {
            if (!(obj is FPVector))
            {
                return(false);
            }
            FPVector other = (FPVector)obj;

            return(((x == other.x) && (y == other.y)) && (z == other.z));
        }
コード例 #17
0
        /// <summary>
        /// Multiplies each component of the vector by the same components of the provided vector.
        /// </summary>
        public static FPVector Scale(FPVector vecA, FPVector vecB)
        {
            FPVector result;

            result.x = vecA.x * vecB.x;
            result.y = vecA.y * vecB.y;
            result.z = vecA.z * vecB.z;

            return(result);
        }
コード例 #18
0
        /// <summary>
        /// Inverses the direction of a vector.
        /// </summary>
        /// <param name="value">The vector to inverse.</param>
        /// <param name="result">The negated vector.</param>
        public static void Negate(ref FPVector value, out FPVector result)
        {
            Fix64 num0 = -value.x;
            Fix64 num1 = -value.y;
            Fix64 num2 = -value.z;

            result.x = num0;
            result.y = num1;
            result.z = num2;
        }
コード例 #19
0
        public static FPQuaternion FromToRotation(FPVector fromVector, FPVector toVector)
        {
            FPVector     w = FPVector.Cross(fromVector, toVector);
            FPQuaternion q = new FPQuaternion(w.x, w.y, w.z, FPVector.Dot(fromVector, toVector));

            q.w += Fix64.Sqrt(fromVector.sqrMagnitude * toVector.sqrMagnitude);
            q.Normalize();

            return(q);
        }
コード例 #20
0
        /// <summary>
        /// Subtracts to vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <param name="result">The difference of both vectors.</param>
        public static void Subtract(ref FPVector value1, ref FPVector value2, out FPVector result)
        {
            Fix64 num0 = value1.x - value2.x;
            Fix64 num1 = value1.y - value2.y;
            Fix64 num2 = value1.z - value2.z;

            result.x = num0;
            result.y = num1;
            result.z = num2;
        }
コード例 #21
0
        /// <summary>
        /// Adds to vectors.
        /// </summary>
        /// <param name="value1">The first vector.</param>
        /// <param name="value2">The second vector.</param>
        /// <param name="result">The sum of both vectors.</param>
        public static void Add(ref FPVector value1, ref FPVector value2, out FPVector result)
        {
            Fix64 num0 = value1.x + value2.x;
            Fix64 num1 = value1.y + value2.y;
            Fix64 num2 = value1.z + value2.z;

            result.x = num0;
            result.y = num1;
            result.z = num2;
        }
コード例 #22
0
 public void Translate(FPVector translation, Space relativeTo)
 {
     if (relativeTo == Space.Self)
     {
         Translate(translation, this);
     }
     else
     {
         this.position += translation;
     }
 }
コード例 #23
0
        public void RotateAround(FPVector point, FPVector axis, Fix64 angle)
        {
            FPVector vector  = this.position;
            FPVector vector2 = vector - point;

            vector2       = FPVector.Transform(vector2, FPMatrix.AngleAxis(angle * Fix64.Deg2Rad, axis));
            vector        = point + vector2;
            this.position = vector;

            Rotate(axis, angle);
        }
コード例 #24
0
 public FPRect(Rect rect)
 {
     this.topLeft     = new FPVector(rect.x, rect.y, 0);
     this.topRight    = new FPVector(rect.xMax, rect.y, 0);
     this.bottomLeft  = new FPVector(rect.x, rect.yMax, 0);
     this.bottomRight = new FPVector(rect.xMax, rect.yMax, 0);
     this.x           = rect.x;
     this.y           = rect.y;
     this.width       = rect.width;
     this.height      = rect.height;
     this.xMax        = rect.xMax;
     this.yMax        = rect.yMax;
 }
コード例 #25
0
 static FPVector()
 {
     one          = new FPVector(1, 1, 1);
     zero         = new FPVector(0, 0, 0);
     left         = new FPVector(-1, 0, 0);
     right        = new FPVector(1, 0, 0);
     up           = new FPVector(0, 1, 0);
     down         = new FPVector(0, -1, 0);
     back         = new FPVector(0, 0, -1);
     forward      = new FPVector(0, 0, 1);
     MinValue     = new FPVector(Fix64.MinValue);
     MaxValue     = new FPVector(Fix64.MaxValue);
     Arbitrary    = new FPVector(1, 1, 1);
     InternalZero = zero;
 }
コード例 #26
0
        public void Rotate(FPVector axis, Fix64 angle, Space relativeTo)
        {
            FPQuaternion result = FPQuaternion.identity;

            if (relativeTo == Space.Self)
            {
                result = this.rotation * FPQuaternion.AngleAxis(angle, axis);
            }
            else
            {
                result = FPQuaternion.AngleAxis(angle, axis) * this.rotation;
            }

            result.Normalize();
            this.rotation = result;
        }
コード例 #27
0
        public void Rotate(FPVector eulerAngles, Space relativeTo)
        {
            FPQuaternion result = FPQuaternion.identity;

            if (relativeTo == Space.Self)
            {
                result = this.rotation * FPQuaternion.Euler(eulerAngles);
            }
            else
            {
                result = FPQuaternion.Euler(eulerAngles) * this.rotation;
            }

            result.Normalize();
            this.rotation = result;
        }
コード例 #28
0
        /// <summary>
        /// Swaps the components of both vectors.
        /// </summary>
        /// <param name="vector1">The first vector to swap with the second.</param>
        /// <param name="vector2">The second vector to swap with the first.</param>
        public static void Swap(ref FPVector vector1, ref FPVector vector2)
        {
            Fix64 temp;

            temp      = vector1.x;
            vector1.x = vector2.x;
            vector2.x = temp;

            temp      = vector1.y;
            vector1.y = vector2.y;
            vector2.y = temp;

            temp      = vector1.z;
            vector1.z = vector2.z;
            vector2.z = temp;
        }
コード例 #29
0
        public static FPQuaternion AngleAxis(Fix64 angle, FPVector axis)
        {
            axis = axis * Fix64.Deg2Rad;
            axis.Normalize();

            Fix64 halfAngle = angle * Fix64.Deg2Rad * Fix64.Half;

            FPQuaternion rotation;
            Fix64        sin = Fix64.Sin(halfAngle);

            rotation.x = axis.x * sin;
            rotation.y = axis.y * sin;
            rotation.z = axis.z * sin;
            rotation.w = Fix64.Cos(halfAngle);

            return(rotation);
        }
コード例 #30
0
        public void SetFromToRotation(FPVector fromDirection, FPVector toDirection)
        {
            FPQuaternion targetRotation = FPQuaternion.FromToRotation(fromDirection, toDirection);

            this.Set(targetRotation.x, targetRotation.y, targetRotation.z, targetRotation.w);
        }