Exemple #1
0
        public static Quaternion ReadQuaternion(this Lidgren.Network.NetIncomingMessage im)
        {
            var maxIndex = im.ReadRangedInteger(0, 3);

            var a = im.ReadRangedSingle(UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            var b = im.ReadRangedSingle(UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            var c = im.ReadRangedSingle(UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            var d = (float)Math.Sqrt(1f - (a * a + b * b + c * c));

            im.ReadPadBits();
            Quaternion q;

            if (maxIndex == 0)
            {
                return(new Quaternion(d, a, b, c));
            }
            if (maxIndex == 1)
            {
                return(new Quaternion(a, d, b, c));
            }
            if (maxIndex == 2)
            {
                return(new Quaternion(a, b, d, c));
            }
            return(new Quaternion(a, b, c, d));
        }