📄 ogldemo.c
字号:
errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSIZE, 1.0)); errChk( createUPlot(pts,xStep,yStep) ); break; } case SINCX2Y2 : { double radxStep = RAD(xStep); double radyStep = RAD(yStep); for(j=0,y=RAD(uniformConfig.y.min);j<=uniformConfig.y.steps;j++,y+=radyStep) { for(i=0,x=RAD(uniformConfig.x.min);i<=uniformConfig.x.steps;i++,ptsPtr++,x+=radxStep) *ptsPtr = SINC(x*x+y*y); } errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_ZDIVISIONS, 1)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSTART, -0.5/3)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSIZE, 1.0/3)); errChk( createUPlot(pts,xStep,yStep) ); break; } case SINX2Y2 : { double radxStep = RAD(xStep); double radyStep = RAD(yStep); for(j=0,y=RAD(uniformConfig.y.min);j<=uniformConfig.y.steps;j++,y+=radyStep) { for(i=0,x=RAD(uniformConfig.x.min);i<=uniformConfig.x.steps;i++,ptsPtr++,x+=radxStep) *ptsPtr = sin(x*x+y*y); } errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_ZDIVISIONS, 5)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSTART, -0.5)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSIZE, 1.0)); errChk( createUPlot(pts,xStep,yStep) ); break; } case EXPXY : { double radxStep = RAD(xStep); double radyStep = RAD(yStep); for(j=0,y=RAD(uniformConfig.y.min);j<=uniformConfig.y.steps;j++,y+=radyStep) { for(i=0,x=RAD(uniformConfig.x.min);i<=uniformConfig.x.steps;i++,ptsPtr++,x+=radxStep) *ptsPtr = exp(-(x+y)/(2*PI))*sin(x*x+y*y); } errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_ZDIVISIONS, 1)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSTART, -0.5/3)); errChk( OGLSetCtrlAttribute (demoPanel, demoControl,OGLATTR_PLOTAREA_ZSIZE, 1.0/3)); errChk( createUPlot(pts,xStep,yStep) ); break; } } break; } }Error : if (!waitCursorState) SetWaitCursor(0); return error;}//----------------------------------------------------------------------------// configSPlot //----------------------------------------------------------------------------int CVICALLBACK configSPlot (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error = 0; switch (event) { case EVENT_COMMIT: { int plot; errChk( GetCtrlVal(demoPanel,DEMOPANEL_SPLOTLIST,&plot) ); switch(plot) { case LISTSPHERE : errChk( SetCtrlVal(sphereConfig.panel,SPHERE_RADIUS,sphereConfig.radius) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LONG_MIN,sphereConfig.longitude.min) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LONG_MAX,sphereConfig.longitude.max) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LONG_STEP,sphereConfig.longitude.steps) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LAT_MIN,sphereConfig.latitude.min) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LAT_MAX,sphereConfig.latitude.max) ); errChk( SetCtrlVal(sphereConfig.panel,SPHERE_LAT_STEP,sphereConfig.latitude.steps) ); InstallPopup(sphereConfig.panel); break; case LISTCYLINDER : errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_RADIUS,cylinderConfig.radius) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_LONG_MIN,cylinderConfig.longitude.min) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_LONG_STEP,cylinderConfig.longitude.steps) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_LONG_MAX,cylinderConfig.longitude.max) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_BOTTOMPOS,cylinderConfig.height.min) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_HEIGHT,cylinderConfig.height.max) ); errChk( SetCtrlVal(cylinderConfig.panel,CYLINDER_HT_STEP,cylinderConfig.height.steps) ); InstallPopup(cylinderConfig.panel); break; case LISTTORUS : errChk( torusConfig.panel = LoadPanel(0, "ogldemo.uir", TORUS) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_MAJORRADIUS,torusConfig.majorrad) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_MINORRADIUS,torusConfig.minorrad) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LONG_MIN,torusConfig.longitude.min) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LONG_MAX,torusConfig.longitude.max) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LONG_STEP,torusConfig.longitude.steps) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LAT_MIN,torusConfig.latitude.min) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LAT_MAX,torusConfig.latitude.max) ); errChk( SetCtrlVal(torusConfig.panel,TORUS_LAT_STEP,torusConfig.latitude.steps) ); InstallPopup(torusConfig.panel); break; case LISTCONE : errChk( coneConfig.panel = LoadPanel(0, "ogldemo.uir", CONE) ); errChk( SetCtrlVal(coneConfig.panel,CONE_BOTTOMRADIUS,coneConfig.bottomrad) ); errChk( SetCtrlVal(coneConfig.panel,CONE_TOPRADIUS,coneConfig.toprad) ); errChk( SetCtrlVal(coneConfig.panel,CONE_LONG_MIN,coneConfig.longitude.min) ); errChk( SetCtrlVal(coneConfig.panel,CONE_LONG_STEP,coneConfig.longitude.steps) ); errChk( SetCtrlVal(coneConfig.panel,CONE_LONG_MAX,coneConfig.longitude.max) ); errChk( SetCtrlVal(coneConfig.panel,CONE_BOTTOMPOS,coneConfig.height.min) ); errChk( SetCtrlVal(coneConfig.panel,CONE_HEIGHT,coneConfig.height.max) ); errChk( SetCtrlVal(coneConfig.panel,CONE_HT_STEP,coneConfig.height.steps) ); InstallPopup(coneConfig.panel); break; } } }Error : return error;}//----------------------------------------------------------------------------// configUPlot//----------------------------------------------------------------------------int CVICALLBACK configUPlot (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error = 0; switch (event) { case EVENT_COMMIT: errChk( SetCtrlVal(uniformConfig.panel,UPLOT_X_MIN,uniformConfig.x.min) ); errChk( SetCtrlVal(uniformConfig.panel,UPLOT_X_STEP,uniformConfig.x.steps) ); errChk( SetCtrlVal(uniformConfig.panel,UPLOT_X_MAX,uniformConfig.x.max) ); errChk( SetCtrlVal(uniformConfig.panel,UPLOT_Y_MIN,uniformConfig.y.min) ); errChk( SetCtrlVal(uniformConfig.panel,UPLOT_Y_STEP,uniformConfig.y.steps) ); errChk( SetCtrlVal(uniformConfig.panel,UPLOT_Y_MAX,uniformConfig.y.max) ); InstallPopup(uniformConfig.panel); break; }Error : return error;}//----------------------------------------------------------------------------// print//----------------------------------------------------------------------------int CVICALLBACK print (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error = 0; switch (event) { case EVENT_COMMIT: { static int printp = -1; errChk( OGLCopyScaledCtrlBitmap (demoPanel, demoControl, 0, -1, -1, printp, DEMOPANEL_PICTURE) ); errChk( PrintCtrl (panel, DEMOPANEL_PICTURE, "", 0, 1) ); break; } }Error : return error;}//----------------------------------------------------------------------------// Picture Control Callback//----------------------------------------------------------------------------int CVICALLBACK picture (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error =0; switch (event) { case OGLEVENT_REFRESH: { GLfloat specularLight0[] ={1.0f, 1.0f, 1.0f, 1.0f}; int fastMode; glPushAttrib(GL_ALL_ATTRIB_BITS); glMatrixMode(GL_PROJECTION); glPushMatrix(); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glEnable(GL_DEPTH_TEST); glShadeModel(GL_SMOOTH); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specularLight0); glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 128); OGLGetCtrlAttribute(panel,control,OGLATTR_FAST_PAN_ZOOM_ROTATE,&fastMode); RenderMolecule(eventData1 && fastMode); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glPopAttrib(); glFlush(); break; } }Error : return error;}//----------------------------------------------------------------------------// DrawGLStuff//----------------------------------------------------------------------------int CVICALLBACK DrawGLStuff (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int error = 0; switch (event) { case EVENT_COMMIT: { int waitCursorState = GetWaitCursorState(); int mol; GetCtrlVal(panel,DEMOPANEL_MOLECULES,&mol); LoadMoleculeFromArray(molecules[mol]); if (molecule != 1) { errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_LATITUDE, &latitude) ); errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_LONGITUDE, &longitude) ); errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_DISTANCE, &distance) ); errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERX, ¢er.x) ); errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERY, ¢er.y) ); errChk( OGLGetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERZ, ¢er.z) ); if (molecule != -1) { errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_LATITUDE, mollatitude) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_LONGITUDE, mollongitude) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_DISTANCE, moldistance) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERX, molcenter.x) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERY, molcenter.y) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_VIEW_CENTERZ, molcenter.z) ); } molecule = 1; } errChk( SetCtrlAttribute (demoPanel, DEMOPANEL_PICTURE, ATTR_CALLBACK_FUNCTION_POINTER, picture) ); errChk( OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_PLOTTING_ENABLE, 0) ); if (!waitCursorState) SetWaitCursor(1); errChk( OGLRefreshGraph(demoPanel,demoControl) ); if (!waitCursorState) SetWaitCursor(0); break; } }Error : return error;}//----------------------------------------------------------------------------// Panel Callback - Since CVI does not know about CVIOGL control, we must// manually resize the CVIOGL control whenever the picture control is resized.//----------------------------------------------------------------------------int CVICALLBACK DemoPanelCallback (int panel, int event, void *callbackData, int eventData1, int eventData2){ int width, height, top, left; switch (event) { case EVENT_PANEL_SIZE: GetCtrlAttribute(demoPanel, DEMOPANEL_PICTURE, ATTR_TOP, &top); GetCtrlAttribute(demoPanel, DEMOPANEL_PICTURE, ATTR_LEFT, &left); GetCtrlAttribute(demoPanel, DEMOPANEL_PICTURE, ATTR_WIDTH, &width); GetCtrlAttribute(demoPanel, DEMOPANEL_PICTURE, ATTR_HEIGHT, &height); OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_TOP, top); OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_LEFT, left); OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_WIDTH, width); OGLSetCtrlAttribute (demoPanel, demoControl, OGLATTR_HEIGHT, height); OGLRefreshGraph(demoPanel,demoControl); break; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -