**学习源于官方文档 Gaze in Unity **

笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文


HoloLens 有三大输入系统,凝视点、手势和声音 ~ 本文主要记录凝视系统的学习笔记 ~

(四)Hololens Unity 开发之 凝视系统

一、概述

Gaze is the first input mechanism on HoloLens. It's the first "G" in Gaze, Gesture, and Voice input models on HoloLens. However, there is no explicit API or Component exposing Gaze in Unity.

凝视系统是HoloLens的第一输入机制~(其实我觉得是借助了cardboard的交互模式),官文上有这么一句话 However, there is no explicit API or Component exposing Gaze in Unity. 凝视系统嘞~ 没有统一的API,所以只需要自己去实现就好~ 不是太复杂,下面是凝视系统的原理。


二、凝视系统原理

原理很简单:射线碰撞检测 ,unity开发者都比较熟悉了下面是官文中对射线碰撞的描述不再翻译

Conceptually, Gaze is implemented by projecting a ray from the user's head where the HoloLens is, in the forward direction they are facing and determining what that ray collides with. In Unity, the user's head position and direction are exposed through the Unity Main Camera, specifically UnityEngine.Camera.main.transform.forward and UnityEngine.Camera.main.transform.position.

Calling Physics.RayCast results in a RaycastHit structure which contains information about the collision including the 3D point where collision occurred and the other GameObject the gaze ray collided with.

上Demo代码~

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class GazeDemo : MonoBehaviour { // Use this for initialization
void Start () { } // Update is called once per frame
void Update () { RaycastHit hitinfo;
if (Physics.Raycast(
Camera.main.transform.position,
Camera.main.transform.forward,
out hitinfo,
20.0f,
Physics.DefaultRaycastLayers)
)
{
Debug.Log("检测到了 物体 ~"); }
}
}

射线检测碰撞 涉及到的一些具体的参数请自行查阅unity文档 案例很简单,下图是模拟器的实际效果

上图可以看出,模拟器的凝视点为屏幕中心点~ 而上面的官文提高过,设备上的凝视点为用户的眼睛 以及 透过全息透镜 确定的直线 来确定的凝视点~ 两点控制一条直线~ 眼睛 -- 全息透镜中心点~


三、Visualizing Gaze 可视化的凝视点~

这个比较容易理解了,类似cardboard中的焦点,当然,也可以自己实现,不过HoloLens在HoloToolkit-Unity的工具中已经提供了一个类 GazeManager.cs ,用于实现可视化焦点~ 而且用起来也挺方便的~

示例代码

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using HoloToolkit.Unity.InputModule; public class VisualizingGazeDemo : MonoBehaviour { private GazeManager gazeManager; // Use this for initialization
void Start () { gazeManager = GazeManager.Instance;
gazeManager.FocusedObjectChanged += OnFocusedObjectChanged; Debug.Log("初始化完成~"); } private void OnFocusedObjectChanged(GameObject previousObject, GameObject newObject)
{
Debug.Log("检测到 物体 的 名字 ~ " + newObject.name);
} // Update is called once per frame
void Update () { }
}

注意了~ GazeManager 是个mono单例类所以一定要把它先挂到场景里面


(四)Hololens Unity 开发之 凝视系统的更多相关文章

  1. (二)Hololens Unity 开发之 语音识别

    学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发之 语音识别 Hol ...

  2. (三)Hololens Unity 开发之 语音识别

    学习源于官方文档 Voice input in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (三)Hololens Unity 开发之 语音识别 Hol ...

  3. (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10)

    (一)Hololens Unity 开发环境搭建(Mac BOOTCAMP WIN10) 系统要求 64位 Windows 10 除了家庭版的 都支持 ~ 64位CPU CPU至少是四核心以上~ 至少 ...

  4. (五)Hololens Unity 开发之 手势识别

    学习源于官方文档 Gestures in Unity 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (五)Hololens Unity 开发之 手势识别 HoloLe ...

  5. (二)Hololens Unity 开发入门 之 Hello HoloLens~

    学习源于官方文档 微软官文~ 笔记一部分是直接翻译官方文档,部分各人理解不一致的和一些比较浅显的保留英文原文 (二)Hololens Unity 开发入门 之 Hello HoloLens~ 本文主要 ...

  6. Hololens开发笔记之使用Unity开发一个简单的应用

    一.Hololens概述 Hololens有以下特性 1.空间映射借助微软特殊定制的全息处理单元(HPU),HoloLens 实现了对周边环境的快速扫描和空间匹配.这保证了 HoloLens能够准确地 ...

  7. HoloLens开发手记 - Unity development overview 使用Unity开发概述

    Unity Technical Preview for HoloLens最新发行版为:Beta 24,发布于 09/07/2016 开始使用Unity开发HoloLens应用之前,确保你已经安装好了必 ...

  8. 使用Unity开发HoloLens应用

    https://developer.microsoft.com/en-us/windows/holographic/install_the_tools 导读:开发者们在陆续收到HoloLens开发者版 ...

  9. Unity开发概览(HoloLens开发系列)

    本文翻译自:Unity development overview 要开始使用Unity创建全息应用,点此安装包含Unity HoloLens技术预览的开发工具.Unity HoloLens技术预览基于 ...

随机推荐

  1. CSS实现单行、多行文本溢出显示省略号

    单行显示省略号 overflow: hidden; text-overflow:ellipsis; white-space: nowrap;多行显示省略号 display: -webkit-box; ...

  2. Win8/8.1 下映像管理和恢复环境的配置

    以前遇过不少次这种问题了,抽空记下来...... 介绍两个东西: 1. dism 部署映像服务和管理工具 主要用途是枚举.安装.卸载.配置和更新 Windows 映像中的功能和程序包. 简单地说就是有 ...

  3. (简单) POJ 3159 Candies,Dijkstra+差分约束。

    Description During the kindergarten days, flymouse was the monitor of his class. Occasionally the he ...

  4. [iOS]使用signal让app能够在从容崩溃

    前言 虽然大家都不愿意看到程序崩溃,但可能崩溃是每个应用必须面对的现实,既然崩溃已经发生,无法阻挡了,那我们就让它崩也崩得淡定点吧. iOS SDK中提供了一个现成的函数 NSSetUncaughtE ...

  5. laravel5 html引用问题

    1. Composer 安装 编辑 composer.json 文件, require 节点下增加: "illuminate/html": "~5.0" 然后 ...

  6. ubuntu12.04安装tar.gz格式的jdk

    注意系统的版本,jdk也有32位和64位的,不然会无效 首先将*.tar.gz压缩包解压 命令: tar -xzvf *.tar.gz 假设得到的文件夹为java 将其移动到/usr/中 命令为:su ...

  7. mysql 大树据表update很慢

    问题描述: 数据表千万量级,update  where gid="adadfadsfasdf",返回结果显示耗时70ms到1s之间 分析: 表很大,那么update,可能先要取索引 ...

  8. 学习wcf

    链接请看下面 第一部分:http://boytnt.blog.51cto.com/966121/796884 第二部分:http://boytnt.blog.51cto.com/966121/7969 ...

  9. iOS开发——沙箱

    iphone沙箱模型的有三个文件夹,documents,tmp,Library.有时开发时要求我们保存一些数据在本地,这就用到了. 1.Documents 目录:您应该将所有de应用程序数据文件写入到 ...

  10. STM32F412应用开发笔记之八:迪文串口屏显示驱动

    迪文的显示屏使用起来比较方便,其使用串口通讯,即可支持RS232,又可以支持TTL电平.在NUCLEO-F412ZG实验板上,USART2已经引到了CN9上,我们就利用USART2来实现与迪文串口屏的 ...