hololensを用いて,視線によるオブジェクトの選択を行いたいです.
より具体的には,オブジェクトある方向と,カメラの方向が一定時間一致したらオブジェクト選択を行うというものです.
以下のスクリプトをcubeに貼り付けたところ,一応の視線入力はできるようになったのですが,時々視線入力のききづらい時があります.
どのように改善を行えばよいか,アドバイスをいただきたいです.
C#
1using HoloToolkit.Unity.InputModule; 2using System.Collections; 3using System.Collections.Generic; 4using UnityEngine; 5 6public class SelectBar1 : MonoBehaviour 7{ 8 public static float[] time = new float[74]; //タップされるまでにかかった時間を格納するための配列 9 private float timer = 0.0f; 10 11 private Vector3 originaldir = new Vector3(0f, 0f, 0f); 12 13 // public static bool check = false; 14 15 // Use this for initialization 16 void Start() 17 { 18 19 } 20 21 // Update is called once per frame 22 void Update() 23 { 24 //barを縦にtap 25 if (TapStart.stage < 38) 26 { 27 //barの角度計算 28 float length = Vector3.Distance(this.transform.position, Camera.main.transform.position); 29 float theta = Mathf.Asin(this.transform.position.y / length) * (180 / Mathf.PI); 30 31 //カメラの角度計算 32 Vector3 gazedir = Camera.main.transform.forward; 33 float gbgazeDirLen = Vector3.Distance(gazedir, originaldir); 34 35 float camdir = Mathf.Asin(gazedir.y / gbgazeDirLen) * (180 / Mathf.PI); 36 37 if (Mathf.Abs(camdir - theta) <= 2f) 38 { 39 timer += Time.deltaTime; 40 if (timer > 0.5f) 41 { 42 LocateManeger.flag = true; 43 time[TapStart.stage] = TimeScript.timeCounter; //配列に時間を格納する 44 45 TapStart.stage++; 46 47 48 TimeScript.timeCounter = 0.0f; //時間の初期化 49 50 timer = 0.0f; 51 } 52 53 } 54 if (Mathf.Abs(camdir - theta) >= 2f) timer = 0.0f; 55 } 56 57 //barを横にtap 58 59 if (TapStart.stage >= 38) 60 { 61 //barの角度計算 62 63 float length = Vector3.Distance(this.transform.position, Camera.main.transform.position); 64 float theta = Mathf.Asin(this.transform.position.x / length) * (180 / Mathf.PI); 65 66 //カメラの角度計算 67 Vector3 gazedir = Camera.main.transform.forward; 68 float gbgazeDirLen = Vector3.Distance(gazedir, originaldir); 69 70 float camdir = Mathf.Asin(gazedir.x / gbgazeDirLen) * (180 / Mathf.PI); 71 72 if (Mathf.Abs(camdir - theta) <= 2f) 73 { 74 timer += Time.deltaTime; 75 if (timer > 0.5f) 76 { 77 LocateManeger.flag = true; 78 time[TapStart.stage] = TimeScript.timeCounter; //配列に時間を格納する 79 80 TapStart.stage++; 81 82 83 TimeScript.timeCounter = 0.0f; //時間の初期化 84 timer = 0.0f; 85 86 } 87 88 } 89 if (Mathf.Abs(camdir - theta) >= 2f) timer = 0.0f; 90 91 } 92 93 } 94 95} 96 97
あなたの回答
tips
プレビュー