資源描述:
《OpenGL魔方設(shè)計與代碼》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在工程資料-天天文庫。
1、#ifndef_MagicCube_H_#define_MagicCube_H_#inelude#inelude#include#inelude#inelude#definePI3.141596typedefstruct{GLfloatXpos⑻;〃xcoordof8pointersGLfloatYpos⑻;GLfloatZpos⑻;GLfloatCenter[3];//Centerpos(x,y,z)JSmallCube;Small
2、CubeSmCube[27];GLuintTexture[27];voidCubelnit();//initialof8SmCubevoidMathlnit();voidEntireRotf);voidEntireRotAng();voidPartRot();//randthespinaxisvoidProPartRotX(intiCube);voidProPartRotY(intiCube);voidProPartRotZ(intiCube);voidPointRotfGLfloat*X1,GLfloat*X2,GLfloat*X
3、3);voidStartEffect();voidDrawSmCube();voidDrawMgCubef);GLfloatPoint⑻⑶=//pointcoordofaSmCube{l.Of,-l.Of,l.Of},//I{l.Of,l.Of,l.Of},〃2-{-l.Of,l.Of,l.Of},〃3{-l.Of,-l.Of,-l.Of},//4-back{-l.Of,l.Of,-l.Of},//5{l.Of,l.Of,-l.Of},//6■-{l.Of,?l.Of,-l.Of},//7};GLfloatCenterlnit[3]
4、={0,0z0};//initcenterpoint//pointsequeneeofSmCubefaceGLintFace[6][4]={{0,l,2,3},{4,567},{3,2,6,5},//front,back,up{0,4,7,1},{1,7,6,2},{0,3,5,4}};//bottom,rightJeftGLintTexCd[4]⑵二{{0,0},{1,0},{1,1},{0,1}};//texturecoordarrayforonesquareintxAng=0;〃entirerotateangleintyAng
5、=0;intzAng=0;intPartRotAng=0;//rememberthepartrotateangintAxis=0;//markthespinaxisGLfloatsina=0;GLfloatcosa=0;intStart=l;#endif#include"MagicCube.h"voidWindowslnit(){glClearColor(0,0z0zl);glClear(GL_DEPTH_BUFFER_BIT
6、GL_COLOR_BUFFER_BIT);glCullFace(GL_FRONT);glEnable(GL
7、_DEPTH_TEST);glEnable(GL_CULL_FACE);glEnable(GL_TEXTURE_2D);//smooththecubeglEnable(GL_POLYGON_SMOOTH);glHint(GL_POLYGON_SMOOTH,GL_NICEST);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);Mathlnit();Cubelnit();}voidMathlnit(){GLfloata=PI/180;//Idegre
8、eforonespinsina=sin(a);cosa=cos(a);}voidCubelnit()//initialofpointersandcenterposition{intijk;intiCube=0;intiPoint=0;GLfloatx,y,z;for(i=0,x=2;i<3;i++,x-=2)for(j=0,y=2;j<3;j++/y-=2)for(k=0,z=2;k<3;k++,z-=2){SmCube[iCube].Center[O]=Centerlnit[O]+x;//initcenter(x,y,z)ofSm
9、Cube[iCube]SmCube[iCube].Center[l]=Centerlnit[l]+y;SmCube[iCube].Center[2]=Centerlnit[2]+z;for(iPoint=0;iPoint<8;iPoi