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