HTC vive Eye pro眼动追踪初识

1, 安装 VIVE_SRanipalInstaller_1.0.3.0

https://download.csdn.net/download/moonlightpeng/11237948

 

 

官方的下载地址 

https://developer.vive.com/resources/?site=cn

HTC vive Eye pro眼动追踪初识_第1张图片

https://developer.vive.com/resources/downloads/?site=cn

HTC vive Eye pro眼动追踪初识_第2张图片

2,在unity工程中导入相应的package

Vive-SRanipal-Unity-Plugin.unitypackage

https://download.csdn.net/download/moonlightpeng/11237918

3, 标定

方案1 在没有运行工程时,直接在头盔中通过手柄来标定。

方案2 用unitypackage里面的标定功能。

HTC vive Eye pro眼动追踪初识_第3张图片

4, 在工程中用红色的小球表示眼睛的注视点,把自动的紫色的射线不显示。

直接把Line Renderer不要勾选。

HTC vive Eye pro眼动追踪初识_第4张图片

5 修改对应的脚本   SRanipal_GazeRaySample.cs

//========= Copyright 2018, HTC Corporation. All rights reserved. ===========
using UnityEngine;
using UnityEngine.Assertions;

namespace ViveSR
{
    namespace anipal
    {
        namespace Eye
        {
            public class SRanipal_GazeRaySample : MonoBehaviour
            {
				private GameObject gazePointer;
                public int LengthOfRay = 25;
                [SerializeField] private LineRenderer GazeRayRenderer;

                private void Start()
                {
					      gazePointer = new GameObject();
                    gazePointer = GameObject.Find("GazePointer");
                    if (gazePointer)
                    {
                        gazePointer.GetComponent().enabled = false;
                    }
                    else
                    {
                        Debug.LogError("cannot find object of gazePointer");
                    }
                    if (!SRanipal_Eye_Framework.Instance.EnableEye)
                    {
						
                        enabled = false;
                        return;
                    }
                    Assert.IsNotNull(GazeRayRenderer);
                }

                private void Update()
                {
                    if (SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.WORKING &&
                        SRanipal_Eye_Framework.Status != SRanipal_Eye_Framework.FrameworkStatus.NOT_SUPPORT) return;
                    Vector3 GazeOriginCombinedLocal, GazeDirectionCombinedLocal;
                    if (SRanipal_Eye.GetGazeRay(GazeIndex.COMBINE, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal)) { }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.LEFT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal)) { }
                    else if (SRanipal_Eye.GetGazeRay(GazeIndex.RIGHT, out GazeOriginCombinedLocal, out GazeDirectionCombinedLocal)) { }
                    else return;
                    Vector3 GazeDirectionCombined = Camera.main.transform.TransformDirection(GazeDirectionCombinedLocal);
                    GazeRayRenderer.SetPosition(0, Camera.main.transform.position - Camera.main.transform.up * 0.05f);
                    GazeRayRenderer.SetPosition(1, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay);
					
					Ray ray = new Ray(Camera.main.transform.position - Camera.main.transform.up * 0.05f, GazeDirectionCombined);
                    Debug.DrawLine(Camera.main.transform.position - Camera.main.transform.up * 0.05f, Camera.main.transform.position + GazeDirectionCombined * LengthOfRay, Color.red);  //这个就是绘制出的射线了,包含发射位置,发射距离和射线的颜色;    
                    RaycastHit hitInfo;

                    if (Physics.Raycast(ray, out hitInfo, 100))
                    {

                        DrawLineInGame(hitInfo.point);

                        GameObject hitme = hitInfo.collider.gameObject; 

                    }
                    else
                    {
                        gazePointer.GetComponent().enabled = false;
                    }
					
                }
				
				 void DrawLineInGame(Vector3 point)
                {
                    //render the position of sphere
                    gazePointer.GetComponent().enabled = true;
                    gazePointer.transform.position = point;

                }
            }
        }
    }
}

HTC vive Eye pro眼动追踪初识_第5张图片

 

 

 

 

 

 

你可能感兴趣的:(VR/AR/MR/XR,unity)