move GL::Widget to RNR::OgreWidget
This commit is contained in:
parent
2d63474c9f
commit
c8a41d027f
|
|
@ -9,7 +9,7 @@ option(COMPILE_STUDIO "Compile the RNR studio" ON)
|
||||||
option(COMPILE_SERVER "Compile the RNR server" ON)
|
option(COMPILE_SERVER "Compile the RNR server" ON)
|
||||||
|
|
||||||
set(DEPENDENCIES_DIR ${CMAKE_SOURCE_DIR}/Dependencies)
|
set(DEPENDENCIES_DIR ${CMAKE_SOURCE_DIR}/Dependencies)
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes") # Ignore attribute warnings generated by Luau
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-attributes -Wno-return-type") # Ignore warnings generated by Luau and Qt
|
||||||
|
|
||||||
find_package(Boost REQUIRED)
|
find_package(Boost REQUIRED)
|
||||||
find_package(cglm REQUIRED CONFIG)
|
find_package(cglm REQUIRED CONFIG)
|
||||||
|
|
|
||||||
|
|
@ -6,10 +6,10 @@ qt_standard_project_setup()
|
||||||
qt_add_library(Common STATIC
|
qt_add_library(Common STATIC
|
||||||
Header/GL/Adorn.hpp
|
Header/GL/Adorn.hpp
|
||||||
Header/GL/RenderContext.hpp
|
Header/GL/RenderContext.hpp
|
||||||
Header/GL/Widget.hpp
|
Header/OgreWidget.hpp
|
||||||
|
|
||||||
Source/GL/Adorn.cpp
|
Source/GL/Adorn.cpp
|
||||||
Source/GL/Widget.cpp
|
Source/OgreWidget.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(Common PUBLIC Header)
|
target_include_directories(Common PUBLIC Header)
|
||||||
|
|
|
||||||
|
|
@ -11,14 +11,14 @@
|
||||||
|
|
||||||
#include <GL/Adorn.hpp>
|
#include <GL/Adorn.hpp>
|
||||||
|
|
||||||
namespace GL
|
namespace RNR
|
||||||
{
|
{
|
||||||
class Widget : public QWidget
|
class OgreWidget : public QWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Widget(Ogre::Root *root, QWidget* parent = nullptr);
|
OgreWidget(Ogre::Root *root, QWidget* parent = nullptr);
|
||||||
|
|
||||||
double delta;
|
double delta;
|
||||||
double render_time;
|
double render_time;
|
||||||
|
|
@ -42,6 +42,7 @@ namespace GL
|
||||||
virtual void mouseMoveEvent(QMouseEvent *event);
|
virtual void mouseMoveEvent(QMouseEvent *event);
|
||||||
virtual void closeEvent(QCloseEvent* event);
|
virtual void closeEvent(QCloseEvent* event);
|
||||||
virtual QPaintEngine* paintEngine() const;
|
virtual QPaintEngine* paintEngine() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QElapsedTimer timer;
|
QElapsedTimer timer;
|
||||||
};
|
};
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include <GL/Widget.hpp>
|
#include <OgreWidget.hpp>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
#ifdef __unix__
|
#ifdef __unix__
|
||||||
|
|
@ -7,9 +7,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// credits to https://github.com/Ekman/Qt-Ogre-Widget
|
// credits to https://github.com/Ekman/Qt-Ogre-Widget
|
||||||
namespace GL
|
namespace RNR
|
||||||
{
|
{
|
||||||
Widget::Widget(Ogre::Root *root, QWidget *parent) : QWidget(parent)
|
OgreWidget::OgreWidget(Ogre::Root *root, QWidget *parent) : QWidget(parent)
|
||||||
{
|
{
|
||||||
this->ogreRoot = root;
|
this->ogreRoot = root;
|
||||||
this->setMinimumSize(640, 480);
|
this->setMinimumSize(640, 480);
|
||||||
|
|
@ -22,7 +22,7 @@ namespace GL
|
||||||
this->setFocusPolicy(Qt::StrongFocus);
|
this->setFocusPolicy(Qt::StrongFocus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::initializeOgre()
|
void OgreWidget::initializeOgre()
|
||||||
{
|
{
|
||||||
Ogre::NameValuePairList options = this->getRenderOptions();
|
Ogre::NameValuePairList options = this->getRenderOptions();
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ namespace GL
|
||||||
this->render_time = 0.0;
|
this->render_time = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::render()
|
void OgreWidget::render()
|
||||||
{
|
{
|
||||||
this->delta = ogreRoot->getTimer()->getMicroseconds() / 1000000.0;
|
this->delta = ogreRoot->getTimer()->getMicroseconds() / 1000000.0;
|
||||||
this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0;
|
this->render_time += ogreRoot->getTimer()->getMilliseconds() / 1000.0;
|
||||||
|
|
@ -75,7 +75,7 @@ namespace GL
|
||||||
ogreRoot->renderOneFrame(this->delta);
|
ogreRoot->renderOneFrame(this->delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ogre::NameValuePairList Widget::getRenderOptions()
|
Ogre::NameValuePairList OgreWidget::getRenderOptions()
|
||||||
{
|
{
|
||||||
Ogre::NameValuePairList options;
|
Ogre::NameValuePairList options;
|
||||||
|
|
||||||
|
|
@ -88,7 +88,7 @@ namespace GL
|
||||||
return options;
|
return options;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ogre::String Widget::getWindowHandle()
|
Ogre::String OgreWidget::getWindowHandle()
|
||||||
{
|
{
|
||||||
Ogre::String windowHandle;
|
Ogre::String windowHandle;
|
||||||
windowHandle = Ogre::StringConverter::toString((unsigned long)winId());
|
windowHandle = Ogre::StringConverter::toString((unsigned long)winId());
|
||||||
|
|
@ -96,7 +96,7 @@ namespace GL
|
||||||
return windowHandle;
|
return windowHandle;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::resizeEvent(QResizeEvent *rEvent)
|
void OgreWidget::resizeEvent(QResizeEvent *rEvent)
|
||||||
{
|
{
|
||||||
QWidget::resizeEvent(rEvent);
|
QWidget::resizeEvent(rEvent);
|
||||||
if(ogreWindow)
|
if(ogreWindow)
|
||||||
|
|
@ -106,20 +106,21 @@ namespace GL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::paintEvent(QPaintEvent *pEvent)
|
void OgreWidget::paintEvent(QPaintEvent *pEvent)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
void OgreWidget::mouseMoveEvent(QMouseEvent *mEvent)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::mouseMoveEvent(QMouseEvent *mEvent)
|
void OgreWidget::closeEvent(QCloseEvent* event)
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void Widget::closeEvent(QCloseEvent* event)
|
|
||||||
{
|
{
|
||||||
ogreWindow->destroy();
|
ogreWindow->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
QPaintEngine *Widget::paintEngine() const
|
QPaintEngine* OgreWidget::paintEngine() const
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -8,7 +8,7 @@
|
||||||
#include <QToolBar>
|
#include <QToolBar>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
|
|
||||||
#include <GL/Widget.hpp>
|
#include <OgreWidget.hpp>
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public QMainWindow
|
||||||
{
|
{
|
||||||
|
|
@ -18,13 +18,14 @@ class MainWindow : public QMainWindow
|
||||||
MainWindow();
|
MainWindow();
|
||||||
|
|
||||||
Ogre::Root* ogreRoot;
|
Ogre::Root* ogreRoot;
|
||||||
GL::Widget* widget;
|
RNR::OgreWidget* ogreWidget;
|
||||||
QTreeWidget* explorer;
|
QTreeWidget* explorer;
|
||||||
QToolBar* toolbar;
|
QToolBar* toolbar;
|
||||||
QMenuBar* menubar;
|
QMenuBar* menubar;
|
||||||
|
|
||||||
void createToolbar();
|
void createToolbar();
|
||||||
void updateTree(RNR::Instance* root_instance);
|
void updateTree(RNR::Instance* root_instance);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance* instance);
|
void recurseTreeAddInstance(QTreeWidgetItem* parent, RNR::Instance* instance);
|
||||||
void closeEvent(QCloseEvent* event);
|
void closeEvent(QCloseEvent* event);
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ MainWindow::MainWindow()
|
||||||
|
|
||||||
createToolbar();
|
createToolbar();
|
||||||
|
|
||||||
this->widget = new GL::Widget(ogreRoot);
|
this->ogreWidget = new RNR::OgreWidget(ogreRoot);
|
||||||
grid->addWidget(this->widget, 2, 0, 1, 2);
|
grid->addWidget(this->ogreWidget, 2, 0, 1, 2);
|
||||||
|
|
||||||
explorer = new QTreeWidget();
|
explorer = new QTreeWidget();
|
||||||
grid->addWidget(explorer, 2, 2, 1, 1);
|
grid->addWidget(explorer, 2, 2, 1, 1);
|
||||||
|
|
|
||||||
|
|
@ -18,18 +18,18 @@ int main(int argc, char** argv)
|
||||||
MainWindow window = MainWindow();
|
MainWindow window = MainWindow();
|
||||||
|
|
||||||
window.show();
|
window.show();
|
||||||
window.widget->initializeOgre();
|
window.ogreWidget->initializeOgre();
|
||||||
|
|
||||||
RNR::World* world = new RNR::World();
|
RNR::World* world = new RNR::World();
|
||||||
window.updateTree(world->getDatamodel());
|
window.updateTree(world->getDatamodel());
|
||||||
|
|
||||||
while (window.isVisible())
|
while (window.isVisible())
|
||||||
{
|
{
|
||||||
window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f", window.widget->delta, window.widget->render_time));
|
window.statusBar()->showMessage(QString::asprintf("Dt=%f, Rt=%f", window.ogreWidget->delta, window.ogreWidget->render_time));
|
||||||
app.processEvents();
|
app.processEvents();
|
||||||
window.widget->render();
|
window.ogreWidget->render();
|
||||||
world->preStep();
|
world->preStep();
|
||||||
world->step(window.widget->delta);
|
world->step(window.ogreWidget->delta);
|
||||||
world->update();
|
world->update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue