在unity3D里建立leap motion API的过程



Setting up aproject in Unity 3Dunity3D建立一个工程

The Leap Motionasset package includes in plugin files for using the Leap Motion device onWindows and Mac computers. The Leap Motion asset package里包括申请使用Leap Motion设备的插件

This packageincludes Hand prefabs, scripts, and demo scenes to help you develop Leap Motionapps quickly.

这个包裹里含有手预制体,脚本,和演示案例场景,这些可以帮助你快速的开发Leap Motion的应用程序

获得 Leap Motion asset package 的网址如下https://developer.leapmotion.com/downloads/unity.

unity3D里创建一个工程的步骤如下

1.   打开unity软件

2.   选择Select File > New Project...

3.   选择一个文件名和其保存的地址路径  

4.   点击Create Project.

接下来,将 Leap Motion asset package 倒入到工程中:

1.   Download the assets.

2.   选择 菜单中的 Assets > Import Package > Custom Package 命令.

3.   找到asset package的下载的地址并打开.

If you are importing the assets into a project thatalready contains Leap Motion assets, it is recommended that you delete the oldassets first (make a backup). The Unity import process only adds new files andoverwrites changed files. It does not remove obsolete files.

如果你已经导入了Leap Motion asset package,建议你删除旧版本,然后再导入新版本,unity导入进程只能增加新的文件和重写改变的文件,它不能自动删除旧的版本。

AddingHands to a Scene添加手到场景

Place theHandController prefab below the point at which you want the hands to appear. 把手控制器预制体放在你想让手出现的点下方。

The hands in thescene are positioned at the same position as your real hands relative to thereal Leap Motion device.

在场景里的手要放置在和真实手相对于真实Leap Motion设备的位置一样

You can changethe scale of HandController object to change the size of the hands and changethe Hand Movement Scale setting to allow the hands to move a within a largervolume.

你可以通过改变手控制器对象的规模,来改变手的大小和改变手部运动规模调到允许手去移动一个内部的更大的容量。

Change the handgraphics by dragging a different hand prefab to the Left/Right Graphics Modelslot.

通过拖拽一个不同的手的预制体来改变手的图形,使其变成左边/右边的图形模型跟踪。

To add hands toa scene添加多个手到场景:

1.   In the Projectpanel, locate the HandController prefab in Assets/LeapMotionPrefabs

在工程面板上,在Assets/LeapMotionPrefabs里查找手控制器的预制体。

2.   Drag theHandController prefab into the Scene view.

拖拽手控制器预制体到场景视图中

3.   Set thetransform position to the desired location.To see hands, the HandControllermust be within the field of view of the camera.

对手控制器预制体进行位置设定,使其在预定的位置上,观察手要在摄像机的视野范围内。

4.   Set transformscale to size the hands appropriately to the scene. A scale of 1 means thehands are rendered at their real size (which is often too small).

设置其尺寸大小,使手的大小适合于该场景,尺寸值设为1时,表示手的绘制成真实尺寸(这时通常显示得比较小)

5.   Set the Left andRight Hand Graphics Model properties of the HandController to the desiredprefab from the HandModelsHuman or HandModelsNonHuman prefab folders. (There isgenerally no need to change the physics model from RigidHand.)

HandModelsHuman or HandModelsNonHumanprefab文件夹里得到所需的预设来设置手控制器的左右手图像绘制模型性质,

Accessingthe Leap Motion API directly快速访问LeapMotion API

In addition tothe prefabs and scripts included in the asset package, you can write your ownscripts to access tracking data from the Leap Motion API.另外,预制体和脚本都包含在资产包里,你可以写你自己的脚本从Leap Motion API去访问追踪数据。

 The Leap Motion classes are defined inthe Leap namespace.A basic MonoBehavior class that accesses the Leap Motion API will look somethinglike the following:

Leap Motion的类都定义在跳跃空间,一个基于MonoBehavior的类访问Leap Motion API,你将看到如下

using UnityEngine;

using System.Collections;

using Leap;

 

public class LeapBehavior : MonoBehaviour {

    Controllercontroller;

    void Start ()

    {

        controller= new Controller();

    }

    void Update ()

    {

        Frame frame= controller.Frame();

        // dosomething with the tracking data in the frame...

    }}

Note that thisexample does not use a Leap.Listener subclass. Since a Unity application has a natural frame rate,the Update() functioncan get the current frame of data from the Leap Motion controller when thefunction is called by the Unity engine.

Thescript, LeapUnityExtensions.cs inAssets/LeapMotion/Scripts/Utils, provides helpful functions for convertingvectors and matrices from the Leap Motion API classes to the Unity API classes– as well as converting the scale and coordinate systems.

Assets/LeapMotion/Scripts/Utils的脚本LeapUnityExtensions.cs ,它为通过转化Leap Motion API类的向量和矩阵来同时转变了Unity API类的尺寸和坐标系系统提供了有用函数。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值