OSG相机相当于视角,也就是观看模型的视角,每个在三维系统中都会有一个默认的相机也就是默认的视角:
osg::Camare的默认朝姿态:
位置在 0,0,0
姿态是:向下看(Z轴负向 0,0,-1)
头向前(Y轴正向 0,1,0,也就是说相机是正着的)
void setCamera() {
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
viewer->addEventHandler(new osgViewer::WindowSizeHandler());
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
//获取模型的包围球
osg::ref_ptr<osg::Node> n1 = osgDB::readNodeFile("cow.osgt");
osg::BoundingSphere bound = n1->getBound();
//设置相机的投影矩阵
double viewDis = bound.radius()*2.0;
double zNear = viewDis - bound.radius();
double zFar = viewDis + bound.radius();
double left = -bound.radius();
double right = bound.radius();
double top = bound.radius();
double bottom = -bound.radius();
camera->setProjectionMatrixAsOrtho(left, right, bottom, top, zNear, zFar);
//设置观察矩阵
osg::Vec3d up(0.0, 1.0, 0.0);
osg::Vec3d center = bound.center();
osg::Vec3d view(0.0, 0.0, 1.0);
osg::Vec3d eye(0.0, -50.0, 0.0);
camera->setViewMatrixAsLookAt(eye, center, up);
camera->addChild(n1.get());
viewer->setSceneData(camera.get());
viewer->run();
}