LeapMotion控制

关于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 
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值