|
我画了一个矩形 并用纹理贴上一个场景俯视图 最后用从相机使它显示在屏幕左下角。
然后我想在这个俯视图里标记出当前视点的位置 也就是鹰眼的的一种实现。
我用的方法是 就是添加一个子相机 往里添加了一个PositionAttitudeTransform节点来标记视点位置的。昨天我写的例子里从摄像机没使用贴图而使用采用俯视能看到视点的位置的。而将它改为纹理贴图的方式就无法显看到那个视点的位置了
我认为应该是被那个从摄像机给覆盖的缘故 请问该如何修改?
我写的代码如下:- osg::Camera* createSkyLook()
- {
- osg::Camera* camera = new osg::Camera;
- camera->setClearColor(osg::Vec4(0.1f,0.1f,0.3f,1.0f));
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- camera->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- camera->setRenderOrder(osg::Camera::POST_RENDER);
- camera->setProjectionMatrix(osg::Matrix::ortho2D(-128,128,-128,128));
- camera->setViewport(0,0,256,256);
- //以下是画一个矩形 并贴上俯视图
- osg::ref_ptr<osg::Geode> upGeode=new osg::Geode;
- camera->addChild(upGeode.get());
- osg::ref_ptr<osg::Geometry> backGeom=new osg::Geometry;
- upGeode->addDrawable(backGeom.get());
- osg::Vec3Array* vert=new osg::Vec3Array;
- vert->push_back(osg::Vec3(-128.,-128.,0.));
- vert->push_back(osg::Vec3(128.,-128.,0.));
- vert->push_back(osg::Vec3(128.,128.,0.));
- vert->push_back(osg::Vec3(-128.,128.,0.));
- backGeom->setVertexArray(vert);
- osg::Vec4Array* color=new osg::Vec4Array;
- backGeom->setColorBinding(osg::Geometry::BIND_OVERALL);
- backGeom->setColorArray(color);
- color->push_back(osg::Vec4(1.0,1.0,1.0,1.0));
- osg::Vec3Array* normal=new osg::Vec3Array;
- backGeom->setNormalBinding(osg::Geometry::BIND_OVERALL);
- backGeom->setNormalArray(normal);
- normal->push_back(osg::Vec3(0.,1.,0.0));
- backGeom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4 ));
- osg::Vec2Array* texcoords = new osg::Vec2Array(4);
- (*texcoords)[0].set(0.0f,0.0f);
- (*texcoords)[1].set(1.0f,0.0f);
- (*texcoords)[2].set(1.0f,1.0f);
- (*texcoords)[3].set(0.0f,1.0f);
- backGeom->setTexCoordArray(0,texcoords);
- backGeom->setDataVariance(osg::Object::DYNAMIC);
- osg::Texture2D* texture=new osg::Texture2D();
- texture->setDataVariance(osg::Object::DYNAMIC);
- texture->setImage(osgDB::readImageFile("a.bmp"));
- osg::StateSet* state=backGeom->getOrCreateStateSet();
- state->setRenderBinDetails(11,"DepthSortedBin");
- state->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
- state->setMode(GL_BLEND,osg::StateAttribute::ON);
- state->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF);
- state->setRenderingHint( osg::StateSet::TRANSPARENT_BIN );
- state->setTextureAttributeAndModes(0,texture,osg::StateAttribute::ON);
- return camera;
- }
- osg::Camera* createHUD2()
- {
- osg::Camera* camera = new osg::Camera;
- camera->setProjectionMatrix(osg::Matrix::ortho2D(-5,5,-4,4));
- camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- camera->setClearMask(GL_DEPTH_BUFFER_BIT);
- camera->setRenderOrder(osg::Camera::POST_RENDER);
- camera->setViewport(0,0,256,256);
- return camera;
- }
- int main()
- {
- //root是小场景
- osg::ref_ptr<osg::Group> root=create();
- osgViewer::Viewer viewer;
- viewer.setUpViewAcrossAllScreens();
- osgViewer::Viewer::Windows windows;
- osg::ref_ptr<PlayerState> player = new PlayerState(osg::Vec3(0,0,0));
- //这个是我写的漫游控制器
- WalkManipulator* walk=new WalkManipulator(player.get());
- viewer.setCameraManipulator(walk);
- viewer.setSceneData(root.get());
- //加入从相机 显示俯视图
- osg::Camera* skyup=createSkyLook();
- viewer.getWindows(windows);
- skyup->setGraphicsContext(windows[0]);
- viewer.addSlave(skyup, false);
- osg::ref_ptr<osg::Camera> node=createHUD2();
- osg::ref_ptr<osg::PositionAttitudeTransform> pat = new osg::PositionAttitudeTransform;
- osg::ref_ptr<osg::Geode> subgeode = dynamic_cast<osg::Geode*>( osgDB::readNodeFile( "Simple.osg"));
- pat->addChild( subgeode.get() );
- PlayerCallback* cal=new PlayerCallback(player.get(), pat.get());
- pat->setEventCallback( cal );
- node->addChild(pat.get());
- //加入一个子相机
- root->addChild( node.get());
- while(!viewer.done())
- {
- viewer.frame();
- }
- }
复制代码
[ 本帖最后由 acmiyou 于 2009-6-7 20:25 编辑 ] |
|