Bezier_curves_and_surfaces



《Bezier_curves_and_surfaces》由会员分享,可在线阅读,更多相关《Bezier_curves_and_surfaces(86页珍藏版)》请在装配图网上搜索。
1、,,Click to edit Master text styles,,Second level,,Third level,,Fourth level,,Fifth level,,KUCG,Click to edit Master title style,,*,,,Computer,Graphics,,,Click to edit Master text styles,,Second level,,Third level,,Fourth level,,Fifth level,,Click to edit Master title style,,*,,Bezier Curves and Sur
2、faces,1,,本章摘要,多边形表示,,曲线/曲面基础知识,,二次曲面,,三次样条,,Bezier,曲线/曲面,,B-样条曲线/曲面,,NURBS曲线/曲面,,OpenGL,中的曲线/曲面,,2,,曲线/曲面基础知识,1963,年,Ferguson,提出参数化方法;,,法国雷诺汽车公司的,Bezier1971,年提出,Bezier,曲线;,,De Boor,于,1972,年提出B样条算法;,Gordon,,,Riesenfeld,将B样条用于自由曲线曲面;,,1975,年,Versprille,在博士论文中首次提出了有理B样条方法;,,1991,年,ISO,将,NURBS,作为定义工业产品几
3、何形状的唯一数学方法.,3,,曲线/曲面基础知识,隐式方程:,,,F(x,y)=0,,问题:,,不具有几何不变性;,,斜率无穷大会出现溢出问题;,,不便于计算与编程等问题.,4,,曲线/曲面基础知识,参数化表示,,,,优点,,满足几何不变性;,,便于几何变换;,,可处理多值问题和斜率无限大问题;,,规格化的参数变量,,便于分片表示;,,更大的自由度控制曲线曲面形状;,,便于计算曲线曲面的位置距离导数等;,,便于用矢量矩阵表示;,5,,插值、逼近和拟合,型值点:是指通过测量或计算得到的曲线或曲面上少量描述其几何形状的数据点。,,,控制点:是指用来控制或调整曲线曲面形状的特殊点,曲线曲面本身不一定
4、通过控制点。,,,插值和逼近:这是曲线曲面设计中的两种不同方法。插值设计方法要求建立的曲线曲面数学模型,严格通过已知的每一个型值点。而逼近设计方法建立的曲线曲面数学模型只是近似地接近已知的型值点。,,,拟合:是指在曲线曲面的设计过程中,用插值或逼近的方法使生成的曲线曲面达到某些设计要求。,,6,,插值、逼近和拟合,7,,曲线段间的连续性定义,,连续性,,:,,,C0,连续(,0,阶参数连续),——,前一段曲线的终点与后一段曲线的起点相同。,,,C1,连续(一阶参数连续),——,两相邻曲线段的连接点处有相同的一阶导数。,,,C2,连续(二阶参数连续),——,两相邻曲线段的连接点处有相同的一阶导数
5、和二阶导数。,,8,,对于参数曲线段,,若,:1),,则 在,P,处具有 连续;,,,2),在点,P,处重合,且在点,P,处的切矢量方向相同,大小不相等,则,,,在点,P,处具有 连续;,,,3),在点,P,处重合,且在,P,点处的切矢量方向相同,大小相等,则 在点,P,处具有 连续;,,9,,4,)若 在点处已有 , 连续性,且 的大小和方向均相同,则 在点,P,处具有 连续;,,,,5),若 在点处已有
6、 , 连续性,且,,的方向相同,大小不相等,则 在点,P,处具有 连续;,,10,,Bezier,曲线/曲面,Bezier,曲线的定义,,在给定空间n+1个点P,0,,,P,1,,,,P,n,,称下列参数曲线为n次的,Bezier,曲线,,,,其中, 是,Bernstein,基函数,即,,,11,,一般称折线P,0,,,P,1,,,,P,n,为,C(u),的控制多边形;P,0,,,P,1,,,,P,n,各点为,C(u),的控制顶点。控制多边形是,C(u),的大致形状的勾画;,C(u),是对P,0,,,P,1,,,
7、,P,n,的逼近。,,Bezier,曲线/曲面,12,,常用,Bezier,曲线的矩阵表示,一次,Bezier,曲线:,,,矩阵表示为:,,,这是一条从 到 的直线段,,13,,常用,Bezier,曲线的矩阵表示,二次,Bezier,曲线,,,,矩阵表示为,,14,,常用,Bezier,曲线的矩阵表示,三次,Bezier,曲线,,,,矩阵表示为:,15,,Bernstein,基函数具有下列性质:,,,1,),非负性:,,对于所有的,i,n,以及 均有,,成立;,,,2,),规范性:,,,,,3),对称性,,,16,,4),递推性,,,,5),端点性,,17,
8、,6),最大性,,:,,,在 处达到最大值;,,7),可导性,,,,8),升阶公式,,,18,,9),分割性,,,10),积分性,,19,,2,.,Bezier,曲线的性质,,,Bezier,曲线,C(u),具有以下性质:,,,1),端点性质,,,,,2),,端点切矢量,,,,,,Bezier,曲线在 点处与边 相切,在点 处与边 相切。,,,,20,,3),端点的曲率,:在,C(u),两端点的曲率分别为:,,,,,,这是因为,,,,21,,4,)对称性,,,若保持原全部顶点的位置不变,只是把次序颠倒过来,则新的,Bezier,曲线形状不变,但方向相
9、反。,,5,)几何不变性,,Bezier,曲线的位置和形状只与特征多边形的顶点的位置有关,它不依赖坐标系的选择。,22,,6,)凸包性,,,因为是多边形各顶点P,0,,,P,1,,,,P,n,的加权平均,而权因子 ,这反映在几何图形上有两重含义:,,a.,,Bezier,曲线,C(u),位于其控制顶点P,0,,,P,1,,,,P,n,的凸包之内;,,b.Bezier,曲线,C(u),随着其控制多边形的变化而变化;,,7,)变差缩减性,,对于平面,Bezier,曲线,C(u),,平面内任意条直线与其交点的个数不多于该直线与其控制多边形的交点个数;,23,
10、,4,.,Bezier,曲线的,De Casteljau,算法,,给定三维空间点 以及一维标量参数,u,;假定:,,,,并且,那么 即为,Bezier,曲线上参数,u,处的点。,,24,,DeCasteljau (P,n,u,C),,{ /* Compute point on a Bezier curve using DeCasteljau algorithm */,,/* Input : P,n,u */,,/* Output: C (a point) */,,for(i=0;i<=n;i++ ),,Q[i]=P[i] ;,,for(k=1; k<=n
11、; k++),,for(i=0; i<=n-k; i++),,Q[i]=(1.0-u)*Q[i]+u*Q[i+1] ;,,C=Q[0] ;,,},,25,,,5,.,Bezier,曲线的几何作图法,,,利用,De Casteljau,算法可以以几何方式计算参数值 处的曲线点:,,1,)根据给定的参数值,u,,在控制多边形的每条边上确定某一分割点,使分割后的线段之比为,u,:(1-u),;由此得分割点为,:,,,由此组成一个边数为(,n-1,)的新的多边形;,,26,,2,)用相同的方法对该多边形再次分割,得到分割点 形成另一个新的
12、多边形,;,,,3,)按相同的过程分割,n-1,次后,得到两个顶点 ,再分割得到所求的点,,即为所求的,u,处的曲线点;,,,27,,Sub-Dividing Bezier Curves,P,0,P,1,P,2,P,3,考试!!,28,,,,,,,,,图,8.6 Bezier,曲线的几何作图法,,29,,6,.,Bezier,曲线的分割,,几何作图法中计算得到 的同时也将原,Bezier,曲线分为两个子曲线段:,,就是定义在 上的子曲线段,而 是定义在 上的子曲线段
13、。,,Bezier,曲线的任意分割是指给定两个参数值,,,求原,Bezier,曲线 上由两点 与 所界定的那段子曲线段的控制顶点:,,1),先用 对原曲线做一分为二的分割;,,,30,,2,),对 那个子曲线用 做一分为二的分割,所得子曲线段就是所求的原,Bezier,曲线的子曲线段,,,,,,,,,,,,Bezier,曲线的分割,,,31,,7,.,Bezier,曲线的升阶,,,有时为了便于,Bezier,曲线的修改,需要增加控制顶点提高灵活性,而不要改变原来
14、曲线的形状,也就是将,n,次的,Bezier,曲线进行升级表达为,n+1,次的,Bezier,曲线,即:,,,,只需将左边乘以 然后比较,,,的系数,即可得到,,,32,,几何意义:,,1,)新的控制顶点是对老的特征多边形在参数 处进行线性插值的结果;,,2,)升阶后的新的特征多边形在老的特征多边形的凸包内;,,3,)升阶后的新的特征多边形更逼近,Bezier,曲线;,,33,,例如对于二次,Bezier,曲线:,,,,,升阶后的控制顶点为,,34,,8.,Bezier,曲线的顶点反求,,已知,Bezier,曲线上给定参数处的位置矢量和参数阶次
15、,,利用,Bezier,曲线定义和,端点特性,可列出一组方程,求解方程组,就可得到相应的,控制顶点。,,例子:,,,已知三次,Bezier,曲线上的四个点分别为,Q0(120,0),Q1(45,0), Q2(0,45),Q3(0,120),,它们对应的参数分别为,0, 1/3, 2/3, 1,,反求三次,Bezier,曲线的控制顶点,。,,由已知条件可得方程组:,,35,,Q,0 =,P,0 (t=0),,Q,1 = (8/27),P,0 + (4/9),P,1 + (2/9),P,2 + (1/27),P,
16、3 (t=1/3),,Q,2 = (1/27),P,0 + (2/9),P,1 + (4/9),P,2 + (8/27),P,3 (t=2/3),,Q,3 =,P,3 (t=1),,zier,曲线的端点性质得到的;其余两式是由三次,Bezier,曲线的展开式:,,C(u)=(1-u),3,P,0,+3u(1-u),2,P,1,+3u,2,(1-u)P,2,+u,3,P,3,,,分别将,Q,0,、,Q,1,、,Q,2,、,Q,3,的,x,、,y,坐标代入方程组求解,可得:,,x0 =
17、 120 x1= 35,,x2 = –27.5 x3 = 0,,y0 = 0 y1 = –27.5,,y2 = 35 x3 = 120,,36,,9. Bezier,曲线的拼接,,设有两条,Bezier,曲线 和 ,其控制顶点分别为:P,0,,,P,2,,,,P,n,,和,Q,0,,Q,2,,,,Q,m,:,,37,,现考虑两条曲线的拼接,不同阶几何连续的条件如下:,,1),一阶连续性,,根据端矢量条件:,,,,,其连续条件为,,即 :,,38,,1,),二阶连续性,,根据二阶导矢量:,,,,为满足连续性条件:,,
18、可得:,,,39,,,,,,,,,,Bezier,曲线的拼接,,40,,Bezier,曲面,,1,.定义,,,在空间给定 个点,,称下列张量积形式的,,,,一般称为,P,ij,为,Bezier,曲面 的控制顶点;把由两组多边形,(i=0, 1, …, n),和,,(j=0,1,2, …., m),组成的网称为,Bezier,曲面 的控制网格,记为,,41,,控制网格 是 的大致形状勾画;,,是对 的逼近。,,,,,,,,,,,,,,,Bezier,曲面,,42,,2,.性质,,Bezier,曲面
19、 具有以下性质:,,1),端点位置,:,,四个端点分别是 这是因为,,,,2),边界曲线,,的四条边界,,线分别是以,,,,为控制多边形的,Bezier,曲线。,,43,,,3),端点的切平面,,,三角形,,,,所在的平面分别在点 与曲面相切,,4),端点法线方向,,,由端点的切平面知是 在点的法线方向;其余各端点,的法向情况也类似,44,,,5),凸包性,,,曲面 位于其控制顶点,,,的凸包性。,,6),几何不变性,,,曲面 的形状和位置与坐标系的选取无关,仅仅与各控制顶点的位置有关,,,7)
20、,,变差递减性,,对于,Bezier,曲面,空间任意条直线与其交点的个数不多于该直线与其控制多边形的交点个数;,,45,,3,.,Bezier,曲面的,De Casteljau,算法,,假定已知 个点,,构成的,Bezier,曲面 以及参数,,下面的,De Casteljau,算法可计算出相应的曲面上的点坐标:,,首先对确定的 计算 ,也就是说利用,De Casteljau,算法计算控制顶点的第,J0,行 ;利用,(m+1),次,,,De Casteljau,算法计算,;,再
21、次对 计算,,的值得到所求的点。,46,,DeCasteljauSurf(P, n, m, u, v, S),,{ /* Compute a point on a Bezier surface */,,/* Input : P , n, m, u, v */,,/* Output : S */,,if(n<=m),,{,,for(j=0;j<=m;j++),,DeCasteljau(P[j][], n, u, Q[j]),,DeCasteljau(Q, m, v, S) ;,,},,else {,,for(i=0;i<=n;i++),,DeCasteljau(P[][i
22、], m, v, Q[i]) ;,,DeCasteljau(Q, n, u, S) ;,,},47,,4,.,Bezier,曲面的微分,,,阶的,Bezier,曲面 的偏微分,,,,,,,5,.,Bezier,曲面的法矢量,,,Bezier,曲面的法矢量等于两个偏微分的叉积;,,48,,6,.,Bezier,曲面的升阶,,,,假设将 阶的,Bezier,曲面升阶为 ,则:,,,,采用,Bezier,曲线升阶类似的处理方法,得到:,,49,,若升阶为 ,则:,,,,,7,.,Bezier,曲面的几种
23、表达形式,,,1),双一次,Bezier,曲面:,,,,这是一双曲抛物面(马鞍面);,,2),双二次,Bezier,曲面,,,,,,50,,该曲面的四条边界是抛物线,,,3),双三次,Bezier,曲面:,,,,该曲面的四条边界都是三次,Bezier,曲线;可通过控制内部的四个控制顶点,,来控制曲面内部的形状;,,,,51,,8,.,Bezier,曲面拼接,,两块曲面拼接时,若在其公共边界上任一点的切平面重合,则称这两曲面沿其公共边界达到了,G,1,连续。,,,设 阶,Bezier,曲面 和另一块 阶曲面 拼接:,,52,,如果下列条件满足,,,,,其中,k
24、,为常数,则 和 沿其公共边界,,,P,(,1,,,v,)达到,G,1,连续。,,,53,,Common edge,54,,What Does OpenGL Support?,Evaluators: a general mechanism for working with the Bernstein polynomials,,Can use any degree polynomials,,Can use in 1-4 dimensions,,Automatic generation of normals and texture coordinates,,NURBS sup
25、ported in GLU,,Quadrics,,GLU and GLUT contain polynomial approximations of quadrics,55,,One-Dimensional Evaluators,Evaluate a Bernstein polynomial of any degree at a set of specified values,,Can evaluate a variety of variables,,Points along a 2, 3 or 4 dimensional curve,,Colors,,Normals,,Texture Coo
26、rdinates,,We can set up multiple evaluators that are all evaluated for the same value,56,,Setting Up an Evaluator,glMap1f(type,u_min,u_max,stride,,,order, pointer_to_array),what we want to evaluate,max and min of,u,1+degree of polynomial,pointer to control data,separation between,,data points,Each t
27、ype must be enabled by,,glEnable(type),57,,Example,Consider an evaluator for a cubic Bezier curve over (0,1),point data[ ]={…………..}; * /3d data /*,,glMap1f(GL_MAP_VERTEX_3,0.0,1.0,3,4,data);,data are 3D vertices,cubic,data are arranged as,x,y,z,x,y,z……,,three floats between data points in array,glEn
28、able(GL_MAP_VERTEX_3);,58,,Evaluating,The function,glEvalCoord1f(u),causes all enabled evaluators to be evaluated for the specified,u,,Can replace,glVertex, glNormal, glTexCoord,,The values of,u,need not be equally spaced,59,,Example,Consider the previous evaluator that was set up,,for a cubic Bezie
29、r over (0,1),Suppose that we want to approximate the curve,,with a 100 point polyline,glBegin(GL_LINE_STRIP),,for(i=0; i<100; i++),,glEvalCoord1f( (float) i/100.0);,,glEnd();,60,,Equally Spaced Points,Rather than use a loop, we can set up an equally spaced mesh (grid) and then evaluate it with one f
30、unction call,glMapGrid(100, 0.0, 1.0);,sets up 100 equally-spaced points on (0,1),glEvalMesh1(GL_LINE, 0, 99);,renders lines between adjacent evaluated,,points from point 0 to point 99,61,,Bezier Surfaces,Similar procedure to 1D but use 2D evaluators in,u,and,v,,Set up with,,,glMap2f(type, u_min, um
31、ax, u_stride, u_order, v_min, v_max, v_stride, v_order, pointer_to_data),,,Evaluate with,glEvalCoord2f(u,v),62,,Example,bicubic over (0,1) x (0,1),point data[4][4]={………};,,glMap2f(GL_MAP_VERTEX_3, 0.0, 1.0, 3, 4,,,0.0, 1.0, 12, 4, data);,Note that in v direction data points,,are separated by 12 floa
32、ts since array,,data,is stored by rows,63,,Rendering with Lines,for(j=0;j<100;j++) {,,glBegin(GL_LINE_STRIP);,,for(i=0;i<100;i++),,glEvalCoord2f((float) i/100.0, (float) j/100.0);,,glEnd();,,glBegin(GL_LINE_STRIP);,,for(i=0;i<100;i++),,glEvalCoord2f((float) j/100.0, (float) i/100.0);,,glEnd();,,},,m
33、ust draw in both directions,64,,Rendering with Quadrilaterals,for(j=0; j<99; j++) {,,glBegin(GL_QUAD_STRIP);,,for(i=0; i<100; i++) {,,glEvalCoord2f ((float) i/100.0,,,(float) j/100.0);,,glEvalCoord2f ((float)(i+1)/100.0,,,(float)j/100.0);,,},,glEnd():,,},We can form a quad mesh and render with lines
34、,65,,Uniform Meshes,We can form a 2D mesh (grid) in a similar manner to 1D for uniform spacing,,glMapGrid2(u_num, u_min, u_max, v_num, v_min, v_max),,,Can evaluate as before with lines or if want filled polygons,,glEvalMesh2( GL_FILL, u_start, u_num, v_start, v_num),66,,Rendering with Lighting,If we
35、 use filled polygons, we have to shade or we will see solid color uniform rendering,,Can specify lights and materials but we need normals,,Let OpenGL find them,,glEnable(GL_AUTO_NORMAL);,67,,OpenGL,中的,Bezier,曲线/曲面,二次曲面,,创建二次曲面对象,,GLUquadricObj*,,gluNewQuadric() ;,,void gluDeleteQuadric(GLUquadric *q
36、obj) ;,,指定二次曲面绘制的方法和状态,,Void gluQuadricDrawStyle(GLUquadric* qobj,Glenum drawstyle) ;,,GLU_FILL,GLU_LINE,GLU_POINT,GLU_SILHOUETTE,,Void gluQuadricNormals(GLUquadric* qobj,GLenum normals) ;,,Void gluQuadricOrientation(GLUquadric* qobj,GLenum orientation) ;,,Void gluQuadricTexture(GLUquadric* qobj,GLe
37、num textureCoords) ;,68,,二次曲面,绘制二次曲面,,球体,,Void gluSphere(GLUquadric* qobj,GLdouble radius,GLint slices, Glint stacks) ;,,园柱,,Void gluCylinder(GLUquadric* qobj,GLdouble baseRadius,GLdouble topRadius,GLdouble height,GLint slices, Glint stacks) ;,,圆盘,,Void gluDisk(GLUquadric* qobj,GLdouble innerRadius,
38、GLdouble outerRadius, GLint slices, Glint stacks) ;,,部分圆盘,,Void gluPartialDisk(GLUquadric* qobj,GLdouble innerRadius,GLdouble outerRadius, GLint slices, GLint loops, GLdouble startAngle,Gldouble sweepAngle) ;,69,,OpenGL,中的二次曲面,二次曲面的绘制请见,quadric.c,70,,OpenGL,中的,Bezier,曲线,#include ,,#include ,,GLfloat
39、 ctrlpoints[4][3] = { { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0}, {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};,,void init(void){,,glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_FLAT); glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, ,,},71,,OpenGL,中的,Bezier,曲线,void display(void){,,int i;,,glClear(GL_COLOR_BUFFER
40、_BIT);,,glColor3f(1.0, 1.0, 1.0);,,glBegin(GL_LINE_STRIP);,,for (i = 0; i <= 30; i++),,glEvalCoord1f((GLfloat) i/30.0);,,glEnd(); /* The following code displays the control points as dots. */,,glPointSize(5.0);,,glColor3f(1.0, 1.0, 0.0);,,glBegin(GL_POINTS);,,for (i = 0; i < 4; i++),,glVertex3fv(,
41、,glEnd();,,glFlush();,,},72,,OpenGL,中的,Bezier,曲线,void reshape(int w, int h){,,glViewport(0, 0, (GLsizei) w, (GLsizei) h);,,glMatrixMode(GL_PROJECTION);,,glLoadIdentity();,,if (w <= h),,glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w, 5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);,,else,,glOrtho
42、(-5.0*(GLfloat)w/(GLfloat)h, 5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);,,glMatrixMode(GL_MODELVIEW);,,glLoadIdentity();,,},73,,OpenGL,中的,Bezier,曲线,void keyboard(unsigned char key, int x, int y){,,switch (key) {,,case 27:,,exit(0);,,break;,,} },,int main(int argc, char** argv
43、){,,glutInit(,,glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);,,glutInitWindowSize (500, 500);,,glutInitWindowPosition (100, 100);,,glutCreateWindow (argv[0]);,,init ();,,glutDisplayFunc(display);,,glutReshapeFunc(reshape);,,glutKeyboardFunc (keyboard);,,glutMainLoop();,,return 0;,,},74,,OpenGL,中的,Bez
44、ier,曲面,#include ,,#include ,,GLfloat ctrlpoints[4][4][3] = { {{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, {0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}}, {{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, {{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, {0.5, 0.5, 3.0}, {1.5, 0.5,
45、4.0}}, {{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}},,};,75,,OpenGL,中的,Bezier,曲面,void display(void){,,int i, j;,,glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);,,glColor3f(1.0, 1.0, 1.0);,,glPushMatrix ();,,glRotatef(85.0, 1.0, 1.0, 1.0);,,for (j = 0; j <= 8; j
46、++) {,,glBegin(GL_LINE_STRIP);,,for (i = 0; i <= 30; i++),,glEvalCoord2f((GLfloat)i/30.0, (GLfloat)j/8.0);,,glEnd();,,glBegin(GL_LINE_STRIP);,,for (i = 0; i <= 30; i++),,glEvalCoord2f((GLfloat)j/8.0, (GLfloat)i/30.0);,,glEnd();,,},,glPopMatrix ();,,glFlush();,,},76,,OpenGL,中的,Bezier,曲面,void init(voi
47、d){,,glClearColor (0.0, 0.0, 0.0, 0.0);,,glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, ,,glEnable(GL_MAP2_VERTEX_3);,,glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);,,glEnable(GL_DEPTH_TEST);,,glShadeModel(GL_FLAT);,,},,void reshape(int w, int h){,,glViewport(0, 0, (GLsizei) w, (GLsizei) h);
48、,,glMatrixMode(GL_PROJECTION);,,glLoadIdentity();,,if (w <= h),,glOrtho(-4.0, 4.0, -4.0*(GLfloat)h/(GLfloat)w, 4.0*(GLfloat)h/(GLfloat)w, -4.0, 4.0);,,else,,glOrtho(-4.0*(GLfloat)w/(GLfloat)h, 4.0*(GLfloat)w/(GLfloat)h, -4.0, 4.0, -4.0, 4.0);,,glMatrixMode(GL_MODELVIEW);,
49、,glLoadIdentity();,,},77,,OpenGL,中的,Bezier,曲面,void keyboard(unsigned char key, int x, int y){,,switch (key) {,,case 27:,,exit(0);,,break;,,}},,int main(int argc, char** argv){,,glutInit(,,glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);,,glutInitWindowSize (500, 500);,,glutInitWindowPositi
50、on (100, 100);,,glutCreateWindow (argv[0]);,,init ();,,glutDisplayFunc(display);,,glutReshapeFunc(reshape);,,glutKeyboardFunc(keyboard);,,glutMainLoop();,,return 0;,,},78,,OpenGL,中的,Bezier,曲面,#include ,,#include ,,GLfloat ctrlpoints[4][4][3] = { { {-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0}, {0.5
51、, -1.5, -1.0}, {1.5, -1.5, 2.0}}, { {-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0}, {0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}}, { {-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0}, {0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}}, { {-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0}, {0.5, 1.5, 0.0}, {1.5, 1.5, -
52、1.0}},,};,79,,OpenGL,中的,Bezier,曲面,void initlights(void){,,GLfloat ambient[] = {0.2, 0.2, 0.2, 1.0};,,GLfloat position[] = {0.0, 0.0, 2.0, 1.0};,,GLfloat mat_diffuse[] = {0.6, 0.6, 0.6, 1.0};,,GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0};,,GLfloat mat_shininess[] = {50.0};,,glEnable(GL_LIGHTING);,,g
53、lEnable(GL_LIGHT0);,,glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);,,glLightfv(GL_LIGHT0, GL_POSITION, position);,,glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);,,glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);,,},80,,OpenGL,中的,Bezier,曲面,void d
54、isplay(void){,,glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);,,glPushMatrix();,,glRotatef(85.0, 1.0, 1.0, 1.0);,,glEvalMesh2(GL_FILL, 0, 20, 0, 20);,,glPopMatrix();,,glFlush();},,void init(void){,,glClearColor(0.0, 0.0, 0.0, 0.0);,,glEnable(GL_DEPTH_TEST);,,glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4,
55、 0, 1, 12, 4, ,,glEnable(GL_MAP2_VERTEX_3);,,glEnable(GL_AUTO_NORMAL);,,glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0);,,initlights(); /* for lighted version only */,,},81,,OpenGL,中的,Bezier,曲面,void reshape(int w, int h){,,glViewport(0, 0, (GLsizei) w, (GLsizei) h);,,glMatrixMode(GL_PROJECTION
56、);,,glLoadIdentity();,,if (w <= h),,glOrtho(-4.0, 4.0, -4.0*(GLfloat)h/(GLfloat)w, 4.0*(GLfloat)h/(GLfloat)w, -4.0, 4.0);,,else,,glOrtho(-4.0*(GLfloat)w/(GLfloat)h, 4.0*(GLfloat)w/(GLfloat)h, -4.0, 4.0, -4.0, 4.0);,,glMatrixMode(GL_MODELVIEW);,,glLoadIdentity();},,void keyb
57、oard(unsigned char key, int x, int y){ switch (key) {,,case 27:,,exit(0);,,break; },,},82,,OpenGL,中的,Bezier,曲面,int main(int argc, char **argv){,,glutInit(,,glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);,,glutInitWindowSize (500, 500);,,glutInitWindowPosition (100, 100);,,glutCreateWindow(argv[0]); init();,,glutReshapeFunc(reshape);,,glutDisplayFunc(display);,,glutKeyboardFunc(keyboard);,,glutMainLoop();,,return 0;,,},83,,Your Shape: Please exercise it!!!,84,,Next Lecture is about NURBS…,85,,QUITTING,TIME,86,86,,
- 温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。