VR開發--HTC Vive基礎(1):按鍵操作


1、手柄的詳細介紹。

手柄對象一欄: http://www.jianshu.com/p/c28fbf480cff

2、獲取手柄上按鍵的對應信息

2-1 :獲取手柄編號
        // 手柄組件 Left = GetComponent<SteamVR_TrackedObject>(); // 獲取手柄編號(左手柄 == 2) Debug.Log((int)Left.index);

在手柄上掛載此腳本

打印結果
2-2 : 獲取扳機按鍵
       // 按下了扳機按鈕調用 if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("trigger"); } 第二種方式也是Ok的 if (device.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger)) { print("123"); }

Paste_Image.png
        // 按下手柄左右的對稱按鈕調用,而且調用頻率跟刷新頻率一致 if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log("Grip"); }

Paste_Image.png
2-3:獲取grid
       // 按下手柄左右的對稱按鈕調用,而且調用頻率跟刷新頻率一致 if (device.GetTouch(SteamVR_Controller.ButtonMask.Grip)) { Debug.Log("Grip"); }
2-4:獲取圓盤

Paste_Image.png
 // 當手放置在觸摸圓盤上的時候調用 if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("touchpad"); } // 當手放置在觸摸圓盤上的時候調用 if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("touchpad"); // 獲取觸摸板上的坐標 Vector2 pad = device.GetAxis(); // Debug.Log("按下了" + pad); // 轉換角度 Vector3 cross = Vector3.Cross(new Vector2(1, 0), pad); float angle = Vector2.Angle(new Vector2(1, 0), pad); float ang = cross.z > 0 ? -angle : angle; Debug.Log(ang); //根據角度來判斷上下左右四個范圍 }
2-5:關於Axis
        // 按下面板的時候打印 if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0)) { Debug.Log("Axis0"); } // 按下扳機鍵的時候打印 if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1)) { Debug.Log("Axis1"); } 其他的Axis2,3,4暫時還沒有什么能夠觸發

3、手柄的震動

             //左手震動 var device1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost); SteamVR_Controller.Input(device1).TriggerHapticPulse(2000); // 獲取左右手柄的標志 var device2 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost); // 設置獲取手柄的震動值 SteamVR_Controller.Input(device2).TriggerHapticPulse(100);


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM