Esempio n. 1
0
        /// 3頂点からラジアンを返す
        static private float getRadian(Vector3 posBase, Vector3 pos1, Vector3 pos2)
        {
            Vector3 calA = pos1 - posBase;
            Vector3 calB = pos2 - posBase;

            float lba    = calA.Length();
            float lca    = calB.Length();
            float radian = FMath.Acos(calA.Dot(calB) / (lba * lca));

            return(radian);
        }
Esempio n. 2
0
        public void TestAcos()
        {
            var a = Fixed.FromFloat(0.54646f);
            var r = Fixed.FromFloat(0.992664887f);

            AssertApproximately(r, FMath.Acos(a));

            a = Fixed.FromFloat(-0.154787f);
            r = Fixed.FromFloat(1.726208178f);
            AssertApproximately(r, FMath.Acos(a));
        }
Esempio n. 3
0
        /// 3頂点から角度を返す
        static private float getAngles(Vector3 posBase, Vector3 pos1, Vector3 pos2)
        {
            Vector3 calA = pos1 - posBase;
            Vector3 calB = pos2 - posBase;

            float lba    = calA.Length();
            float lca    = calB.Length();
            float radian = FMath.Acos(calA.Dot(calB) / (lba * lca));
            float angle  = (float)(180.0f / pi * radian);

            return(angle);
        }
Esempio n. 4
0
        public static Quatf Slerp_NoInvert(Quatf q0, Quatf q1, float t)
        {
            float dot = q0 % q1;

            if (dot > -0.95f && dot < 0.95f)
            {
                float ang = FMath.Acos(dot);
                return((q0 * FMath.Sin(ang * (1.0f - t)) + q1 * FMath.Sin(ang * t)) / FMath.Sin(ang));
            }
            else
            {
                return(Lerp(q0, q1, t));
            }
        }
Esempio n. 5
0
        public static Quatf Slerp(Quatf q0, Quatf q1, float t)
        {
            Quatf q2;
            float dot = q0 % q1;

            if (dot < 0.00f)
            {
                dot = -dot; q2 = q1 * -1.0f;
            }
            else
            {
                q2 = q1;
            }

            if (dot < 0.95f)
            {
                float ang = FMath.Acos(dot);
                return((q0 * FMath.Sin(ang * (1.0f - t)) + q2 * FMath.Sin(ang * t)) / FMath.Sin(ang));
            }
            else
            {
                return(Lerp(q0, q2, t));
            }
        }
Esempio n. 6
0
 public static float SafeAcos(float x)
 {
     Common.Assert(FMath.Abs(x) - 1f < 1E-05f);
     return(FMath.Acos(FMath.Clamp(x, -1f, 1f)));
 }