Exemplo n.º 1
0
        //Fills a 170-byte array, representing the pose and position of both hands
        void fillByteArray(byte[] handData)
        {
            if (handData == null || handData.Length != data.Length)
            {
                handData = new byte[data.Length];
            }
            int index = 0;

            //Left Hand
            for (int i = 0; i < 3; i++)
            {
                BitConverterNonAlloc.GetBytes(Convert.ToInt16(LPos[i] * 4096f), handData, ref index);
            }

            Utils.CompressQuatToBytes(LRot, handData, ref index);

            for (int i = 0; i < 75;)
            {
                handData[index++] = LBones[i++];
            }

            //Right Hand
            for (int i = 0; i < 3; i++)
            {
                BitConverterNonAlloc.GetBytes(Convert.ToInt16(RPos[i] * 4096f), handData, ref index);
            }

            Utils.CompressQuatToBytes(RRot, handData, ref index);

            for (int i = 0; i < 75;)
            {
                handData[index++] = RBones[i++];
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Write a bool to the state.
        /// </summary>
        /// <param name="value">bool value</param>
        public void Write(bool value)
        {
            // Use the shared buffer instead of allocating a new array
            BitConverterNonAlloc.GetBytes(sharedBuffer, value);

            // Write all bytes
            Write(sharedBuffer, 0, sizeof(bool));
        }
    public void TestFromInt32() {
      Int32 value = (Int32)UnityEngine.Random.Range(float.MinValue, float.MaxValue);
      var actual = BitConverter.GetBytes(value);

      int offset = 0;
      BitConverterNonAlloc.GetBytes(value, _bytes, ref offset);

      Assert.That(offset, Is.EqualTo(actual.Length));
      Assert.That(_bytes.Take(offset), Is.EquivalentTo(actual));
    }
Exemplo n.º 4
0
        /// <summary>
        /// Fills the provided byte array with a compressed, 86-byte form of this VectorHand,
        /// starting at the provided offset.
        ///
        /// Throws an IndexOutOfRangeException if the provided byte array doesn't have enough
        /// space (starting from the offset) to write the number of bytes required.
        /// </summary>
        public void FillBytes(byte[] bytesToFill, ref int offset)
        {
            if (_backingJointPositions == null)
            {
                throw new System.InvalidOperationException(
                          "Joint positions array is null. You must fill a VectorHand with data before "
                          + "you can use it to fill byte representations.");
            }

            if (bytesToFill.Length - offset < numBytesRequired)
            {
                throw new System.IndexOutOfRangeException(
                          "Not enough room to fill bytes for VectorHand encoding starting at offset "
                          + offset + " for array of size " + bytesToFill.Length + "; need at least "
                          + numBytesRequired + " bytes from the offset position.");
            }

            // Chirality.
            bytesToFill[offset++] = isLeft ? (byte)0x00 : (byte)0x01;

            // Palm position, each component compressed
            for (int i = 0; i < 3; i++)
            {
                BitConverterNonAlloc.GetBytes(Convert.ToInt16(palmPos[i] * 4096f),
                                              bytesToFill,
                                              ref offset);
            }

            // Palm rotation.
            Utils.CompressQuatToBytes(palmRot, bytesToFill, ref offset);

            // Joint positions.
            for (int j = 0; j < NUM_JOINT_POSITIONS; j++)
            {
                for (int i = 0; i < 3; i++)
                {
                    bytesToFill[offset++] =
                        VectorHandExtensions.FloatToByte(jointPositions[j][i]);
                }
            }
        }