|
如下代码怎么在视口中看不见模型
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
int main( int argc, char** argv )
{
osg::ArgumentParser arguments( &argc, argv );
osg::Node* model = osgDB::readNodeFiles( arguments );
if ( !model ) model = osgDB::readNodeFile( "axes.osg" );
model->getOrCreateStateSet()->setMode( GL_LIGHTING,osg::StateAttribute::OFF );
int texWidth = 512, texHeight = 512;
osg::ref_ptr<osg::Camera> rttCamera = new osg::Camera;
rttCamera->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0));
rttCamera->setViewport( 0, 0, texWidth, texHeight );
osg::BoundingSphere bs = model->getBound();
double viewDistance = 2.0 * bs.radius();
double znear = viewDistance - bs.radius();
double zfar = viewDistance + bs.radius();
float top = 0.6 * znear;
float right = 0.8 * znear;
rttCamera->setProjectionMatrixAsFrustum( -right, right, -top, top, znear, zfar );
osg::Vec3d upDirection( 0.0,0.0,1.0 );
osg::Vec3d viewDirection( 0.0,-1.0,0.0 );
osg::Vec3d center = bs.center();
osg::Vec3d eyePoint = center + viewDirection * viewDistance;
rttCamera->setViewMatrixAsLookAt( eyePoint, center, upDirection );
rttCamera->addChild( model );
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( rttCamera );
osgViewer::Viewer viewer;
viewer.setSceneData( root.get());
return viewer.run();
} |
|