VR開發(fā)實戰(zhàn)之HTC Vive設備介紹即按鍵操作

一.設備介紹

HTC Vive是由HTC 與 Valve聯(lián)合開發(fā)的一款VR頭顯虛擬與顯示頭戴式顯示器產(chǎn)品,與2015年3月在MWC2015上發(fā)布。這款頭顯名為HTC Vive,屏幕刷新率為90Hz,搭配兩個無線控制器,并具備手勢追蹤功能,由于有Valve的SteamVR提供的技術支持,因此在Steam平臺上已經(jīng)可以體驗利用Vive功能的虛擬現(xiàn)實游戲。

關于手柄:

1.菜單按鈕2.觸控板3.系統(tǒng)按鈕(電源鍵)4.狀態(tài)指示燈5.Micro-USB端口6.追蹤感應器7.扳機8.手柄按鈕


二.按鍵操作

獲取手柄對象:
public class HTCVIve_Test : MonoBehaviour {

//獲取手柄對象
public SteamVR_TrackedObject track;
//獲取手柄對象的控制器
public SteamVR_Controller.Device device;

void Start () {
    track = GetComponent<SteamVR_TrackedObject>();
}


void Update () {
    device = SteamVR_Controller.Input((int)track.index);
   }
}
獲取扳機:
void OnTriggerStay(Collider collider)
{
    if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
    {
        Debug.Log("按了“Trigger”扳機鍵");
    }
    if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
    {
        Debug.Log("按下了“Trigger”扳機鍵");
    }
    if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
    {
        Debug.Log("松開了“Trigger”扳機鍵");
    }
}
獲取控制板:

Paste_Image.png

//獲取圓盤(控制板)    
void Update () {
   if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad))
    {
        float angleTrue = ReturnDirection();
        if (angleTrue < -45 && angleTrue > -135)
        {
            Debug.Log("上");
        }
        if (angleTrue > 45 && angleTrue < 135)
        {
            Debug.Log("下");
        }
        if (angleTrue < 180 && angleTrue > 135 || (angleTrue < -135 && angleTrue > -180))
        {
            Debug.Log("左");
        }
        if (angleTrue > 0 && angleTrue < 45 || (angleTrue > -45 && angleTrue < 0))
        {
            Debug.Log("右");
        }
    }
}
public float ReturnDirection() 
{
    //根據(jù)角度來判斷上下左右四個范圍
    Vector2 axis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad);
    Vector3 crossA = Vector3.Cross(Vector2.right,axis);
    float angle = Vector2.Angle(Vector2.right,axis);
    //三目運算法
    return crossA.z > 0 ? -angle : angle;
}
Axis:
 //Axis0,1  其他的Axis2,3,4暫時還沒有什么能夠觸發(fā)
    // 按下面板的時候打印
    if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
    {
        Debug.Log("Axis0");
    }
    // 按下扳機鍵的時候打印
    if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
    {
        Debug.Log("Axis1");
    }
手柄的震動:
 //左手震動  
     var deviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);  
     SteamVR_Controller.Input(deviceIndex).TriggerHapticPulse(3000);  

     //右手震動  
     var deviceIndex1 = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost);  
     SteamVR_Controller.Input(deviceIndex1).TriggerHapticPulse(3000);
系統(tǒng)按鈕(電源鍵):
 if (device.GetTouchDown(SteamVR_Controller.ButtonMask.System))  
    {  
        Debug.Log("按下了 “system”  系統(tǒng)按鈕");  
    }  
    if (device.GetPressDown(SteamVR_Controller.ButtonMask.System))  
    {  
        Debug.Log("用press按下了 “System  系統(tǒng)按鈕");  
    }
菜單按鈕:
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu))  
    {  
        Debug.Log("按下了 “ApplicationMenu” “菜單鍵”");  
    }  
    if (device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu))  
    {  
        Debug.Log("用press按下了 “ApplicationMenu” “菜單鍵”");  
    }
Grip(左、右按鈕):
  //Grip鍵 兩側的鍵 ,每個手柄左右各一功能相同,同一手柄兩個鍵是一個鍵。  
    if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))  
    {  
        Debug.Log("按下了 “Grip”  左/右按鈕");  
    }  
    if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))  
    {  
        Debug.Log("用press按下了 “Grip” 左/右按鈕");  
    }
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容