UNITY 3D –跳跃运动集成(译文)
By robot-v1.0
本文链接 https://www.kyfws.com/games/unity-d-leap-motion-integration-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 18 分钟阅读 - 8845 个词 阅读量 0UNITY 3D –跳跃运动集成(译文)
原文地址:https://www.codeproject.com/Articles/1007186/UNITY-D-Leap-Motion-Integration
原文作者:Vahe Karamian
译文由本站 robot-v1.0 翻译
前言
This article will cover the basics of Leap Motion integration into your Unity 3D project. We will look at the basic setup and implementation of the basics to get you started. In order for you to try the code, you will need to have the Leap Motion hardware.
本文将介绍Leap Motion集成到Unity 3D项目中的基础知识.我们将研究基础的基本设置和实现,以帮助您入门.为了尝试代码,您将需要Leap Motion硬件.
介绍(Introduction)
人机交互(HCI)的未来将发生模式转变.自从计算开始以来,科学家和工程师就一直致力于创建3D环境以及虚拟和增强世界,我们将生活中的数字和物理领域融为一体.从早期的科幻小说和电影中,您可以看到我们一直梦想着创造这样的环境和互动.(The future of human computer interaction (HCI) is about to have a paradigm shift. Ever since the beginning of computing, scientists and engineers have always been working towards creating 3D environments and Virtual and Augmented Worlds where we integrated the digital and the physical spheres of our lives. From early science-fiction books and movies, you can see that we have always dreamt of creating such environments and interactions.)
今天,我们生活在非常激动的时代.我们越来越接近将这些科幻小说的想法变成科学事实.实际上,我们已经在某种程度上做到了.虚拟现实(VR)是一个大话题. VR中的重要主题之一是与数字世界互动的能力.本文将重点介绍使用Leap Motion开发的硬件传感器来实现用户与数字世界的交互.(Today, we live in very exciting times. We are getting closer to making these science-fiction ideas, into science-facts. In fact, we have already done so to some extent. Virtual Reality (VR) is a large topic. One of the important topics within VR is the ability to interact with the digital world. This article is going to concentrate on the interaction of the user with the digital world using the hardware sensor developed by Leap Motion.) 本文将介绍如何将Leap Motion手部运动传感器与Unity 3D集成和使用.本文将不介绍Unity 3D的基础知识.请参考以下文章系列以开始使用Unity 3D.(This article will be covering how to integrate and use Leap Motion hand motion sensor with Unity 3D. We are not going to cover the basics of Unity 3D in this article. Please refer to the following article series to get started with Unity 3D.) 万一这是第一次阅读Unity 3D文章,以防万一,我列出了以下系列的链接:(Just in case if this is the first time reading the Unity 3D articles, I have listed the links to the series below:)
-
Unity 3D –游戏编程–第10部分(Unity 3D – Game Programming – Part 10) Unity 3D网络文章:(Unity 3D Networking Article(s):)
-
Unity 3D-网络游戏编程(Unity 3D - Network Game Programming) 上面列出的文章将为您提供有关Unity 3D的良好入门基础.(The articles listed above will give you a good starting foundation regarding Unity 3D.) **注意:(NOTE:)**为了试验本文提供的代码,您将需要Leap Motion硬件.(In order to experiment with the code provided in this article, you will need to have the Leap Motion hardware.)
游戏编程简介:使用C#和Unity 3D(Introduction to Game Programing: Using C# and Unity 3D*) (Paperback)*)(平装)( 要么(or*) (eBook)*)(电子书)( 是为帮助对计算机科学和游戏编程领域感兴趣的个人而设计和开发的.它旨在说明计算机编程的概念和基础.它使用简单游戏的设计和开发来说明和应用这些概念.(is designed and developed to help individuals that are interested in the field of computer science and game programming. It is intended to illustrate the concepts and fundamentals of computer programming. It uses the design and development of simple games to illustrate and apply the concepts.) [ ](http://www.lulu.com/commerce/index.php?fBuyContent=18159441) 书号:9780997148404(ISBN: 9780997148404) 版本:第一版(Edition: First Edition) 发行人:Noorcon Inc.(Publisher: Noorcon Inc.) 英语语言(Language: English) 274页(Pages: 274) 装订:装订完美的平装本(彩色)(Binding: Perfect-bound Paperback (Full Color)) 尺寸(英寸):6宽x 9高(Dimensions (inches): 6 wide x 9 tall) -
|
||电子书(ePUB)(eBook (ePUB))
书号(ISBN):9780997148428(ISBN: 9780997148428)
版本:第一版(Edition: First Edition)
发行人:Noorcon Inc.(Publisher: Noorcon Inc.)
英语语言(Language: English)
大小:9.98 MB(Size: 9.98 MB) |
---|
背景(Background)
假定本文的读者通常熟悉编程概念.还假定读者具有C#语言的理解和经验.还建议本文的读者也熟悉面向对象的编程和设计概念.我们将根据需要在本文中简要介绍它们,但是由于它们完全是单独的主题,因此我们将不对其进行详细介绍.我们还假设您有学习3D编程的热情,并且具有3D图形和矢量数学的基本理论概念.(It is assumed that the reader of this article is familiar with programming concepts in general. It is also assumed that the reader has an understanding and experience of the C# language. It is also recommended that the reader of the article is familiar with Object-Oriented Programming and Design Concepts as well. We will be covering them briefly throughout the article as needed, but we will not get into the details as they are separate topics altogether. We also assume that you have a passion to learn 3D programming and have the basic theoretical concepts for 3D Graphics and Vector Math.) 最后,本文使用Unity 3D 5.1版,这是截至初始发布日期的最新公共发行版.该系列中讨论的大多数主题都将与旧版本的游戏引擎兼容.(Lastly, the article uses Unity 3D version 5.1 which is the latest public release as of the initial publication date. Most of the topics discussed in the series will be compatible with older versions of the game engine.)
使用代码(Using the Code)
按照说明进行操作.易于设置.(Follow the instructions. Easy to setup.)
什么是跳跃运动?(What is Leap Motion?)
“仅用一只手,您就有29根骨头,29个关节,123条韧带,48条神经和30条动脉.那是复杂,复杂且惊人的技术(两倍).但是感觉很轻松. Leap Motion控制器真的可以解决所有问题."(“In just one hand, you have 29 bones, 29 joints, 123 ligaments, 48 nerves, and 30 arteries. That’s sophisticated, complicated, and amazing technology (times two). Yet it feels effortless. The Leap Motion Controller has come really close to figuring it all out.”)
Leap Motion控制器可以感应到您自然地动手的方式,并以全新的方式使用计算机.它可以跟踪所有10个手指,最高可达1/100(The Leap Motion Controller senses how you naturally move your hands and lets you use your computer in a whole new way. It tracks all 10 fingers up to 1/100)日(th)一毫米它比现有的运动控制技术灵敏得多.这样便可以在一个1英寸的立方体中绘制或绘画微型杰作.(of a millimeter. It’s dramatically more sensitive than existing motion control technology. That’s how you can draw or paint mini masterpieces inside a one-inch cube.)
图1-飞跃运动传感器(Figure 1-Leap Motion Sensor)### Leap Motion设置和Unity 3D集成(Leap Motion Setup and Unity 3D Integration)
首先,您需要下载Leap Motion的SDK.您可以使用以下链接获取最新信息:(First, you will need to download the SDK for Leap Motion. You can get the latest using the following link:) developer.leapmotion.com(developer.leapmotion.com) .我正在使用SDK v.2.2.6.29154.下载SDK之后,请继续并安装运行时.该SDK支持其他平台和语言,建议您使用.为了我们的目的和与Unity的集成,您还需要从Asset Store获取Leap Motion Unity Core资产.这是直接链接到(. I am using SDK v.2.2.6.29154. After you download the SDK, go ahead and install the runtime. The SDK supports other platforms and languages which you are encouraged to look into. For our purposes and integration with Unity, you will need to also get the Leap Motion Unity Core Assets from the Asset store. Here is a direct link to) Leap Motion Unity核心资产v2.3.1(Leap Motion Unity Core Assets v2.3.1) .(.)
假设您已经在计算机上下载并安装了Unity 5,接下来需要做的是从Asset Store获取Leap Motion Unity Core资产.在撰写本文时,资产包的版本为2.3.1.(Assuming you have already downloaded and installed Unity 5 on your machine, the next thing you will need to do is get the Leap Motion Unity Core Assets from the Asset store. At the time of this writing, the asset package was on version 2.3.1.)
图2-Leap Motion核心资产(Figure 2-Leap Motion Core Assets)下载并安装Leap Motion核心资产后,我们可以开始创建简单的场景,并开始学习如何与资产进行交互并扩展其用途.(After downloading and installing the Leap Motion Core Assets, we can start with creating our simple scene and getting to learn how to interact with the assets and extend them for our own purposes.)
图3-跳跃运动的项目文件夹结构(Figure 3-Project Folder Structure for Leap Motion)继续创建一个新的空项目,并将Leap Motion核心资产导入到您的项目中.导入Leap Motion资产后,您的项目窗口应类似于上图.(Go ahead and create a new empty project and import the Leap Motion Core Assets into your project. After you have imported the Leap Motion Assets, your project window should look similar to the figure above.)
飞跃运动核心资产(Leap Motion Core Assets)
在"项目"窗口中,您的主要注意力应该放在(In the Project Window, your main attention should be toward the)**跳跃运动(LeapMotion)**夹.包含OVR的文件夹适合与Leap Motion和Oculus Rift虚拟现实耳机一起使用.我们将在以后的文章中介绍.(folder. The folders that contain OVR are geared towards using Leap Motion with Oculus Rift Virtual Reality headset. We will cover this in future article(s).)
您应该花时间研究结构,更重要的是研究每个文件夹中的内容.您将要熟悉的主要核心资产之一是(You should take the time and study the structure and more importantly, the content within each folder. One of the main core assets that you will want to get familiar with is the) HandController
.这是主要的(. This is the main)预制棒(PreFab)使您可以与场景中的Leap Motion设备进行交互.它位于(that allows you to interact with the Leap Motion device in your scene. It is located under the)**预制件(Prefab)**内的文件夹(folder within the)**跳跃运动(LeapMotion)**夹.它用作在场景中渲染手的锚点.(folder. It serves as the anchor point for rendering your hands in the scene.)
图4-HandController检查器属性(Figure 4-HandController Inspector Properties)的(The) HandController
预制件附带了"手动控制器"脚本,使您可以与设备进行交互.看看通过(prefab has the Hand Controller script attached which enables you to interact with the device. Take a look at some of the properties that are visible through the)检查器窗口(Inspector Window).您会注意到,要在场景中渲染的实际手模型有两个手属性,然后是物理模型有两个手属性,它们是对撞机.这种设计的好处是您可以创建自己的手势模型,并将其与控制器一起使用,以进行视觉表示以及自定义手势等.(. You would notice that there are two hand properties for the actual hand model to be rendered in the scene, and then there are two for the physical model, these are the colliders. The benefit of this design is that you can create your own hand models, and use them with the controller for visual representation and also custom gestures, etc…)
**注意:(NOTE:)Unity和Leap Motion都使用公制.但是,以下内容之间存在差异:Unity单位度量单位为米,而Leap Motion单位为毫米.没什么大不了的,但是在测量坐标时,您需要意识到这一点.(Unity and Leap Motion both use the metric system. But, there is a difference in the following: Unity unit measure is in meters, whereas Leap Motion is in millimeters. Not a big deal, but you will need to be aware of this when you are measuring your coordinates.)
另一个关键属性是"手部运动量表"矢量.规模越大,设备在物理世界中覆盖的面积越大.在此提醒您,您将需要阅读文档和规格,以针对正在处理的特定应用找到正确和适当的调整.(Another key property is the Hand Movement Scale vector. The larger the scale, the larger the area that the device will cover in the physical world. A word of caution here, you will need to read the documentation and specifications for finding out the right and proper adjustments for the particular application that you are working on.)
“手部运动比例"矢量用于更改手部的运动范围,而不会更改表观模型的大小.(The Hand Movement Scale vector is used to change the range of motion of the hands without changing the apparent model size.)
放置(Placing the) HandController
如前所述,对象在场景中很重要,这是锚点所在的位置,因此,您的相机应位于与场景相同的区域(object is important in the scene, as stated, this is where the anchor point is and therefore, your camera should be in the same area as the) HandController
.在我们的演示场景中,继续将(. In our demo scene, go ahead and place the) HandController
在以下位置:(0,-3,3)分别用于(x,y,z)坐标.确保相机位于(0,0,-3).查看坐标并可视化组件在3D空间中的表示方式.这是供您考虑的图表:(at the following position: (0,-3,3) for the (x,y,z) coordinates respectively. Make sure the camera is positioned at (0,0,-3). Take a look at the coordinates and visualize how the components are represented in 3D space. Here is a diagram for you to consider:)
图5-HandController和Camera位置的可视化表示(Figure 5-Visual representation of HandController and Camera positions)换句话说,您想要(In other words, you want the) HandController
在前面(to be in front of the) Camera GameObject
并且也低于某个阈值这里没有魔术数字,您只需要找出最适合您的方法即可.(and also below a certain threshold. There are no magic numbers here, you will just need to figure out what works best for you.)
至此,您已经连接了所有基本部件以实际运行场景并尝试Leap Motion.因此,请尝试一下,如果正确安装了所有软件组件,则应该可以在现场看到您的双手.(At this point, you have connected all of the fundamental pieces to actually run your scene and try out Leap Motion. So go ahead and give it a try, if you have installed all of the software components properly, you should be able to see your hands in the scene.)
下一步(The Next Step)
实际上,您可以自己实际地观察场景中的手部动作,这是所提供资产的一项巨大任务.但是,实际上,要使事情变得更加有趣,您将需要能够与环境互动,并能够更改和操纵场景中的事物.(The fact that you can actually visualize your hand movement in the scene by itself is a huge undertaking by the assets that have been provided. However, in reality, to make things more interesting, you will need to be able to interact with the environment and be able to change and manipulate stuff within the scene.)
为了说明这一点,我们将创建更多(To illustrate this particular point, we will create a few more) GameObject
在场景中,我们将研究如何实现与(s, and within the scene, we will look at how to implement some basic interactions with) GameObject
s.想法是将一个立方体悬浮在空中.我们想改变颜色(s. The idea would be to have a cube suspended in the air. We would like to change the color of the) Cube
通过从代表我们颜色调色板的另一组多维数据集中进行选择.(by selecting from another set of cubes representing our color pallet.)
为了简化场景,我们将放置三个代表颜色调色板的立方体.第一个为红色,第二个为蓝色,第三个为橙色.您可以随意选择任何颜色.我们需要将多维数据集放置在一种易于与用户交互且不会混淆的方式.(For simplicity of the scene, we will place three cubes representing our color pallet. The first one will be red, the second one will be blue and the third one will be orange. You may choose any color you wish by the way. We would need to place the cubes in a way that interaction with them will be easy and non-confusing to the user.)
我们可以按以下顺序放置多维数据集:(We can place the cubes in the following order:)
- 立方体(0,1,3)(The Cube (0,1,3))
- 红色立方体:(3,-1,3)(Red Cube: (3,-1,3))
- 蓝色立方体:(0,-1,3)(Blue Cube: (0,-1,3))
- 橙色立方体:(-3,-1,3)(Orange Cube: (-3,-1,3))
请注意,它们位于(Notice that they are above the)
HandController GameObject
在Y轴上,但它们在Z轴上位于同一坐标.如果您想根据自己的喜好调整这些数字,可以玩这些数字.只要立方体在检测范围的上方和范围内(in the Y-Axis, but they are at the same coordinate in the Z-Axis. You can play with these numbers if you wish to adjust it to your liking. As long as the cubes are above and within the range of detection of the)HandController
,您应该可以.(, you should be fine.) 下一步是创建脚本,以帮助我们与(The next step is to create the script that will help us interact with the)Cube GameObjects
.我叫剧本(. I call the script)CubeInteraction.cs(CubeInteraction.cs):(:)
using UnityEngine;
using System.Collections;
public class CubeInteraction : MonoBehaviour {
public Color c;
public static Color selectedColor;
public bool selectable = false;
void OnTriggerEnter(Collider c)
{
if (c.gameObject.transform.parent.name.Equals("index"))
{
if (this.selectable)
{
CubeInteraction.selectedColor = this.c;
this.transform.Rotate(Vector3.up, 33);
return;
}
transform.gameObject.GetComponent<Renderer>().material.color =
CubeInteraction.selectedColor;
}
}
}
如您所见,代码不是很复杂,但是确实可以帮助我们实现所需的功能.有三种(As you can see, the code is not very complex, but it does help us achieve what we want. There are three) public
用于检测对象是否可选的变量(variables which are used to detect if the object is selectable, the) color
该对象所代表的(that the object represents, and the selected) color
.(.)
逻辑的核心发生在(The core of the logic happens in the) OnTriggerEnter(Collider c)
功能.我们检查一下是否与(function. We check to see if the object that collided with the) Cube
是食指,然后我们检查对象是否可选.如果对象是可选的,我们设置(is the index finger, then we check to see if the object is selectable. If the object is selectable, we set the) selectable color
到预定义的(to the predefined) color
代码并退出功能.(code and exit the function.)
设计虚拟对象之间的此类交互时,另一个好主意是向用户提供实际的视觉反馈.在这种情况下,我选择了(Another good idea when you are designing such interactions between virtual objects, is actual visual feedback to the user. In this case, I made the selected) color
食指每次碰撞时,立方体旋转33°(cube to rotate 33° degrees each time the index finger collides with the) GameObject
.这是一个很好的视觉提示,我们选择了(. This is a good visual clue that we have selected the) color
.(.)
相同的功能还用于应用选定的(This same function is also used to apply the selected) color
到(to the) Cube GameObject
可以画对于这种特殊情况,我们得到(that can be painted. For this particular case, we get the) Renderer
来自的对象(object from the) Cube
并设置材料(and set the material) color
到所选(to the selected) color
.(.)
运行场景(Running the Scene)
以下是您刚刚设置的场景的示例屏幕截图:(The following is a sample screen capture of the scene you just setup:)
图6-左手运行演示场景(Figure 6-Running Demo Scene with Left Hand)您可以在上面的屏幕截图中看到我的左手.我的右手在鼠标上进行屏幕截图!下一个屏幕截图捕获了选择蓝色立方体的操作:(You can see my left hand in the screen capture above. My right hand is on the mouse taking the screen shot! The next screen capture captures selecting the blue cube:)
图7-选择蓝色立方体(Figure 7-Selecting Blue Color Cube)最后将选定的颜色应用于场景中的可着色立方体:(And finally applying the selected color to the colorable cube in the scene:)
图8-蓝色适用于可绘制的多维数据集(Figure 8-Blue Color Applies to Paintable Cube)## 如何移动物体?(How About Moving Object?)
此时,您将对自己说,所有这些都很酷,但是如果我希望能够与3D环境进行更多交互,该怎么办.例如,您要拾取对象并在场景中四处移动.(At this point, you will say to yourself, all this is cool, but what if I wanted to be able to have more interactions with my 3D environment. Say for instance, you want to pick up objects and move them around in the scene.)
好吧,这是非常有可能的,为了使我们实现它,我们需要编写更多代码!扩展我们的示例,我们将实现实际上允许您提取代码的代码.(Well, this is very much so possible and in order for us to make it happen, we need to write more code! Extending our example, we will implement the code that actually will allow you to pick-up the) Cube
对象并在环境中四处移动.(object and move it around in the environment.)
清单中提供了获取场景中给定对象的清单(Listing to grab a given object in the scene is provided in)GrabMyCube.cs(GrabMyCube.cs):(:)
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Leap;
public class GrabMyCube : MonoBehaviour {
public GameObject cubePrefab;
public HandController hc;
private HandModel hm;
public Text lblNoDeviceDetected;
public Text lblLeftHandPosition;
public Text lblLeftHandRotation;
public Text lblRightHandPosition;
public Text lblRightHandRotation;
// Use this for initialization
void Start()
{
hc.GetLeapController().EnableGesture(Gesture.GestureType.TYPECIRCLE);
hc.GetLeapController().EnableGesture(Gesture.GestureType.TYPESWIPE);
hc.GetLeapController().EnableGesture(Gesture.GestureType.TYPE_SCREEN_TAP);
}
private GameObject cube = null;
// Update is called once per frame
Frame currentFrame;
Frame lastFrame = null;
Frame thisFrame = null;
long difference = 0;
void Update()
{
this.currentFrame = hc.GetFrame();
GestureList gestures = this.currentFrame.Gestures();
foreach (Gesture g in gestures)
{
Debug.Log(g.Type);
if (g.Type == Gesture.GestureType.TYPECIRCLE)
{
// create the cube ...
if (this.cube == null)
{
this.cube = GameObject.Instantiate(this.cubePrefab,
this.cubePrefab.transform.position,
this.cubePrefab.transform.rotation)
as GameObject;
}
}
if (g.Type == Gesture.GestureType.TYPESWIPE)
{
if (this.cube != null)
{
Destroy(this.cube);
this.cube = null;
}
}
}
foreach (var h in hc.GetFrame().Hands)
{
if (h.IsRight)
{
this.lblRightHandPosition.text =
string.Format("Right Hand Position: {0}", h.PalmPosition.ToUnity());
this.lblRightHandRotation.text =
string.Format("Right Hand Rotation: <{0},{1},{2}>",
h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
if (this.cube != null)
this.cube.transform.rotation = Quaternion.EulerRotation
(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
foreach (var f in h.Fingers)
{
if (f.Type() == Finger.FingerType.TYPE_INDEX)
{
// this code converts the tip position from leap motion
// to unity world position
Leap.Vector position = f.TipPosition;
Vector3 unityPosition = position.ToUnityScaled(false);
Vector3 worldPosition = hc.transform.TransformPoint(unityPosition);
//string msg = string.Format("Finger ID:{0} Finger Type: {1}
//Tip Position: {2}", f.Id, f.Type(), worldPosition);
//Debug.Log(msg);
}
}
}
if (h.IsLeft)
{
this.lblLeftHandPosition.text = string.Format
("Left Hand Position: {0}", h.PalmPosition.ToUnity());
this.lblLeftHandRotation.text = string.Format
("Left Hand Rotation: <{0},{1},{2}>", h.Direction.Pitch,
h.Direction.Yaw, h.Direction.Roll);
if (this.cube != null)
this.cube.transform.rotation = Quaternion.EulerRotation
(h.Direction.Pitch, h.Direction.Yaw, h.Direction.Roll);
}
}
}
}
此代码中发生了几件事.我将指出最重要的部分,让您自己解决其余部分.例如,我不会讨论UI代码等.您可以查看文章系列,以获取有关如何设置和使用新UI框架的详细说明.(There are several things that are happening in this code. I will point out the most important sections and let you work around the rest yourself. For instance, I am not going to cover the UI code, etc. You can look at the article series for a detailed explanation of how to setup and work with the new UI framework.)
我们有一个(We have a) public HandController
定义为(object defined as) hc
.这是对(. This is a reference to the) HandController
在场景中,因此我们可以根据需要访问功能和属性.我们需要做的第一件事是将手势注册到(in the scene so we can access the functions and properties as needed. The first thing we would need to do is register hand gestures with the) HandController
目的.这是在(object. This is done in the) Start()
功能.默认情况下,已经定义了一些预定义手势,因此我们将使用其中一些手势.在这种情况下,我们已经注册了(function. There are some predefined gestures already defined by default, so we will be using some of them. In this case, we have registered the) CIRCLE
,(,) SWIPE
和(, and) SCREEN_TAP
手势类型.(gesture types.)
我们还定义了两个类型的变量(We have also defined two variables of type) GameObject
命名(named) cubePrefab
和(, and) cube
.变量(. The variable) cubePrefab
是对预制件的引用,该预制件是用适当的材料和与其关联的零件代表我们的立方体的.(is a reference to a prefab that was created to represent our cube with the appropriate materials and components associated with it.)
让我们来看看(Let’s take a look at the) Update()
功能.这是一切发生的核心,一开始可能有些混乱,但是您很快就会掌握它.我们在这里正在做的是,我们正在寻找手势(function. This is the core of where everything happens and it might be a little confusing at first, but you will get a hang of it in no time. What we are doing here, is that we are looking for a hand gesture of) TYPECIRCLE
.这将实例化我们已定义并在变量中引用的预制件(. This will instantiate the prefab we have defined and reference in the variable called) cubePrefab
.因此,我们在函数中要做的第一件事就是从(. So the first thing we are doing in the function is grabbing the current frame from the) HandController
目的.一种(object. A) Frame
对象包含与该给定实例上的手部动作有关的所有信息.下一步是获取传感器检测到的所有手势的列表,并将其存储在列表中.(object contains all of the information pertaining to the hand motion at that given instance. The next step is to get a list of all the gestures that were detected by the sensor and store it in a list.)
接下来,我们将遍历每个手势并检测类型.如果我们检测到(Next, we are going to loop through each gesture and detect the type. If we detect a) CIRCLE
手势,我们将检查是否已经实例化了多维数据集预制体,如果尚未实例化,则将继续进行实例化.下一个手势类型是(gesture, we will check to see if we have already instantiated our cube prefab, and if not, we will go ahead and instantiate it. The next gesture type is of) SWIPE
,这将破坏我们实例化的预制件.(, and this will destroy our instantiated prefab.)
下一循环基本上遍历在当前帧中检测到的手,然后检测是左手还是右手,并根据是哪只手执行特定的操作.在这种情况下,我们只需要获取手的位置和旋转,并根据右手或左手的旋转来旋转实例化的立方体.没有什么花哨!(The next loop basically goes through the hands detected in the current frame, and detects if it is the left hand or the right hand, and based on which hand it is, it perform specific operations. In this case, we just get the position and rotation of the hands, and also rotate our instantiated cube based on the rotation of the right or left hand. Nothing fancy!)
您可以在以下视频中看到结果:(You can see the result in the following video:) 演示(demo) .(.)
兴趣点(Points of Interest)
虚拟现实一直是该行业中的主题之一,这些主题在某个时间点得到大量曝光,然后一切都冷却下来.这次,情况有所不同.使虚拟现实成为可能的硬件和软件生态系统正变得越来越民主.硬件的成本虽然不便宜,但对于真正渴望动手的人们而言却是经济的,这在大多数开发人员可以负担的程度上.(Virtual reality has always been one of those topics in the industry that gets a lot of exposure at a point in time and then everything cools down. This time around, things are a bit different. The hardware and software ecosystem that enables Virtual Reality possible is becoming more and more democratized. The cost of the hardware, even though not cheap, but economical for those who are really eager to get their hands dirty, is at a point that most developers can afford.) 这使开发社区可以提供更好的VR体验和娱乐.必须将手势和手势与VR应用程序集成在一起的想法.我决定研究Leap Motion,因为它是用于非触摸式用户与计算机交互的有前途的输入传感器.下一步是将Leap Motion与Oculus Rift集成在一起.(This enables the development community to provide better VR experiences and entertainment. The idea of integrating hand motion and gestures with VR applications is a must. I have decided to look into Leap Motion as it is a promising input sensor for non-touch user interaction with the computer. The next step would be to integrate Leap Motion with Oculus Rift.)
Unity 3D文章系列(Unity 3D Article Series)
- Unity 3D –游戏编程–第1部分(Unity 3D – Game Programming – Part 1)
- Unity 3D –游戏编程–第2部分(Unity 3D – Game Programming – Part 2)
- Unity 3D –游戏编程–第3部分(Unity 3D – Game Programming – Part 3)
- Unity 3D –游戏编程–第4部分(Unity 3D – Game Programming – Part 4)
- Unity 3D –游戏编程–第5部分(Unity 3D – Game Programming – Part 5)
- Unity 3D –游戏编程–第6部分(Unity 3D – Game Programming – Part 6)
- Unity 3D –游戏编程–第7部分(Unity 3D – Game Programming – Part 7)
- Unity 3D –游戏编程–第8部分(Unity 3D – Game Programming – Part 8)
- Unity 3D –游戏编程–第9部分(Unity 3D – Game Programming – Part 9)
- Unity 3D –游戏编程–第10部分(Unity 3D – Game Programming – Part 10)
Unity 3D网络文章(Unity 3D Networking Article(s))
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C# .NET Mobile Windows Dev Design Architect tools rendering selection 新闻 翻译