#include <OSGSkyBackground.h>
Inheritance diagram for osg::SkyBackground:

The sky is defined by the _mfSkyAngle and _mfSkyColor fields, the ground by the _mfGroundAngle and _mfGround Color fields. The resolution of the sky sphere can be influenced by the _sfSphereRes field. The sky box is defined by the _sfBackTexture, _sfFrontTexture, _sfLeftTexture, _sfRightTexture, _sfTopTexture and _sfBottomTexture fields.
Definition at line 58 of file OSGSkyBackground.h.
|
|
Reimplemented from osg::SkyBackgroundBase. Definition at line 62 of file OSGSkyBackground.h. |
|
|
Reimplemented from osg::BackgroundBase. Definition at line 107 of file OSGSkyBackgroundBase.h. |
|
|
Reimplemented from osg::AttachmentContainer. Definition at line 109 of file OSGSkyBackgroundBase.h. 00110 { 00111 SkyColorFieldId = Inherited::NextFieldId, 00112 SkyAngleFieldId = SkyColorFieldId + 1, 00113 GroundColorFieldId = SkyAngleFieldId + 1, 00114 GroundAngleFieldId = GroundColorFieldId + 1, 00115 SphereResFieldId = GroundAngleFieldId + 1, 00116 BackTextureFieldId = SphereResFieldId + 1, 00117 BottomTextureFieldId = BackTextureFieldId + 1, 00118 FrontTextureFieldId = BottomTextureFieldId + 1, 00119 LeftTextureFieldId = FrontTextureFieldId + 1, 00120 RightTextureFieldId = LeftTextureFieldId + 1, 00121 TopTextureFieldId = RightTextureFieldId + 1, 00122 BoxInsideFieldId = TopTextureFieldId + 1, 00123 TopTexCoordFieldId = BoxInsideFieldId + 1, 00124 BottomTexCoordFieldId = TopTexCoordFieldId + 1, 00125 RightTexCoordFieldId = BottomTexCoordFieldId + 1, 00126 LeftTexCoordFieldId = RightTexCoordFieldId + 1, 00127 FrontTexCoordFieldId = LeftTexCoordFieldId + 1, 00128 BackTexCoordFieldId = FrontTexCoordFieldId + 1, 00129 NextFieldId = BackTexCoordFieldId + 1 00130 };
|
|
|
Definition at line 80 of file OSGSkyBackground.cpp. 00080 : 00081 Inherited() 00082 { 00083 }
|
|
|
Definition at line 85 of file OSGSkyBackground.cpp. 00085 : 00086 Inherited(source) 00087 { 00088 }
|
|
|
Definition at line 90 of file OSGSkyBackground.cpp.
|
|
||||||||||||
|
Reimplemented from osg::Background. Definition at line 100 of file OSGSkyBackground.cpp. References osg::Background::changed(). 00101 { 00102 Inherited::changed(whichField, origin); 00103 }
|
|
||||||||||||
|
Implements osg::Background. Definition at line 164 of file OSGSkyBackground.cpp. References osg::SkyBackgroundBase::_mfGroundAngle, osg::SkyBackgroundBase::_mfGroundColor, osg::SkyBackgroundBase::_mfSkyAngle, osg::SkyBackgroundBase::_mfSkyColor, osg::SkyBackgroundBase::_sfSphereRes, osg::StateChunk::deactivate(), drawFace(), osg::Eps, osg::SkyBackgroundBase::getBackTexCoord(), osg::SkyBackgroundBase::getBackTexture(), osg::SkyBackgroundBase::getBottomTexCoord(), osg::SkyBackgroundBase::getBottomTexture(), osg::DrawActionBase::getCamera(), osg::CameraBase::getFar(), osg::SkyBackgroundBase::getFrontTexCoord(), osg::SkyBackgroundBase::getFrontTexture(), osg::SkyBackgroundBase::getLeftTexCoord(), osg::SkyBackgroundBase::getLeftTexture(), osg::CameraBase::getNear(), osg::Viewport::getPixelHeight(), osg::Viewport::getPixelWidth(), osg::Camera::getProjection(), osg::Camera::getProjectionTranslation(), osg::SkyBackgroundBase::getRightTexCoord(), osg::SkyBackgroundBase::getRightTexture(), osg::SkyBackgroundBase::getTopTexCoord(), osg::SkyBackgroundBase::getTopTexture(), osg::SField< FieldTypeT, fieldNameSpace >::getValue(), osg::TransformationMatrix< ValueTypeT >::getValues(), osg::Color4< ValueTypeT >::getValuesRGBA(), osg::Camera::getViewing(), GLboolean, osg::TransformationMatrix< ValueTypeT >::multLeft(), osg::osgabs(), osg::osgcos(), osg::osgsin(), osg::Pi, osg::MField< FieldTypeT, fieldNameSpace >::size(), and tfac. 00165 { 00166 GLboolean light = glIsEnabled(GL_LIGHTING); 00167 00168 if (light == GL_TRUE) 00169 glDisable(GL_LIGHTING); 00170 00171 GLint fill[2]; 00172 glGetIntegerv(GL_POLYGON_MODE, fill); 00173 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00174 00175 GLint depth; 00176 glGetIntegerv(GL_DEPTH_FUNC, &depth); 00177 glDepthFunc(GL_ALWAYS); 00178 00179 glMatrixMode(GL_MODELVIEW); 00180 glPushMatrix(); 00181 00182 Matrix m,pt; 00183 action->getCamera()->getViewing(m, viewport->getPixelWidth(), 00184 viewport->getPixelHeight()); 00185 action->getCamera()->getProjectionTranslation(pt, 00186 viewport->getPixelWidth(), 00187 viewport->getPixelHeight()); 00188 m.multLeft(pt); 00189 00190 m[3][0] = m[3][1] = m[3][2] = 0; 00191 glLoadMatrixf(m.getValues()); 00192 Real32 viewscale = (m[0].length() + m[1].length() + m[2].length()) / 3.f; 00193 float scale = (action->getCamera()->getFar() + 00194 action->getCamera()->getNear()) / 2 / viewscale; 00195 glScalef(scale, scale, scale); 00196 00197 glMatrixMode(GL_PROJECTION); 00198 glPushMatrix(); 00199 00200 action->getCamera()->getProjection(m, viewport->getPixelWidth(), 00201 viewport->getPixelHeight()); 00202 glLoadMatrixf(m.getValues()); 00203 00204 UInt32 i, j; 00205 UInt32 sr = _sfSphereRes.getValue() + 1; // sphere resolution 00206 00207 // These should be stored somewhere, not recalced. 00208 Real32 *cosval = new Real32 [ sr ]; 00209 Real32 *sinval = new Real32 [ sr ]; 00210 00211 Real32 vcos1,vsin1,vcos2,vsin2; 00212 00213 Real32 da = 2 * Pi / (sr - 1); 00214 for(i = 0; i < sr; ++i) 00215 { 00216 cosval[i] = osgcos(i * da); 00217 sinval[i] = osgsin(i * da); 00218 } 00219 00220 if(_mfSkyAngle.size() > 0) 00221 { 00222 vcos1 = osgcos(_mfSkyAngle[0]); 00223 vsin1 = osgsin(_mfSkyAngle[0]); 00224 00225 glBegin(GL_TRIANGLE_FAN); 00226 glColor4fv((GLfloat*) _mfSkyColor[0].getValuesRGBA()); 00227 glVertex3f(0, 1, 0); 00228 glColor4fv((GLfloat*) _mfSkyColor[1].getValuesRGBA()); 00229 00230 for(i = 0; i < sr; ++i) 00231 { 00232 glVertex3f(vsin1 * sinval[i], vcos1, vsin1 * cosval[i]); 00233 } 00234 00235 glEnd(); 00236 00237 00238 for(j = 0; j < _mfSkyAngle.size() - 1; ++j) 00239 { 00240 Color4f c1, c2; 00241 00242 c1 = _mfSkyColor[j+1]; 00243 c2 = _mfSkyColor[j+2]; 00244 00245 vcos1 = osgcos(_mfSkyAngle[j ]); 00246 vsin1 = osgsin(_mfSkyAngle[j ]); 00247 vcos2 = osgcos(_mfSkyAngle[j+1]); 00248 vsin2 = osgsin(_mfSkyAngle[j+1]); 00249 00250 glBegin(GL_TRIANGLE_STRIP); 00251 00252 for(i = 0; i < sr; ++i) 00253 { 00254 glColor4fv((GLfloat*) c1.getValuesRGBA()); 00255 glVertex3f(vsin1 * sinval[i], vcos1, vsin1 * cosval[i]); 00256 glColor4fv((GLfloat*) c2.getValuesRGBA()); 00257 glVertex3f(vsin2 * sinval[i], vcos2, vsin2 * cosval[i]); 00258 } 00259 glEnd(); 00260 } 00261 00262 if(osgabs(_mfSkyAngle[j] - Pi) > Eps) 00263 { 00264 glBegin(GL_TRIANGLE_FAN); 00265 glColor4fv((GLfloat*) _mfSkyColor[j+1].getValuesRGBA()); 00266 glVertex3f(0, -1, 0); 00267 vcos1 = osgcos(_mfSkyAngle[j]); 00268 vsin1 = osgsin(_mfSkyAngle[j]); 00269 00270 for(i = 0; i < sr; ++i) 00271 { 00272 glVertex3f(vsin1 * sinval[i], vcos1, vsin1 * cosval[i]); 00273 } 00274 00275 glEnd(); 00276 } 00277 } 00278 else // no angles, just fill single color 00279 { 00280 if(_mfSkyColor.size() > 0) 00281 { 00282 glClearColor(_mfSkyColor[0][0], _mfSkyColor[0][1], 00283 _mfSkyColor[0][2], 0); 00284 } 00285 else 00286 { 00287 glClearColor(0, 0, 0, 0); 00288 } 00289 glClear(GL_COLOR_BUFFER_BIT); 00290 } 00291 00292 // Draw the ground. 00293 // It's possible to be smarter about this, but for now just overdraw. 00294 00295 if(_mfGroundAngle.size() > 0) 00296 { 00297 vcos1 = -osgcos(_mfGroundAngle[0]); 00298 vsin1 = osgsin(_mfGroundAngle[0]); 00299 00300 glBegin(GL_TRIANGLE_FAN); 00301 glColor4fv((GLfloat*) _mfGroundColor[0].getValuesRGBA()); 00302 glVertex3f(0, -1, 0); 00303 glColor4fv((GLfloat*) _mfGroundColor[1].getValuesRGBA()); 00304 00305 for(i = 0; i < sr; ++i) 00306 { 00307 glVertex3f(vsin1 * sinval[i], vcos1, vsin1 * cosval[i]); 00308 } 00309 00310 glEnd(); 00311 00312 00313 for(j = 0; j < _mfGroundAngle.size() - 1; ++j) 00314 { 00315 Color4f c1, c2; 00316 00317 c1 = _mfGroundColor[j+1]; 00318 c2 = _mfGroundColor[j+2]; 00319 00320 vcos1 = -osgcos(_mfGroundAngle[j ]); 00321 vsin1 = osgsin(_mfGroundAngle[j ]); 00322 vcos2 = -osgcos(_mfGroundAngle[j+1]); 00323 vsin2 = osgsin(_mfGroundAngle[j+1]); 00324 00325 glBegin(GL_TRIANGLE_STRIP); 00326 00327 for(i = 0; i < sr; ++i) 00328 { 00329 glColor4fv((GLfloat*) c1.getValuesRGBA()); 00330 glVertex3f(vsin1 * sinval[i], vcos1, vsin1 * cosval[i]); 00331 glColor4fv((GLfloat*) c2.getValuesRGBA()); 00332 glVertex3f(vsin2 * sinval[i], vcos2, vsin2 * cosval[i]); 00333 } 00334 glEnd(); 00335 } 00336 } 00337 00338 // now draw the textures, if set 00339 StateChunk *tchunk = NULL; 00340 static Vec3f defaulttc[7][4] = { 00341 // 2D default TCs 00342 { Vec3f(0,0,0), Vec3f(1,0,0), Vec3f(1,1,0), Vec3f(0,1,0) }, 00343 00344 // Cubetex Default TCs 00345 { Vec3f(-1, 1,-1), Vec3f( 1, 1,-1), Vec3f( 1,-1,-1), Vec3f(-1,-1,-1) }, 00346 { Vec3f( 1, 1, 1), Vec3f(-1, 1, 1), Vec3f(-1,-1, 1), Vec3f( 1,-1, 1) }, 00347 { Vec3f( 1, 1,-1), Vec3f(-1, 1,-1), Vec3f(-1, 1, 1), Vec3f( 1, 1, 1) }, 00348 { Vec3f( 1,-1, 1), Vec3f(-1,-1, 1), Vec3f(-1,-1,-1), Vec3f( 1,-1,-1) }, 00349 { Vec3f( 1, 1,-1), Vec3f( 1, 1, 1), Vec3f( 1,-1, 1), Vec3f( 1,-1,-1) }, 00350 { Vec3f(-1, 1, 1), Vec3f(-1, 1,-1), Vec3f(-1,-1,-1), Vec3f(-1,-1, 1) }, 00351 }; 00352 00353 #undef tfac 00354 #define tfac(t,c) \ 00355 defaulttc[(c)*((t) != NullFC && (t)->getImage() != NullFC && \ 00356 (t)->getImage()->getSideCount() == 6)] 00357 00358 drawFace(action, getBackTexture(), tchunk, 00359 Pnt3f(0.5, -0.5, 0.5), 00360 Pnt3f(-0.5, -0.5, 0.5), 00361 Pnt3f(-0.5, 0.5, 0.5), 00362 Pnt3f(0.5, 0.5, 0.5), 00363 getBackTexCoord().size()? 00364 &getBackTexCoord()[0]: 00365 tfac(getBackTexture(), 1)); 00366 00367 drawFace(action, getFrontTexture(), tchunk, 00368 Pnt3f(-0.5, -0.5, -0.5), 00369 Pnt3f(0.5, -0.5, -0.5), 00370 Pnt3f(0.5, 0.5, -0.5), 00371 Pnt3f(-0.5, 0.5, -0.5), 00372 getFrontTexCoord().size()? 00373 &getFrontTexCoord()[0]: 00374 tfac(getFrontTexture(), 2)); 00375 00376 drawFace(action, getBottomTexture(), tchunk, 00377 Pnt3f(-0.5, -0.5, 0.5), 00378 Pnt3f(0.5, -0.5, 0.5), 00379 Pnt3f(0.5, -0.5, -0.5), 00380 Pnt3f(-0.5, -0.5, -0.5), 00381 getBottomTexCoord().size()? 00382 &getBottomTexCoord()[0]: 00383 tfac(getBottomTexture(), 3)); 00384 00385 drawFace(action, getTopTexture(), tchunk, 00386 Pnt3f(-0.5, 0.5, -0.5), 00387 Pnt3f(0.5, 0.5, -0.5), 00388 Pnt3f(0.5, 0.5, 0.5), 00389 Pnt3f(-0.5, 0.5, 0.5), 00390 getTopTexCoord().size()? 00391 &getTopTexCoord()[0]: 00392 tfac(getTopTexture(), 4)); 00393 00394 drawFace(action, getLeftTexture(), tchunk, 00395 Pnt3f(-0.5, -0.5, 0.5), 00396 Pnt3f(-0.5, -0.5, -0.5), 00397 Pnt3f(-0.5, 0.5, -0.5), 00398 Pnt3f(-0.5, 0.5, 0.5), 00399 getLeftTexCoord().size()? 00400 &getLeftTexCoord()[0]: 00401 tfac(getLeftTexture(), 5)); 00402 00403 drawFace(action, getRightTexture(), tchunk, 00404 Pnt3f(0.5, -0.5, -0.5), 00405 Pnt3f(0.5, -0.5, 0.5), 00406 Pnt3f(0.5, 0.5, 0.5), 00407 Pnt3f(0.5, 0.5, -0.5), 00408 getRightTexCoord().size()? 00409 &getRightTexCoord()[0]: 00410 tfac(getRightTexture(), 6)); 00411 #undef tfac 00412 00413 if(tchunk != NULL) 00414 tchunk->deactivate(action); 00415 00416 glClear(GL_DEPTH_BUFFER_BIT); 00417 00418 glPopMatrix(); 00419 glMatrixMode(GL_MODELVIEW); 00420 glPopMatrix(); 00421 00422 glDepthFunc(depth); 00423 glPolygonMode(GL_FRONT, fill[0]); 00424 glPolygonMode(GL_BACK , fill[1]); 00425 if (light == GL_TRUE) 00426 glEnable(GL_LIGHTING); 00427 glColor3f(1.0, 1.0, 1.0); 00428 00429 delete [] sinval; 00430 delete [] cosval; 00431 }
|