简体   繁体   English

麻烦理解 OpenVR 驱动 API

[英]Trouble understanding OpenVR driver API

My end goal is to make a VRidge lightweight clone to understand the OpenVR API, but I'm struggling to understand how to get my code to display something.我的最终目标是制作一个 VRidge 轻量级克隆来理解 OpenVR API,但我很难理解如何让我的代码显示一些东西。 As a starting point, instead of my phone, I want to create a window as the HMD (SFML, SDL, you name it...) and having SteamVR rendering the VR view in it.作为一个起点,而不是我的手机,我想创建一个 window 作为 HMD(SFML,SDL,你的名字......)并让 SteamVR 在其中渲染 VR 视图。

I understand that an object implementing IServerTrackedDeviceProvider is the handler of my driver's devices, ITrackedDeviceServerDriver is the interface of the device itself, and I suspect that my "HMD" device will have to implement IVRDisplayComponent .我知道实现IServerTrackedDeviceProvider的 object 是我的驱动程序设备的处理程序, ITrackedDeviceServerDriver是设备本身的接口,我怀疑我的“HMD”设备必须实现IVRDisplayComponent

Aside from setting some properties and having callbacks to activate and deactivate my device, I have no clue where to get an actual frame to display on the screen.除了设置一些属性并使用回调来激活和停用我的设备之外,我不知道从哪里获得要在屏幕上显示的实际帧。 What am I missing?我错过了什么?

You are almost right.你几乎是对的。

A class inheriting vr::IServerTrackedDeviceProvider (I'll call it the device parent later on) is responsible for registering and maintaining the lifetime of your devices(creating them, registering them, etc.)继承vr::IServerTrackedDeviceProvider的 class (我稍后将其称为设备父级)负责注册和维护设备的生命周期(创建、注册等)

Classes inheriting vr::ITrackedDeviceServerDriver after they have been registered by a device parent are considered a tracked device, device type is set by the device parent on register, also in case of the HMD device GetComponent() method needs to return display components if requested, for other devices it can just return NULL在设备父设备注册后继承vr::ITrackedDeviceServerDriver的类被视为被跟踪设备,设备类型由设备父设备在注册时设置,同样在 HMD 设备GetComponent()方法需要返回显示组件的情况下,如果请求, 对于其他设备,它可以只返回NULL

GetComponent() receives a c string with a component name and version, for example "IVRDisplayComponent_002" stored in vr::IVRDisplayComponent_Version , and if the device has a component with a matching name version pair you need to return a pointer to it, if no match is found return NULL GetComponent()接收带有组件名称和版本的 c 字符串,例如存储在vr::IVRDisplayComponent_Version中的"IVRDisplayComponent_002" ,如果设备具有匹配名称版本对的组件,则需要返回指向它的指针,如果没有找到匹配返回NULL

Also about components, in the driver example that Valve provides its done in a very lazy and bad way, DO NOT INHERIT COMPONENTS TO YOUR DEVICE CLASSES同样关于组件,在 Valve 以非常懒惰和糟糕的方式提供其完成的驱动程序示例中,请勿将组件继承到您的设备类

Segment your components into separate objects that you initialize in your device and return them in GetComponent() accordingly将您的组件分割成您在设备中初始化的单独对象,并相应地在GetComponent()中返回它们

Now, the only thing left for your devices to be properly identified and used by SteamVR is registering them, but there is a catch, you need to specify the device type when you register it by passing one of the values from vr::ETrackedDeviceClass enum(these should be pretty self explanatory when you look at the enum)现在,让 SteamVR 正确识别和使用您的设备的唯一事情就是注册它们,但有一个问题,您需要在注册时指定设备类型,方法是传递来自vr::ETrackedDeviceClass枚举的值之一(当您查看枚举时,这些应该是不言自明的)

This is not all there is to openvr driver of course, for it all to work and for SteamVR to even acknowledge your driver's existence you need to implement an HmdDriverFactory() function, its similarly to GetComponent() except you compare the input c string to a provider name version pair and in case of a device parent its vr::IServerTrackedDeviceProvider_Version , if you get a match return a pointer to the instance of your device parent or any other provider you implemented当然,这并不是 openvr 驱动程序的全部内容,为了让所有这些都正常工作,并且 SteamVR 甚至要确认您的驱动程序的存在,您需要实现一个HmdDriverFactory() function,它类似于GetComponent() ,除了您将输入 c 字符串与提供者名称版本对,如果是设备父级,则为vr::IServerTrackedDeviceProvider_Version ,如果匹配,则返回指向设备父级实例或您实现的任何其他提供者的指针

A few notes:几点注意事项:

  • HMD needs at least one display component HMD至少需要一个显示组件
  • HMD device is very sensitive to how you submit poses to it(dont ask why, it just is) HMD设备对你如何提交姿势非常敏感(不要问为什么,就是这样)
  • Be prepared for the lack of documentation, the best docs that you're gonna get are code comments in openvr_driver.h , ValveSoftware/openvr issue tracker and other people working with openvr drivers (even though there are only few...)为缺乏文档做好准备,您将获得的最佳文档是 openvr_driver.h 中的代码注释、 openvr_driver.h ValveSoftware/openvr问题跟踪器和其他使用 openvr 驱动程序的人(即使只有少数......)

This is not the best explanation of how openvr drivers work, so you're always welcomed to ask for more details in the comments这不是对 openvr 驱动程序如何工作的最佳解释,因此欢迎您在评论中询问更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM