osg指南针怎么绘制代码
时间: 2024-05-31 08:15:08 浏览: 93
osg::Geode *createCompass()
{
osg::ref_ptr<osg::Geometry> compassGeometry = new osg::Geometry();
osg::ref_ptr<osg::Vec3Array> compassVertices = new osg::Vec3Array();
compassVertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
compassVertices->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
compassVertices->push_back(osg::Vec3(0.0f, 0.5f, -0.95f));
compassVertices->push_back(osg::Vec3(0.0f, -0.5f, -0.95f));
compassVertices->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
compassVertices->push_back(osg::Vec3(0.5f, 0.0f, -0.95f));
compassVertices->push_back(osg::Vec3(-0.5f, 0.0f, -0.95f));
compassGeometry->setVertexArray(compassVertices.get());
osg::ref_ptr<osg::DrawArrays> compassPrimitive = new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0, compassVertices->size());
compassGeometry->addPrimitiveSet(compassPrimitive.get());
osg::ref_ptr<osg::Geode> compassNode = new osg::Geode();
compassNode->addDrawable(compassGeometry.get());
return compassNode.release();
}
// 创建osgViewer::Viewer对象
osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer();
// 创建根节点,添加指南针节点
osg::ref_ptr<osg::Group> root = new osg::Group();
root->addChild(createCompass());
// 设置场景数据
viewer->setSceneData(root.get());
// 运行查看器
viewer->run();
阅读全文