|
发表于 2010-4-14 14:02:15
|
显示全部楼层
21# array
int main( int argc, char **argv )
{
//pointers to the root node and the tank model node
osg::ref_ptr<osg::Group> rootNode;
osg::ref_ptr<osg::Group> ownTank;
///osg::ref_ptr<osg::Node> scene;
// build scene with terrain and two tanks
if (!setupScene(rootNode, ownTank))
{
std::cout<< "problem setting up scene" << std::endl;
return -1;
}
// Declare a transform for a position above and behind the tank
// aimed down slightly. Add this transform to the tank node.
osg:ositionAttitudeTransform * followerOffset =
new osg::PositionAttitudeTransform();
followerOffset->setPosition( osg::Vec3(0.0,-25.0,10) );
followerOffset->setAttitude(
osg:uat( osg:egreesToRadians(-15.0), osg::Vec3(1,0,0) ) );
ownTank.get()->addChild(followerOffset);
// Declare a transform accumulator to be used to position a
// camera. Attach transform accumulator to the follower transform.
transformAccumulator* tankFollowerWorldCoords =
new transformAccumulator();
tankFollowerWorldCoords->attachToGroup(followerOffset);
//构建视口类,以及与其相关的图形设备类。
osgViewer::Viewer viewer;
osg::GraphicsContext::WindowingSystemInterface* wsi =
osg::GraphicsContext::getWindowingSystemInterface();
if (!wsi)
{
osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
return 1;
}
unsigned int width, height;
wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);
osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
traits->x = 100;
traits->y = 100;
traits->width = width;
traits->height = height;
traits->windowDecoration = true;
traits->doubleBuffer = true;
traits->sharedContext = 0;
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
if (gc.valid())
{
osg::notify(osg::INFO)<<" GraphicsWindow has been created successfully."<<std::endl;
gc->setClearColor(osg::Vec4f(0.2f,0.2f,0.6f,1.0f));
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
else
{
osg::notify(osg::NOTICE)<<" GraphicsWindow has not been created successfully."<<std::endl;
}
//设置mainCamera的视口参数
osg::Camera* mainCamera = new osg::Camera;
mainCamera->setGraphicsContext(gc.get());
mainCamera->setViewport(0, 0, traits->width/2, traits->height);
mainCamera->addChild( rootNode.get() );
//设置tankFollowCamera的视口参数
osg::Camera* tankFollowerCamera = new osg::Camera;
tankFollowerCamera->setGraphicsContext(gc.get());
tankFollowerCamera->setViewport(traits->width/2, 0, traits->width, traits->height);
tankFollowerCamera->setViewMatrix(tankFollowerWorldCoords->getMatrix()*osg::Matrix::rotate( -3.1415926/2.0, 1, 0, 0 ));
tankFollowerCamera->addChild( rootNode.get() );
viewer.addSlave(mainCamera, true);
viewer.addSlave(tankFollowerCamera, true);
viewer.setSceneData( rootNode.get() );
//osgGA::TrackballManipulator *Tman = new osgGA::TrackballManipulator();
viewer.setCameraManipulator(NULL);
viewer.realize();
while( !viewer.done() )
{
//是不是因为使用的是同一个漫游器,所以摄像机的设置不起作用了?
tankFollowerCamera->setViewMatrix(tankFollowerWorldCoords->getMatrix()
*osg::Matrix::rotate( -3.1415926/2.0, 1, 0, 0 ));
viewer.frame();
}
}
但是我不知道为什么这样设置后却什么也看不到?而我如果用compesiteView 通过加入两个view 却可以看到两个窗口不同的场景。 |
|