資源描述:
《立方體動(dòng)態(tài)畫(huà)家消隱算法》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、#include#include#include#include#defineGLUT_WHEEL_UP3//定義滾輪操作#defineGLUT_WHEEL_DOWN4floatPI=3.1415926;floatpoints[8][3]={{-1.0,-1.0,-1.0},{1.0,-1.0,-1.0},{1.0,1.0,-1.0},{-1.0,1.0,-1.0},{-1.0,-1.0,1.0},{1.0,-1.0,1.0},{1.0,1.0,1.0},{-1.0,1.0,1.0}};floatcolors[6][
2、3]={{0,1,1},{0,0,1},{1,0,0},{1,1,0},{0,1,0},{1,0,1}};intfaces[6][4]={{4,5,6,7},{1,2,6,5},{0,3,2,1},{0,4,7,3},{0,1,5,4},{2,3,7,6}};floatx[4],y[4],z[4];floatanglex=PI*30/180,angley=PI*30/180,anglez=PI*30/180;floatsize=1.0;GLubyteaoyun[]={//0,1,1,1,0,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1,0,0,0,1,1
3、,0,0,0,1,0,1,1,1,0};0x00,0x00,0x00,0x00,0x00,0x1E,0x07,0x00,0x03,0xFE,0x0F,0x80,0x07,0xFF,0x07,0xF0,0x0F,0xFF,0x83,0xF0,0x0F,0xFF,0xC1,0xF0,0x0F,0xFF,0xF0,0xF8,0x0F,0xFF,0xF8,0x78,0x0F,0xF3,0xF8,0x38,0x0F,0x80,0x7C,0x38,0x0F,0x00,0x38,0x78,0x07,0x04,0x30,0x70,0x0F,0x0C,0x20,0xF8,0x07,0x0C,0x01,0xF8
4、,0x07,0x0C,0x03,0xF8,0x00,0x0C,0x0F,0xF8,0x08,0x18,0x1F,0xF0,0x0E,0x38,0x0F,0xF0,0x0F,0xF0,0x8F,0xF0,0x0F,0xF0,0x8F,0xF0,0x0F,0xF0,0x8F,0xF0,0x06,0x00,0x0F,0xF0,0x04,0x00,0x03,0xF0,0x04,0x00,0x00,0x60,0x06,0x7F,0xF0,0x00,0x07,0x7E,0x3E,0x00,0x03,0xFC,0x3F,0x80,0x03,0xFC,0x3F,0x80,0x01,0xFE,0x7E,0x0
5、0,0x00,0xFF,0xF0,0x00,0x00,0x1F,0x00,0x00,0x00,0x00,0x00,0x00};voidRotationx(floatx_,floaty_,floatz_,inti)//點(diǎn)饒X軸旋轉(zhuǎn)時(shí),改變一個(gè)點(diǎn)的坐標(biāo){x[i]=x_;y[i]=y_*cos(anglex)-z_*sin(anglex);z[i]=y_*sin(anglex)+z_*cos(anglex);}voidRotationy(floatx_,floaty_,floatz_,inti)//點(diǎn)饒Y軸旋轉(zhuǎn)時(shí),改變一個(gè)點(diǎn)的坐標(biāo){x[i]=x_*cos(angley)+z_*sin(angley
6、);y[i]=y_;z[i]=z_*cos(angley)-x_*sin(angley);}voidRotationz(floatx_,floaty_,floatz_,inti)//點(diǎn)饒Z軸旋轉(zhuǎn)時(shí),改變一個(gè)點(diǎn)的坐標(biāo){x[i]=x_*cos(anglez)-y_*sin(anglez);y[i]=x_*sin(anglez)+y_*cos(anglez);z[i]=z_;}voidChangex(inta,intb,intc,intd)//一個(gè)平面饒X軸旋轉(zhuǎn)時(shí)4個(gè)點(diǎn)坐標(biāo)的該改{Rotationx(points[a][0],points[a][1],points[a][2],0);Rotatio
7、nx(points[b][0],points[b][1],points[b][2],1);Rotationx(points[c][0],points[c][1],points[c][2],2);Rotationx(points[d][0],points[d][1],points[d][2],3);}voidChangey()//一個(gè)平面饒Y軸旋轉(zhuǎn)時(shí)4個(gè)點(diǎn)坐標(biāo)的該改{Rotationy(x[0],y[0],z[