Пример #1
0
        public static F64Quat LookRotation(F64Vec3 dir, F64Vec3 up)
        { // From: https://answers.unity.com/questions/819699/calculate-quaternionlookrotation-manually.html
            if (dir == F64Vec3.Zero)
            {
                return(Identity);
            }

            if (up != dir)
            {
                up = F64Vec3.NormalizeFastest(up);
                F64Vec3 v = dir + up * -F64Vec3.Dot(up, dir);
                F64Quat q = FromTwoVectors(F64Vec3.AxisZ, v);
                return(FromTwoVectors(v, dir) * q);
            }
            else
            {
                return(FromTwoVectors(F64Vec3.AxisZ, dir));
            }
        }
Пример #2
0
        public static F64Quat LookAtRotation(F64Vec3 from, F64Vec3 to, F64Vec3 up)
        {
            F64Vec3 dir = F64Vec3.NormalizeFastest(to - from);

            return(LookRotation(dir, up));
        }