Show
Ignore:
Timestamp:
11/26/07 22:53:32 (1 year ago)
Author:
vossg
Message:

changed: more flexible navigators, allow user navigator (thanks to M. Spindler for the code)

: add _d when pulling windows dlls

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Source/System/Window/Utilities/OSGFlyEngine.cpp

    r785 r1021  
    33 *                                                                           * 
    44 *                                                                           * 
    5  *             Copyright (C) 2000,2001 by the OpenSG Forum                   * 
     5 *             Copyright (C) 2000-2002 by the OpenSG Forum                   * 
    66 *                                                                           * 
    77 *                            www.opensg.org                                 * 
     
    4242#include "OSGMatrixUtility.h" 
    4343 
    44 #include "OSGFlyNavigator.h" 
     44#include "OSGFlyEngine.h" 
     45 
     46#include "OSGNode.h" 
     47#include "OSGCamera.h" 
     48#include "OSGBackground.h" 
    4549 
    4650OSG_USING_NAMESPACE 
     
    5054\***************************************************************************/ 
    5155 
    52 /*! \class OSG::FlyNavigator 
     56/*! \class OSG::FlyEngine 
    5357    \ingroup GrpSystemWindowNavigators 
    5458 
    55 The FlyNavigator models a simple flying navigation model, see \ref  
     59The FlyEngine models a simple flying navigation model, see \ref  
    5660PageSystemWindowNavigatorsFly for a description. 
    5761 
    5862*/ 
    5963 
    60 /*! \var OSG::FlyNavigator::_rFrom 
     64/*! \var OSG::FlyEngine::_rFrom 
    6165 
    6266    The from point, i.e. the viewer position. 
    6367*/ 
    6468 
    65 /*! \var OSG::FlyNavigator::_rAt 
     69/*! \var OSG::FlyEngine::_rAt 
    6670 
    6771    The at point, i.e. the target position. 
    6872*/ 
    6973 
    70 /*! \var OSG::FlyNavigator::_vUp 
     74/*! \var OSG::FlyEngine::_vUp 
    7175 
    7276    The up vector. 
    7377*/ 
    7478 
    75 /*! \var OSG::FlyNavigator::_tMatrix 
     79/*! \var OSG::FlyEngine::_tMatrix 
    7680 
    7781    The transformation matrix for this navigator. 
    7882*/ 
    7983 
    80  
    8184/*------------------------- constructors ----------------------------------*/ 
    8285 
    83 FlyNavigator::FlyNavigator() 
     86FlyEngine::FlyEngine(void) : Inherited() 
    8487{ 
    8588    _rFrom  .setValues(0,0,0); 
     
    8992} 
    9093 
    91  
    9294/*-------------------------- destructors ----------------------------------*/ 
    9395 
    94 FlyNavigator::~FlyNavigator() 
     96FlyEngine::~FlyEngine() 
    9597{ 
    9698} 
     
    98100/*------------------------------ get --------------------------------------*/ 
    99101 
     102/*! Get the from point. 
     103*/ 
     104const Pnt3f &FlyEngine::getFrom() 
     105{ 
     106    return _rFrom; 
     107} 
     108 
     109/*! Get the at point. 
     110*/ 
     111const Pnt3f &FlyEngine::getAt() 
     112{ 
     113    return _rAt; 
     114} 
     115 
     116/*! Get the up vector. 
     117*/ 
     118const Vec3f &FlyEngine::getUp() 
     119{ 
     120    return _vUp; 
     121} 
     122 
    100123/*! Get the current transformation matrix. 
    101124*/ 
    102 Matrix &FlyNavigator::getMatrix() 
     125const Matrix &FlyEngine::getMatrix() 
    103126{ 
    104127    MatrixLookAt(_tMatrix,_rFrom,_rAt,_vUp); 
     
    106129} 
    107130 
    108 /*! Get the from point. 
    109 */ 
    110 Pnt3f &FlyNavigator::getFrom() 
    111 
    112     return _rFrom; 
    113 
    114  
    115 /*! Get the at point. 
    116 */ 
    117 Pnt3f &FlyNavigator::getAt() 
    118 
    119     return _rAt; 
    120 
    121  
    122 /*! Get the up vector. 
    123 */ 
    124 Vec3f &FlyNavigator::getUp() 
    125 
    126     return _vUp; 
    127 
    128  
     131/*! Not needed by FlyEngine!!! 
     132*/ 
     133// FIXME: remove getDistance() from NavigatorEngine??? 
     134Real32 FlyEngine::getDistance() 
     135
     136    return 0.0f; 
     137
    129138 
    130139/*------------------------------ set --------------------------------------*/ 
     
    133142    of all transformations). 
    134143*/ 
    135 void FlyNavigator::setFrom(Pnt3f new_from) 
     144void FlyEngine::setFrom(Pnt3f new_from) 
    136145{ 
    137146    _rFrom=new_from; 
     
    140149/*! Sets the target point at which the viewer is looking. 
    141150*/ 
    142 void FlyNavigator::setAt(Pnt3f new_At) 
     151void FlyEngine::setAt(Pnt3f new_At) 
    143152{ 
    144153    _rAt=new_At; 
     
    147156/*! Sets the up vector, i.e. the direction that point up on the screen. 
    148157*/ 
    149 void FlyNavigator::setUp(Vec3f new_up) 
     158void FlyEngine::setUp(Vec3f new_up) 
    150159{ 
    151160    _vUp=new_up; 
     
    154163/*! Set the position and the orientation at once. 
    155164*/ 
    156 void FlyNavigator::set(Pnt3f new_from,Pnt3f new_At,Vec3f new_up) 
     165void FlyEngine::set(Pnt3f new_from,Pnt3f new_At,Vec3f new_up) 
    157166{ 
    158167    _rFrom=new_from; 
     
    163172/*! Set the position and the orientation at once using a matrix. 
    164173*/ 
    165 void FlyNavigator::set(Matrix new_matrix) 
     174void FlyEngine::set(const Matrix& new_matrix) 
    166175{ 
    167176    _rFrom= (Pnt3f) new_matrix[3]; 
     
    171180} 
    172181 
     182/*! Moves \var dist steps forward 
     183*/ 
     184void FlyEngine::setDistance(Real32 dist) 
     185{ 
     186    forward(dist); 
     187} 
     188 
     189/*---------------------- navigator engine callbacks ------------------------*/ 
     190 
     191void FlyEngine::buttonPress(Int16 button, Int16 x, Int16 y, Navigator* nav) 
     192{ 
     193    switch (button) 
     194    { 
     195        case Navigator::LEFT_MOUSE:   
     196            _currentState = Navigator::TRANSLATING_ZPLUS; 
     197            break;                             
     198        case Navigator::MIDDLE_MOUSE: 
     199            _currentState = Navigator::ROTATING;            
     200            break;           
     201        case Navigator::RIGHT_MOUSE:   
     202            _currentState = Navigator::TRANSLATING_ZMINUS;  
     203            break; 
     204        case Navigator::UP_MOUSE:   
     205            _currentState = Navigator::IDLE; 
     206            forward(-nav->getMotionFactor()); 
     207            break; 
     208        case Navigator::DOWN_MOUSE: 
     209            _currentState = Navigator::IDLE; 
     210            forward(nav->getMotionFactor()); 
     211            break; 
     212        default: 
     213            FNOTICE(("FlyEngine: buttonPress, unknown button\n")); 
     214            break; 
     215    } 
     216} 
     217 
     218void FlyEngine::buttonRelease(Int16 button, Int16 x,Int16 y,Navigator* nav) 
     219{ 
     220    _currentState = Navigator::IDLE; 
     221} 
     222 
     223void FlyEngine::keyPress(Int16 key, Int16 x,Int16 y,Navigator* nav) 
     224{ 
     225    switch (key) 
     226    { 
     227        case Navigator::LEFTROT: 
     228            rotate(-nav->getRotationAngle(), 0); 
     229            break; 
     230        case Navigator::RIGHTROT: 
     231            rotate(nav->getRotationAngle(), 0); 
     232            break; 
     233        case Navigator::LEFT: 
     234            right(nav->getMotionFactor()); 
     235            break; 
     236        case Navigator::RIGHT: 
     237            right(-nav->getMotionFactor()); 
     238            break; 
     239        case Navigator::FORWARDS: 
     240            forward(-nav->getMotionFactor()); 
     241            break; 
     242        case Navigator::BACKWARDS: 
     243            forward( nav->getMotionFactor()); 
     244            break; 
     245        default: 
     246            FNOTICE(("FlyEngine: keyPress, unknown key\n")); 
     247            break; 
     248    } 
     249} 
     250 
     251void FlyEngine::moveTo(Int16 x,Int16 y,Navigator* nav) 
     252{ 
     253    Real32 fromX,fromY, toX,toY;   
     254 
     255    nav->calcFromTo(x,y, fromX,fromY, toX,toY); 
     256 
     257    Real32 distanceX = -(fromX-toX); 
     258    Real32 distanceY =  (fromY-toY); 
     259    rotate(distanceX, distanceY); 
     260 
     261    switch (_currentState) 
     262    { 
     263        case Navigator::TRANSLATING_ZPLUS: 
     264            forward(-nav->getMotionFactor()); 
     265            break; 
     266        case Navigator::TRANSLATING_ZMINUS: 
     267            forward(nav->getMotionFactor()); 
     268            break;                                     
     269        case Navigator::ROTATING: 
     270            break; 
     271        default: 
     272            //IDLE 
     273            break; 
     274    } 
     275} 
     276 
     277void FlyEngine::idle(Int16 buttons, Int16 x,Int16 y,Navigator* nav) 
     278{ 
     279} 
     280 
     281void FlyEngine::onViewportChanged(ViewportPtr new_viewport) 
     282{ 
     283    // nothing to do here 
     284} 
     285 
    173286/*---------------------- Flyer Transformations ----------------------------*/ 
    174287 
     
    176289    left/right axis. \a deltaX and \a deltaY should be between -Pi and Pi. 
    177290*/ 
    178 void FlyNavigator::rotate(Real32 deltaX, Real32 deltaY) 
     291void FlyEngine::rotate(Real32 deltaX, Real32 deltaY) 
    179292{ 
    180293    // rotate around the up vector 
     
    219332/*! Flies forward, i.e. translation \a step units along the view vector. 
    220333*/ 
    221 Real32 FlyNavigator::forward(Real32 step) 
     334Real32 FlyEngine::forward(Real32 step) 
    222335{ 
    223336    Vec3f lv; 
     
    235348/*! Strafes to the right, i.e. translates along the side vector. 
    236349*/ 
    237 Real32 FlyNavigator::right(Real32 step) 
     350Real32 FlyEngine::right(Real32 step) 
    238351{ 
    239352    Vec3f sv;