osg如何画网格
来源:互联网 发布:汉中交通网络教学平台 编辑:程序博客网 时间:2024/04/28 11:23
osg画网格只要是通过画线来实现的的,代码的的结构主要在于如何构造图元信息,及相应的顶点信息,将Geometry添加至节点即可实现,代码如下:
osg::ref_ptr<osg::MatrixTransform> transformGrid = new osg::MatrixTransform();osg::Geode *geode = new osg::Geode();osg::Geometry *geom = new osg::Geometry();//构造顶点信息osg::Vec3Array *vertices = new osg::Vec3Array();int i;int num = 10;float rad = 5;vertices->push_back( osg::Vec3(0.0f,-rad,0.0f) );vertices->push_back( osg::Vec3(0.0f, rad,0.0f) );vertices->push_back( osg::Vec3(-rad,0.0f,0.0f) );vertices->push_back( osg::Vec3( rad,0.0f,0.0f) );for (i = 1; i<=num; i++){vertices->push_back( osg::Vec3(i,-rad,0.0f) );vertices->push_back( osg::Vec3(i,rad,0.0f) );vertices->push_back( osg::Vec3(-i,-rad,0.0f) );vertices->push_back( osg::Vec3(-i,rad,0.0f) );vertices->push_back( osg::Vec3(-rad,i,0.0f) );vertices->push_back( osg::Vec3(rad,i,0.0f) );vertices->push_back( osg::Vec3(-rad,-i,0.0f) );vertices->push_back( osg::Vec3(rad,-i,0.0f) );}geom->setVertexArray(vertices);//指定颜色数组osg::Vec4Array* colors = new osg::Vec4Array();colors->push_back( osg::Vec4(.9f,.9f,.9f,1.0f) );colors->push_back( osg::Vec4(.9f,.9f,.9f,1.0f) );geom->setColorArray(colors);geom->setColorBinding(osg::Geometry::BIND_PER_PRIMITIVE_SET);//指定法线osg::Vec3Array* normals = new osg::Vec3Array;normals->push_back( osg::Vec3(0.0f,-1.0f,0.0f) );geom->setNormalArray(normals);geom->setNormalBinding(osg::Geometry::BIND_OVERALL);//将图元添加至geometrygeom->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINES,0,4) );geom->addPrimitiveSet( new osg::DrawArrays(osg::PrimitiveSet::LINES,4,vertices->size() - 4) );geode->addDrawable(geom);osg::StateSet *set = new osg::StateSet();set->setMode(GL_LIGHTING,osg::StateAttribute::OFF);set->setAttributeAndModes(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON);set->setMode(GL_LINE_SMOOTH,osg::StateAttribute::ON);geode->setStateSet(set);transformGrid->addChild(geode);transformGrid->setName("transformGrid");
0 0
- osg如何画网格
- osg网格划分
- osg 网格显示球体
- OSG 显示网格和状态信息
- osg如何显示文字
- OSG基本几何体的透明效果和网格模型
- listctrl如何加网格
- OSG
- osg
- OSG
- osg-
- OSG
- osg
- OSG
- 如何制作网格粒子发射器
- Navicat如何将网格隐藏?
- OSG学习之示例遇到的问题二图形不能显示网格模式
- OSG 如何在地形上放置模型
- windows 蓝牙开源工具包分析及C#实例
- 设置UILabel的内间距
- yum 错误TypeError: rpmdb open failed
- MySQL 服务安装启动
- Omnet下安装Inet工具箱
- osg如何画网格
- js正则函数match、exec、test、search、replace、split使用介绍集合
- 用FPGA设计软件无线电和调制解调器
- rdis3.0集群安装
- 【DSP杂记】
- php学习之基础三
- OpenCV示例2
- Design Patterns Uncovered: The Facade Pattern
- Java Exception 捕获和展示