C++编写图形问题(OPENGL)
classwcPt3D{public:GLfloatx,y,z;};typedeffloatMatrix4x4[4][4];Matrix4x4matRot;voidmat...
class wcPt3D{public: GLfloat x,y,z;};typedef float Matrix4x4 [4][4];Matrix4x4 matRot;void matrix4x4SetIdentity(Matrix4x4 matIdent4x4){ GLint row,col; for(row=0;row<4;row++) for(col=0;col<4;col++) matIdent4x4 [row][col]=(row==col);}void matrix4x4PreMultiply(Matrix4x4 m1,Matrix4x4 m2){ GLint row,col; Matrix4x4 matTemp; for(row=0;row<4;row++) for(col=0;col<4;col++) matTemp [row][col]=m1[row][0]*m2[0][col]+m1[row][1]*m2[1][col]+m1[row][2]* m2[2][col]+m1[row][3]*m2[3][col]; for(row=0;row<4;row++) for(col=0;col<4;col++) m2[row][col]=matTemp [row][col];}void translate3D(GLfloat tx,GLfloat ty,GLfloat tz){ Matrix4x4 matTransl3D; matrix4x4SetIdentity(matTransl3D); matTransl3D [0][3]=tx; matTransl3D [1][3]=ty; matTransl3D [2][3]=tz; matrix4x4PreMultiply(matTransl3D,matRot);}void rotate3D(wcPt3D p1,wcPt3D p2,GLfloat radianAngle){ Matrix4x4 matQuaternionRot; GLfloat axisVectLength=sqrt((p2.x-p1.x)*(p2.x-p1.x)+(p2.y-p1.y)*(p2.y-p1.y)+ (p2.z-p1.z)*(p2.z-p1.z)); GLfloat cosA=cos(radianAngle); GLfloat oneC=1-cosA; GLfloat sinA=sin(radianAngle); GLfloat ux=(p2.x-p1.x)/axisVectLength; GLfloat uy=(p2.y-p1.y)/axisVectLength; GLfloat uz=(p2.z-p1.z)/axisVectLength; translate3D(-p1.x,-p1.y,-p1.z); matrix4x4SetIdentity(matQuaternionRot); matQuaternionRot [0][0]=ux*ux*oneC+cosA; matQuaternionRot [0][1]=ux*uy*oneC-uz*sinA; matQuaternionRot [0][2]=ux*uz*oneC+uy*sinA; matQuaternionRot [1][0]=uy*ux*oneC+uz*sinA; matQuaternionRot [1][1]=uy*uy*oneC+cosA; matQuaternionRot [1][2]=uy*uz*oneC-ux*sinA; matQuaternionRot [2][0]=uz*ux*oneC-uy*sinA; matQuaternionRot [2][1]=uz*uy*oneC+ux*sinA; matQuaternionRot [2][2]=uz*uz*oneC+cosA; matrix4x4PreMultiply(matQuaternionRot,matRot); translate3D(p1.x,p1.y,p1.z);}这个是三维旋转代码,怎样才能显示图案出来?就是帮我把程序补充完整!放到VC上能运行,急!
展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询