一.设备介绍
HTC Vive是由HTC 与 Valve联合开发的一款VR头显虚拟与显示头戴式显示器产品,与2015年3月在MWC2015上发布。这款头显名为HTC Vive,屏幕刷新率为90Hz,搭配两个无线控制器,并具备手势追踪功能,由于有Valve的SteamVR提供的技术支持,因此在Steam平台上已经可以体验利用Vive功能的虚拟现实游戏。
关于手柄:
1.菜单按钮2.触控板3.系统按钮(电源键)4.状态指示灯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()
{
//根据角度来判断上下左右四个范围
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暂时还没有什么能够触发
// 按下面板的时候打印
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);
系统按钮(电源键):
if (device.GetTouchDown(SteamVR_Controller.ButtonMask.System))
{
Debug.Log("按下了 “system” 系统按钮");
}
if (device.GetPressDown(SteamVR_Controller.ButtonMask.System))
{
Debug.Log("用press按下了 “System 系统按钮");
}
菜单按钮:
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” 左/右按钮");
}