Monday 2 October 2017

Hololens developing: How to use Holotoolkit and Understanding HoloToolkit (2), GazeManager.HitInfo

In last post, we created a simple Holotoolkit project, created a small Cube, when the user looking at (gaze aiming at) the cube, a cursor will appear on the surface of the cube indicting where you are looking at.

How is everything happened?

let's split the problem into some layers, basic by basic

1) How Hololens can "see" some objects? 

   You can image like this: Hololen device send some "wave" from the sensor in the front of it, when the wave hit object, it will hit back to the receive sensor telling Hololens it hit something, carrying back hit angle, hit distance, and other hit informations. You are right, it is just like a Radar in the battlefield.

Although it works very similar to a radar,  actually it doesn't send any physic wave when hololens try to see anything. Hololens do have sensors to send physic waves, but that is for Spatial Mapping(we will talk about SpatialMapping in later chapters) which hololen try to map and build 3D environment data around the user, Spatial Mapping could be turned off which means hololen knows nothing about the room you are standing in, but still can see the object(like the Cube) you created in Unity;

Hololen can see the object you created because it knows the object's location, its's own location, the direction it is looking at, based on these three parameters, hololens can tell if the object is on the way you are looking at and thus return every parameters you need to react.

Introducing Raycast

Physics.Raycast(Vector3 position, Vector3 direction, out  RaycastHit)
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

like I said above, it cast a ray from (Vector3 position) in direction (Vector3 direction), if hit anything, return back what it hit (out  RaycastHit).

the method return a bool value indicting if the ray hit something or not.

the Holotoolkit, no matter how complex it is, is using Physics.Raycast to explore the  outer world.

let's see how holotoolkit use Physics.Raycast,

In Hierarchy, click the "Input Manager", see the Inspector, there is a "Gaze Manager" script component;























Open this "Gaze Manager (Script)" component in Visual Studio, find this:























You can see the hitInfo which is a RaycastHit value there, keep looking down and Find out void Update() method.

















keep finding RaycastPhysics() method

























you can see from the screenshot the hitInfo is updated by GazeManager through out its void Update() method, which is 60 frames per second.

Just ignore all these if..else code in the screenshot for now(we will talk these things later), just to remember, GazeManager.HitInfo property always has the latest hit information of what hololens is looking at.

Next Chapter, I will introduce how Gaze component is using this GazeManager.HitInfo to show itself to the user


No comments:

Post a Comment