资源描述:
《opengl三维网格坐标,旋转,缩放,灯光设置,纹理读取,模型读取mfc单文档》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、openGL三维网格坐标,旋转,缩放,灯光设置,纹理读取,模型读取(MFC单文档)在我的MFC单文档项目中enableview.h和enableview.cpp负责上面的窗口建立,myopenglview.h和myopenglView.cpp主要是功能的实现1.三维网格建立:voidGLGrid(floatpt1x,floatpt1y,floatpt1z,floatpt2x,floatpt2y,floatpt2z,intnum){constfloat_xLen=(pt2x-pt1x)/num;constfloat_yLen=
2、(pt2y-pt1y)/num;constfloat_zLen=(pt2z-pt1z)/num;glLineWidth(2.f);glLineStipple(1,0x0303);//线条样式glBegin(GL_LINES);glEnable(GL_LINE_SMOOTH);intxi=0;intyi=0;intzi=0;//绘制平行于X的直线for(zi=0;zi<=num;zi++){floatz=_zLen*zi+pt1z;for(yi=0;yi<=num;yi++){floaty=_yLen*yi+pt1y;glVe
3、rtex3f(pt1x,y,z);glVertex3f(pt2x,y,z);}}//绘制平行于Y的直线for(zi=0;zi<=num;zi++){floatz=_zLen*zi+pt1z;for(xi=0;xi<=num;xi++){floatx=_xLen*xi+pt1x;glVertex3f(x,pt1y,z);glVertex3f(x,pt2y,z);}}//绘制平行于Z的直线for(yi=0;yi<=num;yi++){floaty=_yLen*yi+pt1y;for(xi=0;xi<=num;xi++){floa
4、tx=_xLen*xi+pt1x;glVertex3f(x,y,pt1z);glVertex3f(x,y,pt2z);}}glEnd();}voidCmyopenglView::ordination(){glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);glEnable(GL_POINT_SMOOTH);//设置反走样glHint(GL_POINT_SMOOTH_HINT,GL_NICEST);//设置反走样glEnable(GL_LINE
5、_SMOOTH);glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);glEnable(GL_POLYGON_SMOOTH);glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);glRotatef(-45,0.0,1.0,0.0);//网格glPushMatrix();glColor3f(0.9f,0.9f,0.9f);glTranslatef(-4,-4,-4);GLGrid(0,0,0,8,0,8,20);glPopMatrix();glPushMatrix();gl
6、Translated(-4,4,-4);glRotatef(90,1.0,0.0,0.0);glColor3f(0.9f,0.9f,0.0f);GLGrid(0,0,0,8,0,8,20);glPopMatrix();glPushMatrix();glTranslatef(-4,-4,-4);glRotatef(90,0.0,0.0,1.0);glColor3f(0.0f,0.9f,0.0f);GLGrid(0,0,0,8,0,8,20);glPopMatrix();glDisable(GL_BLEND);glDisable
7、(GL_LINE_SMOOTH);glDisable(GL_POINT_SMOOTH);glDisable(GL_POLYGON_SMOOTH);}我们在ordination()函数中增加绘制x,y,z坐标的代码voidCmyopenglView::ordination(){glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);glEnable(GL_POINT_SMOOTH);//设置反走样glHint(GL_POINT_SMOOTH_HIN
8、T,GL_NICEST);//设置反走样glEnable(GL_LINE_SMOOTH);glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);glEnable(GL_POLYGON_SMOOTH);glHint(GL_POLYGON_SMOOTH_HINT,GL_N