




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机图形学课程设计报告 设计题目:钟表 班级学号: 姓 名: 日 期:2011.12.19 钟表 1 内容概述主要完成3d时钟 矩形框架的制作,以及各种3d图贴图的绘制,实现对指定形体的旋转。2 工程的框架结构 2.1 添加的菜单 mydraw 绘制图形 ontimer 指针旋转 2.2 使用到的变量 类型 名称 float rangx float rangy float rangz float bcolor float gcolor 2.3 使用到的主要函数 名称 作用 参数 glgentextures 创建纹理 textureglbindtexture 线形滤波 texturegltex
2、parameteri 线形滤波 byteglenable 启用纹理映射 texture glclearcolor 黑色背景 fglenable 启用深度测试 texturegldepthfunc 所作深度测试的类型 lequalglhint 真正精细的透视修正 hint nicestglclear 清除屏幕和深度缓存 bitglloadidentity 重置当前的模型观察矩阵 voidglbindtexture 选择纹理 textureglbegin 前面 quadsgltexcoord2f 指定纹理的坐标 float glvertex 确定顶点的坐标,点与点的关系 glend(); 表示画图
3、结束 quads glrotated 把坐标轴的视角进行偏移 angle glbegin 表示图形开始 quads glpopmatrix 栈里的出栈 glmatrixmode 指定哪一个矩阵是当前矩阵 projection glloadidentity 视场调节3 主要的算法1.创建纹理存储空间static bool bbusy=false;if(bbusy) return;bbusy=true;aux_rgbimagerec *textureimage1; gluint texture1; char *filename=1.bmp;2.创建六个纹理,使用来自位图的数据创建贴图glbegin
4、(gl_quads);gltexcoord2f(0.0f, 0.0f);glvertex3f(-0.5f, 0.65f, 0.0f);gltexcoord2f(0.0f, -1.0f);glvertex3f(-0.5f, -0.65f, 0.0f);gltexcoord2f(1.0f, -1.0f);glvertex3f( 0.5f, -0.65f, 0.0f);gltexcoord2f(1.0f, 0.0f);glvertex3f(0.5f, 0.65f, 0.0f);glend();3. 表针的定义和旋转glrotated(-rangz,0.0f,0.0f,3.0f);glbegin(gl
5、_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.13f,0.25f,0.0f);glend();glrotated(-rangx,0.0f,0.0f,3.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.2f,0.3f,0.0f);glend();glrotated(-rangy,0.0f,0.0f,1.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(-0.02f,-0.2f,0.0f);glve
6、rtex3f(0.0f,-0.0f,0.0f);glvertex3f(0.02f,-0.2f,0.0f);glvertex3f(-0.02f,-0.2f,0.0f);glvertex3f(-0.0f,-0.4f,0.0f);glvertex3f(0.02f,-0.2f,0.0f);glvertex3f(0.0f,-0.4f,0.0f);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(-0.01f,0.1f,0.0f);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.01f,0.1f,0.0f); glvertex3f(-0.01f
7、,0.1f,0.0f);glvertex3f(-0.f,0.2f,0.0f); glvertex3f(0.01f,0.1f,0.0f);glvertex3f(0.0f,0.2f,0.0f);glend(); 4. 用settimer设置2个定时器,周期不同settimer(1,1000, null);settimer(2,60000, null);hwnd hwnd = this-getsafehwnd(); hdc hdc = :getdc(hwnd); if(this-setwindowpixelformat(hdc)=false) return 0; if(this-createview
8、glcontext(hdc)=false) return 0; return 0;5. 用ontimer()函数响应用settimer()函数设定的定时器void cglview:ontimer(uint nidevent) switch(nidevent)case 1:if(rangy=360.0f)rangy=0.1f;elserangy=rangy+6.0f;break;case 2:if(rangz=360.0f)rangz=0.1f;elserangz=rangz+0.1f;break;this-invalidate(false);cview:ontimer(nidevent);4
9、效果展示完整的时钟体现 5 详细的代码/ glview.cpp : implementation of the cglview class/#include stdafx.h#include gl.h#include / glaux库的头文件#include gldoc.h#include glview.h#ifdef _debug#define new debug_new#undef this_filestatic char this_file = _file_;#endif/ cglviewimplement_dyncreate(cglview, cview)begin_message_m
10、ap(cglview, cview)/afx_msg_map(cglview)on_wm_create()on_wm_destroy()on_wm_size()on_wm_timer()/afx_msg_map/ standard printing commandson_command(id_file_print, cview:onfileprint)on_command(id_file_print_direct, cview:onfileprint)on_command(id_file_print_preview, cview:onfileprintpreview)end_message_m
11、ap()/ cglview construction/destructioncglview:cglview()/ todo: add construction code herethis-m_glpixelindex = 0; this-m_hglcontext = null; rangx=0.0f;rangy=0.0f;rangz=0.0f;int mark=-1;for(int i=0;i100;i+)for(int j=0;jsizex, textureimage0-sizey, 0, gl_rgb, gl_unsigned_byte, textureimage0-data); glte
12、xparameteri(gl_texture_2d,gl_texture_min_filter,gl_linear); / 线形滤波 gltexparameteri(gl_texture_2d,gl_texture_mag_filter,gl_linear); / 线形滤波 glenable(gl_texture_2d); / 启用纹理映射( 新增 ) / 启用阴影平滑 glclearcolor(0.3f, 0.0f, 0.2f, 0.5f); / 黑色背景 / 设置深度缓存 glenable(gl_depth_test); / 启用深度测试 gldepthfunc(gl_lequal); /
13、 所作深度测试的类型 glhint(gl_perspective_correction_hint, gl_nicest); / 真正精细的透视修正 glclear(gl_color_buffer_bit | gl_depth_buffer_bit); / 清除屏幕和深度缓存 glloadidentity(); / 重置当前的模型观察矩阵 glbindtexture(gl_texture_2d, texture0); / 选择纹理/glcolor3f(1.0f,1.0f,1.0f);glbegin(gl_quads);/ 前面 gltexcoord2f(0.0f, 0.0f);glvertex3
14、f(-0.5f, 0.65f, 0.0f); / 纹理和四边形的左下 gltexcoord2f(0.0f, -1.0f);glvertex3f(-0.5f, -0.65f, 0.0f);/ 纹理和四边形的右下 gltexcoord2f(1.0f, -1.0f);glvertex3f( 0.5f, -0.65f, 0.0f);/ 纹理和四边形的右上 gltexcoord2f(1.0f, 0.0f);glvertex3f(0.5f, 0.65f, 0.0f);/ 纹理和四边形的左上 / 后面 glend();glcolor3f(0.5f,0.2f,0.8f); glrotated(-rangz,0
15、.0f,0.0f,3.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.13f,0.25f,0.0f);glend();glrotated(-rangx,0.0f,0.0f,3.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.2f,0.3f,0.0f);glend();glrotated(-rangy,0.0f,0.0f,1.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.0f);glvertex3
16、f(-0.02f,-0.2f,0.0f);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.02f,-0.2f,0.0f);glvertex3f(-0.02f,-0.2f,0.0f);glvertex3f(-0.0f,-0.4f,0.0f);glvertex3f(0.02f,-0.2f,0.0f);glvertex3f(0.0f,-0.4f,0.0f);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(-0.01f,0.1f,0.0f);glvertex3f(0.0f,-0.0f,0.0f);glvertex3f(0.01f,0.1f
17、,0.0f);glvertex3f(-0.01f,0.1f,0.0f);glvertex3f(-0.f,0.2f,0.0f);glvertex3f(0.01f,0.1f,0.0f);glvertex3f(0.0f,0.2f,0.0f);glend(); elsemessagebox(文件不存在);mydraw();swapbuffers(wglgetcurrentdc();bbusy=false;/cglview printingbool cglview:onprepareprinting(cprintinfo* pinfo)/ default preparationreturn doprep
18、areprinting(pinfo);void cglview:onbeginprinting(cdc* /*pdc*/, cprintinfo* /*pinfo*/)/ todo: add extra initialization before printingvoid cglview:onendprinting(cdc* /*pdc*/, cprintinfo* /*pinfo*/)/ todo: add cleanup after printing/cglview diagnostics#ifdef _debugvoid cglview:assertvalid() constcview:
19、assertvalid();void cglview:dump(cdumpcontext& dc) constcview:dump(dc);cgldoc* cglview:getdocument() / non-debug version is inlineassert(m_pdocument-iskindof(runtime_class(cgldoc);return (cgldoc*)m_pdocument;#endif /_debug/ cglview message handlersbool cglview:setwindowpixelformat(hdc hdc)/定义窗口的像素格式p
20、ixelformatdescriptor pixeldesc= sizeof(pixelformatdescriptor),1,pfd_draw_to_window|pfd_support_opengl|pfd_doublebuffer,pfd_type_rgba,24,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,pfd_main_plane,0,0,0,0; this-m_glpixelindex = choosepixelformat(hdc,&pixeldesc); if(this-m_glpixelindex=0) this-m_glpixelindex = 1;
21、 if(describepixelformat(hdc,this-m_glpixelindex,sizeof(pixelformatdescriptor),&pixeldesc)=0) return false;if(setpixelformat(hdc,this-m_glpixelindex,&pixeldesc)=false) return false; return true;bool cglview:createviewglcontext(hdc hdc)this-m_hglcontext = wglcreatecontext(hdc); if(this-m_hglcontext=nu
22、ll)/创建失败 return false; if(wglmakecurrent(hdc,this-m_hglcontext)=false)/选为当前rc失败 return false;return true;int cglview:oncreate(lpcreatestruct lpcreatestruct) if (cview:oncreate(lpcreatestruct) = -1)return -1;/ todo: add your specialized creation code heresettimer(1,1000, null);settimer(2,60000, null)
23、;hwnd hwnd = this-getsafehwnd(); hdc hdc = :getdc(hwnd); if(this-setwindowpixelformat(hdc)=false) return 0; if(this-createviewglcontext(hdc)=false) return 0; return 0;void cglview:ondestroy() cview:ondestroy();/ todo: add your message handler code here if(wglgetcurrentcontext()!=null) wglmakecurrent
24、(null,null); if(this-m_hglcontext!=null) wgldeletecontext(this-m_hglcontext); this-m_hglcontext = null; void cglview:mydraw()gltranslatef(0.0f,0.3f,-6.0f);glenable(gl_line_stipple);glenable(gl_point_smooth);glpushmatrix(); glend();glrotated(rangx,0.0f,0.0f,3.0f);glbegin(gl_lines);glend(); glrotated(
25、rangy,0.0f,0.0f,3.0f);glcolor3f(1.0f,1.0f,1.0f);glbegin(gl_lines);glvertex3f(0.0f,-0.0f,0.3f);glvertex3f(-0.05f,-0.25f,0.3f);glvertex3f(0.0f,-0.0f,0.3f);glvertex3f(0.05f,-0.25f,0.3f);glvertex3f(-0.05f,-0.25f,0.3f);glvertex3f(-0.f,-0.5f,0.3f);glvertex3f(0.05f,-0.25f,0.3f);glvertex3f(0.0f,-0.5f,0.3f);
26、glvertex3f(0.0f,-0.0f,0.3f);glvertex3f(-0.05f,0.2f,0.3f);glvertex3f(0.0f,-0.0f,0.3f);glvertex3f(0.05f,0.2f,0.3f);glvertex3f(-0.05f,0.2f,0.3f);glvertex3f(-0.f,0.3f,0.3f);glvertex3f(0.05f,0.2f,0.3f);glvertex3f(0.0f,0.3f,0.3f);glend(); glpopmatrix(); gldisable(gl_point_smooth);glvertex3f(0.0f,-0.05f,0.0f);glvertex3f(-0.2f,-0.1f,0.3f);gldisable(gl_line_stipple);void cglview:o
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《一体式地下水表阀门井应用技术规范》(征求意见稿)
- 人教宁夏 九年级 下册 语文 第二单元《 综合性学习》习题课 课件
- 人教山西 九年级 下册 语文 第二单元《 变色龙》习题课 课件
- 人教陕西 九年级 下册 语文 第二单元《 单元写作》习题课 课件
- 人教山西 九年级 下册 语文 第一单元《 山西中考题型专练》习题课 课件
- 人教陕西 九年级 下册 语文 期末特训 专题5 情境化基础综合
- 人教版部编版小学语文一年级下册 4 猜字谜 教学设计-教案29
- 铁路路外培训
- 人教版一年级上册数学第一单元《准备课》试卷2
- 交货订单合同范例范例
- 2025国网陕西省电力公司高校毕业生招聘74人(第三批)易考易错模拟试题(共500题)试卷后附参考答案
- 2025年宁波城市职业技术学院单招职业适应性测试题库标准卷
- 2.1坚持依宪治国-八年级道德与法治下册大单元教学同步课件(部编版)
- 交通运输安全员岗位职责概述
- 2025年杨凌职业技术学院高职单招高职单招英语2016-2024历年频考点试题含答案解析
- 2025年沪科版八年级生物下册阶段测试试卷
- 老年活动室委托管理服务合同模板
- 2024年08月浙江龙湾农商银行秋季招考笔试历年参考题库附带答案详解
- 三年级 下册《花钟》课件
- 期末考试成绩分析报告课件
- 银行理财纠纷演练方案
评论
0/150
提交评论