示例#1
0
        /// <summary>
        /// Inverses the direction of a vector.
        /// </summary>
        /// <param name="value">The vector to inverse.</param>
        /// <returns>The negated vector.</returns>
        public static TSVector4 Negate(TSVector4 value)
        {
            TSVector4 result;

            TSVector4.Negate(ref value, out result);
            return(result);
        }
示例#2
0
 /// <summary>
 /// Transforms a vector using a matrix.
 /// </summary>
 /// <param name="v">Vector to transform.</param>
 /// <param name="matrix">Transform to apply to the vector.</param>
 /// <param name="result">Transformed vector.</param>
 public static void Transform(ref TSVector v, ref TSMatrix4x4 matrix, out TSVector4 result)
 {
     result.x = v.x * matrix.M11 + v.y * matrix.M21 + v.z * matrix.M31 + matrix.M41;
     result.y = v.x * matrix.M12 + v.y * matrix.M22 + v.z * matrix.M32 + matrix.M42;
     result.z = v.x * matrix.M13 + v.y * matrix.M23 + v.z * matrix.M33 + matrix.M43;
     result.w = v.x * matrix.M14 + v.y * matrix.M24 + v.z * matrix.M34 + matrix.M44;
 }
示例#3
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 TSVector4 Subtract(TSVector4 value1, TSVector4 value2)
        {
            TSVector4 result;

            TSVector4.Subtract(ref value1, ref value2, out result);
            return(result);
        }
示例#4
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 TSVector4 Multiply(TSVector4 value1, FP scaleFactor)
        {
            TSVector4 result;

            TSVector4.Multiply(ref value1, scaleFactor, out result);
            return(result);
        }
示例#5
0
 /// <summary>
 /// Divides a vector by a factor.
 /// </summary>
 /// <param name="value1">The vector to divide.</param>
 /// <param name="scaleFactor">The scale factor.</param>
 /// <param name="result">Returns the scaled vector.</param>
 public static void Divide(ref TSVector4 value1, FP scaleFactor, out TSVector4 result)
 {
     result.x = value1.x / scaleFactor;
     result.y = value1.y / scaleFactor;
     result.z = value1.z / scaleFactor;
     result.w = value1.w / scaleFactor;
 }
示例#6
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 TSVector4 Add(TSVector4 value1, TSVector4 value2)
        {
            TSVector4 result;

            TSVector4.Add(ref value1, ref value2, out result);
            return(result);
        }
示例#7
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 TSVector4 value1, ref TSVector4 value2, out TSVector4 result)
 {
     result.x = value1.x + value2.x;
     result.y = value1.y + value2.y;
     result.z = value1.z + value2.z;
     result.w = value1.w + value2.w;
 }
示例#8
0
        public static TSVector4 Transform(TSVector position, TSMatrix4x4 matrix)
        {
            TSVector4 result;

            TSVector4.Transform(ref position, ref matrix, out result);
            return(result);
        }
示例#9
0
 public static void Transform(ref TSVector4 vector, ref TSMatrix4x4 matrix, out TSVector4 result)
 {
     result.x = vector.x * matrix.M11 + vector.y * matrix.M12 + vector.z * matrix.M13 + vector.w * matrix.M14;
     result.y = vector.x * matrix.M21 + vector.y * matrix.M22 + vector.z * matrix.M23 + vector.w * matrix.M24;
     result.z = vector.x * matrix.M31 + vector.y * matrix.M32 + vector.z * matrix.M33 + vector.w * matrix.M34;
     result.w = vector.x * matrix.M41 + vector.y * matrix.M42 + vector.z * matrix.M43 + vector.w * matrix.M44;
 }
示例#10
0
 /// <summary>
 /// Gets a vector with the maximum x,y and z values of both vectors.
 /// </summary>
 /// <param name="value1">The first value.</param>
 /// <param name="value2">The second value.</param>
 /// <param name="result">A vector with the maximum x,y and z values of both vectors.</param>
 public static void Max(ref TSVector4 value1, ref TSVector4 value2, out TSVector4 result)
 {
     result.x = (value1.x > value2.x) ? value1.x : value2.x;
     result.y = (value1.y > value2.y) ? value1.y : value2.y;
     result.z = (value1.z > value2.z) ? value1.z : value2.z;
     result.w = (value1.w > value2.w) ? value1.w : value2.w;
 }
示例#11
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 TSVector4 operator /(TSVector4 value1, FP value2)
        {
            TSVector4 result;

            TSVector4.Divide(ref value1, value2, out result);
            return(result);
        }
示例#12
0
        /**
         *  @brief Transform a direction from world space to local space.
         **/
        public TSVector4 InverseTransformDirection(TSVector4 direction)
        {
            Debug.Assert(direction.w == FP.Zero);
            TSMatrix4x4 matrix = TSMatrix4x4.Translate(position) * TSMatrix4x4.Rotate(rotation);

            return(TSVector4.Transform(direction, TSMatrix4x4.Inverse(matrix)));
        }
示例#13
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 TSVector4 value1, ref TSVector4 value2, out TSVector4 result)
 {
     result.x = value1.x - value2.x;
     result.y = value1.y - value2.y;
     result.z = value1.z - value2.z;
     result.w = value1.w - value2.w;
 }
示例#14
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 TSVector4 Divide(TSVector4 value1, FP scaleFactor)
        {
            TSVector4 result;

            TSVector4.Divide(ref value1, scaleFactor, out result);
            return(result);
        }
示例#15
0
 /// <summary>
 /// Multiply a vector with a factor.
 /// </summary>
 /// <param name="value1">The vector to multiply.</param>
 /// <param name="scaleFactor">The scale factor.</param>
 /// <param name="result">Returns the multiplied vector.</param>
 public static void Multiply(ref TSVector4 value1, FP scaleFactor, out TSVector4 result)
 {
     result.x = value1.x * scaleFactor;
     result.y = value1.y * scaleFactor;
     result.z = value1.z * scaleFactor;
     result.w = value1.w * scaleFactor;
 }
示例#16
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 TSVector4 value, out TSVector4 result)
 {
     result.x = -value.x;
     result.y = -value.y;
     result.z = -value.z;
     result.w = -value.w;
 }
示例#17
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 TSVector4 operator *(FP value1, TSVector4 value2)
        {
            TSVector4 result;

            TSVector4.Multiply(ref value2, value1, out result);
            return(result);
        }
示例#18
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 TSVector4 Normalize(TSVector4 value)
        {
            TSVector4 result;

            TSVector4.Normalize(ref value, out result);
            return(result);
        }
示例#19
0
 /// <summary>
 /// Multiplies each component of the vector by the same components of the provided vector.
 /// </summary>
 public void Scale(TSVector4 other)
 {
     this.x = x * other.x;
     this.y = y * other.y;
     this.z = z * other.z;
     this.w = w * other.w;
 }
示例#20
0
 static TSVector4()
 {
     one          = new TSVector4(1, 1, 1, 1);
     zero         = new TSVector4(0, 0, 0, 0);
     MinValue     = new TSVector4(FP.MinValue);
     MaxValue     = new TSVector4(FP.MaxValue);
     InternalZero = zero;
 }
示例#21
0
        public static TSVector4 NormalizeCheck(TSVector4 v)
        {
            //防止溢出
            FP div = TSMath.Max(TSMath.Abs(v.x), TSMath.Abs(v.y), TSMath.Abs(v.z));

            div = TSMath.Max(div, TSMath.Abs(v.w));

            return(v / div);
        }
示例#22
0
        public static TSVector4 ClampMagnitude(TSVector4 vector, FP maxLength)
        {
            if (vector.magnitude <= maxLength)
            {
                return(vector);
            }

            return(Normalize(vector) * maxLength);
        }
示例#23
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 TSVector4))
            {
                return(false);
            }
            TSVector4 other = (TSVector4)obj;

            return(((x == other.x) && (y == other.y)) && (z == other.z) && (w == other.w));
        }
示例#24
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 TSVector4 value, out TSVector4 result)
        {
            FP num2 = ((value.x * value.x) + (value.y * value.y)) + (value.z * value.z) + (value.w * value.w);
            FP num  = FP.One / FP.Sqrt(num2);

            result.x = value.x * num;
            result.y = value.y * num;
            result.z = value.z * num;
            result.w = value.w * num;
        }
示例#25
0
        /// <summary>
        /// Multiplies each component of the vector by the same components of the provided vector.
        /// </summary>
        public static TSVector4 Scale(TSVector4 vecA, TSVector4 vecB)
        {
            TSVector4 result;

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

            return(result);
        }
示例#26
0
        // Reference: http://forum.photonengine.com/discussion/10422/truesync-tsvector-clampmagnitude-is-inconsistent-with-unityengine-vector3-clampmagnitude
        public static TSVector4 ClampMagnitude(TSVector4 vector, FP maxLength)
        {
            TSVector4 result;

            if (vector.sqrMagnitude > maxLength * maxLength)
            {
                result = vector.normalized * maxLength;
            }
            else
            {
                result = vector;
            }
            return(result);
        }
示例#27
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 TSVector4 vector1, ref TSVector4 vector2)
        {
            FP 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;

            temp      = vector1.w;
            vector1.w = vector2.w;
            vector2.w = temp;
        }
示例#28
0
 /**
  *  @brief Transform a vector from world space to local space.
  **/
 public TSVector4 InverseTransformVector(TSVector4 vector)
 {
     Debug.Assert(vector.w == FP.Zero);
     return(TSVector4.Transform(vector, worldToLocalMatrix));
 }
示例#29
0
 /**
  *  @brief Transform a vector from local space to world space.
  **/
 public TSVector4 TransformVector(TSVector4 vector)
 {
     Debug.Assert(vector.w == FP.Zero);
     return(TSVector4.Transform(vector, localToWorldMatrix));
 }
示例#30
0
 public TSVector InverseTransformPoint(TSVector point)
 {
     return(TSVector4.Transform(point, worldToLocalMatrix).ToTSVector());
 }