移动VR添加视线交互
来源:互联网 发布:mac的cmd在哪里 编辑:程序博客网 时间:2024/05/18 01:45
使用MojingSDK+tales from the rift。
1.制作视线点
Crosshair为quad文件,参数如下图:
canvas 和image的参数分别如下:
image中加入的图片为一圈红线,当实现注视物体时,这一圈线会围绕crosshair进行旋转,代表选中物体的一个过程。
2.接下来是添加响应和控制脚本
给eventsystem添加如下脚本:
注意取消其自带的standalone module模块。
给image添加gaze fuze脚本。
3.给main camera 添加physics raycaster组件。
《附录》gaze fuze代码如下:
using UnityEngine;using System.Collections;using UnityEngine.UI;public class GazeFuse : MonoBehaviour { public GameObject gazeGameObject; private Image image; void Start() { image = GetComponent<Image>(); } void Update() { if (gazeGameObject == null || GazeInputModule2.gazeGameObject == gazeGameObject) { FuseAmountChanged(GazeInputModule2.gazeFraction); } } void FuseAmountChanged(float fuseAmount) { if (image != null) { image.fillAmount = fuseAmount; } }}
Gaze input module 2代码如下:
// Gaze Input Module by Peter Koch <peterept@gmail.com>using UnityEngine;using UnityEngine.EventSystems;using System.Collections.Generic;// To use:// 1. Drag onto your EventSystem game object.// 2. Disable any other Input Modules (eg: StandaloneInputModule & TouchInputModule) as they will fight over selections.// 3. Make sure your Canvas is in world space and has a GraphicRaycaster (should by default).// 4. If you have multiple cameras then make sure to drag your VR (center eye) camera into the canvas.public class GazeInputModule2 : PointerInputModule { public enum Mode { Click = 0, Gaze }; public Mode mode; [Header("Click Settings")] public string ClickInputName = "Submit"; [Header("Gaze Settings")] public float GazeTimeInSeconds = 2f; // Current gazed at object and gaze time progress public static float gazeFraction { get; private set; } public static GameObject gazeGameObject { get; private set; } public RaycastResult CurrentRaycast; private PointerEventData pointerEventData; private GameObject currentLookAtHandler; private float currentLookAtHandlerClickTime; public override void Process() { HandleLook(); HandleSelection(); } void HandleLook() { if (pointerEventData == null) { pointerEventData = new PointerEventData(eventSystem); } // fake a pointer always being at the center of the screen pointerEventData.position = new Vector2(Screen.width/2, Screen.height/2); pointerEventData.delta = Vector2.zero; List<RaycastResult> raycastResults = new List<RaycastResult>(); eventSystem.RaycastAll(pointerEventData, raycastResults); CurrentRaycast = pointerEventData.pointerCurrentRaycast = FindFirstRaycast(raycastResults); ProcessMove(pointerEventData); } void HandleSelection() { gazeFraction = 0; if (pointerEventData.pointerEnter != null) { // if the ui receiver has changed, reset the gaze delay timer GameObject handler = ExecuteEvents.GetEventHandler<IPointerClickHandler>(pointerEventData.pointerEnter); if (currentLookAtHandler != handler) { gazeGameObject = currentLookAtHandler = handler; currentLookAtHandlerClickTime = Time.realtimeSinceStartup + GazeTimeInSeconds; } if (mode == Mode.Gaze && currentLookAtHandler != null) // added for progressCursor gazeFraction = Mathf.Clamp01 (1 - (currentLookAtHandlerClickTime - Time.realtimeSinceStartup) / GazeTimeInSeconds); // added for progressCursor // if we have a handler and it's time to click, do it now if (currentLookAtHandler != null && (mode == Mode.Gaze && Time.realtimeSinceStartup > currentLookAtHandlerClickTime) || (mode == Mode.Click && Input.GetButtonDown(ClickInputName))) { if (EventSystem.current.currentSelectedGameObject != null) { // ExecuteEvents.ExecuteHierarchy(EventSystem.current.currentSelectedGameObject, pointerEventData, ExecuteEvents.deselectHandler); } EventSystem.current.SetSelectedGameObject(currentLookAtHandler); gazeFraction = 0; // added for progressCursor ExecuteEvents.ExecuteHierarchy(currentLookAtHandler, pointerEventData, ExecuteEvents.pointerClickHandler); currentLookAtHandlerClickTime = float.MaxValue; ExecuteEvents.ExecuteHierarchy(EventSystem.current.currentSelectedGameObject, pointerEventData, ExecuteEvents.deselectHandler); } } else { gazeGameObject = currentLookAtHandler = null; } }}
0 0
- 移动VR添加视线交互
- VR游戏交互开发的一些体验----1.头控通过捕获头部转动可以很方便的实现交互,成本最低,适合一些纯观景或轻度游戏设计时,要尽量减少头部移动范围,否则用户容易疲惫2.视线按钮使用一个醒
- 【VR】VR中的交互
- 视线
- VR学习第二节:人们是如何在VR世界中进行移动、如何进行自然交互的?
- VR交互方式
- 作为未来VR与移动设备交互新手段,“眼动追踪”怎样用上MEMS?
- 移动VR媒体概览
- VR中的交互方式 好
- Unity.VR.01简单交互
- steam vr 手柄的交互
- 移动VR开发初体验
- 移动VR开发(一)
- Unity VR游戏开发干货教程:VR中的交互方式
- 【翻译】 Unity3D VR 教程:3.VR中的交互
- Unity VR游戏开发干货教程:VR中的交互方式
- VR游戏交互开发的一些体验
- VR下双手与物体的交互
- 使用Moq实现单元测试
- C 基础练习3
- printf 中转义字符大全
- MATLAB中Size的用法
- Launcher.java源码分析
- 移动VR添加视线交互
- 设计模式之工厂模式
- 谈 OpenStack 与 Docker 的落地方案选择
- Spark应用执行机制
- 深入理解Java:注解(Annotation)自定义注解入门
- RobotFramework安装简易步骤
- Leetcode Generate Parentheses 解题思路
- 安装Node和NPM( MAC 系统 )
- 分析php的时间戳转换!