public void TestToInt16() { Int16 expected = BitConverter.ToInt16(_bytes, 0); Int16 actual = BitConverterNonAlloc.ToInt16(_bytes, 0); Assert.That(actual, Is.EqualTo(expected)); }
/// <summary> /// Fills this VectorHand with data read from the provided byte array, starting at /// the provided offset. /// </summary> public void ReadBytes(byte[] bytes, ref int offset) { if (bytes.Length - offset < numBytesRequired) { throw new System.IndexOutOfRangeException( "Not enough room to read bytes for VectorHand encoding starting at offset " + offset + " for array of size " + bytes + "; need at least " + numBytesRequired + " bytes from the offset position."); } // Chirality. isLeft = bytes[offset++] == 0x00; // Palm position and rotation. for (int i = 0; i < 3; i++) { palmPos[i] = Convert.ToSingle( BitConverterNonAlloc.ToInt16(bytes, ref offset)) / 4096f; } palmRot = Utils.DecompressBytesToQuat(bytes, ref offset); // Palm-local bone joint positions. for (int i = 0; i < NUM_JOINT_POSITIONS; i++) { for (int j = 0; j < 3; j++) { jointPositions[i][j] = VectorHandExtensions.ByteToFloat(bytes[offset++]); } } }
//Constructs an interpolable representation from a byte array public override void fillEncoding(byte[] handData) { if (handData == null || handData.Length != data.Length) { handData = new byte[data.Length]; } data = handData; int index = 0; //Left Hand LPos = new Vector3((BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f, (BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f, (BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f); LRot = Utils.DecompressBytesToQuat(data, ref index); for (int i = 0; i < 6;) { LCurl[i++] = data[index++]; } //Right Hand RPos = new Vector3((BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f, (BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f, (BitConverterNonAlloc.ToInt16(data, ref index)) / 4096f); RRot = Utils.DecompressBytesToQuat(data, ref index); for (int i = 0; i < 6;) { RCurl[i++] = data[index++]; } }