VR系列——Oculus Rift 开发者指南:六、Oculus触控

Oculus触控

Oculus SDK为获取每个Oculus触控的位置、状态提供了API。

这些数据体现在两个地方:

  • ovrTrackingState::HandPoses[2]——返回每个触控的姿态以及跟踪状态。
  • ovrInputState——ovr_GetInputState返回的结构体,包含按钮、操纵杆、触发器和电容触摸传感器的状态。

把触控的手势数据从输入状态中分离出来是因为他们来源于不同的系统并且在不同的时间上报。控制姿态是由一系列跟踪系统返回,并且基于传递给GetTrackingState的绝对时间参数,这些姿态可以伴随着耳机同时被预测到。双手与耳机的数据的同时上报提供了一个一致的系统状态快照。

手势跟踪

用来跟踪Oculus Rift头部位置的跟踪器集群同时也跟踪触控制器的姿态。

对于Oculus Rift和Oculus触控器,至少会有两个跟踪器集群来提高跟踪的精确度和解决遮挡问题。

SDK使用与耳机相同的ovrPoseStatef结构体,包含留个自由度(6DoF)和跟踪数据(方向、位置以及它们的一阶、二阶导数)。

以下是获取跟踪数据的示例:

ovrTrackingState     trackState = ovr_GetTrackingState(session, displayMidpointSeconds);
ovrPosef     handPoses[2]
ovrInputState    inputState

在该代码示例中,我们调用了ovr_GetTrackingState来获取预测的姿势。手控制器的姿态数据与耳机在同一个坐标系中上报,并且能够被用来在3D世界中渲染手或其他物体。

在Oculus World Demo中提供了一个这方面的例子。

按钮状态

上报输入按钮的状态是基于HID中断到达电脑。并且能够通过调用ovr_GetInputState来轮询。

下面的示例演示了如何把输入添加到手势中:

ovrTrackingState trackState = ovr_GetTrackingState(session, displayMidpointSeconds);
ovrPosef handPoses[2];
ovrInputState inputState;
//获取有用的手势,来渲染双手或者控制器表征
handPoses[ovrHand_Left] = trackState.HandPoses[ovrHand_Left].ThePose;
handPoses[ovrHand_Right] = trackState.HandPoses[ovrHand_Right].ThePose;

if (OVR_SUCCESS(ovr_GetInputState(session, ovrControllerType_Touch, &inputState)))
{
if (inputState.Buttons & ovrButton_A)
{
// 处理A按钮点击
}
if (inputState.HandTrigger[ovrHand_Left] > 0.5f)
{
//处理手握住的动作… …
}
}

ovrInputState结构体包含以下字段:

字段类型描述
TimeInSecondsdouble控制器状态最后更新的系统时间
ConnectionStateunsigned int以ovrControllerType描述。表明当前控制器的类型;你可以检查ovrControllerType_LTouch 二进制位, 例如验证左边的控制器的连接。详情:
ovrControllerType_LTouch(0x01)
ovrControllerType_RTouch(0x02)
ovrControllerType_Touch(0x03)
Buttonsunsigned int以ovrButtons描述的按钮状态。按下按钮时设置相应的位
Touchesunsigned in按钮和传感器的触摸值,可在ovrTouch中索引。用户触摸按钮或者作出控制器可识别的手势时设置相应的位
IndexTrigger[2]float左右手指触发值(ovrHand_Left和ovrHand_Right),取值范围是0.0到1.0f。值为1.0意味着手完全松开。
HandTrigger[2]float左右手触发值(ovrHand_Left和ovrHand_Right),取值范围是0.0到1.0f。手触发器一般是用来抓取物品。值为1.0意味着触发器被完全释放。
Thumbstick[2]ovrVector2f水平和垂直摇杆轴的坐标值(ovrHand_Left和ovrHand_Right)取值范围是-1.0f到1.0f。API自适应死亡区域,因此开发者不需要明确地处理。

ovrInputState结构体包含有当前的按钮、摇杆、触发器和控制器上的触摸传感器的状态。你可以检查按钮参数来查看按钮是否被按下,就像上面的ovrButton_A例子一样。以下是触控器上可用的二进制按钮列表:

按钮常数描述
ovrButton_A右边触控器上的A按钮
ovrButton_B右边触控器上的B按钮
ovrButton_RThumb右边触控器上的摇杆
ovrButton_X左边触控器上的X按钮
ovrButton_Y左边触控器上的Y按钮
ovrButton_LThumb左边触控器上的摇杆

按钮触发状态

除了按钮,触摸控制器可以检测用户手指是否触摸到一些按钮或在特定的位置。

在触摸领域,这些状态被记作为位,并且可以通过以下的常量之一进行校验:

ovrTouch_A用户触摸在右边控制器上的A按钮
ovrTouch_B用户触摸在右边控制器上的B按钮
ovrTouch_RThumb在右边控制器的摇杆上有一个探测器
ovrTouch_RIndexTrigger用户触摸右边控制器上的手指索引触发器
ovrTouch_X用户触摸在左边控制器上的X按钮
ovrTouch_Y用户触摸在左边控制器上的Y按钮
ovrTouch_LThumb在左边控制器的摇杆上有一个探测器
ovrTouch_LIndexTrigger用户触摸左边控制器上的手指索引触发器
ovrTouch_RIndexPointing用户右边的索引探测器向前越过触发器
ovrTouch_RThumbUp用户右手指向上和远离控制器上按钮用竖起右手大拇指来表示
ovrTouch_LIndexPointing用户左边的索引探测器向前越过触发器
ovrTouch_LThumbUp用户左手指向上和远离控制器上按钮用竖起左手大拇指来表示
ovr_SetControllerVibration( Hmd, ovrControllerType_LTouch, freq, trigger);

震动是通过特定的频路和振幅被启动的。当振幅的范围为0.0f到1.0f范围内时,频率为0.0f、0.5f、1.0f时,能够启动震动。频率和振幅都设为0.0f时禁止震动。

注:长时间高水平的振动会降低位置跟踪的质量。眼下,我们建议只对短时间内开启震动。


原文如下


ovrTrackingState trackState = ovr_GetTrackingState(session, displayMidpointSeconds);
ovrPosef handPoses[2];
ovrInputState inputState;
// Grab hand poses useful for rendering hand or controller representation
handPoses[ovrHand_Left] = trackState.HandPoses[ovrHand_Left].ThePose;
handPoses[ovrHand_Right] = trackState.HandPoses[ovrHand_Right].ThePose;
if (OVR_SUCCESS(ovr_GetInputState(session, ovrControllerType_Touch, &inputState)))
{
 if (inputState.Buttons & ovrButton_A)
  {
 // Handle A button being pressed
 }
 if (inputState.HandTrigger[ovrHand_Left] > 0.5f)
 {
 // Handle hand grip...
 }
}

The ovrInputState struct includes the following fields:

字段类型描述
TimeInSecondsdoubleSystem time when the controller state was last updated.
ConnectionStateunsigned intDescribed by ovrControllerType. Indicates which controller types are present; you can check the ovrControllerType_LTouch bit, for example, to verify that the left touch controller is connected. Options include:
ovrControllerType_LTouch(0x01)
ovrControllerType_RTouch (0x02)
ovrControllerType_Touch (0x03)
Buttonsunsigned intButton state described by ovrButtons. A corresponding bit is set if the button is pressed.
Touchesunsigned inTouch values for buttons and sensors as indexed by ovrTouch. A corresponding bit is set if users finger is touching the button or is in a gesture state detectable by the controller.
IndexTrigger[2]floatLeft and right finger trigger values (ovrHand_Left and ovrHand_Right), in the range 0.0 to 1.0f. A value of 1.0 means that the trigger is fully depressed.
HandTrigger[2]floatLeft and right hand trigger values (ovrHand_Left and ovrHand_Right), in the range 0.0 to 1.0f. Hand trigger is often used to grab items. A value of 1.0 means that the trigger is fully depressed.
Thumbstick[2]ovrVector2fHorizontal and vertical thumbstick axis values (ovrHand_Left and ovrHand_Right), in the range -1.0f to 1.0f. The API automatically applies the dead zone, so developers don’t need to handle it explicitly.

The ovrInputState structure includes the current state of buttons, thumb sticks, triggers and touch sensors onthe controller. You can check whether a button is pressed by checking against one of the button constants, aswas done for ovrButton_A in the above example. The following is a list of binary buttons available on touch controllers:

Button ConstantDescription
ovrButton_AA button on the right Touch controller.
ovrButton_BB button on the right Touch controller.
ovrButton_RThumbThumb stick button on the right Touch controller.
ovrButton_XX button on the left Touch controller.
ovrButton_YY button on the left Touch controller.
ovrButton_LThumbThumb stick button on the left Touch controller.

Button Touch State

In addition to buttons, Touch controllers can detect whether user fingers are touching some buttons or are in certain positions.

These states are reported as bits in the Touches field, and can be checked through one of the following constants:

ovrTouch_AUser in touching A button on the right controller.
ovrTouch_BUser in touching B button on the right controller.
ovrTouch_RThumbUser has a finder on the thumb stick of the right controller.
ovrTouch_RIndexTriggerUser in touching the index finger trigger on the right controller.
ovrTouch_XUser in touching X button on the left controller.
ovrTouch_YUser in touching Y button on the left controller.
ovrTouch_LThumbUser has a finder on the thumb stick of the left controller.
ovrTouch_LIndexTriggerUser in touching the index finger trigger on the left controller.
ovrTouch_RIndexPointingUsers right index finger is pointing forward past the trigger.
ovrTouch_RThumbUpUsers right thumb is up and away from buttons on the controller, a gesture that can be interpreted as right thumbs up.
ovrTouch_LIndexPointingUsers left index finger is pointing forward past the trigger.
ovrTouch_LThumbUpUsers left thumb is up and away from buttons on the controller, a gesture that can be interpreted as left thumbs up

Haptic Feedback

In addition to reporting input state, Oculus touch controllers can provide haptic feedback through vibration.

Vibration is enabled by calling ovr_SetControllerVibration as follows:

ovr_SetControllerVibration( Hmd, ovrControllerType_LTouch, freq, trigger);

Vibration is enabled by specifying frequency and amplitude. Frequency can take on values of 0.0f, 0.5f, and 1.0f, while amplitude ranges from 0.0f to 1.0f. Set amplitude and frequency to 0.0f to disable vibration.

Note: Prolonged high levels of vibration may reduce positional tracking quality. Right now, we recommend turning on vibration only for short periods of time.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值