예제 #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();
            }
        }
예제 #2
0
 public override void Read(Library.Collections.BitStream stream, out UInt16 value, MySerializeInfo info)
 {
     if (info.IsVariant || info.IsVariantSigned)
     {
         value = (UInt16)stream.ReadUInt32Variant();
     }
     else
     {
         value = stream.ReadUInt16();
     }
 }
예제 #3
0
 public override void Read(Library.Collections.BitStream stream, out float value, MySerializeInfo info)
 {
     if (info.IsNormalized && info.IsFixed8)
     {
         value = stream.ReadByte() / 255.0f;
     }
     else if (info.IsNormalized && info.IsFixed16)
     {
         value = stream.ReadUInt16() / 65535.0f;
     }
     else
     {
         value = stream.ReadFloat();
     }
 }