Пример #1
0
        public static MinimumAvatarPacket BufferToPacket(byte[] buf)
        {
            if (buf == null || buf.Length != 31)
            {
                return(null);
            }
            var offset = sizeof(float);
            var userId = BitConverter.ToUInt64(buf, offset);
            var x      = BitConverter.ToInt16(buf, offset += sizeof(long));
            var y      = BitConverter.ToInt16(buf, offset += sizeof(short));
            var z      = BitConverter.ToInt16(buf, offset += sizeof(short));

            offset += sizeof(short);
            var radY = (sbyte)buf[offset];
            var qx   = (sbyte)buf[offset + 1];
            var qy   = (sbyte)buf[offset + 2];
            var qz   = (sbyte)buf[offset + 3];
            var qw   = (sbyte)buf[offset + 4];
            var time = BitConverter.ToDouble(buf, offset + 5);
            MinimumAvatarPacket packet =
                new MinimumAvatarPacket(userId, new Vector3(x, y, z), radY,
                                        new Vector4(qx, qy, qz, qw), time);

            if (packet.CheckRange())
            {
                return(packet);
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        public static List <MinimumAvatarPacket> BufferToPackets(byte[] buf)
        {
            if (buf != null && buf.Length > 0)
            {
                int begin           = sizeof(float);
                var numPackets      = BitConverter.ToInt32(buf, 0);
                var supposedBufSize = numPackets * 27 + begin;
                if (buf.Length == supposedBufSize)
                {
                    List <MinimumAvatarPacket> packets = new List <MinimumAvatarPacket>();
                    for (int i = 0; i < numPackets; ++i)
                    {
                        var offset = begin + i * 27;
                        var userId = BitConverter.ToUInt64(buf, offset);
                        var x      = BitConverter.ToInt16(buf, offset += sizeof(long));
                        var y      = BitConverter.ToInt16(buf, offset += sizeof(short));
                        var z      = BitConverter.ToInt16(buf, offset += sizeof(short));
                        offset += sizeof(short);
                        var radY = (sbyte)buf[offset];
                        var qx   = (sbyte)buf[offset + 1];
                        var qy   = (sbyte)buf[offset + 2];
                        var qz   = (sbyte)buf[offset + 3];
                        var qw   = (sbyte)buf[offset + 4];
                        var time = BitConverter.ToDouble(buf, offset + 5);
                        MinimumAvatarPacket packet = new MinimumAvatarPacket(userId, new Vector3(x, y, z),
                                                                             radY,
                                                                             new Vector4(qx, qy, qz, qw), time);
                        if (packet.CheckRange())
                        {
                            packets.Add(packet);
                        }
                    }

                    return(packets);
                }
            }


            return(null);
        }