OSG绘制基本图形实验一.docx
- 文档编号:14554554
- 上传时间:2023-06-24
- 格式:DOCX
- 页数:10
- 大小:47.33KB
OSG绘制基本图形实验一.docx
《OSG绘制基本图形实验一.docx》由会员分享,可在线阅读,更多相关《OSG绘制基本图形实验一.docx(10页珍藏版)》请在冰点文库上搜索。
OSG绘制基本图形实验一
天津理工大学
计算机科学与技术学院
实验报告
2015至2016学年第二学期
课程名称
计算机图形学
学号
学生姓名
年级
专业
课程号
实验地点
实验时间
主讲教师
辅导教师
实验
(一)
实验名称
绘制基本图形
软件环境
VisualStudio2010
OSG-3.1.0
Windows7
硬件环境
2G内存
显卡GT610
CPU奔腾双核
硬盘320G
实验目的
1.理解图形元素显示的基本原理,掌握扫描转换直线段的常用算法原理,扫描转换圆弧的常用算法原理。
2.熟悉OpenSceneGraph常用几个类(Group,Geode,Geometry,Node,Viewer,osg:
:
Vec3Array)
3.熟悉OpenSceneGraph构建场景的基本框架
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:
:
QUADS,osg:
:
PrimitiveSet:
:
QUAD_STRIP,osg:
:
PrimitiveSet:
:
TRIANGLES,osg:
:
PrimitiveSet:
:
TRIANGLE_STRIP,osg:
:
PrimitiveSet:
:
TRIANGLE_FAN)。
2.实现各自名字的绘制。
3.颜色的设置要合适。
实验要求:
1.设计结构合理、扩展灵活。
2.每个设备类独立封装。
3.提交电子版实验报告及工程代码,试验报告模板可参考计算机学院统一模板
4.提交的工程代码必须删除其中的Debug或Release文件夹
实验过程与实验结果(可包括实验实施的步骤、算法描述、流程、结论等)
节点模型:
实验步骤:
1.在纸上绘制草图,建立三维坐标系,并在坐标系中画出个图形,并设定各点坐标,使其坐标符合逻辑,以供绘制图形坐标的选择;
2.创建Group节点,Geode节点,Geomotry节点,
3.创建顶点坐标数组,颜色数组,法线数组;
4.实现基本绘制。
流程图:
结果展示:
附录(可包括源程序清单或其它说明)
源代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
voidcreateContent1(osgText:
:
Text&textObject,constchar*string);
osg:
:
Geode*draw()
{
osg:
:
ref_ptr : Node>node=newosg: : Node; osg: : ref_ptr : Group>group=newosg: : Group; osg: : ref_ptr : Geode>geode=newosg: : Geode; osg: : ref_ptr : Geometry>geometry=newosg: : Geometry; osg: : ref_ptr : Vec3Array>point=newosg: : Vec3Array; osg: : ref_ptr : Vec3Array>color=newosg: : Vec3Array; osg: : ref_ptr : Vec3Array>normal=newosg: : 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,20)); 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,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,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,18)); 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)); point->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)); point->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)); point->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)); 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(-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)); color->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)); color->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->push_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(newosg: : DrawArrays(osg: : DrawArrays: : POINTS,0,2)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : LINES,2,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : LINE_STRIP,6,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : LINE_STRIP,10,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : POLYGON,14,6)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : LINE_LOOP,20,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : QUADS,24,6)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : QUAD_STRIP,30,6)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : TRIANGLES,36,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : TRIANGLE_STRIP,40,4)); geometry->addPrimitiveSet(newosg: : DrawArrays(osg: : DrawArrays: : TRIANGLE_FAN,44,4)); setlocale(LC_ALL,".936");// 配置地域化信息 constchar*titleString="zhengzhanwei"; osg: : ref_ptr : Text>text0=newosgText: : Text; osg: : ref_ptr : Font>font=newosgText: : Font(); font=osgText: : readFontFile("C: \\WINDOWS\\Fonts\\simhei.ttf"); text0->setFont(font.get()); //text0->setFont("C: \\WINDOWS\\Fonts\\simhei.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->setAxisAlignment(osgText: : Text: : XZ_PLANE); text0->setAlignment(osgText: : Text: : CENTER_TOP); createContent1(*text0,titleString); geode->addDrawable(text0.get()); geode->addDrawable(geometry); returngeode.release(); } voidcreateContent1(osgText: : Text&textObject,constchar*string) { intrequiredSize=mbstowcs(NULL,string,0);//如果mbstowcs第一参数为NULL那么返回字符串的数目 wchar_t*wText=newwchar_t[requiredSize+1]; mbstowcs(wText,string,requiredSize+1);//由char转换成wchar类型 textObject.setText(wText); deletewText; } intmain(intargc,char**argv) { osgViewer: : Viewerviewer; viewer.setSceneData(draw()); returnviewer.run(); }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- OSG 绘制 基本 图形 实验