


单击此处编辑母版标题样式,,单击此处编辑母版文本样式,,第二级,,第三级,,第四级,,第五级,,,*,计算机图形图像绘制技术,,第二讲,,,主要内容,,显示三维坐标的程序(1),,几何对象的变换,,变换矩阵,,平移glTranslatef,,旋转glRotatef,,缩放glScalef,,三维实体,,显示三维坐标的程序(2),,颜色,,点与线的属性,,面的显示,,隐藏面与深度缓冲,,多边形面的方向,,显示模式,,练习,,,,显示三维坐标的程序(1),,,,变换矩阵,,在OpenGL中使用矩阵进行渲染三维场景所需要的数据计算,,为简化操作,OpenGL提供一个矩阵栈,每次用栈顶的矩阵对给定的物体或场景进行渲染,,用glPushMatrix和glPopMatrix函数来将矩阵压栈和出栈,还可以用glScalef和glRotatef等函数对栈顶的矩阵进行缩放和旋转等修改,,Push / Pop Matrix,,void,glPushMatrix,(void);,,,Push Matrix,,Push / Pop Matrix,,Pop Matrix,void,glPopMatrix,(void);,,,,Example,,glPushMatrix();,,glTranslatef(...);,,glRotatef(...);,,glScalef(...);,,glutSolidCylinder(...);,,glPopMatrix();,,,平移glTranslatef,,void glTranslated (GLdouble x, GLdouble y, GLdouble z);,,void glTranslatef (GLfloat x, GLfloat y, GLfloat z);,,,演示,,,旋转glRotatef,,void glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z);,,void glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z);,,,演示,,缩放glScalef,,void glScaled (GLdouble x, GLdouble y, GLdouble z);,,void glScalef (GLfloat x, GLfloat y, GLfloat z);,,,演示,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,,Example,,glLoadIdentity();,,glPushMatrix();,,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,Identity,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,Rotate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,,glPopMatrix();,,glPopMatrix();,,Identity,,Translate,,,Example,,glLoadIdentity();,,glPushMatrix();,,glTranslatef (…);,,glPushMatrix();,,glLoadIdentity();,,glTranslate (…);,,glPopMatrix();,,glPushMatrix();,,glRotatef (…);,,glPopMatrix();,,glPopMatrix();,,Identity,,,平移与旋转的次序很重要,,glLoadIdentity(),,,,glRotated(45, 0, 0, 1),,,,glTranslated(5, 0, 0),OpenGL commands successively define new “local” coordinate spaces in terms of the “current” or previous local space.,,三维实体对象,,Glaux.lib库,,void auxWireSphere(GLdouble);,,void auxSolidSphere(GLdouble);,,void auxWireCube(GLdouble);,,void auxSolidCube(GLdouble);,,void auxWireBox(GLdouble, GLdouble, GLdouble);,,void auxSolidBox(GLdouble, GLdouble, GLdouble);,,void auxWireTorus(GLdouble, GLdouble);,,void auxSolidTorus(GLdouble, GLdouble);,,void auxWireCylinder(GLdouble, GLdouble);,,void auxSolidCylinder(GLdouble, GLdouble);,,void auxWireIcosahedron(GLdouble);,,void auxSolidIcosahedron(GLdouble);,,void auxWireOctahedron(GLdouble);,,void auxSolidOctahedron(GLdouble);,,void auxWireTetrahedron(GLdouble);,,void auxSolidTetrahedron(GLdouble);,,void auxWireDodecahedron(GLdouble);,,void auxSolidDodecahedron(GLdouble);,,void auxWireCone(GLdouble, GLdouble);,,void auxSolidCone(GLdouble, GLdouble);,,void auxWireTeapot(GLdouble);,,void auxSolidTeapot(GLdouble);,球,,立方体,,长方体,,圆环,,圆柱,,二十面体,,八面体,,四面体,,十二面体,,圆锥,,茶壶,,,Glut库,,void glutWireSphere(GLdouble radius, GLint slices, GLint stacks);,,void glutSolidSphere(GLdouble radius, GLint slices, GLint stacks);,,void glutWireCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);,,void glutSolidCone(GLdouble base, GLdouble height, GLint slices, GLint stacks);,,void glutWireCube(GLdouble size);,,void glutSolidCube(GLdouble size);,,void glutWireTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);,,void glutSolidTorus(GLdouble innerRadius, GLdouble outerRadius, GLint sides, GLint rings);,,void glutWireDodecahedron(void);,,void glutSolidDodecahedron(void);,,void glutWireTeapot(GLdouble size);,,void glutSolidTeapot(GLdouble size);,,void glutWireOctahedron(void);,,void glutSolidOctahedron(void);,,void glutWireTetrahedron(void);,,void glutSolidTetrahedron(void);,,void glutWireIcosahedron(void);,,void glutSolidIcosahedron(void);,,显示三维坐标的程序(2),,(演示),,颜色,,glColor3fv(face color),,render_face(),,glColor3fv(eye color),,render_eyes(),,glColor3fv(hair color),,render_hair(),,glColor3fv(teeth color),,render_teeth(),,Colors,颜色其有四个分量:,,,,R - 红 Red.,,G - 绿 Green.,,B - 蓝 Blue.,,A - 透明度 Transparent.,关于透明处理…,在后面讲,!,,glShadeModel(GL_FLAT);,,glBegin(GL_QUADS);,,glColor3f (1.0,0.0,0.0);,,glVertex3f(0.0,0.0,0.0);,,glColor3f (0.0,1.0,0.0);,,glVertex3f(1.0,0.0,0.0);,,glColor3f (0.0,0.0,1.0);,,glVertex3f(1.0,1.0,0.0);,,glColor3f (1.0,1.0,0.0);,,glVertex3f(0.0,1.0,0.0);,,glEnd();,Shading Models,,,glShadeModel(GL_SMOOTH);,,glBegin(GL_QUADS);,,glColor3f (1.0,0.0,0.0);,,glVertex3f(0.0,0.0,0.0);,,glColor3f (0.0,1.0,0.0);,,glVertex3f(1.0,0.0,0.0);,,glColor3f (0.0,0.0,1.0);,,glVertex3f(1.0,1.0,0.0);,,glColor3f (1.0,1.0,0.0);,,glVertex3f(0.0,1.0,0.0);,,glEnd();,Shading Models,,,演示,,,,点与线的属性,,,void,glPointSize(GLfloat,size);,,void,glLineWidth(GLfloat,width);,,glLineStipple(1, 0x3F07);,glEnable(GL_LINE_STIPPLE);,,void,glLineStipple(GLint,factor,,Glushort,pattern);,,演示,,,,深度缓冲区,,当我们从某处看景物时,接近于视点的物体遮挡了离视点较远的物体。
深度缓冲区为每个像素保存一个距离或深度值,以便让OpenGL通过简单方法做隐藏面计算只有当新像素的深度值小于旧像素的深度值时,才允许像素的覆盖画家算法与深度排序,,,,画家算法的局限性,,解决办法:分割成两个,,演示,,,,多边形面的方向,,,,,back-face,normal pointing inside,,法线方向的指定方法一,,v,0,v,1,v,2,v,3,v,0,v,1,v,2,v,3,根据顶点顺序确定,,法线方向的指定方法二,,指定法线,,面的可见性,,void glCullFace (GLenum mode);,,GLenum取值:GL_FRONT、GL_BACK、GL_FRONT_AND_BACK,,多边形显示模式,,glPolygonMode(GLenum face, GLenum mode);,GL_FILL, GL_LINE, GL_POINT,GL_FRONT, GL_BACK, GL_FRONT_AND_BACK,GL_FILL,GL_LINE,GL_POINT,,演示,,,,练习,,1. 简单的城市模型,,,2 三维飞机模型,,,3,,,4 作三维成绩统计饼图或条形图,,第二次课和第三次课练习作为一次大作业;,,可任选题目;,,第一次大作业在第四次课,上课之前交.,,作业发email至:liuzhongtu@,,。