包含左,右,前,后,上,下挥手,物体放大做小,旋转位移等;
可根据需求自由组合。
一:
using Leap;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Leap.Unity;
public class ControlAnimation : MonoBehaviour
{
private Frame frame;
LeapProvider provider;
public HandModelBase leftHandModel;
public HandModelBase rightHandModel;
private const float rotate_sensitive = 1500f; //旋转灵敏度
private const float displacement_sensitive = 0.015f; //位移灵敏度
private const float rotate_initial_value = 0f; //旋转初始位置值
[Tooltip ("Velocity (m/s) move toward ")]//速度(m/s)走向
const float smallestVelocity = 0.1f;
[Tooltip("Velocity (m/s) move toward ")]
protected float deltaVelocity = 0.000001f;
const float deltaCloseFinger = 0.06f;
[Tooltip("Delta degree to check 2 vectors same direction")]//三角度检查2个向量的方向相同
protected float handForwardDegree = 30;
private float deltaAngleThumb = 90;
void Start()
{
provider = FindObjectOfType<LeapProvider>() as LeapProvider;
}
void Update()
{
//Scale();
//Rotation();
//Position();
frame = provider.CurrentFrame;
if (frame.Hands.Count > 0)
{
foreach (var item in frame.Hands)
{
//Debug.Log(item.Fingers.Count + "@" + item.IsLeft+"#"+item.IsRight);
if (item.IsLeft)
{
//isThumbDirection(item, Vector3.up);
Debug.Log(isThumbDirection(item, item.GetPinchPosition()));
}
}
}
}
/// <summary>
/// 缩小
/// </summary>
public void Scale()
{
Frame frame = provider.CurrentFrame;
foreach (Hand hand in frame.Hands)
{
if (isOpenFullHand(hand))
{
Debug.Log("大");
Vector3 value = transform.localScale;
value += new Vector3(value.x * 0.01f, value.y * 0.01f, value.z * 0.01f);
// Debug.Log(value);
transform.localScale = value;
}
if (isCloseHand(hand))
{
Debug.Log("小");
Vector3 value = transform.localScale;
value -= new Vector3(value.x * 0.01f, value.y * 0.01f, value.z * 0.01f);
// Debug.Log(value);
transform.localScale = value;
}
}
}
/// <summary>
/// 旋转
/// </summary>
public void Rotation()
{
Frame frame = provider.CurrentFrame;
foreach (Hand hand in frame.Hands)
{
if (hand.IsLeft || hand.IsRight)
{
Vector3 value = transform.localEulerAngles;
value = new Vector3(hand.PalmPosition.y * rotate_sensitive + rotate_initial_value, hand.PalmPosition.x * rotate_sensitive + rotate_initial_value, 0);
transform.localEulerAngles = value;
}
else
{
hand.PalmPosition.y = transform.localEulerAngles.x;
hand.PalmPosition.x = transform.localEulerAngles.y;
}
}
}
p

本文介绍如何使用LeapMotion传感器在Unity中实现手势识别,包括挥手、物体缩放、旋转和平移等功能。通过分析手部姿势和移动方向,实现交互式动画控制,适用于虚拟现实和增强现实应用。
最低0.47元/天 解锁文章
786

被折叠的 条评论
为什么被折叠?



