Separated movement from draw timer

This commit is contained in:
Muaz Ahmad 2023-05-04 13:21:34 +05:00
parent 7624174d32
commit 2ffd9d8418
4 changed files with 27 additions and 14 deletions

View file

@ -8,9 +8,12 @@ int main(int argc, char **argv) {
QMainWindow w; QMainWindow w;
Ui::MainWindow ui; Ui::MainWindow ui;
ui.setupUi(&w); ui.setupUi(&w);
QTimer timer; QTimer timer_draw;
w.connect(&timer, SIGNAL(timeout()), ui.openGLWidget, SLOT(paintGL())); QTimer timer_cam;
timer.start(16); w.connect(&timer_draw, SIGNAL(timeout()), ui.openGLWidget, SLOT(paintGL()));
w.connect(&timer_cam, SIGNAL(timeout()), ui.openGLWidget, SLOT(update_camera()));
timer_draw.start(16);
timer_cam.start(16);
w.show(); w.show();
return app.exec(); return app.exec();
} }

View file

@ -22,8 +22,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_OPGLWidget_t { struct qt_meta_stringdata_OPGLWidget_t {
QByteArrayData data[3]; QByteArrayData data[4];
char stringdata0[20]; char stringdata0[34];
}; };
#define QT_MOC_LITERAL(idx, ofs, len) \ #define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \ Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -34,10 +34,11 @@ static const qt_meta_stringdata_OPGLWidget_t qt_meta_stringdata_OPGLWidget = {
{ {
QT_MOC_LITERAL(0, 0, 10), // "OPGLWidget" QT_MOC_LITERAL(0, 0, 10), // "OPGLWidget"
QT_MOC_LITERAL(1, 11, 7), // "paintGL" QT_MOC_LITERAL(1, 11, 7), // "paintGL"
QT_MOC_LITERAL(2, 19, 0) // "" QT_MOC_LITERAL(2, 19, 0), // ""
QT_MOC_LITERAL(3, 20, 13) // "update_camera"
}, },
"OPGLWidget\0paintGL\0" "OPGLWidget\0paintGL\0\0update_camera"
}; };
#undef QT_MOC_LITERAL #undef QT_MOC_LITERAL
@ -47,7 +48,7 @@ static const uint qt_meta_data_OPGLWidget[] = {
8, // revision 8, // revision
0, // classname 0, // classname
0, 0, // classinfo 0, 0, // classinfo
1, 14, // methods 2, 14, // methods
0, 0, // properties 0, 0, // properties
0, 0, // enums/sets 0, 0, // enums/sets
0, 0, // constructors 0, 0, // constructors
@ -55,9 +56,11 @@ static const uint qt_meta_data_OPGLWidget[] = {
0, // signalCount 0, // signalCount
// slots: name, argc, parameters, tag, flags // slots: name, argc, parameters, tag, flags
1, 0, 19, 2, 0x0a /* Public */, 1, 0, 24, 2, 0x0a /* Public */,
3, 0, 25, 2, 0x0a /* Public */,
// slots: parameters // slots: parameters
QMetaType::Void,
QMetaType::Void, QMetaType::Void,
0 // eod 0 // eod
@ -70,6 +73,7 @@ void OPGLWidget::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
(void)_t; (void)_t;
switch (_id) { switch (_id) {
case 0: _t->paintGL(); break; case 0: _t->paintGL(); break;
case 1: _t->update_camera(); break;
default: ; default: ;
} }
} }
@ -105,13 +109,13 @@ int OPGLWidget::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0) if (_id < 0)
return _id; return _id;
if (_c == QMetaObject::InvokeMetaMethod) { if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 1) if (_id < 2)
qt_static_metacall(this, _c, _id, _a); qt_static_metacall(this, _c, _id, _a);
_id -= 1; _id -= 2;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) { } else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 1) if (_id < 2)
*reinterpret_cast<int*>(_a[0]) = -1; *reinterpret_cast<int*>(_a[0]) = -1;
_id -= 1; _id -= 2;
} }
return _id; return _id;
} }

View file

@ -26,7 +26,6 @@ void OPGLWidget::initializeGL() {
} }
void OPGLWidget::paintGL() { void OPGLWidget::paintGL() {
for (int i = 0; i < 3; i++) {loc[i] += vel[i];};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); glLoadIdentity();
reorient(); reorient();
@ -72,3 +71,9 @@ void OPGLWidget::resizeGL(int w, int h) {
glFrustum(-right, right, -top, top, 0.1f, 100.0f); glFrustum(-right, right, -top, top, 0.1f, 100.0f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
} }
void OPGLWidget::update_camera() {
for (int i = 0; i < 3; i++) {
loc[i] += vel[i];
};
}

View file

@ -8,6 +8,7 @@ public:
OPGLWidget(QWidget *parent) : QOpenGLWidget(parent) {} OPGLWidget(QWidget *parent) : QOpenGLWidget(parent) {}
public slots: public slots:
void paintGL(); void paintGL();
void update_camera();
protected: protected:
void initializeGL(); void initializeGL();
void resizeGL(int w, int h); void resizeGL(int w, int h);