WaveVR_GazeInputModule¶
Note¶
The script Assets/WaveVR/Extra/GazeInputModule.cs has been obsoleted.
WaveVR provides Assets/WaveVR/Scripts/EventSystem/WaveVR_GazeInputModule.cs for the Gaze feature.
This document introduces how to use WaveVR_GazeInputModule.cs independently.
WaveVR provides Input Module Manager which integrates all input modules including Gaze.
Introduction¶
The Gaze feature is implemented in WaveVR_GazeInputModule.cs.
What is Gaze?
This function is for when you are looking at an object (e.g. a cube, a blob, a menu item, etc.) and the object will perform the designated action.
The Gaze is a way to interact with objects in VR without using a controller.
What is Gaze’s composition?
- Look: The focus of your vision.
- Object: What you are looking at.
- Event: Trigger an object on a designated action.
The WaveVR SDK provides a sample: When gazing at a cube for 2 seconds, the cube will teleport randomly. When gazing at the space of scroll bar, it will scroll.
Resources¶
Assets/WaveVR/Extra/: scripts GOEventTrigger.cs , GazeInputModule.cs (obsolected)
Assets/WaveVR/Scripts/: script WaveVR_Reticle.cs
Assets/WaveVR/Scripts/EventSystem/: script WaveVR_GazeInputModule.cs
Assets/Samples/: sample Gaze_Test
Assets/WaveVR/Prefabs/: prefabs WaveVR and ReticleRing
Gaze Tutorial¶
- Open the scene Gaze_Test in the sample:
- ReticleRing is a prefab in the folder Assets/WaveVR/Prefabs used to generate a reticle which indicates the center point of your view.
- Look in the Inspector of the Cube, there are three important components: Box Collider, GOEventTrigger and Event Trigger.
With a collider, the 3D object can be detected by the raycast
Event Trigger is used to cause an action when receiving an event.
GOEventTrigger.cs is the event handler which has actions that can be triggered by Event Trigger.
- There can be only one EventSystem in a scene and and the EventSystem is used to transfer and receive events between different GameObjects.
In the Inspector of EventSystem, the component WaveVR_GazeInputModule.cs is used to generate input events.
You can change the value of
Time To Gaze
to control the gaze time (default is 2 seconds).Selecting
Progress Rate
lets you see the percentage (count from 0% to 100%, 100% means the time of Time To Gaze option is over) on the screen near the reticle pointer.With the
Progress Counter
option, you can see the counter value (count backward from the value of Time To Gaze setting to zero) on the screen near the reticle pointer.You can adjust the Z-axis position (>= 0) of
Progress Rate
orProgress Counter
to make the text closer.For
Input Event
, there are three event options. Developer can set which event will be sent when gazing.For
Head
, it is a gameobject whose camera will be used to raycast an object for the Gaze feature. Do not set an object without Camera and Physics Raycaster as theHead
. Otherwise, the Gaze feature will not work.Head
is specified to head of prefab WaveVR in this sample.About the
Button Control
option, please refer to below photo:
Button Control
: The option used to enable / disable the feature which you can trigger event to the gazed object by pressing devices’ buttons.
Button Control Devices
: The option used to specify which devices are used for the “button control” feature.
Button Control Keys
: The option used to specify which buttons are used for the “button control” feature.
To complete the sample¶
Follow the steps below to complete this sample:
- Drag the WaveVR prefab to scene
- Drag the head object of the WaveVR prefab to the
Head
field of WaveVR_GazeInputModule
- Add component PhysicsRaycaster to the head
- Expand the Camera settings of the head and change the
Target Eye
toNone (Main Display)
Note: If you do not find this option, please ignore this step.
- Drag the ReticleRing prefab under the head.
Now this sample is completed. In editor mode (just play the scene), you can use Left Alt + Mouse to control the view.
The cube will be transported when the reticle is hovering on the cube.
The Head
field of WaveVR_GazeInputModule can be specified but you should notice:
- The
Head
GameObject should have PhysicsRaycaster - The
Target Eye
of the Camera of theHead
GameObject should be set toNone (Main Display)
Script¶
WaveVR_GazeInputModule inherits PointerInputModule.
The function CastToCenterOfScreen
uses the raycast to detect the object at the center of the screen.
private void CastToCenterOfScreen()
{
if (pointerData == null)
pointerData = new PointerEventData (eventSystem);
pointerData.Reset();
pointerData.position = new Vector2 (0.5f * Screen.width, 0.5f * Screen.height); // center of screen
if (Head != null)
{
Camera _event_camera = Head.GetComponent<Camera> ();
GraphicRaycast (_event_camera);
if (pointerData.pointerCurrentRaycast.gameObject == null)
{
PhysicsRaycaster _raycaster = Head.GetComponent<PhysicsRaycaster> ();
PhysicRaycast (_raycaster);
}
}
}
The function OnTriggeGaze
sends an event to the object taken from the function CastToCenterOfScreen
.
if (sendEvent)
{
if (InputEvent == EGazeInputEvent.PointerClick)
{
ExecuteEvents.ExecuteHierarchy (currentOverGO, pointerData, ExecuteEvents.pointerClickHandler);
pointerData.clickTime = Time.unscaledTime;
} else if (InputEvent == EGazeInputEvent.PointerDown)
{
// Similar to a mouse, press and then release right after. Do not keep the pointerPressRaycast as it is not needed to control the "down" object when not gazing.
pointerData.pressPosition = pointerData.position;
pointerData.pointerPressRaycast = pointerData.pointerCurrentRaycast;
var _pointerDownGO = ExecuteEvents.ExecuteHierarchy (currentOverGO, pointerData, ExecuteEvents.pointerDownHandler);
ExecuteEvents.ExecuteHierarchy (_pointerDownGO, pointerData, ExecuteEvents.pointerUpHandler);
} else if (InputEvent == EGazeInputEvent.PointerSubmit)
{
ExecuteEvents.ExecuteHierarchy (currentOverGO, pointerData, ExecuteEvents.submitHandler);
}
}