コード例 #1
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// copy constructor
 /// </summary>
 public decquat(decquat q)
 {
     this.x = q.x;
     this.y = q.y;
     this.z = q.z;
     this.w = q.w;
 }
コード例 #2
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
        /// <summary>
        /// Create a quaternion from two normalized axis (http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors)
        /// </summary>
        public decquat(decvec3 u, decvec3 v)
        {
            var localW = decvec3.Cross(u, v);
            var dot    = decvec3.Dot(u, v);
            var q      = new decquat(localW.x, localW.y, localW.z, 1m + dot).Normalized;

            this.x = q.x;
            this.y = q.y;
            this.z = q.z;
            this.w = q.w;
        }
コード例 #3
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
        /// <summary>
        /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
        /// </summary>
        public static decquat Mix(decquat x, decquat y, decimal 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((decquat)((Math.Sin((1 - (double)a) * angle) * (dquat)x + Math.Sin((double)a * angle) * (dquat)y) / Math.Sin(angle)));
            }
        }
コード例 #4
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
        /// <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 decquat result)
        {
            result = Zero;
            if (string.IsNullOrEmpty(s))
            {
                return(false);
            }
            var kvp = s.Split(new[] { sep }, StringSplitOptions.None);

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

            result = ok ? new decquat(x, y, z, w) : Zero;
            return(ok);
        }
コード例 #5
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
        /// <summary>
        /// Calculates a proper spherical interpolation between two quaternions (only works for normalized quaternions).
        /// </summary>
        public static decquat SLerp(decquat x, decquat y, decimal 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((decquat)((Math.Sin((1 - (double)a) * angle) * (dquat)x + Math.Sin((double)a * angle) * (dquat)z) / Math.Sin(angle)));
            }
        }
コード例 #6
0
ファイル: decmat3.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Creates a rotation matrix from a decquat.
 /// </summary>
 public decmat3(decquat q)
     : this(q.ToMat3)
 {
 }
コード例 #7
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a decquat from component-wise application of Lerp (min * (1-a) + max * a).
 /// </summary>
 public static decquat Lerp(decimal min, decquat max, decimal a) => new decquat(min * (1 - a) + max.x * a, min * (1 - a) + max.y * a, min * (1 - a) + max.z * a, min * (1 - a) + max.w * a);
コード例 #8
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThanEqual (lhs &lt;= rhs).
 /// </summary>
 public static bvec4 LesserThanEqual(decimal lhs, decquat rhs) => new bvec4(lhs <= rhs.x, lhs <= rhs.y, lhs <= rhs.z, lhs <= rhs.w);
コード例 #9
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThanEqual (lhs &lt;= rhs).
 /// </summary>
 public static bvec4 LesserThanEqual(decquat lhs, decquat rhs) => new bvec4(lhs.x <= rhs.x, lhs.y <= rhs.y, lhs.z <= rhs.z, lhs.w <= rhs.w);
コード例 #10
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThan (lhs &lt; rhs).
 /// </summary>
 public static bvec4 LesserThan(decquat lhs, decquat rhs) => new bvec4(lhs.x < rhs.x, lhs.y < rhs.y, lhs.z < rhs.z, lhs.w < rhs.w);
コード例 #11
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of GreaterThanEqual (lhs &gt;= rhs).
 /// </summary>
 public static bvec4 GreaterThanEqual(decquat lhs, decimal rhs) => new bvec4(lhs.x >= rhs, lhs.y >= rhs, lhs.z >= rhs, lhs.w >= rhs);
コード例 #12
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns the cross product between two quaternions.
 /// </summary>
 public static decquat Cross(decquat q1, decquat q2) => new decquat(q1.w * q2.x + q1.x * q2.w + q1.y * q2.z - q1.z * q2.y, q1.w * q2.y + q1.y * q2.w + q1.z * q2.x - q1.x * q2.z, q1.w * q2.z + q1.z * q2.w + q1.x * q2.y - q1.y * q2.x, q1.w * q2.w - q1.x * q2.x - q1.y * q2.y - q1.z * q2.z);
コード例 #13
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns the inner product (dot product, scalar product) of the two quaternions.
 /// </summary>
 public static decimal Dot(decquat lhs, decquat rhs) => ((lhs.x * rhs.x + lhs.y * rhs.y) + (lhs.z * rhs.z + lhs.w * rhs.w));
コード例 #14
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Tries to convert the string representation of the quaternion into a quaternion representation (using ', ' as a separator), returns false if string was invalid.
 /// </summary>
 public static bool TryParse(string s, out decquat result) => TryParse(s, ", ", out result);
コード例 #15
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns true iff this equals rhs component-wise.
 /// </summary>
 public bool Equals(decquat rhs) => ((x.Equals(rhs.x) && y.Equals(rhs.y)) && (z.Equals(rhs.z) && w.Equals(rhs.w)));
コード例 #16
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of GreaterThan (lhs &gt; rhs).
 /// </summary>
 public static bvec4 GreaterThan(decquat lhs, decquat rhs) => new bvec4(lhs.x > rhs.x, lhs.y > rhs.y, lhs.z > rhs.z, lhs.w > rhs.w);
コード例 #17
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of GreaterThan (lhs &gt; rhs).
 /// </summary>
 public static bvec4 GreaterThan(decquat lhs, decimal rhs) => new bvec4(lhs.x > rhs, lhs.y > rhs, lhs.z > rhs, lhs.w > rhs);
コード例 #18
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Applies squad interpolation of these quaternions
 /// </summary>
 public static decquat Squad(decquat q1, decquat q2, decquat s1, decquat s2, decimal h) => Mix(Mix(q1, q2, h), Mix(s1, s2, h), 2 * (1 - h) * h);
コード例 #19
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of GreaterThanEqual (lhs &gt;= rhs).
 /// </summary>
 public static bvec4 GreaterThanEqual(decimal lhs, decquat rhs) => new bvec4(lhs >= rhs.x, lhs >= rhs.y, lhs >= rhs.z, lhs >= rhs.w);
コード例 #20
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of Equal (lhs == rhs).
 /// </summary>
 public static bvec4 Equal(decquat lhs, decquat rhs) => new bvec4(lhs.x == rhs.x, lhs.y == rhs.y, lhs.z == rhs.z, lhs.w == rhs.w);
コード例 #21
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThan (lhs &lt; rhs).
 /// </summary>
 public static bvec4 LesserThan(decquat lhs, decimal rhs) => new bvec4(lhs.x < rhs, lhs.y < rhs, lhs.z < rhs, lhs.w < rhs);
コード例 #22
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of Equal (lhs == rhs).
 /// </summary>
 public static bvec4 Equal(decquat lhs, decimal rhs) => new bvec4(lhs.x == rhs, lhs.y == rhs, lhs.z == rhs, lhs.w == rhs);
コード例 #23
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThanEqual (lhs &lt;= rhs).
 /// </summary>
 public static bvec4 LesserThanEqual(decquat lhs, decimal rhs) => new bvec4(lhs.x <= rhs, lhs.y <= rhs, lhs.z <= rhs, lhs.w <= rhs);
コード例 #24
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of NotEqual (lhs != rhs).
 /// </summary>
 public static bvec4 NotEqual(decquat lhs, decquat rhs) => new bvec4(lhs.x != rhs.x, lhs.y != rhs.y, lhs.z != rhs.z, lhs.w != rhs.w);
コード例 #25
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a decquat from component-wise application of Lerp (min * (1-a) + max * a).
 /// </summary>
 public static decquat Lerp(decquat min, decquat max, decquat a) => new decquat(min.x * (1 - a.x) + max.x * a.x, min.y * (1 - a.y) + max.y * a.y, min.z * (1 - a.z) + max.z * a.z, min.w * (1 - a.w) + max.w * a.w);
コード例 #26
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of NotEqual (lhs != rhs).
 /// </summary>
 public static bvec4 NotEqual(decquat lhs, decimal rhs) => new bvec4(lhs.x != rhs, lhs.y != rhs, lhs.z != rhs, lhs.w != rhs);
コード例 #27
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a decquat from component-wise application of Lerp (min * (1-a) + max * a).
 /// </summary>
 public static decquat Lerp(decquat min, decimal max, decimal a) => new decquat(min.x * (1 - a) + max * a, min.y * (1 - a) + max * a, min.z * (1 - a) + max * a, min.w * (1 - a) + max * a);
コード例 #28
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of NotEqual (lhs != rhs).
 /// </summary>
 public static bvec4 NotEqual(decimal lhs, decquat rhs) => new bvec4(lhs != rhs.x, lhs != rhs.y, lhs != rhs.z, lhs != rhs.w);
コード例 #29
0
ファイル: decquat.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a decquat from component-wise application of Lerp (min * (1-a) + max * a).
 /// </summary>
 public static decquat Lerp(decimal min, decimal max, decquat a) => new decquat(min * (1 - a.x) + max * a.x, min * (1 - a.y) + max * a.y, min * (1 - a.z) + max * a.z, min * (1 - a.w) + max * a.w);
コード例 #30
0
ファイル: decquat.glm.cs プロジェクト: marcusanth/GlmSharp
 /// <summary>
 /// Returns a bvec4 from component-wise application of LesserThan (lhs &lt; rhs).
 /// </summary>
 public static bvec4 LesserThan(decquat lhs, decquat rhs) => decquat.LesserThan(lhs, rhs);