level 11
using UnityEngine;using System.Collections.Generic;using Leap;public class LeapBehavior : MonoBehaviour { LeapProvider provider; void Start () { provider = FindObjectOfType<LeapProvider>() as LeapProvider; } void Update () { Frame frame = provider.CurrentFrame; foreach (Hand hand in frame.Hands) { if (hand.IsLeft) { transform.position = hand.PalmPosition.ToVector3() + hand.PalmNormal.ToVector3() * (transform.localScale.y * .5f + .02f); transform.rotation = hand.Basis.Rotation(); } } }}
The script, LeapUnityExtensions.cs in Assets/LeapMotion/Scripts/Utils, provides helpful extension functions for converting vectors and matrices from the Leap Motion API classes to the Unity API classes. The functions ToVector3() and Rotation() used above are defined in this script.
Note: In almost every case, you should get Frame objects from the scene’s LeapProvider object. The LeapProvider transforms the frame data into the proper frame of reference. If you get a frame from the Leap.Controller object, the data will still be in the Leap Motion frame of reference and will not match the hands displayed in the scene.
2016年07月20日 07点07分