private static void InitializeHandJointData(ref WVR_HandJointData_t handJointData, ref WVR_Pose_t[] jointsPose, uint count) { handJointData.isValidPose = false; handJointData.confidence = 0; handJointData.jointCount = count; WVR_Pose_t wvr_pose_type = default(WVR_Pose_t); handJointData.joints = Marshal.AllocHGlobal(Marshal.SizeOf(wvr_pose_type) * (int)count); jointsPose = new WVR_Pose_t[count]; long offset = 0; if (IntPtr.Size == 4) { offset = handJointData.joints.ToInt32(); } else { offset = handJointData.joints.ToInt64(); } for (int i = 0; i < jointsPose.Length; i++) { IntPtr wvr_pose_ptr = new IntPtr(offset); Marshal.StructureToPtr(jointsPose[i], wvr_pose_ptr, false); offset += Marshal.SizeOf(wvr_pose_type); } }
private static bool ExtractHandJointData(WVR_HandJointData_t handJointData, ref WVR_Pose_t[] jointsPose) { if (handJointData.jointCount == 0) { Debug.Log("ExtractHandJointData() WVR_GetHandTrackingData WVR_HandJointData_t jointCount SHOULD NOT be 0!!"); return(false); } if (jointsPose.Length != handJointData.jointCount) { Debug.Log("ExtractHandJointData() The WVR_GetHandJointCount count " + jointsPose.Length + " differs from WVR_GetHandTrackingData WVR_HandJointData_t jointCount " + handJointData.jointCount); jointsPose = new WVR_Pose_t[handJointData.jointCount]; } WVR_Pose_t wvr_pose_type = default(WVR_Pose_t); int offset = 0; for (int i = 0; i < jointsPose.Length; i++) { if (IntPtr.Size == 4) { jointsPose[i] = (WVR_Pose_t)Marshal.PtrToStructure(new IntPtr(handJointData.joints.ToInt32() + offset), typeof(WVR_Pose_t)); } else { jointsPose[i] = (WVR_Pose_t)Marshal.PtrToStructure(new IntPtr(handJointData.joints.ToInt64() + offset), typeof(WVR_Pose_t)); } offset += Marshal.SizeOf(wvr_pose_type); } return(true); }
private static void InitializeHandTrackerData( ref WVR_HandTrackingData_t handTrackerData, ref WVR_HandJointData_t handJointDataLeft, ref WVR_HandJointData_t handJointDataRight, ref WVR_Pose_t[] handJointsPoseLeft, ref WVR_Pose_t[] handJointsPoseRight, uint count) { handTrackerData.timestamp = 0; InitializeHandJointData(ref handJointDataLeft, ref handJointsPoseLeft, count); handTrackerData.left = handJointDataLeft; InitializeHandJointData(ref handJointDataRight, ref handJointsPoseRight, count); handTrackerData.right = handJointDataRight; }