Changeset 6109

Show
Ignore:
Timestamp:
02/07/07 17:32:14
Author:
robert
Message:

Added new Transform::ReferenceType? enum ABSOLUTE_RF_INHERIT_VIEWPOINT to support
internal RTT cameras that wish to use the main cameras view/eye point for LOD and other
distance based tests.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • OpenSceneGraph/trunk/include/osg/CullStack

    r5821 r6109  
    1919#include <osg/Viewport> 
    2020#include <osg/fast_back_stack> 
     21#include <osg/Transform> 
    2122 
    2223namespace osg { 
     
    4849        void popProjectionMatrix(); 
    4950 
    50         void pushModelViewMatrix(osg::RefMatrix* matrix); 
     51        void pushModelViewMatrix(osg::RefMatrix* matrix, Transform::ReferenceFrame referenceFrame); 
    5152        void popModelViewMatrix(); 
    5253 
  • OpenSceneGraph/trunk/include/osg/Transform

    r5757 r6109  
    9191        { 
    9292            RELATIVE_RF, 
    93             ABSOLUTE_RF 
     93            ABSOLUTE_RF, 
     94            ABSOLUTE_RF_INHERIT_VIEWPOINT 
    9495        }; 
    9596         
     
    105106          * absolute Transforms at the top of the scene, for such things as 
    106107          * heads up displays. 
     108          * ABSOLUTE_RF_INHERIT_VIEWPOINT is the same as ABSOLUTE_RF except it 
     109          * adds the ability to use the parents view points position in world coordinates 
     110          * as its local viewpoint in the new coordinates frame.  This is useful for 
     111          * Render to texture Cameras that wish to use the main views LOD range computation  
     112          * (which uses the viewpoint rather than the eye point) rather than use the local 
     113          * eye point defined by the this Transforms' abosolute view matrix. 
    107114        */ 
    108115        void setReferenceFrame(ReferenceFrame rf); 
  • OpenSceneGraph/trunk/src/osg/CollectOccludersVisitor.cpp

    r5821 r6109  
    9090    ref_ptr<osg::RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix()); 
    9191    node.computeLocalToWorldMatrix(*matrix,this); 
    92     pushModelViewMatrix(matrix.get()); 
     92    pushModelViewMatrix(matrix.get(), node.getReferenceFrame()); 
    9393     
    9494    handle_cull_callbacks_and_traverse(node); 
  • OpenSceneGraph/trunk/src/osg/CullStack.cpp

    r5821 r6109  
    1414#include <osg/Timer> 
    1515 
     16#include <osg/Notify> 
     17#include <osg/io_utils> 
     18 
    1619using namespace osg; 
    1720 
     
    188191} 
    189192 
    190 void CullStack::pushModelViewMatrix(RefMatrix* matrix) 
    191 
     193void CullStack::pushModelViewMatrix(RefMatrix* matrix, Transform::ReferenceFrame referenceFrame) 
     194
     195    osg::RefMatrix* originalModelView = _modelviewStack.empty() ? 0 : _modelviewStack.back().get(); 
     196 
    192197    _modelviewStack.push_back(matrix); 
    193198     
     
    197202    inv.invert(*matrix); 
    198203 
    199     _eyePointStack.push_back(inv.getTrans()); 
    200     _viewPointStack.push_back(getReferenceViewPoint() * inv); 
     204     
     205    switch(referenceFrame) 
     206    { 
     207        case(Transform::RELATIVE_RF): 
     208            _eyePointStack.push_back(inv.getTrans()); 
     209            _referenceViewPoints.push_back(getReferenceViewPoint()); 
     210            _viewPointStack.push_back(getReferenceViewPoint() * inv); 
     211            break; 
     212        case(Transform::ABSOLUTE_RF): 
     213            _eyePointStack.push_back(inv.getTrans()); 
     214            _referenceViewPoints.push_back(osg::Vec3(0.0,0.0,0.0)); 
     215            _viewPointStack.push_back(_eyePointStack.back()); 
     216            break; 
     217        case(Transform::ABSOLUTE_RF_INHERIT_VIEWPOINT): 
     218        { 
     219            _eyePointStack.push_back(inv.getTrans()); 
     220             
     221            osg::Vec3 referenceViewPoint = getReferenceViewPoint(); 
     222            if (originalModelView) 
     223            { 
     224                osg::Matrix viewPointTransformMatrix; 
     225                viewPointTransformMatrix.invert(*originalModelView); 
     226                viewPointTransformMatrix.postMult(*matrix); 
     227                referenceViewPoint = referenceViewPoint * viewPointTransformMatrix; 
     228            } 
     229 
     230            _referenceViewPoints.push_back(referenceViewPoint); 
     231            _viewPointStack.push_back(getReferenceViewPoint() * inv); 
     232            break; 
     233        } 
     234    } 
    201235 
    202236 
     
    216250     
    217251    _eyePointStack.pop_back(); 
     252    _referenceViewPoints.pop_back(); 
    218253    _viewPointStack.pop_back(); 
    219254 
  • OpenSceneGraph/trunk/src/osg/Transform.cpp

    r5757 r6109  
    6969                    const osg::Camera* camera = dynamic_cast<const osg::Camera*>(*ritr); 
    7070                    if (camera &&  
    71                         (camera->getReferenceFrame()==osg::Transform::ABSOLUTE_RF || camera->getParents().empty())) 
     71                        (camera->getReferenceFrame()!=osg::Transform::RELATIVE_RF || camera->getParents().empty())) 
    7272                    { 
    7373                        break; 
  • OpenSceneGraph/trunk/src/osgPlugins/osg/Transform.cpp

    r3776 r6109  
    5151    if (fr[0].matchWord("referenceFrame")) 
    5252    { 
    53         if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE") || fr[1].matchWord("ABSOLUTE")
     53        if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE") || fr[1].matchWord("ABSOLUTE") || fr[1].matchWord("ABSOLUTE_RF")
    5454        { 
    5555            transform.setReferenceFrame(Transform::ABSOLUTE_RF); 
     
    5757            iteratorAdvanced = true; 
    5858        } 
    59         if (fr[1].matchWord("RELATIVE_TO_PARENTS") || fr[1].matchWord("RELATIVE")) 
     59        if (fr[1].matchWord("RELATIVE_TO_ABSOLUTE") || fr[1].matchWord("ABSOLUTE_RF_INHERIT_VIEWPOINT") ) 
     60        { 
     61            transform.setReferenceFrame(Transform::ABSOLUTE_RF_INHERIT_VIEWPOINT); 
     62            fr += 2; 
     63            iteratorAdvanced = true; 
     64        } 
     65        if (fr[1].matchWord("RELATIVE_TO_PARENTS") || fr[1].matchWord("RELATIVE") || fr[1].matchWord("RELATIVE_RF")) 
    6066        { 
    6167            transform.setReferenceFrame(Transform::RELATIVE_RF); 
     
    7985            fw << "ABSOLUTE\n"; 
    8086            break; 
     87        case Transform::ABSOLUTE_RF_INHERIT_VIEWPOINT: 
     88            fw << "ABSOLUTE_RF_INHERIT_VIEWPOINT\n"; 
     89            break; 
    8190        case Transform::RELATIVE_RF: 
    8291        default: 
  • OpenSceneGraph/trunk/src/osgPlugins/txp/TXPNode.cpp

    r5188 r6109  
    104104            osg::ref_ptr<TileMapper> tileMapper = new TileMapper; 
    105105            tileMapper->setLODScale(cv->getLODScale()); 
     106            tileMapper->pushReferenceViewPoint(cv->getReferenceViewPoint()); 
    106107            tileMapper->pushViewport(cv->getViewport()); 
    107108            tileMapper->pushProjectionMatrix(&(cv->getProjectionMatrix())); 
    108             tileMapper->pushModelViewMatrix(&(cv->getModelViewMatrix())); 
     109            tileMapper->pushModelViewMatrix(&(cv->getModelViewMatrix()), osg::Transform::RELATIVE_RF); 
    109110 
    110111            // traverse the scene graph to search for valid tiles 
     
    114115            tileMapper->popProjectionMatrix(); 
    115116            tileMapper->popViewport(); 
     117            tileMapper->popReferenceViewPoint(); 
    116118 
    117119            //std::cout<<"   found " << tileMapper._tileMap.size() << std::endl; 
  • OpenSceneGraph/trunk/src/osgUtil/CullVisitor.cpp

    r6086 r6109  
    962962    ref_ptr<RefMatrix> matrix = createOrReuseMatrix(getModelViewMatrix()); 
    963963    node.computeLocalToWorldMatrix(*matrix,this); 
    964     pushModelViewMatrix(matrix.get()); 
     964    pushModelViewMatrix(matrix.get(), node.getReferenceFrame()); 
    965965     
    966966    handle_cull_callbacks_and_traverse(node); 
     
    11181118    osg::RefMatrix* modelview = 0; 
    11191119 
    1120     if (camera.getReferenceFrame()==osg::Transform::ABSOLUTE_RF) 
    1121     { 
     1120    if (camera.getReferenceFrame()==osg::Transform::RELATIVE_RF) 
     1121    { 
     1122        if (camera.getTransformOrder()==osg::Camera::POST_MULTIPLY) 
     1123        { 
     1124            projection = createOrReuseMatrix(getProjectionMatrix()*camera.getProjectionMatrix()); 
     1125            modelview = createOrReuseMatrix(getModelViewMatrix()*camera.getViewMatrix()); 
     1126        } 
     1127        else // pre multiply  
     1128        { 
     1129            projection = createOrReuseMatrix(camera.getProjectionMatrix()*getProjectionMatrix()); 
     1130            modelview = createOrReuseMatrix(camera.getViewMatrix()*getModelViewMatrix()); 
     1131        } 
     1132    } 
     1133    else 
     1134    { 
     1135        // an absolute reference frame 
    11221136        projection = createOrReuseMatrix(camera.getProjectionMatrix()); 
    11231137        modelview = createOrReuseMatrix(camera.getViewMatrix()); 
    11241138    } 
    1125     else if (camera.getTransformOrder()==osg::Camera::POST_MULTIPLY) 
    1126     { 
    1127         projection = createOrReuseMatrix(getProjectionMatrix()*camera.getProjectionMatrix()); 
    1128         modelview = createOrReuseMatrix(getModelViewMatrix()*camera.getViewMatrix()); 
    1129     } 
    1130     else // pre multiply  
    1131     { 
    1132         projection = createOrReuseMatrix(camera.getProjectionMatrix()*getProjectionMatrix()); 
    1133         modelview = createOrReuseMatrix(camera.getViewMatrix()*getModelViewMatrix()); 
    1134     } 
    1135  
    1136  
    1137     bool localReferenceViewPoint = true; 
    1138     if (localReferenceViewPoint) 
    1139     {  
    1140         // put the reference view point into the new camera eye coordinates 
    1141         osg::Vec3 referenceViewPoint = getReferenceViewPoint(); 
    1142         if (originalModelView.valid()) 
    1143         { 
    1144             osg::Matrix matrix; 
    1145             matrix.invert(originalModelView); // note should this be view.getCamera()->getViewMatrix() ?? 
    1146             matrix.postMult(*modelview); 
    1147             referenceViewPoint = referenceViewPoint * matrix; 
    1148         } 
    1149         pushReferenceViewPoint(referenceViewPoint); 
    1150     } 
     1139 
    11511140 
    11521141    pushProjectionMatrix(projection); 
    1153     pushModelViewMatrix(modelview); 
     1142    pushModelViewMatrix(modelview, camera.getReferenceFrame()); 
    11541143 
    11551144 
     
    12781267 
    12791268    } 
    1280  
    1281     if (localReferenceViewPoint) 
    1282     { 
    1283         // restore the previous reference view point     
    1284         popReferenceViewPoint(); 
    1285     } 
    12861269     
    12871270    // restore the previous model view matrix. 
  • OpenSceneGraph/trunk/src/osgUtil/IntersectVisitor.cpp

    r5757 r6109  
    805805    if (!camera.isRenderToTextureCamera()) 
    806806    { 
    807         if (camera.getReferenceFrame()==osg::Camera::ABSOLUTE_RF) 
     807        if (camera.getReferenceFrame()==osg::Camera::RELATIVE_RF) 
     808        { 
     809            if (camera.getTransformOrder()==osg::Camera::POST_MULTIPLY) 
     810            { 
     811                runNestedPickVisitor( camera, 
     812                                      camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 
     813                                      _lastProjectionMatrix * camera.getProjectionMatrix(),  
     814                                      _lastViewMatrix * camera.getViewMatrix(), 
     815                                      _mx, _my ); 
     816            } 
     817            else // PRE_MULTIPLY 
     818            { 
     819                runNestedPickVisitor( camera, 
     820                                      camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 
     821                                      camera.getProjectionMatrix() * _lastProjectionMatrix,  
     822                                      camera.getViewMatrix() * _lastViewMatrix, 
     823                                      _mx, _my ); 
     824            } 
     825        } 
     826        else 
    808827        { 
    809828            runNestedPickVisitor( camera, 
     
    813832                                  _mx, _my ); 
    814833        } 
    815         else if (camera.getTransformOrder()==osg::Camera::POST_MULTIPLY) 
    816         { 
    817             runNestedPickVisitor( camera, 
    818                                   camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 
    819                                   _lastProjectionMatrix * camera.getProjectionMatrix(),  
    820                                   _lastViewMatrix * camera.getViewMatrix(), 
    821                                   _mx, _my ); 
    822         } 
    823         else // PRE_MULTIPLY 
    824         { 
    825             runNestedPickVisitor( camera, 
    826                                   camera.getViewport() ? camera.getViewport() : _lastViewport.get(), 
    827                                   camera.getProjectionMatrix() * _lastProjectionMatrix,  
    828                                   camera.getViewMatrix() * _lastViewMatrix, 
    829                                   _mx, _my ); 
    830         } 
    831     } 
    832 
     834    } 
     835
  • OpenSceneGraph/trunk/src/osgUtil/Optimizer.cpp

    r6088 r6109  
    790790                { 
    791791                    if (transform->getDataVariance()==osg::Transform::DYNAMIC) _moreThanOneMatrixRequired=true; 
    792                     else if (transform->getReferenceFrame()==osg::Transform::ABSOLUTE_RF) _moreThanOneMatrixRequired=true; 
     792                    else if (transform->getReferenceFrame()!=osg::Transform::RELATIVE_RF) _moreThanOneMatrixRequired=true; 
    793793                    else 
    794794                    { 
  • OpenSceneGraph/trunk/src/osgUtil/SceneView.cpp

    r6084 r6109  
    660660        _collectOccludersVisistor->pushViewport(getViewport()); 
    661661        _collectOccludersVisistor->pushProjectionMatrix(proj.get()); 
    662         _collectOccludersVisistor->pushModelViewMatrix(mv.get()); 
     662        _collectOccludersVisistor->pushModelViewMatrix(mv.get(),osg::Transform::ABSOLUTE_RF); 
    663663 
    664664        // traverse the scene graph to search for occluder in there new positions. 
     
    737737    cullVisitor->pushViewport(getViewport()); 
    738738    cullVisitor->pushProjectionMatrix(proj.get()); 
    739     cullVisitor->pushModelViewMatrix(mv.get()); 
     739    cullVisitor->pushModelViewMatrix(mv.get(),osg::Transform::ABSOLUTE_RF); 
    740740     
    741741