Changeset 20134

Show
Ignore:
Timestamp:
05/04/07 11:13:26 (2 years ago)
Author:
patrick
Message:

MFT r20007: 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 >

Bumped version to 2.1.26.

Files:

Legend:

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

    r20133 r20134  
    11DATE        AUTHOR      CHANGE 
    22----------- ----------- ------------------------------------------------------- 
     3May-04-2007 patrick     Improved OSG scene view lighting for subclasses of 
     4                        vrj::OsgApp. Submitted by Doug McCorkle. 
     5                        NEW VERSION: 2.1.26 
    36May-04-2007 patrick     Added lighting code to vrj::GlBasicSimulator so that 
    47                        OSG and OpenSG application objects do not have to 
  • juggler/branches/2.2/modules/vrjuggler/VERSION

    r20133 r20134  
     12.1.26-0 @05/04/2007 16:15:00 UTC@ 
    122.1.25-0 @05/04/2007 16:10:00 UTC@ 
    232.1.24-0 @05/02/2007 02:00:00 UTC@ 
  • juggler/branches/2.2/modules/vrjuggler/vrj/Draw/OSG/OsgApp.h

    r20133 r20134  
    9393 
    9494   /** 
     95    * Returns the options to be passed to osgUtil::SceneView::setDefaults() 
     96    * for each scene view that is configured. This is called by the default 
     97    * implementation of vrj::OsgApp::configSceneView(). See 
     98    * osgUtil::SceneView::Options for the available settings. 
     99    * 
     100    * @see configSceneView() 
     101    * 
     102    * @since 2.1.26 
     103    */ 
     104   virtual osgUtil::SceneView::Options getSceneViewDefaults() 
     105   { 
     106      return osgUtil::SceneView::STANDARD_SETTINGS; 
     107   } 
     108 
     109   /** 
    95110    * Configures newly created scene viewers. 
    96111    * This is called immediately after a new scene viewer is created for a 
    97112    * context.  This is the place to configure application background colors 
    98     * and other viewer-specific information. 
     113    * and other viewer-specific information.  Below are some suggestions on 
     114    * how to configure an osgUtil::SceneView instance with lighting. 
     115    * 
     116    * For an application configure with a sky light: 
     117    * 
     118    * \code 
     119    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     120    * { 
     121    *    return osgUtil::SceneView::SKY_LIGHT; 
     122    * } 
     123    * \endcode 
     124    * 
     125    * For an application configured with a headlight: 
     126    * 
     127    * \code 
     128    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     129    * { 
     130    *    return osgUtil::SceneView::HEADLIGHT; 
     131    * } 
     132    * \endcode 
     133    * 
     134    * For an application configure with a user-defined light, there are 
     135    * several steps. 
     136    * 
     137    * \code 
     138    * // First, declare two member variables in your subclass of vrj::OsgApp 
     139    * such as the following: 
     140    * osg::ref_ptr<osg::Light> mLight0; 
     141    * osg::ref_ptr<osg::LightSource> mLightSource0; 
     142    * 
     143    * // Then, in init() do something such as the following: 
     144    * void MyApp::init() 
     145    * { 
     146    *    vrj::OsgApp::init(); 
     147    * 
     148    *    mLight0 = new osg::Light(); 
     149    *    mLight0->setLightNum(0); 
     150    *    mLight0->setAmbient(osg::Vec4f(0.36862f, 0.36842f, 0.36842f, 1.0f)); 
     151    *    mLight0->setDiffuse(osg::Vec4f(0.88627f, 0.88500f, 0.88500f, 1.0f)); 
     152    *    mLight0->setSpecular(osg::Vec4f(0.49019f, 0.48872f, 0.48872f, 1.0f)); 
     153    *    mLight0->setPosition(osg::Vec4f(10000.0f, 10000.0f, 10000.0f, 0.0f)); 
     154    *    mLight0->setDirection(osg::Vec3f(-1.0f, -1.0f, -1.0f)); 
     155    * 
     156    *    mLightSource0 = new osg::LightSource(); 
     157    *    mLightSource0->setLight(mLight0.get()); 
     158    *    mLightSource0->setLocalStateSetModes(osg::StateAttribute::ON); 
     159    * 
     160    *    // Now that we know we have a root node add the default light to the 
     161    *    // scene. 
     162    *    this->getScene()->addChild( mLightSource0.get() ); 
     163    * } 
     164    * 
     165    * // Next, override vrj::OsgApp::getSceneViewDefaults() to change the 
     166    * // option passed to osgUtil::SceneView::setDefaults(). 
     167    * osgUtil::SceneView::Options MyApp::getSceneViewDefaults() 
     168    * { 
     169    *    return osgUtil::SceneView::NO_SCENEVIEW_LIGHT; 
     170    * } 
     171    * 
     172    * // Finally, set up the osgUtil::SceneView instance to use this light. 
     173    * void MyApp::configSceneView(osgUtil::SceneView* newSceneViewer) 
     174    * { 
     175    *    vrj::OsgApp::configSceneView(newSceneViewer); 
     176    * 
     177    *    // add lights and turn on lighting 
     178    *    newSceneViewer->getGlobalStateSet()->setAssociatedModes( 
     179    *       mLight0.get(), osg::StateAttribute::ON 
     180    *    ); 
     181    *    newSceneViewer->getGlobalStateSet()->setMode(GL_LIGHTING, 
     182    *                                                 osg::StateAttribute::ON); 
     183    * } 
     184    * \endcode 
    99185    * 
    100186    * @post \p newSceneViewer is initialized. 
     187    * 
     188    * @see getSceneViewDefaults() 
    101189    */ 
    102190   virtual void configSceneView(osgUtil::SceneView* newSceneViewer) 
    103191   { 
    104       newSceneViewer->setDefaults(); 
     192      newSceneViewer->setDefaults(getSceneViewDefaults()); 
    105193      newSceneViewer->init(); 
    106194      newSceneViewer->setClearColor(osg::Vec4(0.0f, 0.0f, 0.0f, 0.0f)); 
     
    295383   } 
    296384 
    297    // This will eventually be changed to no light and all lighting will be handled 
    298    // by the application.  For the time being it fixes the lighting inconsistanies 
    299    // over multiple screens 
    300    new_sv->setLightingMode(osgUtil::SceneView::SKY_LIGHT); 
    301  
    302385   (*sceneViewer) = new_sv; 
    303386} 
    304  
    305387 
    306388inline void OsgApp::draw()