//============================== // OvrSliderComponent::OnTouchRelative eMsgStatus OvrSliderComponent::OnTouchRelative( App * app, VrFrame const & vrFrame, OvrVRMenuMgr & menuMgr, VRMenuObject * self, VRMenuEvent const & event ) { //LOG( "event.FloatValue = ( %.8f, %.8f )", event.FloatValue.x, event.FloatValue.y ); // project on to the normalized slide delta so that the movement on the pad matches the orientation of the slider Vector2f slideDelta( LocalSlideDelta.x, LocalSlideDelta.y ); slideDelta.Normalize(); Vector2f touchXY( event.FloatValue.x, event.FloatValue.y ); float dot = slideDelta.Dot( touchXY ); float const r = dot * SensitivityScale; SliderFrac = Alg::Clamp( SliderFrac - r, 0.0f, 1.0f ); SetCaretPoseFromFrac( menuMgr, self, SliderFrac ); Menu.OnItemEvent( app, RootId, event ); // update the bubble text UpdateText( menuMgr, self, BubbleId ); return MSG_STATUS_CONSUMED; }
//============================== // OvrSliderComponent::OnTouchUp eMsgStatus OvrSliderComponent::OnTouchUp( OvrGuiSys & guiSys, VrFrame const & vrFrame, VRMenuObject * self, VRMenuEvent const & event ) { OVR_UNUSED( guiSys ); OVR_UNUSED( vrFrame ); OVR_UNUSED( self ); OVR_UNUSED( event ); BubbleFadeOutTime = vrapi_GetTimeInSeconds() + 1.5; //LOG( "event.FloatValue = ( %.8f, %.8f )", event.FloatValue.x, event.FloatValue.y ); // project on to the normalized slide delta so that the movement on the pad matches the orientation of the slider Vector2f slideDelta( LocalSlideDelta.x, LocalSlideDelta.y ); slideDelta.Normalize(); Vector2f touchXY( event.FloatValue.x, event.FloatValue.y ); float dot = slideDelta.Dot( touchXY ); if ( fabsf( dot ) < 0.7071f ) { // if we're more than 45 degrees off axis, don't move at all dot = 0.0f; } else { // move as if we were perfectly aligned with the slider direction if ( dot < 0.0f ) { dot = -1.0f; } else { dot = 1.0f; } } LastDot = dot; if ( LastDot != 0.0f ) { float range = MaxValue - MinValue; float cur = floor( SliderFrac * range ) + MinValue; if ( LastDot < 0.0f ) { SliderFrac = ( cur + 1.0f ) * ( 1.0f / range ); } else { SliderFrac = ( cur - 1.0f ) * ( 1.0f / range ); } SliderFrac = Alg::Clamp( SliderFrac, 0.0f, 1.0f ); SetCaretPoseFromFrac( guiSys.GetVRMenuMgr(), self, SliderFrac ); Menu.OnItemEvent( guiSys, RootId, event ); // update the bubble text UpdateText( guiSys.GetVRMenuMgr(), self, BubbleId ); } LastDot = 0.0f; return MSG_STATUS_CONSUMED; }