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(); } }
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(); } }