OpenSceneGraph in ActiveX by ActiveQt

OpenSceneGraph in ActiveX by ActiveQt

eryar@163.com

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.

Key Words. OpenSceneGraph, ActiveX, COM, ActiveQt

1.Introduction

ActiveX是一个开放的集成平台,为开发人员、用户和Web生产商提供了一个快速而简便的在Internet 和Intranet创建程序集成和内容的方法。使用AcitveX可以轻松方便地在Web页面中插入多媒体效果、交互式对象及复杂程序。编写的ActiveX控件可以在不同的程序上运行,如Internet Explorer, Visual Basic, MFC- and ATL-based containters等等。

本文尝试使用Qt的ActiveQt模块将OpenSceneGraph封装成ActiveX控件,并在Internet Explorer中显示出三维模型。

2.ActiveQt

习惯了用Qt封装的对象,用着舒服。Qt的Windows商业版本和开源版本都提供了ActiveQt框架,使用这个组件我们可以在Qt中使用ActiveX控件,并且也可以开发基于Qt的ActiveX控件。ActiveQt包含了两个组件QAxContainter和QAxServer:

v QAxContainer允许我们使用COM对象,像使用Excel的COM对象,就可以对Excel进行读写了;

v QAxServer可以将我们写的Qt控件导出为COM对象或者ActiveX控件。

使用ActiveQt来编写ActiveX控件还是要简单很多的。

3.OpenSceneGraph

OpenSceneGraph是对OpenGL面向对象的封装,使用OpenSceneGraph可以方便地对三维场景进行处理,可以用于三维可视化,仿真等领域。因为也是纯C++开发,所以产生了将OpenSceneGraph编写成ActiveX控件的想法,这样就可以在Web上来操作三维场景了。

4.Example

首先在Visual Studio中创建一个ActiveQt Server项目,如下图所示:

wpsDE63.tmp

接下来使用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。程序运行结果如下图所示:

wpsDE64.tmp

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

 

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容