Changeset 20007

Show
Ignore:
Timestamp:
04/26/07 12:16:28 (2 years ago)
Author:
patrick
Message:

Improved the handling of lighting for osgUtil::SceneView? instances. This
adds the virtual function vrj::OsgApp::getSceneViewDefaults() which
subclasses can override to change the parameter passed to
osgUtil::SceneView::setDefaults().

Submitted by: Doug McCorkle? < mccdo at iastate dot edu >

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • juggler/trunk/modules/vrjuggler/ChangeLog

    r20006 r20007  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3Apr-26-2007 patrick     Improved OSG scene view lighting for subclasses of 
     4                        vrj::OsgApp. Submitted by Doug McCorkle. 
    35Apr-18-2007 patrick     VR Juggler 2.2 branch created. 
    46                        NEW VERSION: 2.3.0 
  • juggler/trunk/modules/vrjuggler/vrj/Draw/OSG/OsgApp.h

    r19729 r20007  
    8888 
    8989   /** 
     90    * Returns the options to be passed to osgUtil::SceneView::setDefaults() 
     91    * for each scene view that is configured. This is called by the default 
     92    * implementation of vrj::OsgApp::configSceneView(). See 
     93    * osgUtil::SceneView::Options for the available settings. 
     94    * 
     95    * @see configSceneView() 
     96    * 
     97    * @since 2.3.0 
     98    */ 
     99   virtual osgUtil::SceneView::Options getSceneViewDefaults() 
     100   { 
     101      return osgUtil::SceneView::STANDARD_SETTINGS; 
     102   } 
     103 
     104   /** 
    90105    * Configures newly created scene viewers. 
    91106    * This is called immediately after a new scene viewer is created for a 
    92107    * context.  This is the place to configure application background colors 
    93     * and other viewer-specific information. 
     108    * and other viewer-specific information.  Below are some suggestions on 
     109    * how to configure an osgUtil::SceneView instance with lighting. 
     110    * 
     111    * For an application configure with a sky light: 
     112    * 
     113    * \code 
     114    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     115    * { 
     116    *    return osgUtil::SceneView::SKY_LIGHT; 
     117    * } 
     118    * \endcode 
     119    * 
     120    * For an application configured with a headlight: 
     121    * 
     122    * \code 
     123    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     124    * { 
     125    *    return osgUtil::SceneView::HEADLIGHT; 
     126    * } 
     127    * \endcode 
     128    * 
     129    * For an application configure with a user-defined light, there are 
     130    * several steps. 
     131    * 
     132    * \code 
     133    * // First, declare two member variables in your subclass of vrj::OsgApp 
     134    * such as the following: 
     135    * osg::ref_ptr<osg::Light> mLight0; 
     136    * osg::ref_ptr<osg::LightSource> mLightSource0; 
     137    * 
     138    * // Then, in init() do something such as the following: 
     139    * void MyApp::init() 
     140    * { 
     141    *    vrj::OsgApp::init(); 
     142    * 
     143    *    mLight0 = new osg::Light(); 
     144    *    mLight0->setLightNum(0); 
     145    *    mLight0->setAmbient(osg::Vec4f(0.36862f, 0.36842f, 0.36842f, 1.0f)); 
     146    *    mLight0->setDiffuse(osg::Vec4f(0.88627f, 0.88500f, 0.88500f, 1.0f)); 
     147    *    mLight0->setSpecular(osg::Vec4f(0.49019f, 0.48872f, 0.48872f, 1.0f)); 
     148    *    mLight0->setPosition(osg::Vec4f(10000.0f, 10000.0f, 10000.0f, 0.0f)); 
     149    *    mLight0->setDirection(osg::Vec3f(-1.0f, -1.0f, -1.0f)); 
     150    * 
     151    *    mLightSource0 = new osg::LightSource(); 
     152    *    mLightSource0->setLight(mLight0.get()); 
     153    *    mLightSource0->setLocalStateSetModes(osg::StateAttribute::ON); 
     154    * 
     155    *    // Now that we know we have a root node add the default light to the 
     156    *    // scene. 
     157    *    this->getScene()->addChild( mLightSource0.get() ); 
     158    * } 
     159    * 
     160    * // Next, override vrj::OsgApp::getSceneViewDefaults() to change the 
     161    * // option passed to osgUtil::SceneView::setDefaults(). 
     162    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     163    * { 
     164    *    return osgUtil::SceneView::NO_SCENEVIEW_LIGHT; 
     165    * } 
     166    * 
     167    * // Finally, set up the osgUtil::SceneView instance to use this light. 
     168    * void MyApp::configSceneView(osgUtil::SceneView* newSceneViewer) 
     169    * { 
     170    *    vrj::OsgApp::configSceneView(newSceneViewer); 
     171    * 
     172    *    // add lights and turn on lighting 
     173    *    newSceneViewer->getGlobalStateSet()->setAssociatedModes( 
     174    *       mLight0.get(), osg::StateAttribute::ON 
     175    *    ); 
     176    *    newSceneViewer->getGlobalStateSet()->setMode(GL_LIGHTING, 
     177    *                                                 osg::StateAttribute::ON); 
     178    * } 
     179    * \endcode 
    94180    * 
    95181    * @post \p newSceneViewer is initialized. 
     182    * 
     183    * @see getSceneViewDefaults() 
    96184    */ 
    97185   virtual void configSceneView(osgUtil::SceneView* newSceneViewer) 
    98186   { 
    99       newSceneViewer->setDefaults(); 
     187      newSceneViewer->setDefaults(getSceneViewDefaults()); 
    100188      newSceneViewer->init(); 
    101189      newSceneViewer->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); 
     
    284372   new_sv->getState()->setContextID(unique_context_id); 
    285373 
    286    // This will eventually be changed to no light and all lighting will be handled 
    287    // by the application.  For the time being it fixes the lighting inconsistanies 
    288    // over multiple screens 
    289    new_sv->setLightingMode(osgUtil::SceneView::SKY_LIGHT); 
    290  
    291374   (*sceneViewer) = new_sv; 
    292375 
    293    //Setup OpenGL light 
    294    //This should actualy be done in the simulator code 
     376   // Set up OpenGL light so that the simulator components are lit correctly. 
     377   // XXX: This should actualy be done in the simulator code. 
    295378   GLfloat light0_ambient[] = { 0.1f,  0.1f,  0.1f,  1.0f}; 
    296379   GLfloat light0_diffuse[] = { 0.8f,  0.8f,  0.8f,  1.0f}; 
     
    323406   glShadeModel(GL_SMOOTH); 
    324407} 
    325  
    326408 
    327409inline void OsgApp::draw()