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(); }
public static void Send(Lidgren.Network.NetOutgoingMessage message, Canvas canvas, Palette pal) { using (var stream = new MemoryStream()) { Pablo.Save(stream, canvas, pal); stream.Flush(); stream.Seek(0, SeekOrigin.Begin); message.WriteVariableInt32(canvas.Width); message.WriteVariableInt32(canvas.Height); message.WritePadBits(); message.WriteStream((Stream)stream); } }