




已阅读5页,还剩1页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
将Onsize代码替换成如下的代码,使前述的平行投影变成透视投影void CMyOpenGLView:OnSize(UINT nType, int cx, int cy)glViewport(0,0,cx,cy);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(45,(float)cx/(float)cy,0.1,15);glMatrixMode(GL_MODELVIEW);glLoadIdentity();以下是修改Draw方法的代码,以实现不同的功能/2D图形绘制glClearColor(0,0,0,1);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glLoadIdentity();glShadeModel(GL_SMOOTH);glTranslatef(-1.5f,1.0f,-7.0f);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_TRIANGLES);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f);glEnd();glTranslatef(3.0f,0.0f,0.0f);glColor3f(0.0f,0.0f,1.0f);glBegin(GL_QUADS);glVertex3f(-1.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glEnd();glTranslatef(-1.5f,-2.5f,0.0f);glColor3f(1.0f,1.0f,0.0f);glLineWidth(2.0f);glBegin(GL_LINE_LOOP);for(int i=0;i200;i+)glVertex3f(1.0*float(sin(2*3.14*i/200),1.0*float(cos(2*3.14*i/200),0.0);glEnd();SwapBuffers(m_hDC);glFlush();/阴暗处理glClearColor(0,0,0,1);glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);glLoadIdentity();glShadeModel(GL_SMOOTH);/设置平滑插值glTranslatef(-1.5f,1.0f,-7.0f);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_TRIANGLES);glColor3ub(255,0,0);glVertex3f(0.0f,1.0f,0.0f);glColor3ub(0,255,0);glVertex3f(-1.0f,-1.0f,0.0f);glColor3ub(255,255,0);glVertex3f(1.0f,-1.0f,0.0f);glEnd();glTranslatef(3.0f,0.0f,0.0f);glColor3ub(0,255,255);glBegin(GL_QUADS);glVertex3f(-1.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,0.0f);glVertex3f(1.0f,-1.0f,0.0f);glVertex3f(1.0f,1.0f,0.0f);glEnd();glTranslatef(-1.5f,-2.5f,0.0f);glColor3f(1.0f,1.0f,0.0f);glLineWidth(2.0f);glBegin(GL_LINE_LOOP);for(int i=0;i360.0)angle_Left-=360.0;glBegin(GL_TRIANGLES);/正面 glColor3ub(217,167,22);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,1.0f);glVertex3f(1.0f,-1.0f,1.0f);/背面glColor3ub(200,100,22);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(1.0f,-1.0f,-1.0f);glVertex3f(-1.0f,-1.0f,-1.0f);/右侧面glColor3ub(217,122,0);glVertex3f(0.0f,1.0f,0.0f);glVertex3f(1.0f,-1.0f,1.0f);glVertex3f(1.0f,-1.0f,-1.0f);/左侧面glVertex3f(0.0f,1.0f,0.0f);glVertex3f(-1.0f,-1.0f,-1.0f);glVertex3f(-1.0f,-1.0f,1.0f);glEnd();/底面glColor3ub(217,122,100);glBegin(GL_QUADS);glVertex3f(-1.0f,-1.0f,-1.0f);glVertex3f(1.0f,-1.0f,-1.0f);glVertex3f(1.0f,-1.0f,1.0f);glVertex3f(-1.0f,-1.0f,1.0f);glEnd();glPopMatrix();/矩阵出栈glTranslatef(4.0f,0.0f,0.0f);glRotatef(angle_X,1.0f,0.0f,0.0f);glRotatef(angle_Y,0.0f,1.0f,0.0f);DrawCube(2.0f,0.2f,0.2f);DrawCube(0.2f,2.0f,0.2f);SwapBuffers(m_hDC);glFlush();除此之外,我们添加一个Timer函数为消息中WM_TIMER添加响应OnTimer方法,代码如下void CMyOpenGLView:OnTimer(UINT nIDEvent) / TODO: Add your message handler code here and/or call defaultDraw();CView:OnTimer(nIDEvent);则SetTimer(1,100,NULL)是触发Timer消息,而KillTimer(1);是使得响应消亡。为实现能在键盘控制下旋转上述的3D图形为消息WM_KEYUP添加响应OnKeyUpvoid CMyOpenGLView:OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) / TODO: Add your message handler code here and/or call defaultif (nChar = VK_F2)KillTimer(1);if (nChar = VK_F1)SetTimer(1,100,NULL);if (nC
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五借名购房协议书
- 滕秋的离婚协议书
- 探矿权股权转让框架协议范例
- 体现学科核心素养的教学设计
- 二零二五版电影剧组演员合约保密协议
- 股票归女方离婚协议
- 运输协议中的货物损失与灭失责任
- 爆破安全协议书二零二五年
- 二零二五版家具售后服务承诺书范文
- 2025年版劳动合同模板
- JT-T-1045-2016道路运输企业车辆技术管理规范
- ManagementInformationSystem管理信息系统双语教学课件
- 气候类型气温降水分布图
- 小学生飞机知识科普课件
- 交通运输有限责任公司安全生产费用提取使用制度
- 德阳巴蜀文化介绍
- 三年级下册数学课件-4.1 整体与部分 ▏沪教版 (23张PPT)
- 住 用 房 屋 租 金 计 算 表
- 7.4.2超几何分布 课件(共14张PPT)
- 晶状体相关的继发性青光眼进展课件
- DB33T 1192-2020 建筑工程施工质量验收检查用表统一标准
评论
0/150
提交评论