//得到模型的包围盒
osg::BoundingBox bb;
bb.expandBy(positioned->getBound());
//将模型的中心点移动到原点
double xMid = (bb.xMin() + bb.xMax())/2;
double yMid = (bb.yMin() + bb.yMax())/2;
double zMid = (bb.zMin() + bb.zMax())/2;
double radius = bb.radius();
positioned->setMatrix(osg::Matrix::translate(-xMid,-yMid,-zMid));
viewer.setSceneData(positioned.get());
//关闭自动计算远近裁减面
viewer.getCamera()->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
//设置窗口大小
viewer.setUpViewInWindow( 100,100,512,512);
//设置裁减区域
viewer.getCamera()->setProjectionMatrixAsOrtho(bb.xMin(),bb.xMax(),bb.yMin(),
bb.yMax(),1,100+abs(bb.zMax() - bb.zMin()));
王韬 <[EMAIL PROTECTED]> 写道:
Hi all.
I want to set maincamera to a 2D orthographic projection. I do like this
int main( int argc, char **argv )
{
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osg");
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild(loadedModel.get());
viewer.setSceneData(root.get());
#if 1
osg::Matrix matrix;
matrix.makeLookAt(osg::Vec3(0.0,-20.0,0.0),osg::Vec3(0.0,0.0,0.0),osg::Vec3(0.0,0.0,1.0));
viewer.getCamera()->setViewMatrix(matrix);
// viewer.getCamera()->setProjectionMatrixAsPerspective( 60., 1., 1., 100.
);//this OK
viewer.getCamera()->setProjectionMatrixAsOrtho2D(0,1024,0,800);
while(!viewer.done())
{
viewer.frame();
}
return 0;
#else
return viewer.run();
#endif
}
but I can't see anything.who can help me? thanks.
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
---------------------------------
雅虎邮箱,您的终生邮箱!_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org