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

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

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

Vive-SRanipal-Unity-Plugin.unitypackage

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

3, 标定

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

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

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

直接把Line Renderer不要勾选。

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<MeshRenderer>().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<MeshRenderer>().enabled = false;
                    }
					
                }
				
				 void DrawLineInGame(Vector3 point)
                {
                    //render the position of sphere
                    gazePointer.GetComponent<MeshRenderer>().enabled = true;
                    gazePointer.transform.position = point;

                }
            }
        }
    }
}

 

 

 

 

 

 

  • 1
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 18
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值