eryar@163.comhtml
Abstract. Qt’s ActiveX and COM support allows Qt for Windows developers to access and use ActiveX controls and COM objects provided by any ActiveX server in their Qt applications. Make their Qt application available as COM servers, with any number of Qt objects and widgets as COM objects and ActiveX controls. Make OpenSceneGraph to ActiveX controls then you can use it in other place, like IE.app
Key Words. OpenSceneGraph, ActiveX, COM, ActiveQt框架
1.Introductionide
ActiveX是一个开放的集成平台,为开发人员、用户和Web生产商提供了一个快速而简便的在Internet 和Intranet建立程序集成和内容的方法。使用AcitveX能够轻松方便地在Web页面中插入多媒体效果、交互式对象及复杂程序。编写的ActiveX控件能够在不一样的程序上运行,如Internet Explorer, Visual Basic, MFC- and ATL-based containters等等。函数
本文尝试使用Qt的ActiveQt模块将OpenSceneGraph封装成ActiveX控件,并在Internet Explorer中显示出三维模型。测试
2.ActiveQtui
习惯了用Qt封装的对象,用着舒服。Qt的Windows商业版本和开源版本都提供了ActiveQt框架,使用这个组件咱们能够在Qt中使用ActiveX控件,而且也能够开发基于Qt的ActiveX控件。ActiveQt包含了两个组件QAxContainter和QAxServer:this
v QAxContainer容许咱们使用COM对象,像使用Excel的COM对象,就能够对Excel进行读写了;spa
v QAxServer能够将咱们写的Qt控件导出为COM对象或者ActiveX控件。3d
使用ActiveQt来编写ActiveX控件仍是要简单不少的。
3.OpenSceneGraph
OpenSceneGraph是对OpenGL面向对象的封装,使用OpenSceneGraph能够方便地对三维场景进行处理,能够用于三维可视化,仿真等领域。由于也是纯C++开发,因此产生了将OpenSceneGraph编写成ActiveX控件的想法,这样就能够在Web上来操做三维场景了。
4.Example
首先在Visual Studio中建立一个ActiveQt Server项目,以下图所示:
接下来使用osgQt模块来在Qt中使用OpenSceneGraph,只须要增长一个初始化函数,代码以下所示:
void osgActiveX::init() { osgQt::initQtWindowingSystem(); myRootNode = new osg::PositionAttitudeTransform(); myRootNode->addChild(osgDB::readNodeFile("d:/test.stl")); myViewer = new osgViewer::Viewer(); myViewer->addEventHandler(new osgGA::StateSetManipulator(myViewer->getCamera()->getOrCreateStateSet())); myViewer->addEventHandler(new osgViewer::StatsHandler()); myViewer->setCameraManipulator(new osgGA::TrackballManipulator()); myViewer->setSceneData(myRootNode); osgQt::setViewer(myViewer); myOsgWidget = new osgQt::GLWidget(this); myGraphicsContext = new osgQt::GraphicsWindowQt(myOsgWidget); myViewer->getCamera()->setViewport(0, 0, myOsgWidget->width(), myOsgWidget->height()); myViewer->getCamera()->setProjectionMatrixAsPerspective( 30.0f, static_cast<double>(myOsgWidget->width())/static_cast<double>(myOsgWidget->height()), 1.0f, 10000.0f ); myViewer->getCamera()->setGraphicsContext(myGraphicsContext); setCentralWidget(myOsgWidget); }
编译生成一个ActiveX控件后,再写一个HTML文件来测试生成的结果,其中HTML文件中的主要内容以下:
<object ID="OsgActiveX" CLASSID="CLSID:450B2B35-9AC6-4FCD-A883-2ACF0FA19A16"> [Object not available! Did you forget to build and register the server?] </object>
其中CLASSID就是用QAXFACTORY_DEFAULT宏定义注册时的GUID。程序运行结果以下图所示:
5.Conclusion
使用ActiveQt将OpenSceneGraph封装成ActiveX控件,这样的控件就能够在多个程序中使用,如IE,Visual Basic等等。
等熟练理解ActiveQt后,能够对OSG的ActiveX控件进行扩展,使其有更强大的三维交互功能。
6.References
1. Qt’s ActiveX Framework
2. https://zh.wikipedia.org/wiki/ActiveX
PDF Version: OpenSceneGraph in ActiveX by ActiveQt