| | 260 | else |
| | 261 | { |
| | 262 | // make an orthographic projection |
| | 263 | osg::Vec3 lightDir(lightpos.x(), lightpos.y(), lightpos.z()); |
| | 264 | lightDir.normalize(); |
| | 265 | |
| | 266 | // set the position far away along the light direction |
| | 267 | osg::Vec3 position = lightDir * bb.radius() * 20; |
| | 268 | |
| | 269 | float centerDistance = (position-bb.center()).length(); |
| | 270 | |
| | 271 | float znear = centerDistance-bb.radius(); |
| | 272 | float zfar = centerDistance+bb.radius(); |
| | 273 | float zNearRatio = 0.001f; |
| | 274 | if (znear<zfar*zNearRatio) znear = zfar*zNearRatio; |
| | 275 | |
| | 276 | float top = bb.radius(); |
| | 277 | float right = top; |
| | 278 | |
| | 279 | _camera->setReferenceFrame(osg::Camera::ABSOLUTE_RF); |
| | 280 | _camera->setProjectionMatrixAsOrtho(-right, right, -top, top, znear, zfar); |
| | 281 | _camera->setViewMatrixAsLookAt(position,bb.center(),osg::Vec3(0.0f,1.0f,0.0f)); |
| | 282 | |
| | 283 | |
| | 284 | // compute the matrix which takes a vertex from local coords into tex coords |
| | 285 | // will use this later to specify osg::TexGen.. |
| | 286 | osg::Matrix MVPT = _camera->getViewMatrix() * |
| | 287 | _camera->getProjectionMatrix() * |
| | 288 | osg::Matrix::translate(1.0,1.0,1.0) * |
| | 289 | osg::Matrix::scale(0.5f,0.5f,0.5f); |
| | 290 | |
| | 291 | _texgen->setMode(osg::TexGen::EYE_LINEAR); |
| | 292 | _texgen->setPlanesFromMatrix(MVPT); |
| | 293 | } |