| 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 |
|---|