|
osg::Node* createHUD()
{
osg::ref_ptr<osg::Geode> geode=new osg::Geode;
osg::ref_ptr<osg::Geometry> geom=new osg::Geometry;
geode->addDrawable(geom.get());
//申请定点
osg::ref_ptr<osg::Vec3Array> coords=new osg::Vec3Array;
//申请颜色
osg::ref_ptr<osg::Vec4Array> colors=new osg::Vec4Array;
//申请法向量
osg::ref_ptr<osg::Vec3Array> norms=new osg::Vec3Array;
//打开透明度
geode->getOrCreateStateSet()->setMode(GL_BLEND,osg::StateAttribute::ON);
//设置定点颜色
geom->setColorArray(colors.get());
geom->setColorBinding(osg::Geometry::AttributeBinding::BIND_OVERALL);
//设置线宽
osg::ref_ptr<osg:ineWidth> width1=new osg::LineWidth;
//设置法向量
geom->setNormalArray(norms.get());
geom->setNormalBinding(osg::Geometry::AttributeBinding::BIND_OVERALL);
//压入法向量
norms->push_back(osg::Vec3(0.0,-1.0,0.0));
//设置线宽
width1->setWidth(5.0);
geom->getOrCreateStateSet()->setAttributeAndModes(width1.get(),osg::StateAttribute::ON);
//设置定点
geom->setVertexArray(coords.get());
geom->addPrimitiveSet(new osg:rawArrays(osg:rimitiveSet::Mode::LINE_STRIP,0,2));//LINE_STRIP
coords->push_back(osg::Vec3(0,0,0));
coords->push_back(osg::Vec3(1000,0,1000));
//coords->push_back(osg::Vec3(1000,0,600));
//coords->push_back(osg::Vec3(0,0,-600));
colors->push_back(osg::Vec4f(1.0,1.0,1.0,0.5));
colors->push_back(osg::Vec4f(1.0,1.0,1.0,0.5));
//colors->push_back(osg::Vec4f(1.0,1.0,1.0,0.5));
//colors->push_back(osg::Vec4f(1.0,1.0,1.0,0.5));
//设置相机
osg::Camera* camera = new osg::Camera;
camera->setViewMatrix(osg::Matrix::identity());
camera->setRenderOrder(osg::Camera::POST_RENDER);//渲染顺序
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
camera->setAllowEventFocus(false);
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
//设置透视矩阵
camera->setProjectionMatrix(osg::Matrix:rtho2D(0,1360,0,768));// 1360...768
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
camera->addChild(geode);
return camera;
};
int main( int argc, char **argv )
{
osgViewer::Viewer viewer;
osg::ref_ptr<osg::Node> scene = osgDB::readNodeFile("ceep.ive");
osg::ref_ptr<osg::Group> group = new osg::Group;
group->addChild(scene);
//if (scene.valid())group->addChild(scene.get());
group->addChild(createHUD());
viewer.setSceneData(group.get());
viewer.realize();
viewer.run() ;
return 0;
} |
|