Open Inventor练习-SoWin中SoWinRenderArea显示三维场景
来源:互联网 发布:xboxone安卓软件 编辑:程序博客网 时间:2024/05/15 06:43
前面我们演示了SoWinExaminerViewer在三维显示中的应用,这里我们演示它的基类SoWinRenderArea,他没有SoWinExaminerViewer修饰控制边条等功能,然而SoWinExaminerViewer的绝大部分三维显示功能他都是具有的。这里是用SoWinRenderArea显示四个旋转的立方体,下面是例子代码。
// TestCoin.cpp : Defines the entry point for the console application.//#include "stdafx.h"#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/SoWinRenderArea.h>#include <Inventor/nodes/SoCube.h>#include <Inventor/nodes/SoRotor.h>#include <Inventor/nodes/SoArray.h>#include <Inventor/nodes/SoDirectionalLight.h>#include <Inventor/nodes/SoPerspectiveCamera.h>#include <Inventor/nodes/SoSeparator.h>// Set up a simple scenegraph, just for demonstration purposes.static SoSeparator* get_scene_graph(void){SoSeparator * root = new SoSeparator;SoGroup * group = new SoGroup;SoRotor * rotor = new SoRotor;rotor->rotation = SbRotation(SbVec3f(0.2, 0.5, 0.9), M_PI / 4.0);group->addChild(rotor);SoCube * cube = new SoCube;group->addChild(cube);SoArray * array = new SoArray;array->origin = SoArray::CENTER;array->addChild(group);array->numElements1 = 2;array->numElements2 = 2;array->separation1 = SbVec3f(4, 0, 0);array->separation2 = SbVec3f(0, 4, 0);root->addChild(array);return root;}int main(int argc, char ** argv){HWND window = SoWin::init(argv[0]);SoSeparator * root = new SoSeparator;root->ref();SoPerspectiveCamera * camera;root->addChild(camera = new SoPerspectiveCamera);root->addChild(new SoDirectionalLight);SoSeparator * userroot = get_scene_graph();root->addChild(userroot);SoWinRenderArea * renderarea = new SoWinRenderArea(window);camera->viewAll(userroot, renderarea->getViewportRegion());renderarea->setSceneGraph(root);renderarea->setBackgroundColor(SbColor(0.0f, 0.2f, 0.3f));if (argc > 1) {renderarea->setTitle(argv[1]);renderarea->setIconTitle(argv[1]);}renderarea->show();SoWin::show(window);SoWin::mainLoop();delete renderarea;root->unref();return 0;}
SoCube是场景物体,他和SoCone,SoCylinder,SoSphere是三维显示的基本元素,这里利用了SoArray对SoCube阵列扩展显示,origin是原点控制的阵列扩展位置,子节点就是需要阵列扩展的物体节点,numElements1和numElements2分别控制阵列扩展的航和列数目,与之对应的separation1和separation2这是行和列的间隔大小。
SoRotor是三维变换中旋转变换的控制节点,rotation是表示初始显示时旋转的大小,speed用来设置旋转的速度,speed如果不设置则用默认值,这里是初始化沿着0.2, 0.5, 0.9轴旋转45度,速度默认。
SoPerspectiveCamera是perspective摄像头,用来观察SoWinRenderArea的视境,camera->viewAll(userroot, renderarea->getViewportRegion());就是用SoPerspectiveCamera观察场景中的所有内容;再者SoPerspectiveCamera必须放在需要观察的物体节点前面,否则物体放在了摄像头的后面,是无法观察到的,root->addChild(camera = new SoPerspectiveCamera);就是实现这个功能,我们同样可以利用这个性质来隐藏不想显示的节点内容。
SoWinRenderArea的用法与SoWinExaminerViewer类似,设定场景节点,然后显示即可。
如下是程序运行的效果。
- Open Inventor练习-SoWin中SoWinRenderArea显示三维场景
- Open Inventor练习-SoWin中SoWinExaminerViewer显示三维场景
- Open Inventor练习-SoSelection三维场景中查找功能
- Open Inventor练习-三维物体选择操作
- Open Inventor练习-SoSelection节点下三维物体选择功能
- Open Inventor练习-iv文件读写显示1
- Open Inventor练习-iv文件读写显示2
- Open Inventor练习-iv文件读写显示3
- Open Inventor练习-iv文件读写显示4
- Open Inventor练习-一维拖拽器SoTranslate1Dragger
- Open Inventor练习-文件读取
- Open Inventor练习-文件存储
- Open Inventor显示区域SbViewportRegion
- Open Inventor显示区域SbViewportRegion
- 如何保持一个3D场景总是前端显示 —— Open Inventor In Action
- Open Inventor中SoWriteAction扩展
- OpenInventor试图显示SoWinRenderArea
- Open Inventor练习-SoElapsedTime引擎作用
- 内存压缩是什么?有什么用?
- 一个JS+jquery全选函数
- C++委托
- 如何用javascript把数据转EXCEL的饼图输出
- mobile
- Open Inventor练习-SoWin中SoWinRenderArea显示三维场景
- 浅谈HTTP中Get与Post的区别
- HTTP与FTP
- DataReader To List<T>
- 四种强制类型转换的总结
- Android中的intentservice
- Flex 排错
- SqlParameter使用Like的问题
- 写程序+控制cpu占用率-4+绘制CPU使用率的正弦曲线2+C#+实现