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结构体包含以下字段:
字段 | 类型 | 描述 |
---|---|---|
TimeInSeconds | double | 控制器状态最后更新的系统时间 |
ConnectionState | unsigned int | 以ovrControllerType描述。表明当前控制器的类型;你可以检查ovrControllerType_LTouch 二进制位, 例如验证左边的控制器的连接。详情: ovrControllerType_LTouch(0x01) ovrControllerType_RTouch(0x02) ovrControllerType_Touch(0x03) |
Buttons | unsigned int | 以ovrButtons描述的按钮状态。按下按钮时设置相应的位 |
Touches | unsigned 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:
字段 | 类型 | 描述 |
---|---|---|
TimeInSeconds | double | System time when the controller state was last updated. |
ConnectionState | unsigned int | Described 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) |
Buttons | unsigned int | Button state described by ovrButtons. A corresponding bit is set if the button is pressed. |
Touches | unsigned in | Touch 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] | float | Left 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] | float | Left 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] | ovrVector2f | Horizontal 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 Constant | Description |
---|---|
ovrButton_A | A button on the right Touch controller. |
ovrButton_B | B button on the right Touch controller. |
ovrButton_RThumb | Thumb stick button on the right Touch controller. |
ovrButton_X | X button on the left Touch controller. |
ovrButton_Y | Y button on the left Touch controller. |
ovrButton_LThumb | Thumb 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_A | User in touching A button on the right controller. |
ovrTouch_B | User in touching B button on the right controller. |
ovrTouch_RThumb | User has a finder on the thumb stick of the right controller. |
ovrTouch_RIndexTrigger | User in touching the index finger trigger on the right controller. |
ovrTouch_X | User in touching X button on the left controller. |
ovrTouch_Y | User in touching Y button on the left controller. |
ovrTouch_LThumb | User has a finder on the thumb stick of the left controller. |
ovrTouch_LIndexTrigger | User in touching the index finger trigger on the left controller. |
ovrTouch_RIndexPointing | Users right index finger is pointing forward past the trigger. |
ovrTouch_RThumbUp | Users right thumb is up and away from buttons on the controller, a gesture that can be interpreted as right thumbs up. |
ovrTouch_LIndexPointing | Users left index finger is pointing forward past the trigger. |
ovrTouch_LThumbUp | Users 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.