博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
osg 在场景中绘制坐标轴(xyz)
阅读量:5042 次
发布时间:2019-06-12

本文共 2845 字,大约阅读时间需要 9 分钟。

//x y z font_sizeosg::Geode* makeCoordinate(float a_x,float a_y,float a_z,float font_size){    osg::ref_ptr
pSphereShape = new osg::Sphere(osg::Vec3(0, 0, 0), 1.0f); osg::ref_ptr
pShapeDrawable = new osg::ShapeDrawable(pSphereShape.get()); pShapeDrawable->setColor(osg::Vec4(0.0, 0.0, 0.0, 1.0)); //创建保存几何信息的对象 osg::ref_ptr
geom = new osg::Geometry(); //创建四个顶点 osg::ref_ptr
v = new osg::Vec3Array(); v->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); v->push_back(osg::Vec3(a_x, 0.0f, 0.0f)); v->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); v->push_back(osg::Vec3(0.0f, a_y, 0.0f)); v->push_back(osg::Vec3(0.0f, 0.0f, 0.0f)); v->push_back(osg::Vec3(0.0f, 0.0f, a_z)); geom->setVertexArray(v.get()); osg::ref_ptr
c = new osg::Vec4Array(); c->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); c->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f)); c->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); c->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f)); c->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); c->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f)); geom->setColorArray(c.get()); geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); //xyz geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 0, 2)); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 2, 2)); geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES, 4, 2)); osg::ref_ptr
pTextXAuxis1 = new osgText::Text; pTextXAuxis1->setText(L"X"); pTextXAuxis1->setFont("Fonts/simhei.ttf"); pTextXAuxis1->setAxisAlignment(osgText::Text::SCREEN); pTextXAuxis1->setCharacterSize(font_size); pTextXAuxis1->setPosition(osg::Vec3(a_x, 0.0f, 0.0f)); osg::ref_ptr
pTextYAuxis1 = new osgText::Text; pTextYAuxis1->setText(L"Y"); pTextYAuxis1->setFont("Fonts/simhei.ttf"); pTextYAuxis1->setAxisAlignment(osgText::Text::SCREEN); pTextYAuxis1->setCharacterSize(font_size); pTextYAuxis1->setPosition(osg::Vec3(0.0f, a_y, 0.0f)); osg::ref_ptr
pTextZAuxis1 = new osgText::Text; pTextZAuxis1->setText(L"Z"); pTextZAuxis1->setFont("Fonts/simhei.ttf"); pTextZAuxis1->setAxisAlignment(osgText::Text::SCREEN); pTextZAuxis1->setCharacterSize(font_size); pTextZAuxis1->setPosition(osg::Vec3(0.0f, 0.0f, a_z)); osg::ref_ptr
geode = new osg::Geode(); geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); geode->getOrCreateStateSet()->setAttribute(new osg::LineWidth(3.0), osg::StateAttribute::ON); geode->addDrawable(pShapeDrawable.get()); geode->addDrawable(geom.get()); geode->addDrawable(pTextXAuxis1.get()); geode->addDrawable(pTextYAuxis1.get()); geode->addDrawable(pTextZAuxis1.get()); return geode.release(); }

 

效果图片:

 

 

 

参考:https://blog.csdn.net/sun222555888/article/details/52083413

 

转载于:https://www.cnblogs.com/herd/p/11150548.html

你可能感兴趣的文章
oracle导出/导入 expdp/impdp
查看>>
类指针
查看>>
css修改滚动条样式
查看>>
2018.11.15 Nginx服务器的使用
查看>>
Kinect人机交互开发实践
查看>>
百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET...
查看>>
JAVA 技术类分享(二)
查看>>
android客户端向服务器发送请求中文乱码的问
查看>>
Symfony翻译教程已开课
查看>>
TensorFlow2.0矩阵与向量的加减乘
查看>>
NOIP 2010题解
查看>>
javascript中的each遍历
查看>>
String中各方法多数情况下返回新的String对象
查看>>
浅谈tcp粘包问题
查看>>
UVA11524构造系数数组+高斯消元解异或方程组
查看>>
排序系列之——冒泡排序、插入排序、选择排序
查看>>
爬虫基础
查看>>
jquery.lazyload延迟加载图片第一屏问题
查看>>
HDU 1011 Starship Troopers (树形DP)
查看>>
手把手教你写DI_1_DI框架有什么?
查看>>