Adding Air Tap on Lenses

To add an Air Tap gesture, we need to write a custom script for it. But, before that, Go to the Assets folder, navigate to HoloToolkit | Input | Scripts | InputSource, and Attach the GestureInput.cs with Root Object in the Object Explorer. Then perform the following action for writing custom scripts:

  1. Create a folder called Scripts inside the Assets folder.
  2. Add a new script by navigating from the context menu Create | C# Scripts, naming it LensGestureHandler.
  3. Open the script file in Visual Studio.

By default, the LensGestureHandler class is inherited from MonoBehaviour. MonoBehaviour is the base class from which every Unity script derives. In the next step, Implement InputClickHandler interface in the LensGestureHandler class. This interface implement the methods OnInputClicked() that invoke on click input. So, whenever you do an Air Tap Gesture, this method is invoked. Make sure you include using HoloToolkit.Unity.InputModule namespace.

So, the default skeleton for the LenseGestureHandler class would look like the following:

public class LensGestureHandler : MonoBehaviour, IInputClickHandler
{
public void OnInputClicked(InputEventData eventData)
{
throw new NotImplementedException();
}
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

What we want to achieve by the Air Tap event is to expand the inner lenses. To do that we need to first identify the specific objects from Object Hierarchy.

  1. In the Object Hierarchy, find out these three holder_geo, left_projector_geo, right_projector_geo objects.
  2. Select them individually and tag them in Inspector window ImuHolder, LeftProjector and RightProjector respectively.
In Inspector windows, from the Tag Drop Down, Use Add Tag option to add new tags. Once new tags are added, map them with respective controls for tagging.

The purpose of having this tagging is to identify the Game Object easily using script. The following images show when all these three objects are selected together. Our object is to pull these objects down together when Air Tapped:

Selected objects on 3D Model

Add a new method TranslateLenseObjects in the LensGestureHandler class, which transforms all three objects and adjusts their y-position. GameObject.FindWithTag() finds the specific object by the tag name and then we are applying translation upward or downward based on the value of Y passed as parameter.

private void TranslateLenseObjects(float y)
{
var lftprojector = GameObject.FindWithTag("LeftProjector");
var rgtprojector = GameObject.FindWithTag("RightProjector");
var imuhlder = GameObject.FindWithTag("ImuHolder");

lftprojector.transform.Translate(0.0f, y * Time.deltaTime,
0.0f);
rgtprojector.transform.Translate(0.0f, y* Time.deltaTime,
0.0f);
imuhlder.transform.Translate(0.0f, y * Time.deltaTime, 0.0f);
}

Update OnInputClicked method with following code base. This code is self-explanatory. GazeManager.Instance.HitInfo returns the HitInfo property with details of the gazed object. When the Raycast object has some value, which indicates it has gazed and we are calling the TranslateLenseObjects() method with a negative value of Y (-0.5f) and making the tapped is true. In cases when not tapped, we are transforming the object back again to the same position by passing a positive value of Y (0.5f) to the TranslateLenseObjects() method.

RaycastHit hit;
bool isTapped = false;
public void OnInputClicked(InputEventData eventData)
{
hit = GazeManager.Instance.HitInfo;
if (hit.transform.gameObject != null)
{
isTapped = !isTapped;
if (isTapped)
{
TranslateLenseObjects(-5.0f);
}
else
{
TranslateLenseObjects(5.0f);
}
}
}

Finally, attach the LensGestureHandler script with lens_geo object. That's all that is required for Air Tap on Lenses and their transformation on Air Tap.

The IFocusable interface works when the focus of gaze is in or out. You can implement this interface with any Gaze Handler which implements OnFocusEnter() and OnFocusExit() methods. You can use this method for any additional operation or animation and so on.
public void OnFocusEnter()
{ // Do something when Gaze In }
public void OnFocusExit()
{ // Do something when Gaze Out }

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.217.198