2023-11-10 07:17:23 +00:00
|
|
|
|
using OpenCVForUnity.CoreModule;
|
2023-11-15 17:23:16 +00:00
|
|
|
|
using System;
|
2023-11-10 07:17:23 +00:00
|
|
|
|
using System.Collections.Generic;
|
2023-11-15 17:23:16 +00:00
|
|
|
|
using UnityEngine;
|
2023-11-10 07:17:23 +00:00
|
|
|
|
|
|
|
|
|
public class HandsUp : PoseBase
|
|
|
|
|
{
|
2023-11-25 19:37:35 +00:00
|
|
|
|
public override Vector2 GetBasicVectorDirection(List<Point> startPoint, List<Point> endPoint)
|
2023-11-10 07:17:23 +00:00
|
|
|
|
{
|
2023-11-25 19:37:35 +00:00
|
|
|
|
//必要点位 "RShoulder", "LShoulder", "RElbow", "LElbow"
|
|
|
|
|
//计算肩膀到手肘矢量,右手
|
|
|
|
|
Vector2 rightHandVector = GetAverageVector(startPoint, endPoint, "RElbow");
|
|
|
|
|
Vector2 leftHandVector = GetAverageVector(startPoint, endPoint, "LElbow");
|
|
|
|
|
//平均矢量
|
|
|
|
|
Vector2 averageVector = (rightHandVector + leftHandVector) / 2;
|
2023-11-13 02:53:34 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
//如果左右手肘矢量差小于两者平均值的0.3倍,且左右手矢量夹角小于30度,返回左右手矢量平均值
|
|
|
|
|
if ((rightHandVector - leftHandVector).magnitude < averageVector.magnitude * 0.3f
|
|
|
|
|
&& Vector2.Angle(rightHandVector, leftHandVector) < 30)
|
|
|
|
|
{
|
|
|
|
|
return averageVector;
|
|
|
|
|
}
|
2023-11-13 02:53:34 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
return Vector2.zero;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool IsMovePoint(string tagName)
|
|
|
|
|
{
|
|
|
|
|
return "RWrist".Equals(tagName) ||
|
|
|
|
|
"LWrist".Equals(tagName);
|
|
|
|
|
}
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
public override void ValidationMovement(Vector2 distance, TimeSpan totalTimeSpan, int level)
|
|
|
|
|
{
|
2023-11-25 20:52:27 +00:00
|
|
|
|
if (totalTimeSpan.TotalMilliseconds / 1000 < 0.05f)
|
|
|
|
|
{
|
|
|
|
|
LogPrint.Error("TimeSpan too short");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-25 19:37:35 +00:00
|
|
|
|
var angle = Vector2.SignedAngle(Vector2.up, distance);
|
|
|
|
|
LogPrint.Log($"Angle:{angle}", PrintLevel.Normal);
|
|
|
|
|
if (MathF.Abs(angle) < 10)
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_Success); //方向不能偏移超过10°
|
|
|
|
|
else
|
2023-11-25 20:52:27 +00:00
|
|
|
|
{
|
2023-11-25 19:37:35 +00:00
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_Fail);
|
2023-11-25 20:52:27 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
if (level < 1)
|
|
|
|
|
return;
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
LogPrint.Log($"distance x:{distance.x}, y:{distance.y}, magnitude:{distance.magnitude}", PrintLevel.Normal);
|
2023-11-25 20:52:27 +00:00
|
|
|
|
if (distance.magnitude > 80f || distance.magnitude < 20f)
|
2023-11-25 19:37:35 +00:00
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceNotAccurate);
|
|
|
|
|
else
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_MoveDistanceExactly);
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
if (level < 2)
|
|
|
|
|
return;
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
var speed = distance.magnitude / totalTimeSpan.TotalSeconds;
|
|
|
|
|
LogPrint.Log($"speed:{speed}", PrintLevel.Normal);
|
|
|
|
|
if (speed > 0.5f)
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooFast); //速度语音提示
|
|
|
|
|
else if (speed < 0.1f)
|
|
|
|
|
EventManager.Instance.Dispatch(YogaEventType.Action_SpeedTooSlow); //速度语音提示
|
|
|
|
|
}
|
2023-11-15 17:23:16 +00:00
|
|
|
|
|
2023-11-25 19:37:35 +00:00
|
|
|
|
public override void ExcellenceEstimate(List<(TimeSpan, Vector2)> frameData, Vector2 distance, TimeSpan totalTimeSpan)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
2023-11-10 07:17:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|