Exemplo n.º 1
0
        public static void Write(this Lidgren.Network.NetOutgoingMessage om, Quaternion q)
        {
            var maxIndex = 0;
            var maxValue = float.MinValue;
            var sign     = 1f;

            maxValue = Math.Abs(q.X);
            sign     = q.X < 0 ? -1 : 1;

            if (Math.Abs(q.Y) > maxValue)
            {
                maxValue = Math.Abs(q.Y);
                maxIndex = 1;
                sign     = q.Y < 0 ? -1 : 1;
            }
            if (Math.Abs(q.Z) > maxValue)
            {
                maxValue = Math.Abs(q.Z);
                maxIndex = 2;
                sign     = q.Z < 0 ? -1 : 1;
            }
            if (Math.Abs(q.W) > maxValue)
            {
                maxValue = Math.Abs(q.W);
                maxIndex = 3;
                sign     = q.W < 0 ? -1 : 1;
            }
            om.WriteRangedInteger(0, 3, maxIndex);

            if (maxIndex == 0)
            {
                om.WriteRangedSingle(q.Y * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.Z * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.W * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            }
            else if (maxIndex == 1)
            {
                om.WriteRangedSingle(q.X * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.Z * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.W * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            }
            else if (maxIndex == 2)
            {
                om.WriteRangedSingle(q.X * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.Y * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.W * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            }
            else
            {
                om.WriteRangedSingle(q.X * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.Y * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
                om.WriteRangedSingle(q.Z * sign, UNIT_MIN, UNIT_MAX, BITS_COMPONENT);
            }
            om.WritePadBits();
        }
Exemplo n.º 2
0
 public static void WriteRadiansQuantized(this Lidgren.Network.NetOutgoingMessage om, float angle)
 {
     om.WriteRangedSingle(WrapMinMax(angle, ANGLE_MIN, ANGLE_MAX), ANGLE_MIN, ANGLE_MAX, 16);
 }