Open Inventor练习-iv文件读写显示4

// 预定义COIN宏 #define COIN_DLL #define SOWIN_DLL // 加载COIN库文件 #ifdef _DEBUG #pragma comment(lib, "SoWin1d.lib") #pragma comment(lib, "Coin3d.lib") #else #pragma comment(lib, "SoWin1.lib") #pragma comment(lib, "Coin3.lib") #endif // 添加COIN头文件-Window操作显示库和节点库 #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #include <Inventor/nodes/SoSeparator.h> int main(int argc, char **argv) { SoDB::init(); // 初始化SoDB读取iv文件 HWND hWnd = SoWin::init(argv[0]); // 产生窗口句柄 SoSeparator *pRootSeparator = new SoSeparator; pRootSeparator->ref(); // 创建根节点并ref计数 SoInput input; if (input.openFile("03_transorder.iv")) // 加载iv文件并读取全部内容 { pRootSeparator->addChild(SoDB::readAll(&input)); } SoWinExaminerViewer viewer(hWnd); // 创建view窗体显示COIN三维内容 viewer.setSceneGraph(pRootSeparator); // 设置显示的根节点 viewer.show(); // view窗体显示三维内容 SoWin::show(hWnd); // windows下显示三维内容 viewer.viewAll(); // 显示物体全部查看模式 SoWin::mainLoop(); // 进入显示主循环 pRootSeparator->unref(); // unref删除节点计数让COIN释放资源 return 0; }

一下是01.iv的内容

#Inventor V2.1 ascii Separator { Coordinate3 { point [ 0 0 0, 10 0 0, 0 10 0, 0 0 10, ] } IndexedLineSet { coordIndex [ 0,1,-1, 0,2,-1, 0,3,-1 ] } Separator { Rotation { rotation 0 0 1 0.785 } Translation { translation 8 0 0 } Material { diffuseColor 1 0 0 } Cube { } } Separator { Translation { translation 8 0 0 } Rotation { rotation 0 0 1 0.785 } Material { diffuseColor 0 1 0 } Cube { } } }

OpenGL齐次坐标系对平移和旋转的顺序有一定的要求,Open Inventor的这个演示可以很好的说明这一点。

此部分的Open Inventor等价代码如下

// 预定义COIN宏 #define COIN_DLL #define SOWIN_DLL // 加载COIN库文件 #ifdef _DEBUG #pragma comment(lib, "SoWin1d.lib") #pragma comment(lib, "Coin3d.lib") #else #pragma comment(lib, "SoWin1.lib") #pragma comment(lib, "Coin3.lib") #endif // 添加COIN头文件-Window操作显示库和节点库 #include <Inventor/Win/SoWin.h> #include <Inventor/Win/viewers/SoWinExaminerViewer.h> #include <Inventor/nodes/SoSeparator.h> // IV等效代码 #include <Inventor/nodes/SoMaterial.h> #include <Inventor/nodes/SoTransform.h> #include <Inventor/nodes/SoCube.h> #include <Inventor/nodes/SoCoordinate3.h> #include <Inventor/nodes/SoIndexedLineSet.h> #include <Inventor/nodes/SoRotation.h> int main(int argc, char **argv) { SoDB::init(); // 初始化SoDB读取iv文件 HWND hWnd = SoWin::init(argv[0]); // 产生窗口句柄 SoSeparator *pRootSeparator = new SoSeparator; pRootSeparator->ref(); // 创建根节点并ref计数 SoInput input; if (input.openFile("03_transorder.iv")) // 加载iv文件并读取全部内容 { // pRootSeparator->addChild(SoDB::readAll(&input)); // IV等效代码 float fPoints[4][3] = {{0, 0, 0}, {10, 0, 0}, {0, 10, 0}, {0, 0, 10}}; int32_t nLineSets[] = {0, 1, SO_END_LINE_INDEX, 0, 2, SO_END_LINE_INDEX, 0, 3, SO_END_LINE_INDEX}; SoCoordinate3 *pCoordinate3 = new SoCoordinate3; pCoordinate3->point.setValues(0, 4, fPoints); pRootSeparator->addChild(pCoordinate3); SoIndexedLineSet *pIndexedLineSet = new SoIndexedLineSet; pIndexedLineSet->coordIndex.setValues(0, 9, nLineSets); pRootSeparator->addChild(pIndexedLineSet); { SoSeparator *pSeparator = new SoSeparator; SoRotation *pRotation = new SoRotation; pRotation->rotation.setValue(0, 0, 1, 0.785f); pSeparator->addChild(pRotation); SoTransform *pTransform = new SoTransform; pTransform->translation.setValue(8, 0, 0); pSeparator->addChild(pTransform); SoMaterial *pMaterial = new SoMaterial; pMaterial->diffuseColor.setValue(1.0f, 0.0f, 0.0f); pSeparator->addChild(pMaterial); pSeparator->addChild(new SoCube); pRootSeparator->addChild(pSeparator); } { SoSeparator *pSeparator = new SoSeparator; SoTransform *pTransform = new SoTransform; pTransform->translation.setValue(8, 0, 0); pSeparator->addChild(pTransform); SoRotation *pRotation = new SoRotation; pRotation->rotation.setValue(0, 0, 1, 0.785f); pSeparator->addChild(pRotation); SoMaterial *pMaterial = new SoMaterial; pMaterial->diffuseColor.setValue(0.0f, 1.0f, 0.0f); pSeparator->addChild(pMaterial); pSeparator->addChild(new SoCube); pRootSeparator->addChild(pSeparator); } } SoWinExaminerViewer viewer(hWnd); // 创建view窗体显示COIN三维内容 viewer.setSceneGraph(pRootSeparator); // 设置显示的根节点 viewer.show(); // view窗体显示三维内容 SoWin::show(hWnd); // windows下显示三维内容 viewer.viewAll(); // 显示物体全部查看模式 SoWin::mainLoop(); // 进入显示主循环 pRootSeparator->unref(); // unref删除节点计数让COIN释放资源 return 0; }


显示的效果如下


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值