|
如何在在main中修改camera的位置
例如:- #include <osgDB/ReadFile>
- #include <osgViewer/Viewer>
- #include <osg/Node>
- #include <osg/MatrixTransform>
- #include <osg/Geometry>
- #include <osg/Camera>
- osg::ref_ptr<osg::Node> createQuad()
- {
- osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
- //首先定义四个点
- osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;
- geom->setVertexArray( v.get() );
- v->push_back( osg::Vec3( -1.f, 0.f, -1.f ) );
- v->push_back( osg::Vec3( 1.f, 0.f, -1.f ) );
- v->push_back( osg::Vec3( 1.f, 0.f, 1.f ) );
- v->push_back( osg::Vec3( -1.f, 0.f, 1.f ) );
- //定义颜色数组
- osg::ref_ptr<osg::Vec4Array> c = new osg::Vec4Array;
- geom->setColorArray( c.get() );
- geom->setColorBinding( osg::Geometry::BIND_PER_VERTEX );
- c->push_back( osg::Vec4( 1.f, 0.f, 0.f, 1.f ) );
- c->push_back( osg::Vec4( 0.f, 1.f, 0.f, 1.f ) );
- c->push_back( osg::Vec4( 0.f, 0.f, 1.f, 1.f ) );
- c->push_back( osg::Vec4( 1.f, 1.f, 1.f, 1.f ) );
- //定义法线
- osg::ref_ptr<osg::Vec3Array> n = new osg::Vec3Array;
- geom->setNormalArray( n.get() );
- geom->setNormalBinding( osg::Geometry::BIND_OVERALL );
- n->push_back( osg::Vec3( 0.f, -1.f, 0.f ) );
- //设置顶点关联方式
- geom->addPrimitiveSet(
- new osg::rawArrays( osg::rimitiveSet::UADS, 0, 4 ) );
- //几何组结点
- osg::ref_ptr<osg::Geode> geode = new osg::Geode;
- geode->addDrawable( geom.get() );
- return geode.get();
- }
- void main()
- {
- osgViewer::Viewer viewer;
- osg::ref_ptr<osg::Node> master=createQuad();
-
- osg::ref_ptr<osg::Group> root=new osg::Group;
- osg::ref_ptr<osg::MatrixTransform> trans=new osg::MatrixTransform;
-
- trans->addChild(master.get());
- root->addChild(trans.get());
- viewer.setSceneData(root.get());
- osg::ref_ptr<osg::Camera> camera=viewer.getCamera();
- osg::Vec3 eye(20.f, 0.f, 10.f);
- osg::Vec3 center(0.f, 0.f, -25.f);
- osg::Vec3 up(0.f, 1.f, 0.f);
- camera->setViewMatrixAsLookAt(eye, center, up);
- viewer.realize();
- viewer.run();
- }
复制代码 虽然我在main里重设了camera的位置
可是程序运行时和没设置时的一样
file:///E:\\2009-04-25_164525.jpg
总是这么个四边形
我试了好久都没有奏效
请Array或者FreeSouth老兄帮个忙
[ 本帖最后由 philips123 于 2009-4-25 17:09 编辑 ] |
|