美国海军(NPS)的OSG教程——示例代码一
来源:互联网 发布:赫哲族数据图 编辑:程序博客网 时间:2024/05/03 18:46
//OSG 3.2版本osg::Group *root = new osg::Group();osg::Geode *pyramidGeode = new osg::Geode();deprecated_osg::Geometry *pyramidGeometry = new deprecated_osg::Geometry();//注意,用deprecated_osg,某些功能以后可能去掉pyramidGeode->addDrawable( pyramidGeometry );root->addChild( pyramidGeode );//定义点osg::Vec3Array *pyramidVertices = new osg::Vec3Array();pyramidVertices->push_back( osg::Vec3(0,0,0) );//左前pyramidVertices->push_back( osg::Vec3(10,0,0) );//右前pyramidVertices->push_back( osg::Vec3(10,10,0) );//右后pyramidVertices->push_back( osg::Vec3(0,10,0) );//左后pyramidVertices->push_back( osg::Vec3(5,5,10) );//塔尖pyramidGeometry->setVertexArray( pyramidVertices );//定义面osg::DrawElementsUInt *pyramidBase = new osg::DrawElementsUInt( osg::PrimitiveSet::QUADS, 0 );pyramidBase->push_back(3);pyramidBase->push_back(2);pyramidBase->push_back(1);pyramidBase->push_back(0);pyramidGeometry->addPrimitiveSet( pyramidBase );osg::DrawElementsUInt *pyramidFaceOne = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );pyramidFaceOne->push_back(0);pyramidFaceOne->push_back(1);pyramidFaceOne->push_back(4);pyramidGeometry->addPrimitiveSet( pyramidFaceOne );osg::DrawElementsUInt *pyramidFaceTwo = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );pyramidFaceTwo->push_back(1);pyramidFaceTwo->push_back(2);pyramidFaceTwo->push_back(4);pyramidGeometry->addPrimitiveSet( pyramidFaceTwo );osg::DrawElementsUInt *pyramidFaceThree = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );pyramidFaceThree->push_back(2);pyramidFaceThree->push_back(3);pyramidFaceThree->push_back(4);pyramidGeometry->addPrimitiveSet( pyramidFaceThree );osg::DrawElementsUInt *pyramidFaceFour = new osg::DrawElementsUInt( osg::PrimitiveSet::TRIANGLES, 0 );pyramidFaceFour->push_back(3);pyramidFaceFour->push_back(0);pyramidFaceFour->push_back(4);pyramidGeometry->addPrimitiveSet( pyramidFaceFour );//定义颜色osg::Vec4Array *colors = new osg::Vec4Array;colors->push_back( osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) );//红色colors->push_back( osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) );//绿色colors->push_back( osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) );//蓝色colors->push_back( osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) );//白色osg::TemplateIndexArray< unsigned int, osg::Array::UIntArrayType, 4, 4 > *colorIndexArray;colorIndexArray = new osg::TemplateIndexArray< unsigned int, osg::Array::UIntArrayType, 4, 4 >;colorIndexArray->push_back(0);colorIndexArray->push_back(1);colorIndexArray->push_back(2);colorIndexArray->push_back(3);colorIndexArray->push_back(0);pyramidGeometry->setColorArray( colors );pyramidGeometry->setColorIndices( colorIndexArray );pyramidGeometry->setColorBinding( deprecated_osg::Geometry::BIND_PER_VERTEX );osg::Vec2Array *texcoords = new osg::Vec2Array(5);(*texcoords)[0].set(0.00f,0.0f);(*texcoords)[1].set(0.25f,0.0f);(*texcoords)[2].set(0.50f,0.0f);(*texcoords)[3].set(0.75f,0.0f);(*texcoords)[4].set(0.50f,1.0f);pyramidGeometry->setTexCoordArray(0, texcoords);//必须加osgUtil::Optimizer optimizer ;optimizer.optimize(root) ;osgViewer::Viewer viewer;viewer.setSceneData(root);//初始化并创建窗口//viewer.realize();viewer.run();
0 0
- 美国海军(NPS)的OSG教程——示例代码一
- 美国海军(NPS)的OSG教程链接与资源下载
- OSG(美国海军NPS)教程学习加实践(2)
- 美国海军研究生学校(NPS)OSG教程学习笔记——第一课
- 美国海军研究生学校(NPS)OSG教程学习笔记——第二课
- 美国海军研究生学校(NPS)OSG教程学习笔记——第三课
- 美国海军osg教程
- 美国海军osg教程
- OSG for Android新手教程系列(三)——HelloWorld,第一个示例
- 你的产品该如何做好?—NPS
- 政府中的Linux应用—美国海军的OSS?
- py2exe使用教程(一)——简单的示例
- Android AIDL 教程 (一)—— 简单的示例
- osg示例代码解析---osgdelaunay
- OSG学习:阴影代码示例
- 美国海军战列舰——田纳西号(Tennessee)
- OSG for Android新手教程系列(四)——JNI与NDK的使用
- 美国海军的事后回顾
- 全手机弹出的dialog和观察者设计模式
- 如何用cordova创建web app
- [leetcode] 152 Maximum Product Subarray
- ios8.1 - UITableView.h 头文件方法 翻译,以及部分使用场合
- Mathematica画莫比乌斯环
- 美国海军(NPS)的OSG教程——示例代码一
- hdu 5163 Taking Bus (BestCoder Round #27)
- 省市区域 选择器 UIPicker \area \picker
- Android contacts content provider学习小结
- 进程间通信机制(IPC)
- Android ContactsProvider源码分析
- Word Search
- bitcoin-cli 命令整理
- Linux下Gcc生成和使用静态库和动态库详解