|
发表于 2013-8-9 13:25:04
|
显示全部楼层
本帖最后由 VR_user_happy 于 2013-8-9 13:31 编辑
//创建HUD相机
osg::ref_ptr<osg::Camera> pHUDcamera = new osg::Camera;
pHUDcamera->setClearMask( GL_DEPTH_BUFFER_BIT );
pHUDcamera->setRenderOrder(osg::Camera:: POST_RENDER );
pHUDcamera->setReferenceFrame( osg::Camera::ABSOLUTE_RF );
//设置相交的视点
pHUDcamera->setViewMatrixAsLookAt(osg::Vec3(0.0f,-100.0f,0.0f), osg::Vec3(0.0,-99.0,0.0), osg::Vec3(0.0f,0.0f,1.0f));
double dFovy,dR,dNear,dFar;
//设置相交的镜头视锥体
//得到主摄像机的视锥参数---m_Viewer为主视图对象指针
m_Viewer->getCamera()->getProjectionMatrixAsPerspective(dFovy,dR,dNear,dFar);
pHUDcamera->setProjectionMatrixAsPerspective(dFovy,dR,dNear,dFar);
// 初始化根节点
osg::Group* root = new osg::Group();
// 设置HUD 文字的参数
string sFontsPath="C:\\WINDOWS\\Fonts\\";
string sFontsName="SIMFANG.TTF";
osg::Geode* HUDGeode2 = new osg::Geode();
osgText::Text* textTWO = new osgText::Text();
sFontsName=sFontsPath+sFontsName;
textTWO->setFont(sFontsName);
textTWO->setText(L"钓客笑傲江湖!");
textTWO->setAxisAlignment(osgText::Text::SCREEN);
textTWO->setPosition(osg::Vec3(-120.0, 165, -1.47));
textTWO->setColor(osg::Vec4(199, 77, 15, 1));
osg::ref_ptr<osg::Group> pTxtGrp=new osg::Group;
pTxtGrp->addChild(HUDGeode2);
HUDGeode2->addDrawable(textTWO);
pHUDcamera->addChild(pTxtGrp);
//
root->addChild(pHUDcamera.get()); |
|