|
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osg/Node>
#include <osg/Camera>
int
main()
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
camera->setClearColor(osg::Vec4(1,1,1,1));
osg::ref_ptr<osg::Node> node = new osg::Node();
node = osgDB::readNodeFile("cow.osg");
camera->addChild(node);
viewer.setSceneData(camera);
if (!viewer.getSceneData())
{
osg::notify( osg::FATAL ) << "Unable to load data file. Exiting." << std::endl;
return 1;
}
camera->setProjectionMatrixAsPerspective(40,1,1,100);
camera->setViewMatrixAsLookAt(osg::Vec3(0,0,0),osg::Vec3(0,0,-1),osg::Vec3(0,1,0));
camera->setViewport(0,0,800,800);
//创建矩阵,指定到视点的距离
osg::Matrix trans;
trans.makeTranslate(0,0,-10);
//旋转角度
double angle = 0.0;
while (!viewer.done())
{
//创建旋转矩阵
osg::Matrix rot;
rot.makeRotate(angle,osg::Vec3(1,0,0));
angle += 0.01;
//设置视口矩阵
camera->setViewMatrix(rot * trans);
//绘制下一帧
viewer.frame();
}
return 0;
}
为什么读取的模型显示不出来 |
|