1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/*=========================================================================
Program: Visualization Toolkit
Module: vtkOpenVRControlsHelper.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkOpenVRControlsHelper.h"
#include "vtkObjectFactory.h"
#include "vtkOpenVRModel.h"
#include "vtkOpenVRRenderWindow.h"
#include "vtkRenderer.h"
VTK_ABI_NAMESPACE_BEGIN
vtkStandardNewMacro(vtkOpenVRControlsHelper);
//------------------------------------------------------------------------------
void vtkOpenVRControlsHelper::InitControlPosition()
{
if (!this->Renderer->GetRenderWindow()->GetInteractor())
{
return;
}
vtkOpenVRRenderWindow* renWin =
static_cast<vtkOpenVRRenderWindow*>(this->Renderer->GetRenderWindow());
if (!renWin)
{
return;
}
// Get the active controller device
vtkEventDataDevice controller = this->Device;
// Get the active controller model
vtkVRModel* mod = renWin->GetModelForDevice(controller);
// Hide controls tooltips if the controller is off
if (!mod)
{
this->LabelVisible = false;
return;
}
// Compute the component position offset. It corresponds to the vector from the
// controller origin to the button origin, expressed in local coordinates.
uint32_t nbOfComponents =
renWin->GetOpenVRRenderModels()->GetComponentCount(mod->GetName().c_str());
// for all existing components
for (uint32_t i = 0; i < nbOfComponents; i++)
{
char componentName[100];
// get the component name
renWin->GetOpenVRRenderModels()->GetComponentName(
mod->GetName().c_str(), i, componentName, 100);
std::string strComponentName = std::string(componentName);
if (strComponentName == this->ComponentName)
{
vr::RenderModel_ControllerMode_State_t pState;
vr::RenderModel_ComponentState_t pComponentState;
vr::VRControllerState_t cstate;
// Get the controller state
renWin->GetHMD()->GetControllerState(
renWin->GetDeviceHandleForDevice(controller), &cstate, sizeof(cstate));
// Get the component state
renWin->GetOpenVRRenderModels()->GetComponentState(
mod->GetName().c_str(), this->ComponentName.c_str(), &cstate, &pState, &pComponentState);
vr::HmdMatrix34_t mTrackingToLocal = pComponentState.mTrackingToComponentLocal;
// Save position offset
this->ControlPositionLC[0] = mTrackingToLocal.m[0][3];
this->ControlPositionLC[1] = mTrackingToLocal.m[1][3];
this->ControlPositionLC[2] = mTrackingToLocal.m[2][3];
break; // Don't need to check other components. break.
}
}
}
VTK_ABI_NAMESPACE_END
|