对于个人开发者来说,选择开源工具应该是最好的选择。 此次选择 开源建模软件Blender + 开源3d渲染引擎Ogre + 开源程序框架Qt来实现。
Ogre下载 https://www.ogre3d.org/
Blender下载 https://www.blender.org/
Blender导出Ogre模型 https://github.com/OGRECave/blender2ogre
Qt调用Ogre https://ogrecave.github.io/ogre/api/latest/setup.html https://wiki.ogre3d.org/Integrating+Ogre+into+QT5
继承基类,创建自己的app类
class MyTestApp : public OgreBites::ApplicationContextQt, public OgreBites::InputListener
{
public:
MyTestApp();
bool keyPressed(const OgreBites::KeyboardEvent& evt);
bool mouseMoved(const OgreBites::MouseMotionEvent& evt);
bool mousePressed(const OgreBites::MouseButtonEvent &evt);
bool mouseReleased(const OgreBites::MouseButtonEvent &evt);
void setup(void);
Ogre::SceneNode* node;
bool mPressed;
};
。。。 然后获取Ogre的窗口widget
{
...
mApp = new MyTestApp();
QWindow *mWindow = new QWindow();
mApp->injectMainWindow(mWindow);
mApp->initApp();
auto widget = QWidget::createWindowContainer(mWindow);
OgreView *v = new OgreView();
v->setOgreWidget(widget);
QVBoxLayout *mLayout = new QVBoxLayout();
mLayout->addWidget(v);
...
}
void OgreView::resizeEvent(QResizeEvent *e)
{
qDebug() << e << mOrgWid;
qDebug() << this->rect() << mOrgWid->rect();
if(mOrgWid != nullptr)
{
mOrgWid->setGeometry(8, 31, this->width() - 16, this->height() - 39);
}
}
他的例程。
|