山大教材资料`交互式计算机图形学`附录源码.doc山大教材资料`交互式计算机图形学`附录源码.doc

收藏 分享

资源预览需要最新版本的Flash Player支持。
您尚未安装或版本过低,建议您

交互式计算机图形学基于OPENGL的自顶向下方法山东大学数字媒体技术专业课本教材附录程序第四版A1SIERPINSKI镂垫程序/TWODIMENSIONALSIERPINSKIGASKET//GENERATEDUSINGRANDOMLYSELECTEDVERTICES//ANDBISECTION/INCLUDEGL/GLUTH/YOUMAYHAVETOCHANGETHEINCLUDETOGLUTHORELSEWHEREDEPENDINGONWHEREITISSTOREDONYOURSYSTEM//GLUTHUSUALLYHASINCLUDEDFORGLHANDGLUH/VOIDMYINITVOID{/ATTRIBUTES/GLCLEARCOLOR10,10,10,10;/WHITEBACKGROUND/GLCOLOR3F10,00,00;/DRAWINRED//SETUPVIEWING//500500CAMERACOORDINATEWINDOWWITHORIGINLOWERLEFT/GLMATRIXMODEGL_PROJECTION;GLLOADIDENTITY;GLUORTHO2D00,500,00,500;GLMATRIXMODEGL_MODELVIEW;}VOIDDISPLAYVOID{/ATRIANGLE/GLFLOATVERTICES32{{00,00},{250,500},{500,00}};INTI,J,K;INTRAND;/STANDARDRANDOMNUMBERGENERATOR/GLFLOATP2{75,50};/ANARBITRARYINITIALPOINTINSIDETRAINGLE/GLCLEARGL_COLOR_BUFFER_BIT;/CLEARTHEWINDOW/GLBEGINGL_POINTS;/COMPUTEANDPLOTS5000NEWPOINTS/交互式计算机图形学基于OPENGL的自顶向下方法第4版586FORK0;K5000;K{JRAND3;/PICKAVERTEXATRANDOM//COMPUTEPOINTHALFWAYBETWEENSELECTEDVERTEXANDOLDPOINT/P0P0VERTICESJ0/20;P1P1VERTICESJ1/20;/PLOTNEWPOINT/GLVERTEX2FVP;}GLEND;GLFLUSH;/CLEARBUFFERS/}VOIDMAININTARGC,CHARARGV{/STANDARDGLUTINITIALIZATION/GLUTINITARGC,ARGV;GLUTINITDISPLAYMODEGLUT_SINGLE|GLUT_RGB;/DEFAULT,NOTNEEDED/GLUTINITWINDOWSIZE500,500;/500500PIXELWINDOW/GLUTINITWINDOWPOSITION0,0;/PLACEWINDOWTOPLEFTONDISPLAY/GLUTCREATEWINDOWSIERPINSKIGASKET;/WINDOWTITLE/GLUTDISPLAYFUNCDISPLAY;/DISPLAYCALLBACKINVOKEDWHENWINDOWOPENED/MYINIT;/SETATTRIBUTES/GLUTMAINLOOP;/ENTEREVENTLOOP/}A2生成SIERPINSKI镂垫的递归程序/RECURSIVESUBDIVISIONOFTRIANGLETOFORMSIERPINSKIGASKET//NUMBEROFRECURSIVESTEPSGIVENONCOMMANDLINE/INCLUDEGL/GLUTHINCLUDESTDLIBH/INITIALTRIANGLE/GLFLOATV32{{10,058},{10,058},{00,115}};INTN;VOIDTRIANGLEGLFLOATA,GLFLOATB,GLFLOATC/DISPLAYONETRIANGLE/附录A实例程序587{GLVERTEX2FVA;GLVERTEX2FVB;GLVERTEX2FVC;}VOIDDIVIDE_TRIANGLEGLFLOATA,GLFLOATB,GLFLOATC,INTM{/TRIANGLESUBDIVISIONUSINGVERTEXNUMBERS/GLFLOATV02,V12,V22;INTJ;IFM0{FORJ0;J2;JV0JAJBJ/2;FORJ0;J2;JV1JAJCJ/2;FORJ0;J2;JV2JBJCJ/2;DIVIDE_TRIANGLEA,V0,V1,M1;DIVIDE_TRIANGLEC,V1,V2,M1;DIVIDE_TRIANGLEB,V2,V0,M1;}ELSETRIANGLEA,B,C;/DRAWTRIANGLEATENDOFRECURSION/}VOIDDISPLAYVOID{GLCLEARGL_COLOR_BUFFER_BIT;GLBEGINGL_TRIANGLES;DIVIDE_TRIANGLEV0,V1,V2,N;GLEND;GLFLUSH;}VOIDMYINIT{GLMATRIXMODEGL_PROJECTION;GLLOADIDENTITY;GLUORTHO2D20,20,20,20;GLMATRIXMODEGL_MODELVIEW;GLCLEARCOLOR10,10,10,10;GLCOLOR3F00,00,00;}VOIDMAININTARGC,CHARARGV{NATOIARGV1;/ORSETNUMBEROFSUBDIVISIONSTEPSHERE/GLUTINITARGC,ARGV;GLUTINITDISPLAYMODEGLUT_SINGLE|GLUT_RGB;GLUTINITWINDOWSIZE500,500;GLUTCREATEWINDOWSIERPINSKIGASKET;交互式计算机图形学基于OPENGL的自顶向下方法第4版588GLUTDISPLAYFUNCDISPLAY;MYINIT;GLUTMAINLOOP;}A3三维SIERPINSKI镂垫的递归程序/RECURSIVESUBDIVISIONOFATETRAHEDRONTOFORM3DSIERPINSKIGASKET//NUMBEROFRECURSIVESTEPSGIVENONCOMMANDLINE/INCLUDESTDLIBHINCLUDEGL/GLUTH/INITIALTETRAHEDRON/GLFLOATV43{{00,00,10},{00,0942809,033333},{0816497,0471405,0333333},{0816497,0471405,0333333}};GLFLOATCOLORS43{{10,00,00},{00,10,00},{00,00,10},{00,00,00}};INTN;VOIDTRIANGLEGLFLOATVA,GLFLOATVB,GLFLOATVC{GLVERTEX3FVVA;GLVERTEX3FVVB;GLVERTEX3FVVC;}VOIDTETRAGLFLOATA,GLFLOATB,GLFLOATC,GLFLOATD{GLCOLOR3FVCOLORS0;TRIANGLEA,B,C;GLCOLOR3FVCOLORS1;TRIANGLEA,C,D;GLCOLOR3FVCOLORS2;TRIANGLEA,D,B;GLCOLOR3FVCOLORS3;TRIANGLEB,D,C;}VOIDDIVIDE_TETRAGLFLOATA,GLFLOATB,GLFLOATC,GLFLOATD,INTM{GLFLOATMID63;INTJ;IFM0{/COMPUTESIXMIDPOINTS/附录A实例程序589FORJ0;J3;JMID0JAJBJ/2;FORJ0;J3;JMID1JAJCJ/2;FORJ0;J3;JMID2JAJDJ/2;FORJ0;J3;JMID3JBJCJ/2;FORJ0;J3;JMID4JCJDJ/2;FORJ0;J3;JMID5JBJDJ/2;/CREATE4TETRAHEDRONSBYSUBDIVISION/DIVIDE_TETRAA,MID0,MID1,MID2,M1;DIVIDE_TETRAMID0,B,MID3,MID5,M1;DIVIDE_TETRAMID1,MID3,C,MID4,M1;DIVIDE_TETRAMID2,MID4,D,MID5,M1;}ELSETETRAA,B,C,D;/DRAWTETRAHEDRONATENDOFRECURSION/}VOIDDISPLAYVOID{GLCLEARGL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT;GLBEGINGL_TRIANGLES;DIVIDE_TETRAV0,V1,V2,V3,N;GLEND;GLFLUSH;}VOIDMYRESHAPEINTW,INTH{GLVIEWPORT0,0,W,H;GLMATRIXMODEGL_PROJECTION;GLLOADIDENTITY;IFWHGLORTHO20,20,20GLFLOATH/GLFLOATW,20GLFLOATH/GLFLOATW,100,100;ELSEGLORTHO20GLFLOATW/GLFLOATH,20GLFLOATW/GLFLOATH,20,20,100,100;GLMATRIXMODEGL_MODELVIEW;GLUTPOSTREDISPLAY;}VOIDMAININTARGC,CHARARGV{NATOIARGV1;/ORENTERNUMBEROFSUBDIVISIONSTEPSHERE/GLUTINITARGC,ARGV;GLUTINITDISPLAYMODEGLUT_SINGLE|GLUT_RGB|GLUT_DEPTH;GLUTINITWINDOWSIZE500,500;GLUTCREATEWINDOW3DGASKET;交互式计算机图形学基于OPENGL的自顶向下方法第4版590GLUTRESHAPEFUNCMYRESHAPE;GLUTDISPLAYFUNCDISPLAY;GLENABLEGL_DEPTH_TEST;GLCLEARCOLOR10,10,10,10;GLUTMAINLOOP;}A4MARCHINGSQUARE程序/GENERATESCONTOURSUSINGMARCHINGSQUARES//REGIONSIZE/DEFINEX_MAX10DEFINEY_MAX10DEFINEX_MIN10DEFINEY_MIN10/NUMBEROFCELLS/DEFINEN_X50DEFINEN_Y50/CONTOURVALUE/DEFINETHRESHOLD00INCLUDEGL/GLUTHVOIDDISPLAY{DOUBLEFDOUBLE,DOUBLE;INTCELLDOUBLE,DOUBLE,DOUBLE,DOUBLE;VOIDLINESINT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE;DOUBLEDATAN_XN_Y;INTI,J;INTC;GLCLEARGL_COLOR_BUFFER_BIT;/FORMDATAARRAYFROMFUNCTION/FORI0;IN_X;IFORJ0;JN_Y;JDATAIJFX_MINIX_MAXX_MIN/N_X10,Y_MINJY_MAXY_MIN/N_Y10;/PROCESSEACHCELL/附录A实例程序591FORI0;IN_X;IFORJ0;JN_Y;J{CCELLDATAIJ,DATAI1J,DATAI1J1,DATAIJ1;LINESC,I,J,DATAIJ,DATAI1J,DATAI1J1,DATAIJ1;}GLFLUSH;}/DEFINEFUNCTIONFX,Y/DOUBLEFDOUBLEX,DOUBLEY{DOUBLEA049,B05;/OVALSOFCASSINI/RETURNXXYYAAXXYYAA4AAXXBBBB;}/DEFINECELLVERTICES/INTCELLDOUBLEA,DOUBLEB,DOUBLEC,DOUBLED{INTN0;IFATHRESHOLDN1;IFBTHRESHOLDN8;IFCTHRESHOLDN4;IFDTHRESHOLDN2;RETURNN;}/DRAWLINESEGMENTSFOREACHCASE/VOIDLINESINTNUM,INTI,INTJ,DOUBLEA,DOUBLEB,DOUBLEC,DOUBLED{VOIDDRAW_ONEINT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE;VOIDDRAW_ADJACENTINT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE;VOIDDRAW_OPPOSITEINT,INT,INT,DOUBLE,DOUBLE,DOUBLE,DOUBLE;SWITCHNUM{CASE1CASE2CASE4CASE7CASE8CASE11CASE13CASE14DRAW_ONENUM,I,J,A,B,C,D;BREAK;CASE3CASE6CASE9CASE12交互式计算机图形学基于OPENGL的自顶向下方法第4版592DRAW_ADJACENTNUM,I,J,A,B,C,D;BREAK;CASE5CASE10DRAW_OPPOSITENUM,I,J,A,B,C,D;BREAK;CASE0CASE15BREAK;}}VOIDDRAW_ONEINTNUM,INTI,INTJ,DOUBLEA,DOUBLEB,DOUBLEC,DOUBLED{DOUBLEX1,Y1,X2,Y2;DOUBLEOX,OY;DOUBLEDX,DY;DXX_MAXX_MIN/N_X10;DYY_MAXY_MIN/N_Y10;OXX_MINIX_MAXX_MIN/N_X10;OYY_MINJY_MAXY_MIN/N_Y10;SWITCHNUM{CASE1CASE14X1OX;Y1OYDYTHRESHOLDA/DA;X2OXDXTHRESHOLDA/BA;Y2OY;BREAK;CASE2CASE13X1OX;Y1OYDYTHRESHOLDA/DA;X2OXDXTHRESHOLDD/CD;Y2OYDY;BREAK;CASE4CASE11X1OXDXTHRESHOLDD/CD;Y1OYDY;X2OXDX;Y2OYDYTHRESHOLDB/CB;BREAK;CASE7CASE8X1OXDXTHRESHOLDA/BA;Y1OY;X2OXDX;Y2OYDYTHRESHOLDB/CB;BREAK;}GLBEGINGL_LINES;GLVERTEX2DX1,Y1;附录A实例程序593GLVERTEX2DX2,Y2;GLEND;}VOIDDRAW_ADJACENTINTNUM,INTI,INTJ,DOUBLEA,DOUBLEB,DOUBLEC,DOUBLED{DOUBLEX1,Y1,X2,Y2;DOUBLEOX,OY;DOUBLEDX,DY;DXX_MAXX_MIN/N_X10;DYY_MAXY_MIN/N_Y10;OXX_MINIX_MAXX_MIN/N_X10;OYY_MINJY_MAXY_MIN/N_Y10;SWITCHNUM{CASE3CASE12X1OXDXTHRESHOLDA/BA;Y1OY;X2OXDXTHRESHOLDD/CD;Y2OYDY;BREAK;CASE6CASE9X1OX;Y1OYDYTHRESHOLDA/DA;X2OXDX;Y2OYDYTHRESHOLDB/CB;BREAK;}GLBEGINGL_LINES;GLVERTEX2DX1,Y1;GLVERTEX2DX2,Y2;GLEND;}VOIDDRAW_OPPOSITEINTNUM,INTI,INTJ,DOUBLEA,DOUBLEB,DOUBLEC,DOUBLED{DOUBLEX1,Y1,X2,Y2,X3,Y3,X4,Y4;DOUBLEOX,OY;DOUBLEDX,DY;DXX_MAXX_MIN/N_X10;DYY_MAXY_MIN/N_Y10;OXX_MINIX_MAXX_MIN/N_X10;OYY_MINJY_MAXY_MIN/N_Y10;SWITCHNUM{CASE5X1OX;Y1OYDYTHRESHOLDA/DA;X2OXDXTHRESHOLDA/BA;
编号:201312012329378658    类型:共享资源    大小:217.50KB    格式:DOC    上传时间:2013-12-01
  
9
关 键 词:
专业文献 学术论文 精品文档 山大教材
  人人文库网所有资源均是用户自行上传分享,仅供网友学习交流,未经上传用户书面授权,请勿作他用。
关于本文
本文标题:山大教材资料`交互式计算机图形学`附录源码.doc
链接地址:http://www.renrendoc.com/p-138658.html

当前资源信息

4.0
 
(2人评价)
浏览:22次
21ask上传于2013-12-01

官方联系方式

客服手机:17625900360   
2:不支持迅雷下载,请使用浏览器下载   
3:不支持QQ浏览器下载,请用其他浏览器   
4:下载后的文档和图纸-无水印   
5:文档经过压缩,下载后原文更清晰   

精品推荐

相关阅读

人人文库
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服客服 - 联系我们

网站客服QQ:2846424093    人人文库上传用户QQ群:460291265   

copyright@ 2016-2018  renrendoc.com 网站版权所有   南天在线技术支持

经营许可证编号:苏ICP备12009002号-5