// doc in parent
bool FirstPersonManipulator::handleMouseWheel( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();

    // handle centering
    if( _flags & SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT )
    {

        if( ((sm == GUIEventAdapter::SCROLL_DOWN) && (_wheelMovement > 0.)) ||
            ((sm == GUIEventAdapter::SCROLL_UP)   && (_wheelMovement < 0.)) )
        {

            // stop thrown animation
            _thrown = false;

            if( getAnimationTime() <= 0. )

                // center by mouse intersection (no animation)
                setCenterByMousePointerIntersection( ea, us );

            else {

                // start new animation only if there is no animation in progress
                if( !isAnimating() )
                    startAnimationByMousePointerIntersection( ea, us );

            }
        }
    }

    switch( sm )
    {

        // mouse scroll up event
        case GUIEventAdapter::SCROLL_UP:
        {
            // move forward
            moveForward( isAnimating() ? dynamic_cast< FirstPersonAnimationData* >( _animationData.get() )->_targetRot : _rotation,
                         -_wheelMovement * (getRelativeFlag( _wheelMovementFlagIndex ) ? _modelSize : 1. ));
            us.requestRedraw();
            us.requestContinuousUpdate( isAnimating() || _thrown );
            return true;
        }

        // mouse scroll down event
        case GUIEventAdapter::SCROLL_DOWN:
        {
            // move backward
            moveForward( _wheelMovement * (getRelativeFlag( _wheelMovementFlagIndex ) ? _modelSize : 1. ));
            _thrown = false;
            us.requestRedraw();
            us.requestContinuousUpdate( isAnimating() || _thrown );
            return true;
        }

        // unhandled mouse scrolling motion
        default:
            return false;
    }
}
Пример #2
0
/// Handles GUIEventAdapter::RELEASE event.
bool StandardManipulator::handleMouseRelease( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    if( ea.getButtonMask() == 0 )
    {

        double timeSinceLastRecordEvent = _ga_t0.valid() ? (ea.getTime() - _ga_t0->getTime()) : DBL_MAX;
        if( timeSinceLastRecordEvent > 0.02 )
            flushMouseEventStack();

        if( isMouseMoving() )
        {

            if( performMovement() && _allowThrow )
            {
                us.requestRedraw();
                us.requestContinuousUpdate( true );
                _thrown = true;
            }

            return true;
        }
    }

    flushMouseEventStack();
    addMouseEvent( ea );
    if( performMovement() )
        us.requestRedraw();
    us.requestContinuousUpdate( false );
    _thrown = false;

    return true;
}
Пример #3
0
// doc in parent
bool OrbitManipulator::handleMouseWheel( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();

    // handle centering
    if( _flags & SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT )
    {

        if( ((sm == GUIEventAdapter::SCROLL_DOWN && _wheelZoomFactor > 0.)) ||
            ((sm == GUIEventAdapter::SCROLL_UP   && _wheelZoomFactor < 0.)) )
        {

            if( getAnimationTime() <= 0. )
            {
                // center by mouse intersection (no animation)
                setCenterByMousePointerIntersection( ea, us, _wheelZoomFactor );
            }
            else
            {
                // start new animation only if there is no animation in progress
                if( !isAnimating() )
                    startAnimationByMousePointerIntersection( ea, us );

            }

        }
    }

    switch( sm )
    {
        // mouse scroll up event
        case GUIEventAdapter::SCROLL_UP:
        {
            // perform zoom
            zoomModel( _wheelZoomFactor, true );
            us.requestRedraw();
            us.requestContinuousUpdate( isAnimating() || _thrown );
            return true;
        }

        // mouse scroll down event
        case GUIEventAdapter::SCROLL_DOWN:
        {
            // perform zoom
            zoomModel( -_wheelZoomFactor, true );
            us.requestRedraw();
            us.requestContinuousUpdate( /*isAnimating() || _thrown*/ false );
            return true;
        }

        // unhandled mouse scrolling motion
        default:
            return false;
   }
}
Пример #4
0
bool StateSetManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& aa)
{
    if(!_stateset.valid()) return false;

    if (!_initialized)
    {
        _initialized = true;
        _backface = (_stateset->getMode(GL_CULL_FACE)&osg::StateAttribute::ON);
        _lighting =(_stateset->getMode(GL_LIGHTING)&osg::StateAttribute::ON);

        unsigned int mode = osg::StateAttribute::INHERIT|osg::StateAttribute::ON;

        _texture = (_stateset->getTextureMode(0,GL_TEXTURE_2D)&mode)!=0 ||
                   (_stateset->getTextureMode(0,GL_TEXTURE_3D)&mode)!=0 ||
                   (_stateset->getTextureMode(0,GL_TEXTURE_RECTANGLE)&mode)!=0 ||
                   (_stateset->getTextureMode(0,GL_TEXTURE_CUBE_MAP)&mode)!=0;

        #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE)
            _texture |= ((_stateset->getTextureMode(0,GL_TEXTURE_1D)&mode)!=0);
        #endif
    }

    if (ea.getHandled()) return false;

    if (ea.getEventType()==osgGA::GUIEventAdapter::KEYDOWN)
    {

        if ( ea.getKey() == _keyEventToggleBackfaceCulling )
        {
            setBackfaceEnabled(!getBackfaceEnabled());
            aa.requestRedraw();
            return true;
        }
        if ( ea.getKey() == _keyEventToggleLighting )
        {
                setLightingEnabled(!getLightingEnabled());
                aa.requestRedraw();
                return true;
        }
        if ( ea.getKey() == _keyEventToggleTexturing )
        {
                setTextureEnabled(!getTextureEnabled());
                aa.requestRedraw();
                return true;
        }
        if ( ea.getKey() == _keyEventCyclePolygonMode )
        {
                cyclePolygonMode();
                aa.requestRedraw();
                return true;
        }
    }

    return false;
}
Пример #5
0
/// Handles GUIEventAdapter::RESIZE event.
bool StandardManipulator::handleResize( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    init( ea, us );
    us.requestRedraw();

    return true;
}
Пример #6
0
void TerrainManipulator::home(const GUIEventAdapter& ,GUIActionAdapter& us)
{
    if (getAutoComputeHomePosition()) computeHomePosition();

    computePosition(_homeEye, _homeCenter, _homeUp);
    us.requestRedraw();
}
Пример #7
0
// doc in parent
bool FlightManipulator::handleFrame( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    addMouseEvent( ea );
    if( performMovement() )
        us.requestRedraw();

    return false;
}
Пример #8
0
/// General flight-style event handler
bool FlightManipulator::flightHandleEvent( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    addMouseEvent( ea );
    us.requestContinuousUpdate( true );
    if( performMovement() )
        us.requestRedraw();

    return true;
}
Пример #9
0
bool Vwr::CameraManipulator::handle(const GUIEventAdapter& ea, GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
        case(GUIEventAdapter::FRAME):
        {
			return handleFrame(ea, us);
        }
        default:
            break;
    }

    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(GUIEventAdapter::PUSH):
        {
			return handlePush(ea, us);
        }
        case(GUIEventAdapter::RELEASE):
        {
            return handleRelease(ea, us);
        }
        case(GUIEventAdapter::DRAG):
        case(GUIEventAdapter::SCROLL):
        {
			return handleScroll(ea, us);
        }
        case(GUIEventAdapter::MOVE):
        {
            return false;
        }
		case(GUIEventAdapter::KEYDOWN):
		{
			return handleKeyDown(ea, us);
		}
		case(GUIEventAdapter::KEYUP):
		{
			return handleKeyUp( ea, us );
		}
        case(GUIEventAdapter::FRAME):
		{
            if (_thrown)
            {
                if (calcMovement()) us.requestRedraw();
            }

            return false;
		}
        default:
            return false;
    }
}
Пример #10
0
void PanoManipulator::halt(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
if(_node.get())
    {
	_velocity = 0.0f;
    us.requestRedraw();
	// warp pointer no longer needed
    //us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
    flushMouseEventStack();
    } // if

} // PanoManipulator::halt
Пример #11
0
/// Handles GUIEventAdapter::DRAG event.
bool StandardManipulator::handleMouseDrag( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    addMouseEvent( ea );

    if( performMovement() )
        us.requestRedraw();

    us.requestContinuousUpdate( false );
    _thrown = false;

    return true;
}
Пример #12
0
// Home : compute home and warp mouse cursor to screen center.
void ViroManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us){
	if (getAutoComputeHomePosition()) computeHomePosition();

	computePosition(_homeEye, _homeCenter, _homeUp);
	_holdTarget = _homeCenter;

	_speed = 0.0;

	us.requestRedraw();

	//us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);
	flushMouseEventStack();
}
Пример #13
0
bool SelectionManipulator::handleMouseDrag( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
	m_curView = (osgViewer::View*)us.asView();
	addMouseEvent( ea );

	if( performMovement() )
		us.requestRedraw();

	us.requestContinuousUpdate( false );
	_thrown = false;

	return true;
}
Пример #14
0
/** Move the camera to the default position.

    If autoComputeHomePosition is on, home position is computed.
    The computation considers camera fov and model size and
    positions camera far enough to fit the model to the screen.

    StandardManipulator implementation only updates its internal data.
    If home position is expected to be supported by the descendant manipulator,
    it has to reimplement the method to update manipulator transformation.*/
void StandardManipulator::home( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    if( getAutoComputeHomePosition() )
    {
        const Camera *camera = us.asView() ? us.asView()->getCamera() : NULL;
        computeHomePosition( camera, ( _flags & COMPUTE_HOME_USING_BBOX ) != 0 );
    }

    _thrown = false;
    setTransformation( _homeEye, _homeCenter, _homeUp );

    us.requestRedraw();
    us.requestContinuousUpdate( false );
    flushMouseEventStack();
}
Пример #15
0
void DriveManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    if (getAutoComputeHomePosition()) computeHomePosition();

    computePosition(_homeEye, _homeCenter, _homeUp);
    
    _velocity = 0.0;
    
    _pitch = 0.0;

    us.requestRedraw();
    us.requestContinuousUpdate(false);

    us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);

    flushMouseEventStack();
}
Пример #16
0
/// Makes the manipulator progress in its current animation.
bool StandardManipulator::performAnimationMovement( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    double f = (ea.getTime() - _animationData->_startTime) / _animationData->_animationTime;
    if( f >= 1. )
    {
        f = 1.;
        _animationData->_isAnimating = false;
        if( !_thrown )
            us.requestContinuousUpdate( false );
    }

    applyAnimationStep( f, _animationData->_phase );

    _animationData->_phase = f;
    us.requestRedraw();

    return _animationData->_isAnimating;
}
Пример #17
0
/// Handles GUIEventAdapter::FRAME event.
bool StandardManipulator::handleFrame( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
    double current_frame_time = ea.getTime();

    _delta_frame_time = current_frame_time - _last_frame_time;
    _last_frame_time = current_frame_time;

    if( _thrown && performMovement() )
    {
        us.requestRedraw();
    }

    if( _animationData && _animationData->_isAnimating )
    {
        performAnimationMovement( ea, us );
    }

   return false;
}
Пример #18
0
void GliderManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    if(_node.get())
    {

        const osg::BoundingSphere& boundingSphere=_node->getBound();

        osg::Vec3 eye = boundingSphere._center+osg::Vec3(-boundingSphere._radius*0.25f,-boundingSphere._radius*0.25f,-boundingSphere._radius*0.03f);

        computePosition(eye,
            osg::Vec3(1.0f,1.0f,-0.1f),
            osg::Vec3(0.0f,0.0f,1.0f));

        _velocity = boundingSphere._radius*0.01f;

        us.requestRedraw();

        us.requestWarpPointer((ea.getXmin()+ea.getXmax())/2.0f,(ea.getYmin()+ea.getYmax())/2.0f);

        flushMouseEventStack();

    }

}
void SceneGraphManipulator::home(const GUIEventAdapter& ea ,GUIActionAdapter& us)
{
    home(ea.getTime());
    us.requestRedraw();
}
bool SceneGraphManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    if (ea.getHandled()) return false;

    BaseViewer *v = dynamic_cast<BaseViewer*>(&us);
    if (!v)
        return false;
    else if (!_init) {_sceneGraph = dynamic_cast<SceneGraph*>(getUserData()); _init=true;}

    Viewer2D3D *v2d3d = dynamic_cast<Viewer2D3D*>(v->getGraphicsViewer());
    if (!v2d3d)
        return false;

    if(_sceneGraph.valid() && _sceneGraph->getScene())
        setInteractionMode(v2d3d->getProjectionType(), (_sceneGraph->getScene()->getBound()).center(), v2d3d->getZoom());

    switch(ea.getEventType())
    {
    case(GUIEventAdapter::PUSH):
        flushMouseEventStack();
        addMouseEvent(ea);
        if (calcMovement()) us.requestRedraw();
        us.requestContinuousUpdate(false);
        _thrown = false;
        return true;

    case(GUIEventAdapter::RELEASE):
        if (ea.getButtonMask()==0)
            if (isMouseMoving())
            {
                if (calcMovement())
                {
                    us.requestRedraw();
                    us.requestContinuousUpdate(false);
                    _thrown = false;
                }
            }
            else
            {
                flushMouseEventStack();
                addMouseEvent(ea);
                if (calcMovement()) us.requestRedraw();
                us.requestContinuousUpdate(false);
                _thrown = false;
            }
        else
        {
            flushMouseEventStack();
            addMouseEvent(ea);
            if (calcMovement()) us.requestRedraw();
            us.requestContinuousUpdate(false);
            _thrown = false;
        }
        return true;

    case(GUIEventAdapter::DRAG):
        addMouseEvent(ea);
        if (calcMovement()) us.requestRedraw();
        us.requestContinuousUpdate(false);
        _thrown = false;
        return true;

    case(GUIEventAdapter::MOVE):
        return false;

    case(GUIEventAdapter::KEYDOWN):
        if (ea.getKey()== _resetCameraKey) // reset camera
        {
            flushMouseEventStack();
            _thrown = false;
            home(ea,us);
            us.requestRedraw();
            us.requestContinuousUpdate(false);
            return true;
        }
        else if(ea.getKey() >= 0xFFE1 && ea.getKey() <= 0xFFEE)
        { // modifier keys
            _currentModifier = ea.getKey();
            return true;
        }
        return false;
    case(GUIEventAdapter::KEYUP):
    {
        if(ea.getKey() == _currentModifier)
        {
            _currentModifier = 0;
            return true;
        }
        return false;
    }
    case(GUIEventAdapter::FRAME):
        if (_thrown && calcMovement()) us.requestRedraw();
        return false;
    default:
        return false;
    }
}
Пример #21
0
bool PanoManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{

if(StartMoment == 0.0) // only do this once at actual startup of drawing
	{
	ClearStartMoment();
	} // if

unsigned int buttonMask = ea.getButtonMask();

switch(ea.getEventType())
    {
    case(GUIEventAdapter::PUSH):
        {
		GlobalTipSupport->HideBalloonTip();
		if(GetGlobalViewer())
			{
			SetCapture(GetGlobalViewerHWND());
			} // if
		if((buttonMask & GUIEventAdapter::LEFT_MOUSE_BUTTON) && (Navigation::GetCurrentNavMode() == Navigation::NAV_NM_QUERY))
			{
			PossibleQueryInitiating = true;
			} // if
		else
			{
			if(buttonMask & GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
				{ // determine and record orbit point
				osg::Vec3 NewOrbitCenter;
				if(GetFirstTangibleHitLocation(ea.getX(), ea.getY(), NewOrbitCenter))
					{
					SetOrbitCenter(NewOrbitCenter);
					} // if
				else
					{
					ClearOrbitCenter();
					} // else
				} // if
			PossibleQueryInitiating = false;
			addMouseEvent(ea);
			us.requestContinuousUpdate(true);
			if(GetDelayedGoto())
				{
				Goto(ea.getX(), ea.getY());
				} // if
			else
				{
				if (calcMovement(ea, us)) us.requestRedraw();
				} // else
			} // if
        return true;
        } // PUSH
    case(GUIEventAdapter::RELEASE):
        {
        if(buttonMask & GUIEventAdapter::MIDDLE_MOUSE_BUTTON)
			{
			ClearOrbitCenter();
			} // if
		if(GetGlobalViewer())
			{
			if(GetCapture() == GetGlobalViewerHWND())
				{
				ReleaseCapture();
				} // if
			} // if
        addMouseEvent(ea);
        us.requestContinuousUpdate(true);
        if(Navigation::GetCurrentNavMode() == Navigation::NAV_NM_QUERY)
			{
#ifdef NVW_SUPPORT_QUERYACTION
			// Query/Action fires on mouseUP, to no weird state is interfering with newly-opened windows
			if(PossibleQueryInitiating) PerformQueryAction(ea.getX(), ea.getY(), false);
#endif // NVW_SUPPORT_QUERYACTION
			} // if
		else
			{
			PossibleQueryInitiating = false;
	        if (calcMovement(ea, us)) us.requestRedraw();
	        } // else
        return true;
        } // RELEASE
    case(GUIEventAdapter::DRAG):
        {
        addMouseEvent(ea);
        us.requestContinuousUpdate(true);
        if (calcMovement(ea, us)) us.requestRedraw();
        return true;
        } // DRAG
    case(GUIEventAdapter::MOVE):
        {
        MarkLastMouseMoveMoment();
        addMouseEvent(ea);
        us.requestContinuousUpdate(true);
        if (calcMovement(ea, us)) us.requestRedraw();

        return true;
        } // MOVE
    case(GUIEventAdapter::KEYDOWN):
		{
        if (ea.getKey()==' ')
            {
			GlobalTipSupport->HideBalloonTip();
            EventDispatcher::DispatchEvent(EventDispatcher::NVW_EC_NAVIGATION, EventDispatcher::NVW_ESC_NAVIGATION_THROTTLE, EventDispatcher::NVW_PC_ZERO);
			flushMouseEventStack();
            home(ea,us);
            us.requestRedraw();
            us.requestContinuousUpdate(false);
            return true;
            } // if
        if (ea.getKey()=='.')
            {
			GlobalTipSupport->HideBalloonTip();
			EventDispatcher::DispatchEvent(EventDispatcher::NVW_EC_NAVIGATION, EventDispatcher::NVW_ESC_NAVIGATION_THROTTLE, EventDispatcher::NVW_PC_ZERO);
            flushMouseEventStack();
            halt(ea,us);
            us.requestRedraw();
            us.requestContinuousUpdate(false);
            return true;
            } // if
        return false;
		} // KEYDOWN
    case(GUIEventAdapter::FRAME):
		{
		if(!GetMouseInactiveOneShot() && GetMouseInactiveTime() > NVW_PANOMANIPULATOR_MOUSE_INACTIVE_TIME_SECONDS && (GetSystemTimeFP() - GetLastMovementMoment()) > NVW_PANOMANIPULATOR_MOUSE_INACTIVE_TIME_SECONDS)
			{
			SetMouseInactiveOneShot(true); // make it only fire once
			EventDispatcher::DispatchEvent(EventDispatcher::NVW_EC_ACTION, EventDispatcher::NVW_ESC_ACTION_QUERYHERE, EventDispatcher::NVW_PC_LESS);
			} // if
		GlobalTipSupport->HandleBalloonTipTimeout();
        addMouseEvent(ea);
		if(GetTourInProgress())
			{
			GlobalTipSupport->HideBalloonTip();
			InternalTour();
			// we don't redraw, as the animation part of the tour is handled by Transition code, below
			} // if
		if(GetTransitionInProgress())
			{
			GlobalTipSupport->HideBalloonTip();
			InternalTrans();
			us.requestRedraw();
			} // if
		else if(GetAnimationInProgress())
			{
			GlobalTipSupport->HideBalloonTip();
			InternalAnim();
			us.requestRedraw();
			} // if
		else
			{
			// handle HotNav disk
			if(MasterScene.GetHotNavFwdBackAmount() != 0.0 || MasterScene.GetHotNavSideAmount() != 0.0 )
				{
				GlobalTipSupport->HideBalloonTip();
				ExecuteMovement(MasterScene.GetHotNavSideAmount(), MasterScene.GetHotNavFwdBackAmount(), 0.0);
				us.requestRedraw();
				} // if
			// handle HotTurn disk
			if(MasterScene.GetHotTurnHAmount() != 0.0 || MasterScene.GetHotTurnVAmount() != 0.0 )
				{
				// hot turn is too hot without the constant scaling factor
				GlobalTipSupport->HideBalloonTip();
				ExecuteRotate(MasterScene.GetHotTurnHAmount() * .01, 0.0, MasterScene.GetHotTurnVAmount() * .01); 
				us.requestRedraw();
				} // if
	        if (calcMovement(ea, us)) us.requestRedraw();
			} // else
        return true;
		} // FRAME
    case(GUIEventAdapter::RESIZE):
		{
		GlobalTipSupport->HideBalloonTip();
        init(ea,us);
        us.requestRedraw();
        return true;
		} // RESIZE
    default:
        return false;
    } // switch
} // PanoManipulator::handle
Пример #22
0
//Event Listener
bool ViroManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us){
	_lastFrameTime = ea.getTime();
	switch( ea.getEventType() ){
		case(GUIEventAdapter::FRAME):{
			addMouseEvent(ea);

			// Main auto-management engine
			if (RollWithYaw >0.0 || isEnabled(COLLISIONS)) AutoControl( ea.time() );
			
			// Check if Trace is needed
			if ( _bNeedUpdateTrace ) Trace();
			
			// Handle Fly-To if any
			if (_bFlying) handleFlyToTransition( ea.time() );

			if ( MouseListener() ) us.requestRedraw();
			us.requestContinuousUpdate(true);
			return false;
			}
		case(GUIEventAdapter::RESIZE):{
			init(ea,us);
			us.requestRedraw();
			return true;
			}
		case(GUIEventAdapter::MOVE):{
			addMouseEvent(ea);

			if ( MouseListener() ) us.requestRedraw();
			us.requestContinuousUpdate(true);
			return true;
			}
		case(GUIEventAdapter::SCROLL):{
			//addMouseEvent(ea);
			//osg::notify(ALWAYS) << "Scroll\n";
			switch (ea.getScrollingMotion()){
				case(GUIEventAdapter::SCROLL_UP):{
					addMouseEvent(ea);
					osg::notify(ALWAYS) << "Scroll-up\n";

					if ( MouseListener() ) us.requestRedraw();
					us.requestContinuousUpdate(true);
					return true;
					}
				case(GUIEventAdapter::SCROLL_DOWN):{
					addMouseEvent(ea);
					osg::notify(ALWAYS) << "Scroll-down\n";

					if ( MouseListener() ) us.requestRedraw();
					us.requestContinuousUpdate(true);
					return true;
					}
				}

			//if ( MouseListener() ) us.requestRedraw();
			//us.requestContinuousUpdate(true);
			//return true;
			}

/* OLD IMPLEMENTATION for OSG 1.0
		case(GUIEventAdapter::SCROLL_UP):{
			addMouseEvent(ea);
			osg::notify(ALWAYS) << "Scroll-up\n";

			if ( MouseListener() ) us.requestRedraw();
			us.requestContinuousUpdate(true);
			return true;
			}
		case(GUIEventAdapter::SCROLL_DOWN):{
			addMouseEvent(ea);
			osg::notify(ALWAYS) << "Scroll-down\n";

			if ( MouseListener() ) us.requestRedraw();
			us.requestContinuousUpdate(true);
			return true;
			}
*/
		// double click
/*
		case(GUIEventAdapter::DOUBLECLICK):{
			osg::notify(DEBUG_INFO)<<"Double Left click.\n";
			_bSatMode = false;
			if (handlePick(_ev0->getXnormalized(),_ev0->getYnormalized())&&!_bFlying) FlyTo(ea.time());
			}
*/
		// Mouse Button Push
		case(GUIEventAdapter::PUSH):{
			//addMouseEvent(ea);
			
			// Mid Button
			if (ea.getButtonMask() == GUIEventAdapter::MIDDLE_MOUSE_BUTTON){	
				//osg::notify(DEBUG_INFO)<<"Mid-Mouse pressed.\n";
				//_bSatMode = false;
				_bMidButton = true;

				// During a Fly-To, stop flying...
				if (_bFlying){
					_speed     = 0.0;
					_bFlying   = false;
					Disable(PERIPHERAL_LOCK);
					}

				else {
					float a = 0.4;
					if (_bHoldCTRL) a = 0.0;

					if (!_Viewer && handlePick(_ev0->getX() ,_ev0->getY(),a) &&!_bFlying) FlyTo(ea.time());
					else if (handlePick(_ev0->getXnormalized(),_ev0->getYnormalized(),a) &&!_bFlying) FlyTo(ea.time());
					}
				}
			
			// Left Button
			else if (ea.getButtonMask() == GUIEventAdapter::LEFT_MOUSE_BUTTON){
				
				// Double-Click
				/*
				if ((ea.time() -_tLastLMB) < 0.4){
					osg::notify(DEBUG_INFO)<<"Double Left click.\n";
					_bSatMode = false;
					//if (handlePick(_ev0->getXnormalized(),_ev0->getYnormalized())&&!_bFlying) FlyTo(ea.time());
					//if (handlePick(_ev0->getX(),_ev0->getY())&&!_bFlying) FlyTo(ea.time());
					if (!_Viewer && handlePick(_ev0->getX() ,_ev0->getY())&&!_bFlying) FlyTo(ea.time());
					else if (handlePick(_ev0->getXnormalized(),_ev0->getYnormalized())&&!_bFlying) FlyTo(ea.time());
					}
				*/
				// Single Click
				/* else */ {
					osg::notify(DEBUG_INFO)<<"Left Button pressed.\n";
					// During a Fly-To, stop flying...
					if (_bFlying){
						_bFlying   = false;
						//Disable(PERIPHERAL_LOCK);
						}

					_speed = 0.0;
					_UserControlPercentage = 1.0;
					}
				_tLastLMB = ea.time();	// Update time last LMB.
				}

			// Right Button
			else if (ea.getButtonMask() == GUIEventAdapter::RIGHT_MOUSE_BUTTON){
				Disable(PERIPHERAL_LOCK);
				/*
				if (_bHoldCTRL){
					if (!_bFlying && handlePick(_ev0->getXnormalized(),_ev0->getYnormalized())) _vLastPickedPoint = _vStoredEye[TO]; 
					}
				*/
				}

			if ( MouseListener() ) us.requestRedraw();
			//us.requestContinuousUpdate(true);
			return true;
			}

		case(GUIEventAdapter::RELEASE):{
			Enable(PERIPHERAL_LOCK);

			
			if (ea.getButtonMask() == GUIEventAdapter::MIDDLE_MOUSE_BUTTON){
				_bMidButton = false;
				}

			//handleRelease( ea );
			us.requestContinuousUpdate(false);
			return true;
			}

		// Keyboard
		case(GUIEventAdapter::KEYDOWN):{
			//osg::notify(DEBUG_INFO) << "A key has been pressed...\n";

			if (ea.getKey()==GUIEventAdapter::KEY_Control_L){
				_bHoldCTRL = true;

				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()==' '){
				flushMouseEventStack();
				//home(ea,us);
				
				requestFlyToHome();
				FlyTo( ea.getTime() );

				us.requestRedraw();
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== 'v'){
				flushMouseEventStack();

				//_vStoredEye[ViroManipulator::TO]      = _vEye;	OLD
				//_qStoredRotation[ViroManipulator::TO] = _qRotation;		OLD
				storeView();

				osg::notify(ALWAYS) << "Position stored. Press 'c' when you want to recall it.\n";
				us.requestContinuousUpdate(false);
				return true;
				}
			/*
			if (ea.getKey()== 'c'){
				flushMouseEventStack();
				osg::notify(ALWAYS) << "Recalled stored position.\n";
				
				//FlyTo( ea.time() ); OLD
				reloadView();

				us.requestRedraw();
				us.requestContinuousUpdate(false);
				return true;
				}
			*/
			if (ea.getKey()== 'S'){
				flushMouseEventStack();
				Invert(SPIDERMAN_PICKING);
				if (isEnabled(SPIDERMAN_PICKING)) osg::notify(ALWAYS) << "SpiderMan Mode ON.\n";
				else osg::notify(ALWAYS) << "SpiderMan Mode OFF.\n";
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== GUIEventAdapter::KEY_Up){
				_padEvent = NAVPAD_FORWARD;
				us.requestContinuousUpdate(false);
				}
			if (ea.getKey()== GUIEventAdapter::KEY_Down){
				_padEvent = NAVPAD_BACKWARD;
				us.requestContinuousUpdate(false);
				}
			if (ea.getKey()== GUIEventAdapter::KEY_Page_Up){
				_padEvent = NAVPAD_UP;
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== GUIEventAdapter::KEY_Left){
				_padEvent = NAVPAD_STRAFELEFT;
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== GUIEventAdapter::KEY_Right){
				_padEvent = NAVPAD_STRAFERIGHT;
				us.requestContinuousUpdate(false);
				return true;
			}
			if (ea.getKey()== GUIEventAdapter::KEY_Page_Down){
				_padEvent = NAVPAD_DOWN;
				us.requestContinuousUpdate(false);
				return true;
			}
			if (ea.getKey()== 'f'){
				
				// TODO : Switch Fullscreen ON/OFF
				
				return true;
				}
			if (ea.getKey()== 'l' || ea.getKey()== 'L'){
				/*
				_HeadLight->getLight()->setLightNum(3);
				_HeadLight->getLight()->setDiffuse( Vec4(1,1,1, 0) );
				_HeadLight->getLight()->setDirection( _vLook );
				_HeadLight->getLight()->setPosition( Vec4(_vEye.x(),_vEye.y(),_vEye.z(), 0) );
				*/
				//_bLockZ = !_bLockZ;
				Invert(Z_LOCK);

				if ( isEnabled(Z_LOCK) ){
					_zLock = _vEye.z();
					/*
					SyncData();
					osg::Vec3d D = _vLook;
					D.normalize();
					_vLockDir = D;
					*/
					}

				us.requestContinuousUpdate(false);
				return true;
				}
				
			if (ea.getKey()== 'c' || ea.getKey()== 'C'){
				flushMouseEventStack();
				Invert(COLLISIONS);
				//if (isEnabled(COLLISIONS)) osg::notify(ALWAYS) << "Model Collision ON.\n";
				//else osg::notify(ALWAYS) << "Model Collision OFF.\n";
				us.requestContinuousUpdate(false);
				return true;
				}
			/*
			if (ea.getKey()== 'i'){
				flushMouseEventStack();
				_Viewer->getCamera()->setProjectionMatrixAsPerspective(30.0,3, 0.01,50);
				us.requestContinuousUpdate(false);
				return true;
				}
			*/
			if (ea.getKey()== 'g' || ea.getKey()== 'w'){
				flushMouseEventStack();
				Invert(GRAVITY);
				//if (isEnabled(GRAVITY)) osg::notify(ALWAYS) << "Gravity ON.\n";
				//else osg::notify(ALWAYS) << "Gravity OFF.\n";
				us.requestContinuousUpdate(false);
				return true;
				}
				
			// Keyboard navigation
			if (ea.getKey()== 'a'){
				/*
				//flushMouseEventStack();
				Enable(PERIPHERAL_LOCK);
				double d = 50.;
				turn( d*getDtime(), 0.0);
				SyncData();
				*/
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== 'd'){
				/*
				//flushMouseEventStack();
				Enable(PERIPHERAL_LOCK);
				double d = 50.;
				turn(-d* getDtime(), 0.0);
				SyncData();
				*/
				us.requestContinuousUpdate(false);
				return true;
			}
			if (0&& ea.getKey()== 'w'){
				/*
				//flushMouseEventStack();
				Enable(PERIPHERAL_LOCK);
				_speed += Acceleration * getDtime();
				boost();
				SyncData();
				*/
				us.requestContinuousUpdate(false);
				return true;
			}
			if (ea.getKey()== 's'){
				/*
				//flushMouseEventStack();
				Enable(PERIPHERAL_LOCK);
				_speed = 0.0;
				*/
				us.requestContinuousUpdate(false);
				return true;
			}
			if (ea.getKey()== 'x'){
				/*
				//flushMouseEventStack();
				Enable(PERIPHERAL_LOCK);
				_speed -= Acceleration * getDtime();
				boost();
				SyncData();
				*/
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== '+'){
				double l,r,b,t,z,Z;
				_Viewer->getCamera()->getProjectionMatrixAsFrustum(l,r,b,t,z,Z);
				l *= 0.9;
				r *= 0.9;
				b *= 0.9;
				t *= 0.9;
				_Viewer->getCamera()->setProjectionMatrixAsFrustum(l,r,b,t,z,Z);
				us.requestContinuousUpdate(false);
				return true;
				}
			if (ea.getKey()== '-'){
				double l,r,b,t,z,Z;
				_Viewer->getCamera()->getProjectionMatrixAsFrustum(l,r,b,t,z,Z);
				l *= 1.1;
				r *= 1.1;
				b *= 1.1;
				t *= 1.1;
				_Viewer->getCamera()->setProjectionMatrixAsFrustum(l,r,b,t,z,Z);
				us.requestContinuousUpdate(false);
				return true;
				}

			return true;
			}
		case(GUIEventAdapter::KEYUP):{
			_padEvent = NAVPAD_NONE;

			if (ea.getKey()==GUIEventAdapter::KEY_Control_L){
				_bHoldCTRL = false;

				us.requestContinuousUpdate(false);
				return true;
				}

			return true;
			}
		
		default: return false;
		}
//	return false;
}
Пример #23
0
bool GliderManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
#if 0   
        case(GUIEventAdapter::PUSH):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::RELEASE):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            // if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::DRAG):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            // if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::MOVE):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            // if (calcMovement()) us.requestRedraw();

            return true;
        }
#endif
        case(GUIEventAdapter::KEYDOWN):
            if (ea.getKey()==' ')
            {
                flushMouseEventStack();
                home(ea,us);
                us.requestRedraw();
                us.requestContinuousUpdate(false);
                return true;
            }
            else if (ea.getKey()=='q')
            {
                _yawMode = YAW_AUTOMATICALLY_WHEN_BANKED;
                return true;
            }
            else if (ea.getKey()=='a')
            {
                _yawMode = NO_AUTOMATIC_YAW;
                return true;
            }
            return false;

        case(GUIEventAdapter::FRAME):
            addMouseEvent(ea);
            if (calcMovement()) us.requestRedraw();
            return true;

        case(GUIEventAdapter::RESIZE):
            init(ea,us);
            us.requestRedraw();
            return true;

        default:
            return false;
    }
}
// --------------------------------------------------------------------------------------------------
void SphericalManipulator::home(const GUIEventAdapter &ea, GUIActionAdapter &us)
{
    home(ea.getTime());
    us.requestRedraw();
    us.requestContinuousUpdate(false);
}
Пример #25
0
bool DriveManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{
    switch(ea.getEventType())
    {
        case(GUIEventAdapter::FRAME):
            addMouseEvent(ea);
            if (calcMovement()) us.requestRedraw();
            return false;

        case(GUIEventAdapter::RESIZE):
            init(ea,us);
            us.requestRedraw();
            return true;
        default:
            break;
    }

    if (ea.getHandled()) return false;

    switch(ea.getEventType())
    {
        case(GUIEventAdapter::PUSH):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::RELEASE):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::DRAG):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::MOVE):
        {

            addMouseEvent(ea);
            us.requestContinuousUpdate(true);
            if (calcMovement()) us.requestRedraw();
            return true;
        }

        case(GUIEventAdapter::KEYDOWN):
        {
            if (ea.getKey()==GUIEventAdapter::KEY_Space)
            {
                flushMouseEventStack();
                home(ea,us);
                return true;
            }
            else if (ea.getKey()=='q')
            {
                _speedMode = USE_MOUSE_Y_FOR_SPEED;
                return true;
            }
            else if (ea.getKey()=='a')
            {
                _speedMode = USE_MOUSE_BUTTONS_FOR_SPEED;
                return true;
            }
#ifdef KEYBOARD_PITCH
            else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up ||
                     ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up ||
                     ea.getKey()=='9')
            {
                _pitchUpKeyPressed = true;
                return true;
            }
            else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down ||
                     ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Down ||
                     ea.getKey()=='6')
            {
                _pitchDownKeyPressed = true;
                return true;
            }
#endif
            return false;
        }

        case(GUIEventAdapter::KEYUP):
        {
#ifdef KEYBOARD_PITCH
            if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Up ||
                     ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Up ||
                     ea.getKey()=='9')
            {
                _pitchUpKeyPressed = false;
                return true;
            }
            else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Down ||
                     ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Down ||
                     ea.getKey()=='6')
            {
                _pitchDownKeyPressed = false;
                return true;
            }
#endif
            return false;
        }

        default:
            return false;
    }
}
Пример #26
0
bool TerrainManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapter& us)
{

    switch(ea.getEventType())
    {
        case(GUIEventAdapter::FRAME):
            if (_thrown)
            {
                if (calcMovement()) us.requestRedraw();
            }
            return false;
        default:
            break;
    }


    if (ea.getHandled()) return false;


    switch(ea.getEventType())
    {
        case(GUIEventAdapter::PUSH):
        {
            flushMouseEventStack();
            addMouseEvent(ea);
            if (calcMovement()) us.requestRedraw();
            us.requestContinuousUpdate(false);
            _thrown = false;
            return true;
        }

        case(GUIEventAdapter::RELEASE):
        {
            if (ea.getButtonMask()==0)
            {

                if (isMouseMoving())
                {
                    if (calcMovement())
                    {
                        us.requestRedraw();
                        us.requestContinuousUpdate(true);
                        _thrown = true;
                    }
                }
                else
                {
                    flushMouseEventStack();
                    addMouseEvent(ea);
                    if (calcMovement()) us.requestRedraw();
                    us.requestContinuousUpdate(false);
                    _thrown = false;
                }

            }
            else
            {
                flushMouseEventStack();
                addMouseEvent(ea);
                if (calcMovement()) us.requestRedraw();
                us.requestContinuousUpdate(false);
                _thrown = false;
            }
            return true;
        }

        case(GUIEventAdapter::DRAG):
        {
            addMouseEvent(ea);
            if (calcMovement()) us.requestRedraw();
            us.requestContinuousUpdate(false);
            _thrown = false;
            return true;
        }

        case(GUIEventAdapter::MOVE):
        {
            return false;
        }

        case(GUIEventAdapter::KEYDOWN):
            if (ea.getKey()== GUIEventAdapter::KEY_Space)
            {
                flushMouseEventStack();
                _thrown = false;
                home(ea,us);
                us.requestRedraw();
                us.requestContinuousUpdate(false);
                return true;
            }
            return false;
        default:
            return false;
    }
}
// --------------------------------------------------------------------------------------------------
bool SphericalManipulator::handle(const GUIEventAdapter &ea, GUIActionAdapter &us)
{
    switch (ea.getEventType())
    {
    case (GUIEventAdapter::FRAME):
    {
        double current_frame_time = ea.getTime();

        _delta_frame_time = current_frame_time - _last_frame_time;
        _last_frame_time  = current_frame_time;

        if (_thrown)
        {
            if (calcMovement())
                us.requestRedraw();
        }

        return false;
    }

    default:
        break;
    }

    if (ea.getHandled())
        return false;

    switch (ea.getEventType())
    {
    case (GUIEventAdapter::PUSH):
    {
        flushMouseEventStack();
        addMouseEvent(ea);
        us.requestContinuousUpdate(false);
        _thrown = false;
        return true;
    }

    case (GUIEventAdapter::RELEASE):
    {
        if (ea.getButtonMask() == 0)
        {
            double timeSinceLastRecordEvent = _ga_t0.valid() ? (ea.getTime() - _ga_t0->getTime()) : DBL_MAX;
            if (timeSinceLastRecordEvent > 0.02)
                flushMouseEventStack();

            if (isMouseMoving())
            {
                if (calcMovement())
                {
                    us.requestRedraw();
                    us.requestContinuousUpdate(true);
                    _thrown = _allowThrow;
                }
            }
            else
            {
                flushMouseEventStack();
                addMouseEvent(ea);
                if (calcMovement())
                    us.requestRedraw();

                us.requestContinuousUpdate(false);
                _thrown = false;
            }
        }
        else
        {
            flushMouseEventStack();
            addMouseEvent(ea);
            if (calcMovement())
                us.requestRedraw();

            us.requestContinuousUpdate(false);
            _thrown = false;
        }

        return true;
    }

    case (GUIEventAdapter::DRAG):
    case (GUIEventAdapter::SCROLL):
    {
        addMouseEvent(ea);
        if (calcMovement())
            us.requestRedraw();

        us.requestContinuousUpdate(false);
        _thrown = false;
        return true;
    }

    case (GUIEventAdapter::MOVE):
    {
        return false;
    }

    case (GUIEventAdapter::KEYDOWN):
        if (ea.getKey() == GUIEventAdapter::KEY_Space)
        {
            flushMouseEventStack();
            _thrown = false;
            home(ea, us);
            return true;
        }

        return false;

    case (GUIEventAdapter::FRAME):
        if (_thrown)
        {
            if (calcMovement())
                us.requestRedraw();
        }

        return false;

    default:
        return false;
    }

    return false;
}
Пример #28
0
bool SelectionManipulator::handleMouseWheel( const GUIEventAdapter& ea, GUIActionAdapter& us )
{
	osgGA::GUIEventAdapter::ScrollingMotion sm = ea.getScrollingMotion();
	osgViewer::View* curView = (osgViewer::View*)us.asView();

	//float x = ea.getX();
	//float y = ea.getY();

	osg::Camera* masterCam = curView->getCamera();

	double left,right,bottom,top,zNear,zFar;
	masterCam->getProjectionMatrixAsOrtho(left,right,
		bottom,top,zNear,zFar);

	// handle centering
	if( _flags & SET_CENTER_ON_WHEEL_FORWARD_MOVEMENT )
	{

		if( ((sm == GUIEventAdapter::SCROLL_DOWN && _wheelZoomFactor > 0.)) ||
			((sm == GUIEventAdapter::SCROLL_UP   && _wheelZoomFactor < 0.)) )
		{

			if( getAnimationTime() <= 0. )
			{
				// center by mouse intersection (no animation)
				setCenterByMousePointerIntersection( ea, us );
			}
			else
			{
				// start new animation only if there is no animation in progress
				if( !isAnimating() )
					startAnimationByMousePointerIntersection( ea, us );

			}

		}
	}

	switch( sm )
	{
		// mouse scroll up event
	case GUIEventAdapter::SCROLL_UP:
		{
			// perform zoom
			float scale = 1.0f + _wheelZoomFactor;
			masterCam->setProjectionMatrixAsOrtho(left*scale,right*scale,
				bottom*scale,top*scale,zNear,zFar);
			us.requestRedraw();
			us.requestContinuousUpdate( isAnimating() || _thrown );
			return true;
		}

		// mouse scroll down event
	case GUIEventAdapter::SCROLL_DOWN:
		{
			// perform zoom
			float scale = 1.0f - _wheelZoomFactor;
			masterCam->setProjectionMatrixAsOrtho(left*scale,right*scale,
				bottom*scale,top*scale,zNear,zFar);
			us.requestRedraw();
			us.requestContinuousUpdate( false );
			return true;
		}

		// unhandled mouse scrolling motion
	default:
		return false;
	}
}