//得到镜像 转 正常 的骨架信息 世界坐标 public static Vector3 GetWorldPos(OrbbecUser user, SkeletonType skeletonType) { if (IsUserActive(user)) { SkeletonType skeletonType2 = OrbbecUtils.GetFlipSkeletonType(skeletonType); Vector3 vec = user.BoneWorldPos[jointToIntDict[skeletonType2]]; return(vec); } return(Vector3.zero); }
//得到镜像 转 正常 的骨架的 屏幕百分比数据 public static Vector3 GetScreenPercentPos(OrbbecUser user, SkeletonType skeletonType) { if (IsUserActive(user)) { SkeletonType skeletonType2 = OrbbecUtils.GetFlipSkeletonType(skeletonType); Vector3 vec = user.BoneScreenPos[jointToIntDict[skeletonType2]]; vec = new Vector3(vec.x / depthSize.x, (depthSize.y - vec.y) / depthSize.y, 1f); return(vec); } return(Vector3.zero); }
//每帧记录标定 public void UpdateTracking(float dt) { trackingTime += dt; trackingMissCnt = 0; Dictionary <SkeletonType, Vector3> boneWorldPosDict = new Dictionary <SkeletonType, Vector3> (); Dictionary <SkeletonType, Vector3> boneScreenPercentPosDict = new Dictionary <SkeletonType, Vector3> (); foreach (KeyValuePair <SkeletonType, int> kv in OrbbecUtils.jointToIntDict) { if (kv.Key != SkeletonType.Invalid) { boneWorldPosDict.Add(kv.Key, OrbbecUtils.GetWorldPos(bindUser, kv.Key)); boneScreenPercentPosDict.Add(kv.Key, OrbbecUtils.GetScreenPercentPos(bindUser, kv.Key)); } } _trackingBoneWorldPosDictList.Add(boneWorldPosDict); _trackingBoneScreenPercentPosDictList.Add(boneScreenPercentPosDict); if (boneWorldPosDict != null && boneWorldPosDict.ContainsKey(SkeletonType.Torso)) { torsoPos = boneWorldPosDict [SkeletonType.Torso]; } }
//得到当前的 镜像 转 正常 的骨架信息 屏幕百分比坐标 public Vector3 GetScreenPercentPos(SkeletonType skeletonType) { return(OrbbecUtils.GetScreenPercentPos(bindUser, skeletonType)); }
//得到当前的 镜像 转 正常 的骨架信息 世界坐标 public Vector3 GetWorldPos(SkeletonType skeletonType) { return(OrbbecUtils.GetWorldPos(bindUser, skeletonType)); }
//检测标定 void TrackingPlayer(OrbbecPlayerOnTracking tplayer) { //未开始标定,获取新user,启动标定 if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.none) { tmpUser = GetNewUser(); if (tmpUser != null) { tplayer.bindUser = tmpUser; tplayer.StartTracking(); } } //正在标定,判定是否失去焦点,有焦点则记录信息,失去焦点或不举手则取消标定 else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracking) { bool isMissing = false; bool IsRisingHands = false; if (OrbbecUtils.IsUserActive(tplayer.bindUser)) { if (OrbbecManager.Instance.IsRisingHands(tplayer.UserId)) { IsRisingHands = true; } else { //允许中途连续丢失3帧举手 tplayer.trackingMissCnt++; if (tplayer.trackingMissCnt >= allowTrackingMissCnt) { isMissing = true; } } } else { isMissing = true; } if (!isMissing) { if (IsRisingHands) { tplayer.UpdateTracking(Time.unscaledDeltaTime); //lth: 使用unscaledTime以适应游戏中暂停 if (tplayer.trackingTime >= needTrackingTime) { tplayer.FinishTracking(); } } } else { tplayer.CancelTracking(); } } else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked) { bool isMissing = false; if (!OrbbecUtils.IsUserActive(tplayer.bindUser)) { isMissing = true; } if (isMissing) { tplayer.CancelTracking(); } } }