OSG绘制基本图形实验一.doc

上传人:一*** 文档编号:2744334 上传时间:2020-05-02 格式:DOC 页数:10 大小:139KB
返回 下载 相关 举报
OSG绘制基本图形实验一.doc_第1页
第1页 / 共10页
OSG绘制基本图形实验一.doc_第2页
第2页 / 共10页
点击查看更多>>
资源描述

《OSG绘制基本图形实验一.doc》由会员分享,可在线阅读,更多相关《OSG绘制基本图形实验一.doc(10页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、/天津理工大学计算机科学与技术学院实验报告2015 至 2016 学年 第 二 学期课程名称计算机图形学学号学生姓名年级专业课程号实验地点实验时间主讲教师辅导教师实验( 一 )实验名称绘制基本图形软件环境Visual Studio 2010OSG-3.1.0Windows 7硬件环境2G内存显卡GT610CPU奔腾双核硬盘320G实验目的1. 理解图形元素显示的基本原理,掌握扫描转换直线段的常用算法原理,扫描转换圆弧的常用算法原理。2. 熟悉OpenSceneGraph常用几个类(Group,Geode,Geometry,Node,Viewer,osg:Vec3Array)3. 熟悉OpenS

2、ceneGraph构建场景的基本框架4. 掌握绘制不同大小和颜色的点的方法5. 掌握绘制不同线型和颜色的直线的方法(直线,折线,环线)6. 掌握绘制彩色多边形边框的方法(各种设备)7. 熟悉OpenSceneGraph的编程环境实验内容(应包括实验题目、实验要求、实验任务等)实验题目:1. 绘制基本形状(osg:PrimitiveSet:POINTS,osg:PrimitiveSet:LINES,osg:PrimitiveSet:LINE_STRIP,osg:PrimitiveSet:LINE_LOOP,osg:PrimitiveSet:POLYGON,osg:PrimitiveSet:QUA

3、DS,osg:PrimitiveSet:QUAD_STRIP,osg:PrimitiveSet:TRIANGLES,osg:PrimitiveSet:TRIANGLE_STRIP,osg:PrimitiveSet:TRIANGLE_FAN)。2. 实现各自名字的绘制。3. 颜色的设置要合适。实验要求:1. 设计结构合理、扩展灵活。2. 每个设备类独立封装。3. 提交电子版实验报告及工程代码,试验报告模板可参考计算机学院统一模板4. 提交的工程代码必须删除其中的Debug或Release文件夹实验过程与实验结果(可包括实验实施的步骤、算法描述、流程、结论等)GeometryGeode节点模型:N

4、odeGroup点线三角形四边形文字实验步骤:1. 在纸上绘制草图,建立三维坐标系,并在坐标系中画出个图形,并设定各点坐标,使其坐标符合逻辑,以供绘制图形坐标的选择;2. 创建Group节点,Geode节点,Geomotry节点,3. 创建顶点坐标数组,颜色数组,法线数组;4. 实现基本绘制。流程图:开始设置顶点坐标,并设置其对应顶点坐标设置顶点坐标与颜色对应关系,为一一对应模式使用addDrawable函数结束viewer.run()用viewer设置SetSceneData()结果展示:附录(可包括源程序清单或其它说明)源代码:#include #include#include#inclu

5、de#include#include #include#include#include#include#include #include void createContent1(osgText:Text& textObject,const char* string);osg:Geode* draw()osg:ref_ptr node = new osg:Node;osg:ref_ptr group = new osg:Group;osg:ref_ptr geode = new osg:Geode;osg:ref_ptr geometry = new osg:Geometry;osg:ref_p

6、tr point = new osg:Vec3Array;osg:ref_ptr color = new osg:Vec3Array;osg:ref_ptr normal =new osg:Vec3Array;point-push_back(osg:Vec3(0,0,0);point-push_back(osg:Vec3(0,3,0);color-push_back(osg:Vec3(0,0,0);color-push_back(osg:Vec3(0,0,0);point-push_back(osg:Vec3(-20,0,20);point-push_back(osg:Vec3(-15,0,2

7、0);point-push_back(osg:Vec3(-15,0,18);point-push_back(osg:Vec3(-20,0,18);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-14,0,20);point-push_back(osg:Vec3(-10,0,20);point-push_back(osg:Vec3(-10,

8、0,18);point-push_back(osg:Vec3(-14,0,18);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-9,0,20);point-push_back(osg:Vec3(-6,0,20);point-push_back(osg:Vec3(-6,0,18);point-push_back(osg:Vec3(-9,0

9、,18);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-5,0,20);point-push_back(osg:Vec3(-3,0,21);point-push_back(osg:Vec3(-1,0,20);point-push_back(osg:Vec3(-1,0,19);point-push_back(osg:Vec3(-3,0,1

10、8);point-push_back(osg:Vec3(-5,0,19);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);color-push_back(osg:Vec3(0,0.7,0.5);color-push_back(osg:Vec3(1,1,1);point-push_back(osg:Vec3(0,0,20);point-push_back(osg:Vec3(1,0,20);p

11、oint-push_back(osg:Vec3(1,0,18);point-push_back(osg:Vec3(0,0,18);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-20,0,15);point-push_back(osg:Vec3(-20,0,11);point-push_back(osg:Vec3(-15,0,11);po

12、int-push_back(osg:Vec3(-15,0,15);point-push_back(osg:Vec3(-12,0,9);point-push_back(osg:Vec3(-12,0,13);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);color-push_back(osg:Vec3(0,0.7,0.5);color-push_back(osg:Vec3(1,1,1);po

13、int-push_back(osg:Vec3(-11,0,15);point-push_back(osg:Vec3(-11,0,11);point-push_back(osg:Vec3(-9,0,15);point-push_back(osg:Vec3(-9,0,11);point-push_back(osg:Vec3(-7,0,13);point-push_back(osg:Vec3(-7,0,9);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);c

14、olor-push_back(osg:Vec3(1,1,0);color-push_back(osg:Vec3(0,0.7,0.5);color-push_back(osg:Vec3(1,1,1);point-push_back(osg:Vec3(-5,0,10);point-push_back(osg:Vec3(-1,0,15);point-push_back(osg:Vec3(1,0,10);point-push_back(osg:Vec3(-1,0,5);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);col

15、or-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-20,0,-1);point-push_back(osg:Vec3(-16,0,5);point-push_back(osg:Vec3(-14,0,-1);point-push_back(osg:Vec3(-16,0,-6);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);colo

16、r-push_back(osg:Vec3(1,1,0);point-push_back(osg:Vec3(-12,0,-1);point-push_back(osg:Vec3(-8,0,5);point-push_back(osg:Vec3(-6,0,-1);point-push_back(osg:Vec3(-8,0,-6);color-push_back(osg:Vec3(1,0,0);color-push_back(osg:Vec3(0,1,0);color-push_back(osg:Vec3(0,1,1);color-push_back(osg:Vec3(1,1,0);normal-p

17、ush_back(osg:Vec3(0,-1,0);geometry-setVertexArray(point.get();geometry-setColorArray(color.get();geometry-setNormalArray(normal.get();geometry-setNormalBinding(osg:Geometry:BIND_OVERALL);geometry-setColorBinding(osg:Geometry:BIND_PER_VERTEX);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays

18、:POINTS,0,2);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:LINES,2,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:LINE_STRIP,6,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:LINE_STRIP,10,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:POLYGON

19、,14,6);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:LINE_LOOP,20,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:QUADS,24,6);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:QUAD_STRIP,30,6);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:TRIANGLES,36

20、,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:TRIANGLE_STRIP,40,4);geometry-addPrimitiveSet(new osg:DrawArrays(osg:DrawArrays:TRIANGLE_FAN,44,4);setlocale(LC_ALL,.936);/配置地域化信息const char* titleString=zhengzhanwei;osg:ref_ptr text0 = new osgText:Text; osg:ref_ptr font = new osgText:F

21、ont();font = osgText:readFontFile(C:WINDOWSFontssimhei.ttf);text0-setFont(font.get();/text0-setFont(C:WINDOWSFontssimhei.ttf);text0-setFontResolution( 128, 128 ); text0-setColor(osg:Vec4(255, 0, 0, 1); text0-setCharacterSize( .6f ); text0-setPosition( osg:Vec3( 0.f, 0.f, 0.f ) ); text0-setAxisAlignm

22、ent( osgText:Text:XZ_PLANE ); text0-setAlignment( osgText:Text:CENTER_TOP ); createContent1(*text0,titleString); geode-addDrawable( text0.get() ); geode-addDrawable(geometry);return geode.release();void createContent1(osgText:Text& textObject,const char* string)int requiredSize=mbstowcs(NULL,string,0);/如果mbstowcs第一参数为NULL那么返回字符串的数目wchar_t* wText=new wchar_trequiredSize+1;mbstowcs(wText,string,requiredSize+1);/由char转换成wchar类型textObject.setText(wText);delete wText;int main(int argc,char * argv)osgViewer:Viewer viewer;viewer.setSceneData(draw();return viewer.run();

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 教案示例

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁