编写OIV程序的基本步骤: 1. 首先创建一个用于场景渲染的窗口。(不同的平台有不同的实现方式) 2. 创建属性喝形体节点,并将他们合并到组节点中,最后建立场景。 key code: ///基于Open Inventor-Coin3D开发环境的第一个测试程序 // 2009.09.08 邵延华 #include <Inventor/OivDef.h> int main(int, char ** argv) { //初始化SoWin(同时隐含初始化Coin),之后将返回一个顶层窗口供我们使用 HWND window = SoWin::init(argv[0]); if (window==NULL) exit(1); //创建一个观察器(Viewer) SoWinExaminerViewer * viewer = new SoWinExaminerViewer(window); //场景是由两个节点组成的:根节点和几何物体 SoSeparator * root = new SoSeparator;//根节点 SoCone * cone = new SoCone; //几何物体 root->ref(); root->addChild(cone); //将几何物体作为子节点增加到根节点中 root->addChild(new SoDirectionalLight); //为观察器设置渲染场景(用根节点来表示) viewer->setSceneGraph(root); viewer->show(); //让SoWin显示窗口,并进入消息循环 SoWin::show(window); SoWin::mainLoop(); //应用程序结束后,要删除观察器,我们还要对根节点调用unref()函数 //delete viewer; root->unref(); return 0; } 以下为自定义的头文件 /**************************************************************************/ * * 文件名:OivDef.h * 作 用:简化OIV的使用 * 作 者:邵延华 shao_yanhua@163.com * 日 期:2009.10.1 * /**************************************************************************/ #ifndef Oiv_Def_h__ #define Oiv_Def_h__ //所需要的预定义 #define COIN_DLL #define SOWIN_DLL #pragma warning(disable:4819) #ifdef _DEBUG 调试版本连接 #define COIN_LIB "coin3d.lib" #define SOWIN_LIB "sowin1d.lib" #else 非调试版本连接 #define COIN_LIB "coin3.lib" #define SOWIN_LIB "sowin1.lib" #endif #pragma comment(lib,COIN_LIB) #pragma comment(lib,SOWIN_LIB) #include <Inventor/Win/SoWin.h> #include <Inventor/nodes/SoSeparator.h> #include <Inventor/nodes/SoSwitch.h> #include <Inventor/nodes/SoSelection.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #include <Inventor/nodes/SoCube.h> #include <Inventor/nodes/SoCone.h> #include <Inventor/nodes/SoSphere.h> #include <Inventor/nodes/SoCylinder.h> #include <Inventor/nodes/SoCoordinate3.h> #include <Inventor/nodes/SoPointSet.h> #include <Inventor/nodes/SoLineSet.h> #include <Inventor/nodes/SoFaceSet.h> #include <Inventor/nodes/SoIndexedFaceSet.h> #include <Inventor/nodes/SoTriangleStripSet.h> #include <Inventor/nodes/SoQuadMesh.h> #include <Inventor/nodes/SoNurbsSurface.h> #include <Inventor/nodes/SoIndexedLineSet.h> #include <Inventor/nodes/SoText2.h> #include <Inventor/nodes/SoText3.h> #include <Inventor/nodes/SoFont.h> #include <Inventor/nodes/SoRotor.h> #include <Inventor/nodes/SoScale.h> #include <Inventor/nodes/SoRotation.h> #include <Inventor/nodes/SoTranslation.h> #include <Inventor/nodes/SoTransformSeparator.h> #include <Inventor/nodes/SoCamera.h> #include <Inventor/nodes/SoOrthographicCamera.h> #include <Inventor/nodes/SoPerspectiveCamera.h> #include <Inventor/nodes/SoShapeHints.h> #include <Inventor/nodes/SoPointLight.h> #include <Inventor/nodes/SoDirectionalLight.h> #include <Inventor/nodes/SoLightModel.h> #include <Inventor/nodes/SoComplexity.h> #include <Inventor/nodes/SoBaseColor.h> #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoMaterialBinding.h> #include <Inventor/nodes/SoNormal.h> #include <Inventor/nodes/SoNormalBinding.h> #include <Inventor/nodes/SoDrawStyle.h> #include <Inventor/nodes/SoPickStyle.h> #include <Inventor/nodes/SoTexture2.h> #include <Inventor/nodes/SoTextureUnit.h> #include <Inventor/nodes/SoTextureCoordinate2.h> #include <Inventor/nodes/SoTextureCoordinateEnvironment.h> #include <Inventor/VRMLnodes/SoVRMLMovieTexture.h> #include <Inventor/nodes/SoEventCallback.h> #include <Inventor/events/SoKeyboardEvent.h> #include <Inventor/events/SoMouseButtonEvent.h> #include <Inventor/sensors/SoTimerSensor.h> #include <Inventor/engines/SoCalculator.h> #include <Inventor/engines/SoTimeCounter.h> #include <Inventor/nodes/SoShuttle.h> #include <Inventor/nodes/SoBlinker.h> #include <Inventor/SoInput.h> #include <Inventor/nodes/SoCallback.h> #include <Inventor/nodes/SoClipPlane.h> #include <Inventor/nodes/SoEnvironment.h> #include <Inventor/SoOffscreenRenderer.h> #include <Inventor/SbViewportRegion.h> #include <Inventor/nodes/SoShaderProgram.h> #include <Inventor/nodes/SoVertexShader.h> #include <Inventor/nodes/SoShaderParameter.h> #endif // Oiv_Def_h__