コード例 #1
0
        private void convert_button_Click(object sender, EventArgs e)
        {
            string hexStr = hex_txt.Text.Trim();

            if (!isValidHex(ref hexStr) || hexStr.Length % 4 != 0)
            {
                convert_res.Text = "Invalid hex!";
                return;
            }

            string halfStr = "";

            for (int i = 0; i < hexStr.Length; i += 4)
            {
                string          tmpStr    = hexStr.Substring(i, 4);
                UInt16          hex       = UInt16.Parse(tmpStr, System.Globalization.NumberStyles.HexNumber);
                byte[]          halfBytes = BitConverter.GetBytes(hex);
                SystemHalf.Half half      = SystemHalf.Half.ToHalf(hex);
                halfStr += half.ToString() + "\r\n";
            }

            convert_res.Text = halfStr;
        }
コード例 #2
0
        public void UnpackAnimations(byte[] recBuffer)
        {
            int receivedPacketSequence = BitConverter.ToInt32(recBuffer, 0);

            bool ordered = true;

            if (receivedPacketSequence < currentAnimationPacket - 5)
            {
                ordered = false;
            }
            else
            {
                currentAnimationPacket = Math.Max(currentAnimationPacket, receivedPacketSequence);
            }

            MultiplayerFrameBufferObject currentBufferObject = new MultiplayerFrameBufferObject();

            currentBufferObject.key       = recBuffer[4] == (byte)1 ? true : false;
            currentBufferObject.animFrame = receivedPacketSequence;

            currentBufferObject.frameTime = BitConverter.ToSingle(recBuffer, recBuffer.Length - 4);

            if (this.firstFrameTime != -1f && currentBufferObject.frameTime < this.firstFrameTime)
            {
                return;
            }

            Vector3[]    vectors     = new Vector3[77];
            Quaternion[] quaternions = new Quaternion[77];

            float[]           floatValues = null;
            ushort[]          halfValues  = null;
            SystemHalf.Half[] halfArray   = null;

            if (currentBufferObject.key)
            {
                halfValues = new ushort[77 * 6];
                halfArray  = new SystemHalf.Half[77 * 6];

                Buffer.BlockCopy(recBuffer, 5, halfValues, 0, 77 * 6 * sizeof(ushort));

                for (int i = 0; i < halfValues.Length; i++)
                {
                    halfArray[i]       = new SystemHalf.Half();
                    halfArray[i].Value = halfValues[i];
                }
            }
            else
            {
                floatValues = new float[77 * 6];

                Buffer.BlockCopy(recBuffer, 5, floatValues, 0, 77 * 6 * sizeof(float));
            }

            for (int i = 0; i < 77; i++)
            {
                if (currentBufferObject.key)
                {
                    vectors[i].x = SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6]);
                    vectors[i].y = SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6 + 1]);
                    vectors[i].z = SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6 + 2]);

                    quaternions[i].eulerAngles = new Vector3(SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6 + 3]),
                                                             SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6 + 4]),
                                                             SystemHalf.HalfHelper.HalfToSingle(halfArray[i * 6 + 5]));
                }
                else
                {
                    vectors[i].x = floatValues[i * 6];
                    vectors[i].y = floatValues[i * 6 + 1];
                    vectors[i].z = floatValues[i * 6 + 2];

                    quaternions[i].eulerAngles = new Vector3(floatValues[i * 6 + 3], floatValues[i * 6 + 4], floatValues[i * 6 + 5]);
                }
            }

            currentBufferObject.vectors     = vectors;
            currentBufferObject.quaternions = quaternions;

            if (ordered)
            {
                this.animationFrames.Add(currentBufferObject);

                this.animationFrames.Sort((f, f2) => f.animFrame.CompareTo(f2.animFrame));
                //this.animationFrames = this.animationFrames.OrderBy(f => f.animFrame).ToList();
            }

            if ((this.replayAnimationFrames.Count > 0 && this.replayAnimationFrames[0] != null && this.replayAnimationFrames[0].animFrame > currentBufferObject.animFrame) ||
                (!currentBufferObject.key && this.replayAnimationFrames.Count < 1))
            {
                return;
            }

            if (this.startAnimTime == -1f && this.firstFrameTime == -1f && currentBufferObject.key)
            {
                this.firstFrameTime = currentBufferObject.frameTime;
                this.startAnimTime  = PlayTime.time;
            }

            while (this.replayAnimationFrames.Count > 30 * 120)
            {
                this.replayAnimationFrames.RemoveAt(0);
            }

            Vector3[]    replayVectors     = new Vector3[vectors.Length];
            Quaternion[] replayQuaternions = new Quaternion[quaternions.Length];
            vectors.CopyTo(replayVectors, 0);
            quaternions.CopyTo(replayQuaternions, 0);

            MultiplayerFrameBufferObject replayFrameObject = new MultiplayerFrameBufferObject {
                key         = currentBufferObject.key,
                frameTime   = currentBufferObject.frameTime,
                animFrame   = currentBufferObject.animFrame,
                vectors     = replayVectors,
                quaternions = replayQuaternions
            };

            currentBufferObject.replayFrameBufferObject = replayFrameObject;

            this.replayAnimationFrames.Add(replayFrameObject);
        }