Changeset 972

Show
Ignore:
Timestamp:
10/15/07 15:39:48 (1 year ago)
Author:
patrick
Message:

Centralize viewport coordinate normalization in the new method
OSG::Viewport::getNormalizedCoordinates(). This implementation comes from
OSG::Camera::calcViewRay().

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/fcptr_stable_jun07/Source/System/Window/Base/OSGCamera.cpp

    r714 r972  
    319319    cctowc.invertFrom(wctocc); 
    320320 
    321     Real32  rx = 
    322         (x - port.getPixelLeft()) / 
    323         (Real32) port.getPixelWidth() * 2.f - 1.f; 
    324  
    325     Real32 ry = 1.f - ( 
    326         ( y - (port.getParent()->getHeight() - port.getPixelTop()) ) / 
    327         (Real32) port.getPixelHeight()) * 2.f; 
     321    Real32 rx(0.f), ry(0.f); 
     322    port.getNormalizedCoordinates(rx, ry, x, y); 
    328323 
    329324    Pnt3f from, at; 
  • branches/fcptr_stable_jun07/Source/System/Window/Base/OSGViewport.cpp

    r714 r972  
    215215{ 
    216216    return cast_dynamic<WindowPtrConst>(_sfParent.getValue()); 
     217} 
     218 
     219/*! Returns normalized coordintes from viewport coordinates. 
     220 
     221   @param normX Normalized X coordinate in the range [-1.0,1.0]. 
     222   @param normY Normalized Y coordinate in the range [-1.0,1.0]. 
     223   @param vpX   X coordinate of this viewport in the range [0,width]. 
     224   @param vpY   Y coordinate of this viewport in the range [0,height]. 
     225 
     226   @note Out-of-range input values lead to out-of-range output values. 
     227 */ 
     228void Viewport::getNormalizedCoordinates(      Real32& normX, 
     229                                              Real32& normY, 
     230                                        const Int32   vpX  , 
     231                                        const Int32   vpY  ) const 
     232{ 
     233    normX = 
     234        (vpX - getPixelLeft()) / 
     235        static_cast<Real32>(getPixelWidth()) * 2.f - 1.f; 
     236 
     237    normY = 1.f - ( 
     238        (vpY - (getParent()->getHeight() - getPixelTop())) / 
     239        static_cast<Real32>(getPixelHeight())) * 2.f; 
    217240} 
    218241 
  • branches/fcptr_stable_jun07/Source/System/Window/Base/OSGViewport.h

    r714 r972  
    9696    WindowPtrConst getParent(void) const; 
    9797 
     98            void  getNormalizedCoordinates(      Real32& normX, 
     99                                                 Real32& normY, 
     100                                           const Int32   vpX  , 
     101                                           const Int32   vpY  ) const; 
     102                                           
    98103    /*! \}                                                                 */ 
    99104    /*---------------------------------------------------------------------*/ 
  • branches/fcptr_stable_jun07/Source/System/Window/Utilities/OSGNavigator.cpp

    r714 r972  
    375375    _moved = true; 
    376376 
    377     Real32 width  = Real32(_vp->getPixelWidth()); 
    378     Real32 height = Real32(_vp->getPixelHeight()); 
    379  
    380     if(width <= 0 || height <= 0) 
    381         return; 
    382  
    383     WindowPtr par = _vp->getParent(); 
    384     Real32 winHeight; 
    385      
    386     if(par != NullFC) 
    387         winHeight = (Real32)par->getHeight(); 
    388     else 
    389         winHeight = height; 
    390          
    391     Real32 fromX = (2.0f * (_lastX - _vp->getPixelLeft())- width)/  width; 
    392     Real32 fromY = (2.0f * (winHeight - _lastY - _vp->getPixelBottom())  
    393                                 - height)  / height; 
    394     Real32 toX   = (2.0f * (x - _vp->getPixelLeft()) - width) / width; 
    395     Real32 toY   = (2.0f * (winHeight - y - _vp->getPixelBottom())  
    396                                 - height)/height; 
     377    Real32 fromX(0.f), fromY(0.f); 
     378    _vp->getNormalizedCoordinates(fromX, fromY, _lastX, _lastY); 
     379    Real32 toX(0.f), toY(0.f); 
     380    _vp->getNormalizedCoordinates(toX, toY, x, y); 
     381 
    397382    switch (_currentMode) 
    398383    {