一.設(shè)備介紹
HTC Vive是由HTC 與 Valve聯(lián)合開發(fā)的一款VR頭顯虛擬與顯示頭戴式顯示器產(chǎn)品,與2015年3月在MWC2015上發(fā)布。這款頭顯名為HTC Vive,屏幕刷新率為90Hz,搭配兩個(gè)無線控制器,并具備手勢追蹤功能,由于有Valve的SteamVR提供的技術(shù)支持,因此在Steam平臺上已經(jīng)可以體驗(yàn)利用Vive功能的虛擬現(xiàn)實(shí)游戲。
關(guān)于手柄:
1.菜單按鈕2.觸控板3.系統(tǒng)按鈕(電源鍵)4.狀態(tài)指示燈5.Micro-USB端口6.追蹤感應(yīng)器7.扳機(jī)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);
}
}
獲取扳機(jī):
void OnTriggerStay(Collider collider)
{
if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("按了“Trigger”扳機(jī)鍵");
}
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("按下了“Trigger”扳機(jī)鍵");
}
if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
{
Debug.Log("松開了“Trigger”扳機(jī)鍵");
}
}
獲取控制板:
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ù)角度來判斷上下左右四個(gè)范圍
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);
//三目運(yùn)算法
return crossA.z > 0 ? -angle : angle;
}
Axis:
//Axis0,1 其他的Axis2,3,4暫時(shí)還沒有什么能夠觸發(fā)
// 按下面板的時(shí)候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis0))
{
Debug.Log("Axis0");
}
// 按下扳機(jī)鍵的時(shí)候打印
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Axis1))
{
Debug.Log("Axis1");
}
手柄的震動(dòng):
//左手震動(dòng)
var deviceIndex = SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost);
SteamVR_Controller.Input(deviceIndex).TriggerHapticPulse(3000);
//右手震動(dòng)
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鍵 兩側(cè)的鍵 ,每個(gè)手柄左右各一功能相同,同一手柄兩個(gè)鍵是一個(gè)鍵。
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("按下了 “Grip” 左/右按鈕");
}
if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip))
{
Debug.Log("用press按下了 “Grip” 左/右按鈕");
}