|
- #include <osgDB/ReadFile>
- #include <osg/Texture2D>
- #include <osgViewer/Viewer>
- #include <osg/ShapeDrawable>
- #ifdef _DEBUG
- #pragma comment(lib,"osgGAd.lib")
- #pragma comment(lib,"osgViewerd.lib")
- #pragma comment(lib,"osgDBd.lib")
- #pragma comment(lib,"OpenThreadsd.lib")
- #pragma comment(lib,"osgd.lib")
- #pragma comment(lib,"osgUtild.lib")
- #else
- #pragma comment(lib,"osgGA.lib")
- #pragma comment(lib,"osgViewer.lib")
- #pragma comment(lib,"osgDB.lib")
- #pragma comment(lib,"OpenThreads.lib")
- #pragma comment(lib,"osg.lib")
- #pragma comment(lib,"osgUtil.lib")
- #pragma comment(lib,"osgText.lib")
- #pragma comment(lib,"Winmm.lib")
- #endif
- int main()
- {
- osgViewer::Viewer *viewer = new osgViewer::Viewer;
- {
- osg::Camera *c = new osg::Camera;
- c->setViewport(0,0,800,600);
- c->setViewMatrixAsLookAt(osg::Vec3(0,0,0),osg::Vec3(0,0,-1),osg::Vec3(0,1,0));
- c->setProjectionMatrixAsOrtho(0,800,0,600,-5,5);
- c->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
- c->setRenderOrder(osg::Camera::POST_RENDER);
- osg::Geode *bg = new osg::Geode;
- bg->addDrawable(new osg::ShapeDrawable( new osg::Box(osg::Vec3(100,600/2,-1),20,40,1) ) );
- bg->addDrawable(new osg::ShapeDrawable( new osg::Box(osg::Vec3(300,600/2,0),50,50,1) ) );
- bg->addDrawable(new osg::ShapeDrawable( new osg::Box(osg::Vec3(500,600/2,1),100,50,1) ) );
- c->addChild(bg);
- viewer->setSceneData(c);
- }
- while (!viewer->done())
- {
- viewer->frame();
- }
- return 0;
- }
复制代码
第三个osg::Box死活要修改ViewMatrix,让视点再后退一点才行。在测试中发现应该是osg需要顶点位于镜头前面才能进行显示。
但是按照opengl的定义,代码里面这个默认的ViewMatrix加上(0,800,0,600,-5,5)的ortho已经足以显示z坐标位于(-5,5)之间的顶点。
第三个Box明显应该能显示出来才对。
what happened? 哪位大神能测试,给个解释? |
|