Changeset 9441

Show
Ignore:
Timestamp:
01/05/09 17:53:29 (6 years ago)
Author:
robert
Message:

From Roland Smeenk, "Attached you will find an improved Collada plugin to properly support camera's.
A Collada camera will be added to the scenegraph as osg::CameraView?. This allows the user to create a set of predefined camera viewpoints. I also added a new MatrixManipulator? to osgGA called CameraViewSwitchManipulator? and added usage of this to the osgviewer example. This manipulator allows switching between the predefined camera viewpoints. The current design limition I ran into is that a MatrixManipulator? only manipulates the ViewMatrix?, but for this particular manipulator I also want to update the projectionMatrix of the camera when switching to a new viewpoint. This is not implemented because I don't know what would be the best way to design it. Any ideas?


Furthermore Collada also supports orthographic camera's, where an osg::CameraView? only supports a perspective camera. Would it be useful to create a CameraView? with customizable optics for this?"

Location:
OpenSceneGraph/trunk
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/src/osgGA/CMakeLists.txt

    r8211 r9441  
    2626    ${HEADER_PATH}/UFOManipulator 
    2727    ${HEADER_PATH}/Version 
     28    ${HEADER_PATH}/CameraViewSwitchManipulator 
    2829) 
    2930 
     
    4748    UFOManipulator.cpp 
    4849    Version.cpp 
     50    CameraViewSwitchManipulator.cpp 
    4951) 
    5052 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeRSceneObjects.cpp

    r9228 r9441  
    2525#include <osgSim/MultiSwitch> 
    2626#include <osg/Sequence> 
     27#include <osg/CameraView> 
    2728 
    2829using namespace osgdae; 
     
    485486// 0..1 <asset> 
    486487// 1    <optics> 
    487 //        1        <technique_common> 
     488//        1       <technique_common> 
    488489//                1        <orthographic>, <perspective> 
    489490//        0..*    <technique> 
    490491//        0..*    <extra> 
    491492// 0..* <imager> 
    492 //        1        <technique> 
     493//        1       <technique> 
    493494//        0..*    <extra> 
    494495// 0..* <extra> 
    495496osg::Node* daeReader::processCamera( domCamera * dcamera ) 
    496497{ 
    497     osg::Node *node = new osg::Switch(); 
    498  
    499     //TODO: Make the camera actually make a camera to view from. Not just draw a cone. 
    500     osg::Cone* cone = new osg::Cone(); 
    501  
    502     osg::ShapeDrawable* sd = new osg::ShapeDrawable(cone); 
    503  
    504     cone->setRadius(0.3); 
    505     cone->setHeight(1.0); 
    506  
    507     osg::Geode* geode = new osg::Geode(); 
    508  
    509     geode->addDrawable(sd); 
    510     geode->setName("camera"); 
    511  
    512     osg::Switch* svitch = static_cast<osg::Switch*>(node); 
    513  
    514     // Switched of by default to avoid excessively large scene bound 
    515     svitch->addChild(geode,false); 
    516  
    517     return node; 
     498    osg::CameraView* pOsgCameraView = new osg::CameraView; 
     499    pOsgCameraView->setName(dcamera->getId()); 
     500 
     501    domCamera::domOptics::domTechnique_common *pDomTechniqueCommon = dcamera->getOptics()->getTechnique_common(); 
     502    domCamera::domOptics::domTechnique_common::domPerspective *pDomPerspective = pDomTechniqueCommon->getPerspective(); 
     503    domCamera::domOptics::domTechnique_common::domOrthographic *pDomOrthographic = pDomTechniqueCommon->getOrthographic(); 
     504    if (pDomPerspective) 
     505    { 
     506        // <perspective> 
     507        // 1    <xfov>, <yfov>, <xfov> and <yfov>, <xfov> and <aspect_ratio>, <yfov> and <aspect_ratio> 
     508        // 1    <znear> 
     509        // 1    <zfar> 
     510        domTargetableFloat *pXfov = daeSafeCast< domTargetableFloat >(pDomPerspective->getXfov()); 
     511        domTargetableFloat *pYfov = daeSafeCast< domTargetableFloat >(pDomPerspective->getYfov()); 
     512        domTargetableFloat *pAspectRatio = daeSafeCast< domTargetableFloat >(pDomPerspective->getAspect_ratio()); 
     513 
     514        if (pXfov) 
     515        { 
     516            if (pYfov) 
     517            { 
     518                // <xfov> and <yfov> 
     519                pOsgCameraView->setFieldOfView(pXfov->getValue()); 
     520                pOsgCameraView->setFieldOfViewMode(osg::CameraView::HORIZONTAL); 
     521                 
     522                if (pAspectRatio) 
     523                { 
     524                    osg::notify(osg::WARN) << "Unexpected <aspectratio> in <camera> '" << dcamera->getId() << "'" << std::endl; 
     525                } 
     526            } 
     527            else if (pAspectRatio) 
     528            { 
     529                // <xfov> and <aspect_ratio> 
     530                pOsgCameraView->setFieldOfView(pXfov->getValue() * pAspectRatio->getValue()); 
     531                pOsgCameraView->setFieldOfViewMode(osg::CameraView::HORIZONTAL); 
     532            } 
     533            else  
     534            { 
     535                // <xfov> 
     536                pOsgCameraView->setFieldOfView(pXfov->getValue()); 
     537                pOsgCameraView->setFieldOfViewMode(osg::CameraView::HORIZONTAL); 
     538            } 
     539        } 
     540        else if (pYfov) 
     541        { 
     542            if (pAspectRatio) 
     543            { 
     544                // <yfov> and <aspect_ratio> 
     545                pOsgCameraView->setFieldOfView(pYfov->getValue() / pAspectRatio->getValue()); 
     546                pOsgCameraView->setFieldOfViewMode(osg::CameraView::VERTICAL); 
     547            } 
     548            else 
     549            { 
     550                // <yfov> 
     551                pOsgCameraView->setFieldOfView(pYfov->getValue()); 
     552                pOsgCameraView->setFieldOfViewMode(osg::CameraView::VERTICAL); 
     553            } 
     554        } 
     555        else 
     556        { 
     557            // xfov or yfov expected 
     558            osg::notify(osg::WARN) << "Expected <xfov> or <yfov> in <camera> '" << dcamera->getId() << "'" << std::endl; 
     559        } 
     560 
     561        domTargetableFloat *pZnear = daeSafeCast< domTargetableFloat >(pDomPerspective->getZnear()); 
     562        domTargetableFloat *pZfar = daeSafeCast< domTargetableFloat >(pDomPerspective->getZfar()); 
     563 
     564        // TODO The current osg::CameraView does not support storage of near far 
     565    } 
     566    else if (pDomOrthographic) 
     567    { 
     568        // <orthographic>  
     569        // 1    <xmag>, <ymag>, <xmag> and <ymag>, <xmag> and <aspect_ratio>, <ymag> and <aspect_ratio> 
     570        // 1    <znear> 
     571        // 1    <zfar> 
     572        domTargetableFloat *pXmag = daeSafeCast< domTargetableFloat >(pDomOrthographic->getXmag()); 
     573        domTargetableFloat *pYmag = daeSafeCast< domTargetableFloat >(pDomOrthographic->getYmag()); 
     574        domTargetableFloat *pAspectRatio = daeSafeCast< domTargetableFloat >(pDomOrthographic->getAspect_ratio()); 
     575 
     576        // TODO The current osg::CameraView does not support an orthographic view 
     577        osg::notify(osg::WARN) << "Orthographic in <camera> '" << dcamera->getId() << "' not supported" << std::endl; 
     578 
     579        domTargetableFloat *pZnear = daeSafeCast< domTargetableFloat >(pDomOrthographic->getZnear()); 
     580        domTargetableFloat *pZfar = daeSafeCast< domTargetableFloat >(pDomOrthographic->getZfar());     
     581 
     582        // TODO The current osg::CameraView does not support storage of near far 
     583    } 
     584 
     585    return pOsgCameraView; 
    518586} 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWSceneObjects.cpp

    r9228 r9441  
    2727#include <osg/Sequence> 
    2828#include <osg/Billboard> 
     29#include <osg/CameraView> 
    2930 
    3031using namespace osgdae; 
     
    394395    traverse( node ); 
    395396} 
     397 
     398void daeWriter::apply( osg::CameraView &node) 
     399{ 
     400    debugPrint( node ); 
     401 
     402    domInstance_camera *ic = daeSafeCast< domInstance_camera >( currentNode->add( "instance_camera" ) ); 
     403    std::string name = node.getName(); 
     404    if ( name.empty() ) 
     405    { 
     406        name = uniquify( "camera" ); 
     407    } 
     408    std::string url = "#" + name; 
     409    ic->setUrl( url.c_str() ); 
     410 
     411    if ( lib_cameras == NULL ) 
     412    { 
     413        lib_cameras = daeSafeCast< domLibrary_cameras >( dom->add( COLLADA_ELEMENT_LIBRARY_CAMERAS ) ); 
     414    } 
     415    domCamera *cam = daeSafeCast< domCamera >( lib_cameras->add( COLLADA_ELEMENT_CAMERA ) ); 
     416    cam->setId( name.c_str() ); 
     417 
     418    domCamera::domOptics *optics = daeSafeCast< domCamera::domOptics >( cam->add( COLLADA_ELEMENT_OPTICS ) ); 
     419    domCamera::domOptics::domTechnique_common *techniqueCommon = daeSafeCast< domCamera::domOptics::domTechnique_common >( optics->add( COLLADA_ELEMENT_TECHNIQUE_COMMON ) ); 
     420    domCamera::domOptics::domTechnique_common::domPerspective *pDomPerspective = daeSafeCast< domCamera::domOptics::domTechnique_common::domPerspective >( techniqueCommon->add( COLLADA_ELEMENT_PERSPECTIVE ) ); 
     421 
     422    domTargetableFloat *pXfov = NULL; 
     423    domTargetableFloat *pYfov = NULL; 
     424    switch(node.getFieldOfViewMode()) 
     425    { 
     426        case(osg::CameraView::UNCONSTRAINED):  
     427            pXfov = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_XFOV ) ); 
     428            pXfov->setValue(node.getFieldOfView()); 
     429            break; 
     430        case(osg::CameraView::HORIZONTAL):  
     431            pXfov = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_XFOV ) ); 
     432            pXfov->setValue(node.getFieldOfView()); 
     433            break; 
     434        case(osg::CameraView::VERTICAL):  
     435            pYfov = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_YFOV ) ); 
     436            pYfov->setValue(node.getFieldOfView()); 
     437            break; 
     438    } 
     439 
     440    // Using hardcoded values for <aspect_ratio>, <znear> and <zfar> 
     441    domTargetableFloat *pAspectRatio = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_ASPECT_RATIO ) ); 
     442    pAspectRatio->setValue(1.0); 
     443 
     444    domTargetableFloat *pNear = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_ZNEAR ) ); 
     445    pNear->setValue(1); 
     446 
     447    domTargetableFloat *pFar = daeSafeCast< domTargetableFloat >( pDomPerspective->add( COLLADA_ELEMENT_ZFAR ) ); 
     448    pFar->setValue(1000); 
     449} 
  • OpenSceneGraph/trunk/src/osgPlugins/dae/daeWriter.h

    r9228 r9441  
    111111    //virtual void  apply( osg::TexGenNode &node) 
    112112    virtual void    apply( osg::Transform &node ); 
    113     //virtual void  apply( osg::CameraView &node) 
     113    virtual void    apply( osg::CameraView &node); 
    114114    //virtual void  apply( osg::PagedLOD &node) 
    115115    //virtual void  apply( osg::ClearNode &node)