void Start() { th = gameObject.GetComponent <TrackerHub>(); mouseFinger = new FingerStruct(); mouseFinger.id = 0; mouseFinger.pos = new Vector2(0, 0); mouseFinger.action = 3; }
private void rawDeserialize(byte[] rawdatas) { int handIndex = 0; int fingerIndex = 0; int touchIndex = 0; int startIndex = 0; int frameCount = 0; int dataSize = rawdatas.Length; bool stop = false; while (startIndex < dataSize - 1) { byte[] typeByte = new byte[4]; Array.Copy(rawdatas, startIndex, typeByte, 0, 4); int type = BitConverter.ToInt32(typeByte, 0); switch (type) { case 1: HandStruct handStruct = new HandStruct(); getHandStruct(ref handStruct, rawdatas, startIndex); startIndex += handStructSize; handsData [handIndex] = handStruct; handIndex++; break; case 2: FingerStruct fingerStruct = new FingerStruct(); getFingerStruct(ref fingerStruct, rawdatas, startIndex); startIndex += fingerStructSize; fingersData [fingerIndex] = fingerStruct; fingerIndex++; break; case 4: TouchStruct touchStruct = new TouchStruct(); getTouchStruct(ref touchStruct, rawdatas, startIndex); startIndex += touchStructSize; touchesData [touchIndex] = touchStruct; touchIndex++; break; default: stop = true; break; } if (stop == true) { break; } } }
public Finger(FingerStruct fingerStruct) { fingerId = fingerStruct.fingerId; handId = fingerStruct.handId; frame = fingerStruct.frame; //Transform the position to the screen reference GameObject screenReference = GameObject.Find("ScreenReference"); fingerPosition = screenReference.transform.InverseTransformPoint(new Vector3(fingerStruct.fingerPosition.x, fingerStruct.fingerPosition.y, fingerStruct.fingerPosition.z)); fingerOrientation = screenReference.transform.InverseTransformPoint(new Vector3(fingerStruct.fingerOrientation.x, fingerStruct.fingerOrientation.y, fingerStruct.fingerOrientation.z)); }
public static void getFingerStruct(ref FingerStruct fingerStruct, byte[] rawdatas, int startIndex) { fingerStruct.structType = DataStruct.Finger; byte[] fingerByte = new byte[fingerStructSize]; Array.Copy(rawdatas, startIndex, fingerByte, 0, fingerStructSize); byte[] validByte = new byte[1]; Array.Copy(fingerByte, 4, validByte, 0, 1); fingerStruct.valid = BitConverter.ToBoolean(validByte, 0); byte[] fingerIdByte = new byte[4]; Array.Copy(fingerByte, 5, fingerIdByte, 0, 4); fingerStruct.fingerId = BitConverter.ToInt32(fingerIdByte, 0); byte[] handIdByte = new byte[4]; Array.Copy(fingerByte, 9, handIdByte, 0, 4); fingerStruct.handId = BitConverter.ToInt32(handIdByte, 0); byte[] frameByte = new byte[4]; Array.Copy(fingerByte, 13, frameByte, 0, 4); fingerStruct.frame = BitConverter.ToInt32(frameByte, 0); byte[] positionXByte = new byte[4]; byte[] positionYByte = new byte[4]; byte[] positionZByte = new byte[4]; Array.Copy(fingerByte, 17, positionXByte, 0, 4); Array.Copy(fingerByte, 21, positionYByte, 0, 4); Array.Copy(fingerByte, 25, positionZByte, 0, 4); fingerStruct.fingerPosition.x = BitConverter.ToSingle(positionXByte, 0); fingerStruct.fingerPosition.y = BitConverter.ToSingle(positionYByte, 0); fingerStruct.fingerPosition.z = BitConverter.ToSingle(positionZByte, 0); byte[] orientationXByte = new byte[4]; byte[] orientationYByte = new byte[4]; byte[] orientationZByte = new byte[4]; Array.Copy(fingerByte, 29, orientationXByte, 0, 4); Array.Copy(fingerByte, 33, orientationYByte, 0, 4); Array.Copy(fingerByte, 37, orientationZByte, 0, 4); fingerStruct.fingerOrientation.x = BitConverter.ToSingle(orientationXByte, 0); fingerStruct.fingerOrientation.y = BitConverter.ToSingle(orientationYByte, 0); fingerStruct.fingerOrientation.z = BitConverter.ToSingle(orientationZByte, 0); }