예제 #1
0
 /// <summary>
 /// copy constructor
 /// </summary>
 public dquat(dquat q)
 {
     this.x = q.x;
     this.y = q.y;
     this.z = q.z;
     this.w = q.w;
 }
예제 #2
0
        /// <summary>
        /// Create a quaternion from two normalized axis (http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors)
        /// </summary>
        public dquat(dvec3 u, dvec3 v)
        {
            var localW = dvec3.Cross(u, v);
            var dot    = dvec3.Dot(u, v);
            var q      = new dquat(localW.x, localW.y, localW.z, 1.0 + dot).Normalized;

            this.x = q.x;
            this.y = q.y;
            this.z = q.z;
            this.w = q.w;
        }
예제 #3
0
        /// <summary>
        /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
        /// </summary>
        public static dquat Mix(dquat x, dquat y, double a)
        {
            var cosTheta = (double)Dot(x, y);

            if (cosTheta > 1 - float.Epsilon)
            {
                return(Lerp(x, y, a));
            }
            else
            {
                var angle = Math.Acos((double)cosTheta);
                return((Math.Sin((1 - (double)a) * angle) * x + Math.Sin((double)a * angle) * y) / Math.Sin(angle));
            }
        }
예제 #4
0
        /// <summary>
        /// Tries to convert the string representation of the quaternion into a quaternion representation (using a designated separator), returns false if string was invalid.
        /// </summary>
        public static bool TryParse(string s, string sep, out dquat result)
        {
            result = Zero;
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }
            var kvp = s.Split(new[] { sep }, StringSplitOptions.None);

            if (kvp.Length != 4)
            {
                return(false);
            }
            double x = 0.0, y = 0.0, z = 0.0, w = 0.0;
            var    ok = ((double.TryParse(kvp[0].Trim(), out x) && double.TryParse(kvp[1].Trim(), out y)) && (double.TryParse(kvp[2].Trim(), out z) && double.TryParse(kvp[3].Trim(), out w)));

            result = ok ? new dquat(x, y, z, w) : Zero;
            return(ok);
        }
예제 #5
0
        /// <summary>
        /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
        /// </summary>
        public static dquat SLerp(dquat x, dquat y, double a)
        {
            var z        = y;
            var cosTheta = (double)Dot(x, y);

            if (cosTheta < 0)
            {
                z = -y; cosTheta = -cosTheta;
            }
            if (cosTheta > 1 - float.Epsilon)
            {
                return(Lerp(x, z, a));
            }
            else
            {
                var angle = Math.Acos((double)cosTheta);
                return((Math.Sin((1 - (double)a) * angle) * x + Math.Sin((double)a * angle) * z) / Math.Sin(angle));
            }
        }
예제 #6
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsNaN (double.IsNaN(v)).
 /// </summary>
 public static bvec4 IsNaN(dquat v) => dquat.IsNaN(v);
예제 #7
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsInfinity (double.IsInfinity(v)).
 /// </summary>
 public static bvec4 IsInfinity(dquat v) => dquat.IsInfinity(v);
예제 #8
0
 /// <summary>
 /// Returns true iff this equals rhs type- and component-wise.
 /// </summary>
 public static bool Equals(dquat q, object obj) => q.Equals(obj);
예제 #9
0
 /// <summary>
 /// Returns the number of components (4).
 /// </summary>
 public static int Count(dquat q) => q.Count;
예제 #10
0
 /// <summary>
 /// Returns a string representation of this quaternion using a provided seperator and a format for each component.
 /// </summary>
 public static string ToString(dquat q, string sep, string format) => q.ToString(sep, format);
예제 #11
0
 /// <summary>
 /// Returns a string representation of this quaternion using ', ' as a seperator.
 /// </summary>
 public static string ToString(dquat q) => q.ToString();
예제 #12
0
 /// <summary>
 /// Creates a dmat4 that realizes the rotation of this quaternion
 /// </summary>
 public static dmat4 ToMat4(dquat q) => q.ToMat4;
예제 #13
0
 /// <summary>
 /// Creates a dmat3 that realizes the rotation of this quaternion
 /// </summary>
 public static dmat3 ToMat3(dquat q) => q.ToMat3;
예제 #14
0
 /// <summary>
 /// Rotates this quaternion from an axis and an angle (in radians).
 /// </summary>
 public static dquat Rotated(dquat q, double angle, dvec3 v) => q.Rotated(angle, v);
예제 #15
0
 /// <summary>
 /// Returns the represented euler angles (pitch, yaw, roll) of this quaternion.
 /// </summary>
 public static dvec3 EulerAngles(dquat q) => q.EulerAngles;
예제 #16
0
 /// <summary>
 /// Returns a dquat from component-wise application of Lerp (min * (1-a) + max * a).
 /// </summary>
 public static dquat Lerp(dquat min, dquat max, dquat a) => dquat.Lerp(min, max, a);
예제 #17
0
 /// <summary>
 /// Returns an enumerator that iterates through all components.
 /// </summary>
 public static IEnumerator <double> GetEnumerator(dquat q) => q.GetEnumerator();
예제 #18
0
 /// <summary>
 /// Returns an array with all values
 /// </summary>
 public static double[] Values(dquat q) => q.Values;
예제 #19
0
 /// <summary>
 /// Returns a string representation of this quaternion using a provided seperator.
 /// </summary>
 public static string ToString(dquat q, string sep) => q.ToString(sep);
예제 #20
0
 /// <summary>
 /// Returns the conjugated quaternion
 /// </summary>
 public static dquat Conjugate(dquat q) => q.Conjugate;
예제 #21
0
 /// <summary>
 /// Returns a string representation of this quaternion using a provided seperator and a format and format provider for each component.
 /// </summary>
 public static string ToString(dquat q, string sep, string format, IFormatProvider provider) => q.ToString(sep, format, provider);
예제 #22
0
 /// <summary>
 /// Returns the inverse quaternion
 /// </summary>
 public static dquat Inverse(dquat q) => q.Inverse;
예제 #23
0
 /// <summary>
 /// Returns true iff this equals rhs component-wise.
 /// </summary>
 public static bool Equals(dquat q, dquat rhs) => q.Equals(rhs);
예제 #24
0
 /// <summary>
 /// Returns the cross product between two quaternions.
 /// </summary>
 public static dquat Cross(dquat q1, dquat q2) => dquat.Cross(q1, q2);
예제 #25
0
 /// <summary>
 /// Returns a hash code for this instance.
 /// </summary>
 public static int GetHashCode(dquat q) => q.GetHashCode();
예제 #26
0
 /// <summary>
 /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
 /// </summary>
 public static dquat Mix(dquat x, dquat y, double a) => dquat.Mix(x, y, a);
예제 #27
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsFinite (!double.IsNaN(v) &amp;&amp; !double.IsInfinity(v)).
 /// </summary>
 public static bvec4 IsFinite(dquat v) => dquat.IsFinite(v);
예제 #28
0
 /// <summary>
 /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
 /// </summary>
 public static dquat SLerp(dquat x, dquat y, double a) => dquat.SLerp(x, y, a);
예제 #29
0
 /// <summary>
 /// Returns a bvec4 from component-wise application of IsPositiveInfinity (double.IsPositiveInfinity(v)).
 /// </summary>
 public static bvec4 IsPositiveInfinity(dquat v) => dquat.IsPositiveInfinity(v);
예제 #30
0
 /// <summary>
 /// Applies squad interpolation of these quaternions
 /// </summary>
 public static dquat Squad(dquat q1, dquat q2, dquat s1, dquat s2, double h) => dquat.Squad(q1, q2, s1, s2, h);