|
在控制台下,
#include <osg/Camera>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osg/BoundingSphere>
osg::Camera* createBirdsEye( const osg::BoundingSphere& bs )
{
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearMask(/* GL_COLOR_BUFFER_BIT |*/ GL_DEPTH_BUFFER_BIT );
camera->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
double viewDistance = 2.0 * bs.radius();
double znear = viewDistance - bs.radius();
double zfar = viewDistance + bs.radius();
float top = bs.radius();
float right = bs.radius();
camera->setProjectionMatrixAsOrtho( -right, right, -top, top, znear, zfar );
osg::Vec3d upDirection( 0.0,1.0,0.0 );
osg::Vec3d viewDirection( 0.0,0.0,1.0 );
osg::Vec3d center = bs.center();
osg::Vec3d eyePoint = center + viewDirection * viewDistance;;
camera->setViewMatrixAsLookAt( eyePoint, center, upDirection );
return camera.release();
}
int main( int argc, char** argv )
{
osg::ArgumentParser arguments( &argc, argv );
osg::Node* model = osgDB::readNodeFiles( arguments );
if ( !model ) model = osgDB::readNodeFile( "lz.osg" );
osg::ref_ptr<osg::Group>root=new osg::Group;//总根节点
osg::ref_ptr<osg::Group>root1=new osg::Group;//存场景放
root->addChild(root1);
root1->addChild(osgDB::readNodeFile("cow.osg"));
root1->addChild( model );
osg::Camera* camera = createBirdsEye(root1->getBound() );//俯视相机
root->addChild(camera);
camera->addChild(root1);
camera->setViewport(500.0f,400.0f,500,500.0f);
/*camera->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,0.0f));*/
/*root->addChild(model);*/
osgViewer::Viewer viewer;
viewer.setSceneData( root );
return viewer.run();
}
这样就有个俯视图了,但是我现在想加入到MFC中,按照同样的方式,发现不可以。。 |
|