Coin3D三维可视化教程8

基于windows的coin3d窗口

从SoQt到SoWin

好久没摸coin3d了,最近想继续学学。之前的例子都是用SoQt平台下做的,很适合通过widget组件和已有Qt代码组成大的软件系统,但如果仅仅为了学习,不想很麻烦的配置qt,采用SoWin更容易些,这里展示一个用SoWin而非SoQt的简单例子。具体代码如下

#include <iostream>
#include <Inventor/Win/SoWin.h>
#include <Inventor/Win/viewers/SoWinExaminerViewer.h>
#include <Inventor/nodes/SoCube.h>
#include <Inventor/nodes/SoDirectionalLight.h>
#include <Inventor/nodes/SoMaterial.h>
#include <Inventor/nodes/SoPerspectiveCamera.h>
#include <Inventor/nodes/SoSeparator.h>


int main(int argc, char* argv[])
{
	std::cout << "Hello World!\n";
	HWND myWindow = SoWin::init(argv[0]);
	if (myWindow == NULL)exit(1);

	SoSeparator* root = new SoSeparator;
	root->ref();
	SoMaterial* myMaterial = new SoMaterial;
	myMaterial->diffuseColor.setValue(1, 0, 0);
	root->addChild(myMaterial);
	root->addChild(new SoCube);

	SoWinExaminerViewer* myViewer = new SoWinExaminerViewer(myWindow);
	myViewer->setSceneGraph(root);
	myViewer->setTitle("Examiner Viewer");
	myViewer->show();

	SoWin::show(myWindow);
	SoWin::mainLoop();

	return 0;

}

效果如下
SoCube的显示效果
对比之前的教程2可以看出,改动很少
https://blog.csdn.net/yanfeng1022/article/details/105908803
QWidget* myWindow = SoQt::init(argv[0]);
改为
HWND myWindow = SoWin::init(argv[0]);
最后的
SoQt::show(myWindow); //Display main window
SoQt::mainLoop(); //Main Inventor event loop
改为
SoWin::show(myWindow);
SoWin::mainLoop();
基本是一目了然。

posted @ 2022-08-21 10:12  Oliver2022  阅读(218)  评论(0编辑  收藏  举报