at[k][j]); return c; } Matrix translate(Matrix p, double x, double y, double z) // 平移 { Matrix tmp; memset(tmp.mat,0,sizeof(tmp.mat)); for (int i=1;i<=4;i++) tmp.mat[i][i]=1; tmp.mat[1][4] = x; tmp.mat[2][4] = y; tmp.mat[3][4] = z; p=matMul(tmp,p,4); return p; } Matrix scale(Matrix p, double a, double b, double c) //缩放 { Matrix tmp; memset(tmp.mat,0,sizeof(tmp.mat)); for (int i=1;i<=4;i++) tmp.mat[i][i]=1; tmp.mat[1][1] = a; tmp.mat[2][2] = b; tmp.mat[3][3] = c; p=matMul(tmp,p,4); return p; } Matrix rotate(Matrix p, double x, double y, double z, double d) // 旋转 { double di = sqrt(x*x+y*y+z*z); // 单位化 x/=di, y/=di, z/=di; Matrix tmp; memset(tmp.mat,0,sizeof(tmp.mat)); tmp.mat[1][1] = (1-cos(d))*x*x + cos(d); tmp.mat[1][2] = (1-cos(d))*x*y - z*sin(d); tmp.mat[1][3] = (1-cos(d))*x*z + y*sin(d); tmp.mat[2][1] = (1-cos(d))*x*y + z*sin(d); tmp.mat[2][2] = (1-cos(d))*y*y + cos(d); tmp.mat[2][3] = (1-cos(d))*y*z - x*sin(d); tmp.mat[3][1] = (1-cos(d))*x*z - y*sin(d); tmp.mat[3][2] = (1-cos(d))*y*z + x*sin(d); tmp.mat[3][3] = (1-cos(d))*z*z + cos(d); tmp.mat[4][4]=1; p=matMul(tmp,p,4); return p; } Matrix work() { Matrix p; int i; double x,y,z,d; memset(p.mat,0,sizeof(p.mat)); for (i=1;i<=4;i++) p.mat[i][i]=1; for (i=cnt-3;i>0;i--) { if (opstr[i][2]=='T') { sscanf(opstr[i],"glTranslatef(%lf,%lf,%lf);",&x,&y,&z); p=translate(p,x,y,z); } else if (opstr[i][2]=='S') { sscanf(opstr[i],"glScalef(%lf,%lf,%lf);",&x,&y,&z); p=scale(p,x,y,z); } else if (opstr[i][2]=='R') { sscanf(opstr[i],"glRotatef(%lf,%lf,%lf,%lf);",&d,&x,&y,&z); p=rotate(p,x,y,z |