在OSGMFC程序基础上修改OSG_MFC类的方法,如下:

 void cOSG::InitSceneGraph(void)
{
// Init the main Root Node/Group
mRoot = new osg::Group; //// Load the Model from the model name
//mModel = osgDB::readNodeFile(m_ModelName);
//if (!mModel) return; // Optimize the model
//osgUtil::Optimizer optimizer;
//optimizer.optimize(mModel.get());
//optimizer.reset(); //// Add the model to the scene
//mRoot->addChild(mModel.get()); osg::Geode* pyramidGeode = new osg::Geode();
osg::Geometry* pyramidGeometry = new osg::Geometry();
pyramidGeode->addDrawable(pyramidGeometry);
mRoot->addChild(pyramidGeode); osg::Vec3Array* pyramidVertices = new osg::Vec3Array;
pyramidVertices->push_back( osg::Vec3( , , ) ); // front left
pyramidVertices->push_back( osg::Vec3(, , ) ); // front right
pyramidVertices->push_back( osg::Vec3(,, ) ); // back right
pyramidVertices->push_back( osg::Vec3( ,, ) ); // back left
pyramidVertices->push_back( osg::Vec3( , ,) ); // peak pyramidGeometry->setVertexArray( pyramidVertices ); osg::DrawElementsUInt* pyramidBase = new osg::DrawElementsUInt(osg::PrimitiveSet::QUADS, );
pyramidBase->push_back();
pyramidBase->push_back();
pyramidBase->push_back();
pyramidBase->push_back();
pyramidGeometry->addPrimitiveSet(pyramidBase); osg::DrawElementsUInt* pyramidFaceOne = new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, );
pyramidFaceOne->push_back();
pyramidFaceOne->push_back();
pyramidFaceOne->push_back();
pyramidGeometry->addPrimitiveSet(pyramidFaceOne); osg::DrawElementsUInt* pyramidFaceTwo =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, );
pyramidFaceTwo->push_back();
pyramidFaceTwo->push_back();
pyramidFaceTwo->push_back();
pyramidGeometry->addPrimitiveSet(pyramidFaceTwo); osg::DrawElementsUInt* pyramidFaceThree =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, );
pyramidFaceThree->push_back();
pyramidFaceThree->push_back();
pyramidFaceThree->push_back();
pyramidGeometry->addPrimitiveSet(pyramidFaceThree); osg::DrawElementsUInt* pyramidFaceFour =
new osg::DrawElementsUInt(osg::PrimitiveSet::TRIANGLES, );
pyramidFaceFour->push_back();
pyramidFaceFour->push_back();
pyramidFaceFour->push_back();
pyramidGeometry->addPrimitiveSet(pyramidFaceFour); osg::Vec4Array* colors = new osg::Vec4Array;
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 0 red
colors->push_back(osg::Vec4(0.0f, 1.0f, 0.0f, 1.0f) ); //index 1 green
colors->push_back(osg::Vec4(0.0f, 0.0f, 1.0f, 1.0f) ); //index 2 blue
colors->push_back(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f) ); //index 3 white
colors->push_back(osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f) ); //index 4 red pyramidGeometry->setColorArray(colors);
pyramidGeometry->setColorBinding(osg::Geometry::BIND_PER_VERTEX); // Declare and initialize a transform node.
osg::PositionAttitudeTransform* pyramidTwoXForm = new osg::PositionAttitudeTransform; // Use the 'addChild' method of the osg::Group class to
// add the transform as a child of the root node and the
// pyramid node as a child of the transform.
mRoot->addChild(pyramidTwoXForm);
pyramidTwoXForm->addChild(pyramidGeode); // Declare and initialize a Vec3 instance to change the
// position of the tank model in the scene
osg::Vec3 pyramidTwoPosition(,,);
pyramidTwoXForm->setPosition( pyramidTwoPosition ); osgUtil::Optimizer optimizer;
optimizer.optimize(mRoot.get());
optimizer.reset(); // Add the model to the scene
// mRoot->addChild(root.get()); }

运行效果:

http://blog.csdn.net/column/details/osgdemo.html

http://trac.openscenegraph.org/projects/osg//wiki/Support/Tutorials/BasicGeometry

OSG绘制几何图形的更多相关文章

  1. Cocos2D中使用CCDrawNode绘制几何图形崩溃的解决

    在cocos2D v3.x中已经不能像在v2.x中那样直接调用ccDrawXXX函数来绘制几何图形了. 我们可以使用CCDrawNode或者CCRenderer来绘制图形. 但是官方的Api手册中说的 ...

  2. Win10系列:VC++绘制几何图形2

    新建了Direct2D中的资源后,接下来初始化用于绘制图形的应用窗口.在解决方案资源管理器窗口中右键点击项目图标,在弹出的菜单栏中选中"添加", 并在"添加"的 ...

  3. Win10系列:VC++绘制几何图形1

    本小节主要介绍如何使用Direct2D来绘制几何图形,其中会使用到FillGeometry函数和FillEllipse函数,FillGeometry函数用于填充几何图形的内部区域,而FillEllip ...

  4. HTML5绘制几何图形

    <!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head>    < ...

  5. OpenGL入门学习 课程 (三) 绘制几何图形的一些细节问题

    http://oulehui.blog.163.com/blog/static/79614698201191832753312/ 先回顾一下我们都学习了些什么: 第一课,编写第一个OpenGL程序第二 ...

  6. C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码

    原文:C#WPF 如何绘制几何图形 图示教程 绘制sin曲线 正弦 绘制2D坐标系 有图有代码 C#WPF 如何绘制几何图形? 怎么绘制坐标系?绘制sin曲线(正弦曲线)? 这离不开Path(Syst ...

  7. HTML5实现绘制几何图形

    HTML5新增了一个<canvas.../>属性.该元素自身并不绘制图形,只是相当于一张空画布.如果开发者需要向<canvas.../>上绘制图形则必须使用JavaScript ...

  8. css3绘制几何图形

    用css3绘制你需要的几何图形 1.圆形 示例: 思路:给任何正方形元素设置一个足够大的 border-radius ,就可以把它变成一个圆形.代码如下: html: <div class=&q ...

  9. Canvas上绘制几何图形

    重要的类自定义View组件要重写View组件的onDraw(Canvase)方法,接下来是在该 Canvas上绘制大量的几何图形,点.直线.弧.圆.椭圆.文字.矩形.多边形.曲线.圆角矩形,等各种形状 ...

随机推荐

  1. Ubuntu 启动停止脚本

    /etc/init.d 目录下的开机启动脚本 1. more redis_8010 #/bin/sh #Configurations injected by install_server below. ...

  2. HDU 1075 What Are You Talking About(Trie的应用)

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  3. 移动端单页视图库,适用于制作移动Web touchbox

    ouchBox 原文:https://github.com/maxzhang/touchbox 移动端单页视图库,适用于制作移动专题 DEMO http://jsbin.com/vatuma/late ...

  4. 移动Web单页应用开发实践——实现Pull to Request(上/下拉请求操作)

    在单页应用开发中,无论是页面结构化,还是Pull to Request,都离不开一个技术——页面局部滚动.当下的移动web技术,主要使用下面两种方式实现局部区域的滚动: 基于IScroll组件,也有很 ...

  5. maven Ubuntu14.04 安装

    参考:linux上安装使用maven 下载链接:官网Download 解压. 在root用户下执行: cd /opt mkdir maven chmod 755 /opt/maven tar -zvx ...

  6. Redis 笔记与总结2 String 类型和 Hash 类型

    Linux 版本信息: cat /etc/issue 或cat /etc/redhat-release(Linux查看版本当前操作系统发行版信息) CentOS release 6.6 (Final) ...

  7. Javascript 笔记与总结(2-4)Javascript 内置对象

    ① String 字符串对象 fromCharCode() 静态方法, 用作为参数而传递的字符代码创建一个新的字符串. length 字符串的长度. charAt() 抽取字符串中指定位置的字符. c ...

  8. python多线程使用

    内容链接: http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/00138683236 ...

  9. 通过SocketLog快速分析OneThink程序

    通过SocketLog快速分析OneThink程序 http://www.thinkphp.cn/topic/10846.html   浏览:2332 发布日期:2014/02/08 分类:技术分享 ...

  10. Bootstrap页面布局10 - BS代码

    网页中标记代码内容使用code和pre标签 要在HTML中显示标签本来的样子需要转化为实体 在此附上百度的实体字符:http://baike.baidu.com/view/4757776.htm#3 ...