Commit a6fc9e52 authored by Ken Martin's avatar Ken Martin Committed by Kitware Robot

Merge topic 'oculus_support'

799c638c fix a few issues with occulus controller support
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Csaba Pinter's avatarCsaba Pinter <csaba.pinter@queensu.ca>
Acked-by: Lucas Gandel's avatarLucas Gandel <lucas.gandel@kitware.com>
Merge-request: !4685
parents d15f5201 799c638c
......@@ -38,6 +38,7 @@ enum class vtkEventDataDeviceInput {
Unknown = -1,
Trigger,
TrackPad,
Joystick,
Grip,
ApplicationMenu,
NumberOfInputs
......@@ -51,6 +52,8 @@ enum class vtkEventDataAction {
Unknown = -1,
Press,
Release,
Touch,
Untouch,
NumberOfActions
};
......@@ -94,6 +97,11 @@ class vtkEventDataForDevice : public vtkEventData
{
public:
vtkTypeMacro(vtkEventDataForDevice,vtkEventData);
static vtkEventDataForDevice *New() {
vtkEventDataForDevice *ret = new vtkEventDataForDevice;
ret->InitializeObjectBase();
return ret;
};
vtkEventDataDevice GetDevice() const { return this->Device; }
vtkEventDataDeviceInput GetInput() const { return this->Input; }
......
......@@ -252,8 +252,11 @@ void vtkInteractorStyle3D::Dolly3D(vtkEventData *ed)
// movement can be determined from the camera scale.
// movement speed is scaled by the touchpad
// y coordinate
float *tpos = rwi->GetTouchPadPosition();
float tpos[3];
rwi->GetTouchPadPosition(
edd->GetDevice(),
vtkEventDataDeviceInput::Unknown,
tpos);
// 2.0 so that the max is 2.0 times the average
// motion factor
double factor = tpos[1]*2.0*this->DollyMotionFactor/90.0;
......
......@@ -33,6 +33,8 @@
#include "vtkRenderWindowInteractor.h"
class vtkCamera;
enum class vtkEventDataDevice;
enum class vtkEventDataDeviceInput;
class VTKRENDERINGCORE_EXPORT vtkRenderWindowInteractor3D : public vtkRenderWindowInteractor
{
......@@ -227,10 +229,12 @@ public:
//@{
/**
* Set/Get the latest touchpad position
* Get the latest touchpad or joystick position for a device
*/
vtkSetVector2Macro(TouchPadPosition,float);
vtkGetVector2Macro(TouchPadPosition,float);
virtual void GetTouchPadPosition(
vtkEventDataDevice,
vtkEventDataDeviceInput,
float [3]) { };
//@}
//@{
......@@ -264,7 +268,6 @@ protected:
int MouseInWindow;
int StartedMessageLoop;
float TouchPadPosition[2];
double Translation3D[3];
double LastTranslation3D[3];
......
......@@ -215,15 +215,17 @@ void vtkOpenVRInteractorStyle::OnMove3D(vtkEventData *edata)
{
return;
}
int idev = static_cast<int>(edd->GetDevice());
//Set current state and interaction prop
this->InteractionProp = this->InteractionProps[idev];
// joystick moves?
int idev = static_cast<int>(edd->GetDevice());
//Update current state
int x = this->Interactor->GetEventPosition()[0];
int y = this->Interactor->GetEventPosition()[1];
//Set current state and interaction prop
this->InteractionProp = this->InteractionProps[idev];
switch (this->InteractionState[idev])
{
case VTKIS_POSITION_PROP:
......
......@@ -172,22 +172,66 @@ void vtkOpenVRRenderWindowInteractor::ConvertPoseToWorldCoordinates(
}
}
void vtkOpenVRRenderWindowInteractor::UpdateTouchPadPosition(
vr::IVRSystem *pHMD,
vr::TrackedDeviceIndex_t tdi)
void vtkOpenVRRenderWindowInteractor::GetTouchPadPosition(
vtkEventDataDevice device,
vtkEventDataDeviceInput input,
float result[3]
)
{
vtkOpenVRRenderWindow *renWin =
vtkOpenVRRenderWindow::SafeDownCast(this->RenderWindow);
vr::IVRSystem *pHMD = renWin->GetHMD();
if (!pHMD)
{
return;
}
auto tdi =
renWin->GetTrackedDeviceIndexForDevice(device);
vr::VRControllerState_t cstate;
pHMD->GetControllerState(tdi, &cstate, sizeof(cstate));
for (unsigned int i = 0; i < vr::k_unControllerStateAxisCount; i++)
// input Unknown defaults to Axis0
int offset = 0;
if (input == vtkEventDataDeviceInput::TrackPad)
{
if (pHMD->GetInt32TrackedDeviceProperty(tdi,
static_cast<vr::ETrackedDeviceProperty>(vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32 + i))
== vr::EVRControllerAxisType::k_eControllerAxis_TrackPad)
for (offset = 0; offset < vr::k_unControllerStateAxisCount; ++offset)
{
this->SetTouchPadPosition(cstate.rAxis[i].x,cstate.rAxis[i].y);
auto axisType =
pHMD->GetInt32TrackedDeviceProperty(tdi,
static_cast<vr::ETrackedDeviceProperty>(
vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32 + offset));
if (axisType == vr::EVRControllerAxisType::k_eControllerAxis_TrackPad)
{
break;
}
}
}
if (input == vtkEventDataDeviceInput::Joystick)
{
for (offset = 0; offset < vr::k_unControllerStateAxisCount; ++offset)
{
auto axisType =
pHMD->GetInt32TrackedDeviceProperty(tdi,
static_cast<vr::ETrackedDeviceProperty>(
vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32 + offset));
if (axisType == vr::EVRControllerAxisType::k_eControllerAxis_Joystick)
{
break;
}
}
}
if (offset == vr::k_unControllerStateAxisCount)
{
return;
}
result[0] = cstate.rAxis[offset].x;
result[1] = cstate.rAxis[offset].y;
}
//----------------------------------------------------------------------------
......@@ -287,19 +331,20 @@ void vtkOpenVRRenderWindowInteractor::DoOneEvent(vtkOpenVRRenderWindow *renWin,
{
vr::TrackedDeviceIndex_t tdi = event.trackedDeviceIndex;
vr::ETrackedControllerRole role = pHMD->GetControllerRoleForTrackedDeviceIndex(tdi);
// 0 = right hand 1 = left
int pointerIndex =
(role == vr::ETrackedControllerRole::TrackedControllerRole_RightHand ? 0 : 1);
// is it a controller button action?
if (pHMD->GetTrackedDeviceClass(tdi) ==
vr::ETrackedDeviceClass::TrackedDeviceClass_Controller &&
(event.eventType == vr::VREvent_ButtonPress ||
event.eventType == vr::VREvent_ButtonUnpress))
event.eventType == vr::VREvent_ButtonUnpress ||
event.eventType == vr::VREvent_ButtonTouch ||
event.eventType <= vr::VREvent_ButtonUntouch))
{
vr::ETrackedControllerRole role = pHMD->GetControllerRoleForTrackedDeviceIndex(tdi);
this->UpdateTouchPadPosition(pHMD,tdi);
// 0 = right hand 1 = left
int pointerIndex =
(role == vr::ETrackedControllerRole::TrackedControllerRole_RightHand ? 0 : 1);
this->PointerIndexLookup[pointerIndex] = tdi;
vr::TrackedDevicePose_t &tdPose = renWin->GetTrackedDevicePose(tdi);
......@@ -324,31 +369,65 @@ void vtkOpenVRRenderWindowInteractor::DoOneEvent(vtkOpenVRRenderWindow *renWin,
vtkNew<vtkEventDataButton3D> ed;
ed->SetDevice(pointerIndex ? vtkEventDataDevice::LeftController : vtkEventDataDevice::RightController);
ed->SetAction(event.eventType == vr::VREvent_ButtonPress
? vtkEventDataAction::Press : vtkEventDataAction::Release);
switch(event.eventType)
{
default:
case vr::VREvent_ButtonPress:
ed->SetAction(vtkEventDataAction::Press);
break;
case vr::VREvent_ButtonUnpress:
ed->SetAction(vtkEventDataAction::Release);
break;
case vr::VREvent_ButtonTouch:
ed->SetAction(vtkEventDataAction::Touch);
break;
case vr::VREvent_ButtonUntouch:
ed->SetAction(vtkEventDataAction::Untouch);
break;
}
ed->SetWorldPosition(pos);
ed->SetWorldOrientation(wxyz);
ed->SetWorldDirection(wdir);
bool knownButton = true;
switch (event.data.controller.button)
{
default:
case vr::EVRButtonId::k_EButton_Axis1:
ed->SetInput(vtkEventDataDeviceInput::Trigger);
break;
case vr::EVRButtonId::k_EButton_Axis0:
ed->SetInput(vtkEventDataDeviceInput::TrackPad);
vr::VRControllerState_t cstate;
pHMD->GetControllerState(tdi, &cstate, sizeof(cstate));
for (unsigned int i = 0; i < vr::k_unControllerStateAxisCount; i++)
{
if (pHMD->GetInt32TrackedDeviceProperty(tdi,
static_cast<vr::ETrackedDeviceProperty>(vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32 + i))
== vr::EVRControllerAxisType::k_eControllerAxis_TrackPad)
// temporarily map joystick touch events on axis0 to button press/release
// until we add action into the logic for mapping events
// to actions in the interactorstyle
auto axisType =
pHMD->GetInt32TrackedDeviceProperty(tdi,
static_cast<vr::ETrackedDeviceProperty>(
vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32));
if (axisType == vr::EVRControllerAxisType::k_eControllerAxis_Joystick)
{
ed->SetTrackPadPosition(cstate.rAxis[i].x,cstate.rAxis[i].y);
if (ed->GetAction() == vtkEventDataAction::Touch)
{
ed->SetAction(vtkEventDataAction::Press);
}
if (ed->GetAction() == vtkEventDataAction::Untouch)
{
ed->SetAction(vtkEventDataAction::Release);
}
}
}
// vr::VRControllerState_t cstate;
// pHMD->GetControllerState(tdi, &cstate, sizeof(cstate));
// for (unsigned int i = 0; i < vr::k_unControllerStateAxisCount; i++)
// {
// if (pHMD->GetInt32TrackedDeviceProperty(tdi,
// static_cast<vr::ETrackedDeviceProperty>(vr::ETrackedDeviceProperty::Prop_Axis0Type_Int32 + i))
// == vr::EVRControllerAxisType::k_eControllerAxis_TrackPad)
// {
// ed->SetTrackPadPosition(cstate.rAxis[i].x,cstate.rAxis[i].y);
// }
// }
break;
case vr::EVRButtonId::k_EButton_Grip:
ed->SetInput(vtkEventDataDeviceInput::Grip);
......@@ -356,9 +435,12 @@ void vtkOpenVRRenderWindowInteractor::DoOneEvent(vtkOpenVRRenderWindow *renWin,
case vr::EVRButtonId::k_EButton_ApplicationMenu:
ed->SetInput(vtkEventDataDeviceInput::ApplicationMenu);
break;
default:
knownButton = false;
break;
}
if (this->Enabled)
if (this->Enabled && knownButton && event.data.controller.button)
{
this->InvokeEvent(vtkCommand::Button3DEvent, ed);
//----------------------------------------------------------------------------
......@@ -420,11 +502,6 @@ void vtkOpenVRRenderWindowInteractor::DoOneEvent(vtkOpenVRRenderWindow *renWin,
this->PointerIndexLookup[pointerIndex] = unTrackedDevice;
this->SetPointerIndex(pointerIndex);
if (this->PointersDown[pointerIndex])
{
this->UpdateTouchPadPosition(pHMD, unTrackedDevice);
}
double pos[3];
double ppos[3];
double wxyz[4];
......
......@@ -97,13 +97,20 @@ public:
double ppos[3],
double wdir[3]);
//@{
/**
* Get the latest touchpad or joystick position for a device
*/
void GetTouchPadPosition(
vtkEventDataDevice,
vtkEventDataDeviceInput,
float [3]) override;
//@}
protected:
vtkOpenVRRenderWindowInteractor();
~vtkOpenVRRenderWindowInteractor();
void UpdateTouchPadPosition(vr::IVRSystem *pHMD,
vr::TrackedDeviceIndex_t tdi);
//@{
/**
* Class variables so an exit method can be defined for this class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment