查看: 1449|回复: 2

困扰很久的osgcamera问题

[复制链接]

该用户从未签到

发表于 2010-5-25 14:41:12 | 显示全部楼层 |阅读模式
如下代码怎么在视口中看不见模型
#include <osg/Texture2D>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
int main( int argc, char** argv )
{
osg::ArgumentParser arguments( &argc, argv );
osg::Node* model = osgDB::readNodeFiles( arguments );
if ( !model ) model = osgDB::readNodeFile( "axes.osg" );
model->getOrCreateStateSet()->setMode( GL_LIGHTING,osg::StateAttribute::OFF );
int texWidth = 512, texHeight = 512;
osg::ref_ptr<osg::Camera> rttCamera = new osg::Camera;
rttCamera->setClearColor(osg::Vec4(0.0,0.0,0.0,1.0));
rttCamera->setViewport( 0, 0, texWidth, texHeight );
osg::BoundingSphere bs = model->getBound();
double viewDistance = 2.0 * bs.radius();
double znear = viewDistance - bs.radius();
double zfar = viewDistance + bs.radius();
float top = 0.6 * znear;
float right = 0.8 * znear;
rttCamera->setProjectionMatrixAsFrustum( -right, right, -top, top, znear, zfar );
osg::Vec3d upDirection( 0.0,0.0,1.0 );
osg::Vec3d viewDirection( 0.0,-1.0,0.0 );
osg::Vec3d center = bs.center();
osg::Vec3d eyePoint = center + viewDirection * viewDistance;
rttCamera->setViewMatrixAsLookAt( eyePoint, center, upDirection );
rttCamera->addChild( model );

osg::ref_ptr<osg::Group> root = new osg::Group;
root->addChild( rttCamera );
osgViewer::Viewer viewer;
viewer.setSceneData( root.get());
return viewer.run();
}

该用户从未签到

发表于 2010-5-25 16:47:14 | 显示全部楼层
double viewDistance = 2.0 * bs.radius();
double znear = viewDistance - bs.radius();
double zfar = viewDistance + bs.radius();
float top = 0.6 * znear;
float right = 0.8 * znear;
rttCamera->setProjectionMatrixAsFrustum( -right, right, -top, top, znear, zfar );
我想您需要再好好检视一下这段代码,我个人觉得这里面的计算方法存在不少问题

该用户从未签到

 楼主| 发表于 2010-5-25 21:45:05 | 显示全部楼层
终于弄清楚了貌似要设置
rttCamera->setReferenceFrame(osg::Camera::ABSOLUTE_RF);
才行
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表