using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Text;
public class PoseDetectorScript : MonoBehaviour
{
//avatarModel就是需要被做到目标动作的模型
[Tooltip("User avatar model, who needs to reach the target pose.")]
public PoseModelHelper avatarModel;
//poseModel测试者需要被达到的动作
[Tooltip("Model in pose that need to be reached by the user.")]
public PoseModelHelper poseModel;
[Tooltip("List of joints to compare.")]
public List<KinectInterop.JointType> poseJoints = new List<KinectInterop.JointType>();
[Tooltip("Threshold, above which we consider the pose is matched.")]
public float matchThreshold = 0.7f;
[Tooltip("GUI-Text to display information messages.")]
public GUIText infoText;
// match percent (between 0 and 1)
private float fMatchPercent = 0f;
// whether the pose is matched or not
private bool bPoseMatched = false;
/// <summary>
/// Gets the pose match percent.
/// </summary>
/// <returns>The match percent (value between 0 and 1).</returns>
public float GetMatchPercent()
{
return fMatchPercent;
}
/// <summary>
/// Determines whether the target pose is matched or not.
/// </summary>
/// <returns><c>true</c> if the target pose is matched; otherwise, <c>false</c>.</returns>
public bool IsPoseMatched()
{
return bPoseMatched;
}
void Update ()
{
KinectManager kinectManager = KinectManager.Instance;
AvatarController avatarCtrl = avatarModel ? avatarModel.gameObject.GetComponent<AvatarController>() : null;
if(kinectManager != null && kinectManager.IsInitialized() &&
avatarModel != null && avatarCtrl && kinectManager.IsUserTracked(avatarCtrl.playerId))
{
// get mirrored state
bool isMirrored = avatarCtrl.mirroredMovement;
// get the difference
//sDiffDetails这里面为啥要先弄成空字符串
string sDiffDetails = string.Empty;
fMatchPercent = 1f - GetPoseDifference(isMirrored, true, ref sDiffDetails);
bPoseMatched = (fMatchPercent >= matchThreshold);
//
string sPoseMessage = string.Format("Pose match: {0:F0}% {1}", fMatchPercent * 100f,
(bPoseMatched ? "- Matched" : ""));
//上面的那行文字显示出来
if(infoText != null)
{
infoText.text = sPoseMessage + "\n\n" + sDiffDetails;
}
}
else
{
// no user found
if(infoText != null)
{
infoText.text = "Try to match the pose on the left."