------------------------------------------------------------------------------
| 12 | |
| 13 | //------------------------------------------------------------------------------ |
| 14 | void vtkOpenVRControlsHelper::InitControlPosition() |
| 15 | { |
| 16 | if (!this->Renderer->GetRenderWindow()->GetInteractor()) |
| 17 | { |
| 18 | return; |
| 19 | } |
| 20 | |
| 21 | vtkOpenVRRenderWindow* renWin = |
| 22 | static_cast<vtkOpenVRRenderWindow*>(this->Renderer->GetRenderWindow()); |
| 23 | if (!renWin) |
| 24 | { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | // Get the active controller device |
| 29 | vtkEventDataDevice controller = this->Device; |
| 30 | |
| 31 | // Get the active controller model |
| 32 | vtkVRModel* mod = renWin->GetModelForDevice(controller); |
| 33 | |
| 34 | // Hide controls tooltips if the controller is off |
| 35 | if (!mod) |
| 36 | { |
| 37 | this->LabelVisible = false; |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | // Compute the component position offset. It corresponds to the vector from the |
| 42 | // controller origin to the button origin, expressed in local coordinates. |
| 43 | uint32_t nbOfComponents = |
| 44 | renWin->GetOpenVRRenderModels()->GetComponentCount(mod->GetName().c_str()); |
| 45 | // for all existing components |
| 46 | for (uint32_t i = 0; i < nbOfComponents; i++) |
| 47 | { |
| 48 | char componentName[100]; |
| 49 | // get the component name |
| 50 | renWin->GetOpenVRRenderModels()->GetComponentName( |
| 51 | mod->GetName().c_str(), i, componentName, 100); |
| 52 | std::string strComponentName = std::string(componentName); |
| 53 | |
| 54 | if (strComponentName == this->ComponentName) |
| 55 | { |
| 56 | vr::RenderModel_ControllerMode_State_t pState; |
| 57 | vr::RenderModel_ComponentState_t pComponentState; |
| 58 | vr::VRControllerState_t cstate; |
| 59 | |
| 60 | // Get the controller state |
| 61 | renWin->GetHMD()->GetControllerState( |
| 62 | renWin->GetDeviceHandleForDevice(controller), &cstate, sizeof(cstate)); |
| 63 | |
| 64 | // Get the component state |
| 65 | renWin->GetOpenVRRenderModels()->GetComponentState( |
| 66 | mod->GetName().c_str(), this->ComponentName.c_str(), &cstate, &pState, &pComponentState); |
| 67 | |
| 68 | vr::HmdMatrix34_t mTrackingToLocal = pComponentState.mTrackingToComponentLocal; |
| 69 | |
| 70 | // Save position offset |
| 71 | this->ControlPositionLC[0] = mTrackingToLocal.m[0][3]; |
nothing calls this directly
no test coverage detected