htc vive 控制器 圓盤 touchpad
vive手把圓盤控制
vive圓盤偵測是手指放上去就會偵測,由二為座標組成 Axis(右圖)
vive 回偵測到座標送回,用Controller.GetAxis().x
Controller.GetAxis().y
通常遊戲會用圓盤換武器,或是當按鈕使用通常照座標象限分4等分比較準確
using System.Collections;
using System.Collections.Generic; using UnityEngine; public class ControlTest : MonoBehaviour { private SteamVR_TrackedObject trackedObj; public Vector3 controllerTransform; private float touchpad_Recordy; private SteamVR_Controller.Device Controller { get { return SteamVR_Controller.Input((int)trackedObj.index); } } void Awake() { trackedObj = GetComponent<SteamVR_TrackedObject>(); } // Use this for initialization void Start () { } // Update is called once per frame void Update () { // 1 if (Controller.GetAxis().x > 0 && Controller.GetAxis().y > 0 && Controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("按圓盤右上"); } if (Controller.GetAxis().x > 0 && Controller.GetAxis().y > 0 && Controller.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("放開圓盤右上"); } if (Controller.GetAxis().x > 0 && Controller.GetAxis().y > 0 && Controller.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("手位置圓盤右上");// } if (Controller.GetAxis().x < 0 && Controller.GetAxis().y > 0 && Controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("圓盤左上"); } if (Controller.GetAxis().x > 0 && Controller.GetAxis().y < 0 && Controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("圓盤右下"); } if (Controller.GetAxis().x < 0 && Controller.GetAxis().y < 0 && Controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("圓盤左下"); } } }
-----------------------------------------------------------------------------
Controller.GetPressDown( 裡放的是一個參數對應控制按鈕) 例如:圓盤(tochpad)或是板機(trigger)
steamvr 定義好了buttonMask 來對應參數//Controller.GetPressDown("控制器對應的Mask參數")//Controller.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) //public class SteamVR_Controller { public class ButtonMask { public const ulong System = (1ul << (int)EVRButtonId.k_EButton_System); // reserved public const ulong ApplicationMenu = (1ul << (int)EVRButtonId.k_EButton_ApplicationMenu); public const ulong Grip = (1ul << (int)EVRButtonId.k_EButton_Grip); public const ulong Axis0 = (1ul << (int)EVRButtonId.k_EButton_Axis0); public const ulong Axis1 = (1ul << (int)EVRButtonId.k_EButton_Axis1); public const ulong Axis2 = (1ul << (int)EVRButtonId.k_EButton_Axis2); public const ulong Axis3 = (1ul << (int)EVRButtonId.k_EButton_Axis3); public const ulong Axis4 = (1ul << (int)EVRButtonId.k_EButton_Axis4); public const ulong Touchpad = (1ul << (int)EVRButtonId.k_EButton_SteamVR_Touchpad); public const ulong Trigger = (1ul << (int)EVRButtonId.k_EButton_SteamVR_Trigger); }
No comments:
Post a Comment