Ejemplo n.º 1
0
        public override void Read(Library.Collections.BitStream stream, out Quaternion value, MySerializeInfo info)
        {
            if (info.IsNormalized)
            {
                bool   cwNeg = stream.ReadBool();
                bool   cxNeg = stream.ReadBool();
                bool   cyNeg = stream.ReadBool();
                bool   czNeg = stream.ReadBool();
                ushort cx    = stream.ReadUInt16();
                ushort cy    = stream.ReadUInt16();
                ushort cz    = stream.ReadUInt16();

                // Calculate w from x,y,z
                value.X = (float)(cx / 65535.0);
                value.Y = (float)(cy / 65535.0);
                value.Z = (float)(cz / 65535.0);
                if (cxNeg)
                {
                    value.X = -value.X;
                }
                if (cyNeg)
                {
                    value.Y = -value.Y;
                }
                if (czNeg)
                {
                    value.Z = -value.Z;
                }
                float difference = 1.0f - value.X * value.X - value.Y * value.Y - value.Z * value.Z;
                if (difference < 0.0f)
                {
                    difference = 0.0f;
                }
                value.W = (float)(Math.Sqrt(difference));
                if (cwNeg)
                {
                    value.W = -value.W;
                }
            }
            else
            {
                Debug.Fail("Not normalized quaternion?");
                value.X = stream.ReadFloat();
                value.Y = stream.ReadFloat();
                value.Z = stream.ReadFloat();
                value.W = stream.ReadFloat();
            }
        }
Ejemplo n.º 2
0
 public override void Read(Library.Collections.BitStream stream, out TEnum value, MySerializeInfo info)
 {
     if (m_valueCount == 1)
     {
         value = m_firstValue;
     }
     else if (m_valueCount == 2)
     {
         value = stream.ReadBool() ? m_firstValue : m_secondValue;
     }
     else if (m_valueCount > 2)
     {
         if (HasNegativeValues)
         {
             value = MyEnum <TEnum> .SetValue((ulong)stream.ReadInt64Variant());
         }
         else
         {
             value = MyEnum <TEnum> .SetValue(stream.ReadUInt64(m_bitCount));
         }
     }
     else
     {
         value = default(TEnum);
     }
 }
Ejemplo n.º 3
0
 public override void Read(Library.Collections.BitStream stream, out T?value, MySerializeInfo info)
 {
     if (stream.ReadBool())
     {
         T val;
         m_serializer.Read(stream, out val, info);
         value = val;
     }
     else
     {
         value = null;
     }
 }
Ejemplo n.º 4
0
 public override void Read(Library.Collections.BitStream stream, out bool value, MySerializeInfo info)
 {
     value = stream.ReadBool();
 }