1118OPSSNew/Assets/Zion/Scripts/GameScene/Processes/ObjRotateController.cs

61 lines
1.9 KiB
C#

using Microsoft.MixedReality.Toolkit.Input;
using Microsoft.MixedReality.Toolkit.Utilities;
using UnityEngine;
public class ObjRotateController : MonoBehaviour
{
private float flatHandThreshold = 45.0f;
/// <summary>
/// 手掌向上的法线与摄像头向前射线的夹角
/// </summary>
private float facingCameraTrackingThreshold = 80.0f;
/// <summary>
/// 是否要求手指打开
/// </summary>
private bool requireFlatHand = true;
private bool IsPalmMeetingThresholdRequirements()
{
MixedRealityPose palmPose;
if (requireFlatHand)
{
MixedRealityPose indexTipPose, ringTipPose;
Handedness handedness = Handedness.Left;
if (HandJointUtils.TryGetJointPose(TrackedHandJoint.IndexTip, Handedness.Right, out indexTipPose)
&& HandJointUtils.TryGetJointPose(TrackedHandJoint.RingTip, Handedness.Right, out ringTipPose)
&& HandJointUtils.TryGetJointPose(TrackedHandJoint.Palm, Handedness.Right, out palmPose))
{
var handNormal = Vector3.Cross(indexTipPose.Position - palmPose.Position,
ringTipPose.Position - indexTipPose.Position).normalized;
handNormal *= (handedness == Handedness.Right) ? 1.0f : -1.0f;
if (Vector3.Angle(palmPose.Up, handNormal) > flatHandThreshold)
{
return false;
}
}
}
if (HandJointUtils.TryGetJointPose(TrackedHandJoint.Palm, Handedness.Right, out palmPose))
{
float palmCameraAngle = Vector3.Angle(palmPose.Up, CameraCache.Main.transform.forward);
return palmCameraAngle < facingCameraTrackingThreshold;
}
return false;
}
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}