1、labwindows中opengl三维编程设计Fuzhu.c文件内容如下:#include #include #include #include #include #include #include #include #include #include #include #include #include #include kaifa.h#include cviogl.h#include fuzhu.hextern int panelHandle;extern char readBuf100;extern struct sd dd; /extern GLfloat ctrlpoints443
2、;extern double anglh,angrh,angll,angrl;/extern GLfloat ctlpoints443 ;/GLfloat knots8 = 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0; / NURBS曲面的控制向量 void initial(void) /设置程序窗口为正常 SetPanelAttribute(panelHandle,ATTR_WINDOW_ZOOM,VAL_NO_ZOOM); /将PIC控件转化为OPENGL控件 dd.OGLPanel=OGLConvertCtrl(panelHandle,PANEL_PIC
3、TURE); /设置光源 OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_LIGHTING_ENABLE, 1); OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_LIGHT_SELECT, 1); OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_LIGHT_ENABLE, 1); OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_LIGHT_DISTANCE, 2.0);
4、OGLSetCtrlAttribute (panelHandle, dd.OGLPanel,OGLATTR_LIGHT_LATITUDE, DFLT_LIGHT_LATITUDE); /设置坐标系的视点 OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_PROJECTION_TYPE, OGLVAL_PERSPECTIVE); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel,OGLATTR_VIEW_DIRECTION, OGLVAL_USER_DEFINED); OGLSetCtrlAttrib
5、ute (panelHandle, dd.OGLPanel,OGLATTR_VIEW_LATITUDE, DFLT_VIEW_LATITUDE); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel,OGLATTR_VIEW_LONGITUDE, DFLT_VIEW_LONGITUDE); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel, OGLATTR_VIEW_CENTERX,DFLT_VIEWPOINT_X); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel,
6、OGLATTR_VIEW_CENTERY,DFLT_VIEWPOINT_Y); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel, OGLATTR_VIEW_CENTERZ,DFLT_VIEWPOINT_Z); OGLSetCtrlAttribute(panelHandle,dd.OGLPanel,OGLATTR_VIEW_DISTANCE,DFLT_VIEW_DISTANCE); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel, OGLATTR_BGCOLOR, OGLVAL_BLUE); OGLSetCt
7、rlAttribute (panelHandle, dd.OGLPanel, OGLATTR_XY_GRID_VISIBLE, OGLVAL_TRUE);/ OGLSetCtrlAttribute (panelHandle, dd.OGLPanel, OGLATTR_XY_PLANE_ZLOCATION, 1.0); OGLSetCtrlAttribute (panelHandle, dd.OGLPanel, OGLATTR_XY_PLANE_VISIBLE, OGLVAL_TRUE); /去掉坐标系显示 OGLSetCtrlAttribute (panelHandle,dd.OGLPanel
8、, OGLATTR_PLOTTING_ENABLE, 0); /设置OPENGL弹出属性对话框 OGLSetCtrlAttribute (panelHandle,dd.OGLPanel, OGLATTR_ENABLE_PROPERTY_POPUP, 1); / 刷新OPENGL显示 OGLRefreshGraph(panelHandle, dd.OGLPanel);/*void InitSurface()int u, v;for (u = 0; u 4; u+) for (v = 0; v 4; v+) ctlpointsuv0 = 2.0 * (GLfloat)u - 1.5);ctlpoi
9、ntsuv1 = 2.0 * (GLfloat)v - 1.5);if (u = 1 | u = 2) & (v = 1 | v = 2) ctlpointsuv2 = 6;else ctlpointsuv2 = -6;*/AUX_RGBImageRec * LoadBMP(char* Filename) FILE *File=NULL; / 文件句柄 if (!Filename) / 确保文件名已提供。 return NULL; / 如果没提供,返回 NULL File=fopen(Filename,r); / 尝试打开文件 if (File) / 文件存在么? fclose(File);
10、/ 关闭句柄 return auxDIBImageLoad(Filename); / 载入位图并返回指针 return NULL; / 如果载入失败,返回 NULL void drawing(int fastFlag) double radius,h1,h2,h3,h4,h5,angle2=20 ; / dd.og.dd.og.theNurb = gluNewNurbsRenderer() ;/*InitSurface(); / 初始化控制点dd.og.theNurb = gluNewNurbsRenderer(); / 创建一个NURBS曲面对象/ 修改NURBS曲面对象的属性gluNurb
11、sProperty(dd.og.theNurb, GLU_SAMPLING_TOLERANCE, 5.0);gluNurbsProperty(dd.og.theNurb, GLU_DISPLAY_MODE, GLU_FILL);glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); / 清屏glPushMatrix(); / 入栈glRotatef(30.0, -1.0, 0.0, 0.0); / 旋转变换glScalef (0.5, 0.5, 0.5); / 缩放变换gluBeginSurface(dd.og.theNurb); / 开始曲面绘
12、制gluNurbsSurface(dd.og.theNurb, 8, knots, 8, knots, 4 * 3, 3, &ctlpoints000, 4, 4, GL_MAP2_VERTEX_3); / 定义曲面的数学模型,确定其形状gluEndSurface(dd.og.theNurb); / 结束曲面绘制glPopMatrix(); / 出栈glFlush(); / 强制刷新 */ /* glPushMatrix(); glMap2f(GL_MAP2_VERTEX_3,0,1,3,4,0,1,12, 4, &ctrlpoints000);/ 定义曲面glEnable(GL_MAP2_V
13、ERTEX_3); / 启用曲面glEnable(GL_AUTO_NORMAL); / 启用曲面法向向量计算glEnable(GL_NORMALIZE); / 启用法向归一化glMapGrid2f(20, 0.0, 1.0, 20, 0.0, 1.0); / 定义参数空间的均匀网格 glPopMatrix(); */*for(u=0;u4;u+) for (v = 0; v 4; v+) ctlpointsuv0 = 2.0 * (GLfloat)u - 1.5);ctlpointsuv1 = 2.0 * (GLfloat)v - 1.5);if (u = 1 | u = 2) & (v =
14、1 | v = 2) ctlpointsuv2 = 6;else ctlpointsuv2 = -6; */ glPointSize(1); /gluPartialDisk (dd.og.object,0,0.5,30,15,10,20); / gluBeginSurface(dd.og.object); /auxSolidCube(1.0);/ auxWireBox(0.1,1, 0.1); /auxWireTeapot(0.5);/ auxWireTorus(1, 1) ;/ auxSolidIcosahedron(0.5);/ auxWireOctahedron(0.5); /auxWi
15、reSphere(1);/* glBegin(GL_LINES); glVertex2i(1,1); glVertex2i(0.1, 1); glEnd(); */ / 创建一个新的二次曲面目标 dd.og.object = gluNewQuadric(); gluQuadricNormals(dd.og.object, GLU_SMOOTH); / 使用平滑法线 gluQuadricTexture(dd.og.object, GL_TRUE); glPushMatrix(); auxSolidBox(3.0, 3.0, 0.0001); / glColor3f(21,0, 21); glTr
16、anslatef(0.0, 0.0, 0.75); auxSolidBox(0.07, 0.2, 0.07); glTranslatef(0.0, -0.1, 0.0); gluSphere (dd.og.object,0.06,15,10 ); /臀部 glRotated(150-angrl,1,0,0); gluCylinder(dd.og.object, 0.05, 0.04, 0.3, 15,10); glTranslatef(0.0, 0.0, 0.3) ; gluSphere (dd.og.object,0.045,15,10 ); gluCylinder(dd.og.object
17、, 0.04, 0.035, 0.4, 15,10); glTranslatef(0.0, 0.0, 0.4) ; gluSphere (dd.og.object,0.04,15,10 ); glTranslatef(0.02, 0, 0.02); auxSolidBox(0.12, 0.06, 0.03); /右腿/ glRotated( 210,1,0,0); glPopMatrix(); glPushMatrix(); / glRotated( 180,1,0,0);/ glRotated( 180,1,0,0); glTranslatef(0.0, 0.1, 0.75); / glTr
18、anslatef(-0.02, 0.2, 0.72) ; gluSphere (dd.og.object,0.06,15,10 ); glRotated( 210-angll,1,0,0); gluCylinder(dd.og.object, 0.05, 0.04, 0.3, 15,10); glTranslatef(0.0, 0.0, 0.3) ; gluSphere (dd.og.object,0.045,15,10 ); gluCylinder(dd.og.object, 0.04, 0.035, 0.4, 15,10); glTranslatef(0.0, 0.0, 0.4) ; gl
19、uSphere (dd.og.object,0.04,15,10 ); glTranslatef(0.02, 0, 0.02); auxSolidBox(0.12, 0.06, 0.03); /左腿/ glRotated(150 ,1,0,0); glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.0, 0.75); / glTranslatef(-0.02, -0.1, 0.72); auxSolidBox(0.07, 0.2, 0.07); glTranslatef(-0.02, 0.0, 0.0) ; gluSphere (dd.og.o
20、bject,0.07,15,10 );/屁股 glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.0, 0.95); / glTranslatef(0.02, 0.0, 0.2) ; auxSolidBox(0.1, 0.2, 0.4); glTranslatef(0.0, 0.0, 0.15) ; auxSolidBox(0.07, 0.3, 0.07); /身体 glPopMatrix(); glPushMatrix(); glTranslatef(0.0, -0.15, 1.1) ; gluSphere (dd.og.object,0.0
21、6,15,10 ); glRotated( 90-angrh,1,0,0); /glRotated(90,1,0,0); gluCylinder(dd.og.object, 0.04, 0.035, 0.25, 15,10); glTranslatef(0.0, 0.0, 0.25) ; gluSphere (dd.og.object,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.03, 0.2, 15,10); glTranslatef(0.0, 0.0, 0.2) ; gluSphere (dd.og.object,0.035,15,10
22、 ); / glTranslatef(0.0, 0.0, -0.75) ; / glRotated( 270,1,0,0); /右臂 glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.15, 1.1) ; gluSphere (dd.og.object,0.06,15,10 ); glRotated( 270-anglh,1,0,0); gluCylinder(dd.og.object, 0.04, 0.035, 0.25, 15,10); glTranslatef(0.0, 0.0, 0.25) ; gluSphere (dd.og.obj
23、ect,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.03, 0.2, 15,10); glTranslatef(0.0, 0.0, 0.2) ; gluSphere (dd.og.object,0.035,15,10 ); glTranslatef(0.0, 0.0, -0.6) ; / glRotated( 90,1,0,0); /左臂 glPopMatrix(); glPushMatrix(); glTranslatef(0.0, 0.0, 1.15) ; gluSphere (dd.og.object,0.05,15,10 ); gl
24、uCylinder(dd.og.object, 0.04, 0.03, 0.05, 15,10); glTranslatef(0.0, 0.0, 0.1) ; gluSphere (dd.og.object,0.08,15,10 ); /头部 /* glTranslatef(0.0, -0.1, 0); auxSolidBox(0.12, 0.06, 0.03); glTranslatef(-0.02, 0, 0.02); gluSphere (dd.og.object,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.04, 0.4, 15,1
25、0); glTranslatef(0.0, 0.0, 0.4) ; gluSphere (dd.og.object,0.045,15,10 ); gluCylinder(dd.og.object, 0.04, 0.05, 0.3, 15,10); glTranslatef(0.0, 0.0, 0.3) ; gluSphere (dd.og.object,0.06,15,10 ); / 右腿 glTranslatef(0.02, 0.2, -0.72) ; auxSolidBox(0.12, 0.06, 0.03); glTranslatef(-0.02, 0, 0.02); gluSphere
26、 (dd.og.object,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.04, 0.4, 15,10); glTranslatef(0.0, 0.0, 0.4) ; gluSphere (dd.og.object,0.045,15,10 ); gluCylinder(dd.og.object, 0.04, 0.05, 0.3, 15,10); glTranslatef(0.0, 0.0, 0.3) ; gluSphere (dd.og.object,0.06,15,10 ); /左腿 glTranslatef(0.0, -0.1, 0.0
27、1) ; auxSolidBox(0.07, 0.2, 0.07); glTranslatef(-0.02, 0.0, 0.0) ; gluSphere (dd.og.object,0.07,15,10 ); /屁股 glTranslatef(0.02, 0.0, 0.2) ; auxSolidBox(0.1, 0.2, 0.4); glTranslatef(0.0, 0.0, 0.15) ; auxSolidBox(0.07, 0.3, 0.07); /身体 glTranslatef(0.0, -0.15, 0.0) ; gluSphere (dd.og.object,0.06,15,10
28、); glRotated( 90,1,0,0); /glRotated(90,1,0,0); gluCylinder(dd.og.object, 0.04, 0.035, 0.25, 15,10); glTranslatef(0.0, 0.0, 0.25) ; gluSphere (dd.og.object,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.03, 0.2, 15,10); glTranslatef(0.0, 0.0, 0.2) ; gluSphere (dd.og.object,0.035,15,10 ); glTranslat
29、ef(0.0, 0.0, -0.75) ; glRotated( 270,1,0,0); /右臂 gluSphere (dd.og.object,0.06,15,10 ); glRotated( 270,1,0,0); gluCylinder(dd.og.object, 0.04, 0.035, 0.25, 15,10); glTranslatef(0.0, 0.0, 0.25) ; gluSphere (dd.og.object,0.04,15,10 ); gluCylinder(dd.og.object, 0.035, 0.03, 0.2, 15,10); glTranslatef(0.0, 0.0, 0.2) ; gluSphere (dd.og.object,0.035,15,10 ); glTranslatef(0.0, 0.0, -0.6) ; glRotated( 90,1,0,0); /左臂 glTranslatef(0.0, 0.0, 0.04) ; gluSphere (dd.og.object,0.05,15,10 ); gluCylinder(dd.og.object, 0.04, 0.03, 0.05,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1