关于leapMotion控制的部分代码,如下
第一部分:LeapManager,用来初始化leapMotion
using UnityEngine;
using System.Collections;
using Leap;
public class LeapManager : MonoBehaviour {
public Camera _mainCam; //Not required to be set. Defaults to camera tagged "MainCamera".
public static float _forwardFingerContraint = 0.7f; // Min result of dot product between finger direction and hand direction to determine if finger is facing forward.
private static Controller _leapController = new Controller(); //实例化控制器
private static Frame _currentFrame = Frame.Invalid; // 实例化帧
private static bool _pointerAvailible = false; //判断指示器是否实例化
private Vector2 _pointerPositionScreen = new Vector3(0,0); //指示器屏幕坐标(由指示器世界坐标转换而来)
private Vector3 _pointerPositionWorld = new Vector3(0,0,0);//指示器世界坐标
private Vector3 _pointerPositionScreenToWorld = new Vector3(0,0,0);//指示器屏幕转世界坐标(由指示器屏幕坐标+z轴转换而来)
private float _screenToWorldDistance = 10.0f;// 屏幕转世界坐标时的z轴设置
//Accessors
/*
* A direct reference to the Controller for accessing the LeapMotion data yourself rather than going through the helper.
*/
public Controller leapController{ //获得实例化的控制器
get { return _leapController; }
}
/*
* The most recent frame of data from the LeapMotion controller.
*/
public Frame currentFrame // 获得LeapMotion每一帧
{
get { return _currentFrame; }
}
/*
* Is there a pointing finger currently tracked in the scene.
*/
public bool pointerAvailible {//指示器是否实例化(如果手实例化了,指示器也就同时实例化)
get{ return _pointerAvailible; }
}
/*
* The currently tracked (if any) pointing finger in screen space.
*/
public Vector2 pointerPositionScreen { //指示器在屏幕坐标
get { return _pointerAvailible ? _pointerPositionScreen : Vector2.zero; }
}
/*
* The currently tracked (if any) pointing finger in world space.
*/
public Vector3 pointerPositionWorld {//指示器在世界坐标
get { return _pointerAvailible ? _pointerPositionWorld : Vector3.zero; }
}
/*
* The screen position of the currently tracked (if any) pointing finger projected into world space
* at a distance of [screenToWorldDistance].
*/
public Vector3 pointerPositionScreenToWorld { // 指示器在屏幕坐标转世界坐标
get { return _pointerPositionScreenToWorld; }
}
/*
* The projection distance for the pointerPositionScreenToWorld calculation.
* Default Value is 10.0f
*/
public float screenToWorldDistance { //屏幕到世界的距离,z轴
get { return _screenToWorldDistance; }
set { _screenToWorldDistance = value; }
}
//Public Static Functions
/*
* Returns the most likely finger to be pointing on the given hand.
* Returns Finger.Invalid if no such finger exists.
*/
public static Finger pointingFigner(Hand hand)//寻找手指中z轴位置最小的手指
{
Finger forwardFinger = Finger.Invalid;//手指是否实例化
ArrayList forwardFingers = forwardFacingFingers(hand);
if(forwardFingers.Count > 0)
{
float minZ