Commit ea51a0e1 authored by Robin Eschbach's avatar Robin Eschbach
Browse files

[ADD #720] reset view to grip buttons

parent 8cd849e3
......@@ -267,39 +267,28 @@ void WMVRCamera::handleVREvent( vr::VREvent_t vrEvent )
void WMVRCamera::handleControllerEvent( vr::VREvent_t vrEvent )
{
switch( vrEvent.eventType )
WVRController* controller = vrEvent.trackedDeviceIndex == m_leftController->getDeviceID() ? m_leftController.get() :
vrEvent.trackedDeviceIndex == m_rightController->getDeviceID() ? m_rightController.get() : nullptr;
if( !controller )
{
case vr::VREvent_ButtonPress:
// check for any changes regarding controller device IDs on any button press
updateDeviceIDs();
return; // Not a controller
}
if( vrEvent.data.controller.button == vr::EVRButtonId::k_EButton_SteamVR_Trigger )
{
if( vrEvent.trackedDeviceIndex == m_leftController->getDeviceID() )
{
m_leftController->setTriggered( true );
}
else if( vrEvent.trackedDeviceIndex == m_rightController->getDeviceID() )
{
m_rightController->setTriggered( true );
}
}
break;
case vr::VREvent_ButtonUnpress:
if( vrEvent.data.controller.button == vr::EVRButtonId::k_EButton_SteamVR_Trigger )
{
if( vrEvent.trackedDeviceIndex == m_leftController->getDeviceID() )
{
m_leftController->setTriggered( false );
}
else if( vrEvent.trackedDeviceIndex == m_rightController->getDeviceID() )
{
m_rightController->setTriggered( false );
}
}
break;
default:
break;
bool pressed = vrEvent.eventType == vr::VREvent_ButtonPress ? true : false;
if( !pressed && vrEvent.eventType != vr::VREvent_ButtonUnpress )
{
return; // neither press nor unpress
}
switch( vrEvent.data.controller.button )
{
case vr::EVRButtonId::k_EButton_SteamVR_Trigger:
controller->setTriggered( pressed );
break;
case vr::EVRButtonId::k_EButton_Grip:
controller->setGripped( pressed );
break;
}
}
......@@ -355,6 +344,11 @@ void WMVRCamera::updateControllerPoses()
m_sceneTransform->setMatrix( m_dataRotation * osg::Matrixd::translate( m_dataPosition ) );
}
if( m_leftController->isGripped() && m_rightController->isGripped() )
{
ResetHMDPosition();
}
}
void WMVRCamera::updateHMDPose()
......
......@@ -30,6 +30,7 @@ WVRController::WVRController( int role ):
m_role( role )
{
m_triggered = false;
m_gripped = false;
}
void WVRController::setDeviceID( uint32_t deviceID )
......@@ -42,6 +43,11 @@ void WVRController::setTriggered( bool triggered )
m_triggered = triggered;
}
void WVRController::setGripped( bool gripped )
{
m_gripped = gripped;
}
uint32_t WVRController::getDeviceID()
{
return m_deviceID;
......@@ -77,6 +83,11 @@ bool WVRController::isTriggered()
return m_triggered;
}
bool WVRController::isGripped()
{
return m_gripped;
}
void WVRController::updatePose( vr::IVRSystem* vrSystem, osg::Vec3 cameraPosition )
{
if( vrSystem->GetControllerRoleForTrackedDeviceIndex( m_deviceID ) == m_role )
......
......@@ -62,6 +62,12 @@ public:
*/
void setTriggered( bool triggered );
/**
* Sets the state of the grip button.
* \param gripped Whether the grip button is pressed or not.
*/
void setGripped( bool gripped );
/**
* Gets the device id
* \return int the device id.
......@@ -105,6 +111,13 @@ public:
*/
bool isTriggered();
/**
* Gets the state of the grip button
* \return true The grip button is pressed.
* \return false The grip button is not pressed.
*/
bool isGripped();
/**
* Creates the geometry with a model at the given path.
* \param path The path to the model.
......@@ -131,6 +144,7 @@ private:
osg::Quat m_prevRotation; //!< The rotation of the previous frame.
bool m_triggered; //!< Whether the trigger button is pressed or not.
bool m_gripped; //!< Whether the grip button is pressed or not.
};
#endif // WVRCONTROLLER_H
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