Пример #1
0
        /**
         * @note Exp should really only be used after Log.
         * Assumes a quaternion with W=0 and V=theta*v (where |v| = 1).
         * Exp(q) = (sin(theta)*v, cos(theta))
         */
        public FQuat Exp()
        {
            float Angle    = (float)FMath.Sqrt(X * X + Y * Y + Z * Z);
            float SinAngle = (float)FMath.Sin(Angle);

            FQuat Result = new FQuat();

            Result.W = (float)FMath.Cos(Angle);

            if (FMath.Abs(SinAngle) >= Const.SMALL_NUMBER)
            {
                float Scale = SinAngle / Angle;
                Result.X = Scale * X;
                Result.Y = Scale * Y;
                Result.Z = Scale * Z;
            }
            else
            {
                Result.X = X;
                Result.Y = Y;
                Result.Z = Z;
            }

            return(Result);
        }
Пример #2
0
        /**
         * @return quaternion with W=0 and V=theta*v.
         */
        public FQuat Log()
        {
            FQuat Result = new UnrealEngine.FQuat();

            Result.W = 0.0f;

            if (FMath.Abs(W) < 1.0f)
            {
                float Angle    = (float)FMath.Acos(W);
                float SinAngle = (float)FMath.Sin(Angle);

                if (FMath.Abs(SinAngle) >= Const.SMALL_NUMBER)
                {
                    float Scale = Angle / SinAngle;
                    Result.X = Scale * X;
                    Result.Y = Scale * Y;
                    Result.Z = Scale * Z;

                    return(Result);
                }
            }

            Result.X = X;
            Result.Y = Y;
            Result.Z = Z;

            return(Result);
        }
Пример #3
0
        /**
         * Checks whether another Quaternion is equal to this, within specified tolerance.
         *
         * @param Q The other Quaternion.
         * @param Tolerance Error Tolerance.
         * @return true if two Quaternion are equal, within specified tolerance, otherwise false.
         */
        public override bool Equals(object Obj)
        {
            FQuat Q         = (FQuat)Obj;
            float Tolerance = Const.KINDA_SMALL_NUMBER;

            return((FMath.Abs(X - Q.X) <= Tolerance && FMath.Abs(Y - Q.Y) <= Tolerance && FMath.Abs(Z - Q.Z) <= Tolerance && FMath.Abs(W - Q.W) <= Tolerance) ||
                   (FMath.Abs(X + Q.X) <= Tolerance && FMath.Abs(Y + Q.Y) <= Tolerance && FMath.Abs(Z + Q.Z) <= Tolerance && FMath.Abs(W + Q.W) <= Tolerance));
        }
Пример #4
0
        /**
         * Checks whether another Matrix is equal to this, within specified tolerance.
         *
         * @param Other The other Matrix.
         * @param Tolerance Error Tolerance.
         * @return true if two Matrix are equal, within specified tolerance, otherwise false.
         */
        public override bool Equals(object Obj)
        {
            FMatrix Other     = (FMatrix)Obj;
            float   Tolerance = Const.KINDA_SMALL_NUMBER;

            for (int X = 0; X < 4; X++)
            {
                for (int Y = 0; Y < 4; Y++)
                {
                    if (FMath.Abs(this[X, Y] - Other[X, Y]) > Tolerance)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Пример #5
0
        /**
         * Compare two points and see if they're within specified distance.
         *
         * @param Point1 First vector.
         * @param Point2 Second vector.
         * @param Dist Specified distance.
         * @return Whether two points are within the specified distance. Uses fast distance approximation (linear per-component distance).
         */
        public static bool PointsAreNear(FVector Point1, FVector Point2, float Dist)
        {
            float Temp;

            Temp = (Point1.X - Point2.X); if (FMath.Abs(Temp) >= Dist)
            {
                return(false);
            }
            Temp = (Point1.Y - Point2.Y); if (FMath.Abs(Temp) >= Dist)
            {
                return(false);
            }
            Temp = (Point1.Z - Point2.Z); if (FMath.Abs(Temp) >= Dist)
            {
                return(false);
            }
            return(true);
        }
Пример #6
0
 // Return true if this quaternion is normalized
 public bool IsNormalized()
 {
     return(FMath.Abs(1.0f - SizeSquared()) < Const.THRESH_QUAT_NORMALIZED);
 }
Пример #7
0
 bool Equals(FRotator R, float Tolerance = Const.KINDA_SMALL_NUMBER)
 {
     return((FMath.Abs(NormalizeAxis(Pitch - R.Pitch)) <= Tolerance) &&
            (FMath.Abs(NormalizeAxis(Yaw - R.Yaw)) <= Tolerance) &&
            (FMath.Abs(NormalizeAxis(Roll - R.Roll)) <= Tolerance));
 }
Пример #8
0
 bool AllComponentsEqual(float Tolerance)
 {
     return(FMath.Abs(X - Y) <= Tolerance && FMath.Abs(X - Z) <= Tolerance && FMath.Abs(Y - Z) <= Tolerance);
 }
Пример #9
0
 /**
  * Get a copy of this vector with absolute value of each component.
  *
  * @return A copy of this vector with absolute value of each component.
  */
 public FVector GetAbs()
 {
     return(new FVector(FMath.Abs(X), FMath.Abs(Y), FMath.Abs(Z)));
 }
Пример #10
0
 /**
  * Get the minimum absolute value of the vector's components.
  *
  * @return The minimum absolute value of the vector's components.
  */
 public float GetAbsMin()
 {
     return(FMath.Min(FMath.Min(FMath.Abs(X), FMath.Abs(Y)), FMath.Abs(Z)));
 }