From d6c332f1e7f2d82c5573418a30881b69a5df9e83 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Sun, 1 Dec 2024 13:08:45 +0100 Subject: [PATCH] cursor schmovement --- .clangd | 5 ++++- editor/main.cpp | 5 +++++ editor/mainglwidget.cpp | 34 +++++++++++++++++++++++++++------- editor/mainglwidget.h | 4 ++++ editor/mainwindow.cpp | 27 ++++++++++++++++++++++++++- editor/mainwindow.h | 6 ++++++ editor/mainwindow.ui | 2 +- 7 files changed, 73 insertions(+), 10 deletions(-) diff --git a/.clangd b/.clangd index c96f078..f0eb4d6 100644 --- a/.clangd +++ b/.clangd @@ -2,7 +2,10 @@ CompileFlags: # Tweak the parse settings, example directory given to show format Add: - "--include-directory=../../src" - "--include-directory=../src" + - "--include-directory=./editor_autogen/include" + - "--include-directory=../.." - "--include-directory=/usr/include/qt6/QtWidgets" - "--include-directory=/usr/include/qt6/QtOpenGLWidgets" - "--include-directory=/usr/include/qt6" - - "--include-directory=/usr/include/qt6/QtGui" \ No newline at end of file + - "--include-directory=/usr/include/qt6/QtGui" + - "--include-directory=/usr/include/qt6/QtCore" \ No newline at end of file diff --git a/editor/main.cpp b/editor/main.cpp index 647e5d2..765f5c2 100644 --- a/editor/main.cpp +++ b/editor/main.cpp @@ -4,6 +4,11 @@ #include #include #include +#include + +#include "physics/simulation.h" +#include "qcoreevent.h" +#include "qobject.h" int main(int argc, char *argv[]) { diff --git a/editor/mainglwidget.cpp b/editor/mainglwidget.cpp index 8cbfe09..e117730 100644 --- a/editor/mainglwidget.cpp +++ b/editor/mainglwidget.cpp @@ -1,6 +1,11 @@ -#include "GL/glew.h" +#include +#include + +#include #include "part.h" +#include "qevent.h" +#include "qnamespace.h" #include "rendering/renderer.h" #include "physics/simulation.h" #include "camera.h" @@ -55,12 +60,27 @@ void MainGLWidget::resizeGL(int w, int h) { // ... } -float lastTime = glfwGetTime(); void MainGLWidget::paintGL() { - float deltaTime = glfwGetTime() - lastTime; - lastTime = glfwGetTime(); - - // processInput(NULL); - physicsStep(deltaTime); ::render(NULL); } + +bool isMouseDragging = false; +QPoint lastMousePos; +void MainGLWidget::mouseMoveEvent(QMouseEvent* evt) { + // if (!(evt->buttons() & Qt::RightButton)) return; + if (!isMouseDragging) return; + + camera.processRotation(evt->pos().x() - lastMousePos.x(), evt->pos().y() - lastMousePos.y()); + lastMousePos = evt->pos(); +} + +void MainGLWidget::mousePressEvent(QMouseEvent* evt) { + if (evt->button() != Qt::RightButton) return; + + lastMousePos = evt->pos(); + isMouseDragging = true; +} + +void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) { + isMouseDragging = false; +} \ No newline at end of file diff --git a/editor/mainglwidget.h b/editor/mainglwidget.h index 8c4d642..92350dd 100644 --- a/editor/mainglwidget.h +++ b/editor/mainglwidget.h @@ -12,6 +12,10 @@ protected: void initializeGL() override; void resizeGL(int w, int h) override; void paintGL() override; + + void mouseMoveEvent(QMouseEvent* evt) override; + void mousePressEvent(QMouseEvent* evt) override; + void mouseReleaseEvent(QMouseEvent* evt) override; }; #endif // MAINGLWIDGET_H diff --git a/editor/mainwindow.cpp b/editor/mainwindow.cpp index 2918f80..36164cc 100644 --- a/editor/mainwindow.cpp +++ b/editor/mainwindow.cpp @@ -5,13 +5,38 @@ #include #include #include -#include "mainglwidget.h" +#include +#include +#include + +#include "common.h" +#include "physics/simulation.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); + timer.start(33, this); + setMouseTracking(true); +} + +std::chrono::time_point lastTime = std::chrono::steady_clock::now(); +void MainWindow::timerEvent(QTimerEvent* evt) { + if (evt->timerId() != timer.timerId()) { + QWidget::timerEvent(evt); + return; + } + + float deltaTime = std::chrono::duration_cast>(std::chrono::steady_clock::now() - lastTime).count(); + lastTime = std::chrono::steady_clock::now(); + + physicsStep(deltaTime); + ui->mainWidget->update(); +} + +void MainWindow::updateMainWidget() { + ui->mainWidget->update(); } MainWindow::~MainWindow() diff --git a/editor/mainwindow.h b/editor/mainwindow.h index f511371..6232382 100644 --- a/editor/mainwindow.h +++ b/editor/mainwindow.h @@ -1,6 +1,8 @@ #ifndef MAINWINDOW_H #define MAINWINDOW_H +#include "qbasictimer.h" +#include "qcoreevent.h" #include #include @@ -17,8 +19,12 @@ class MainWindow : public QMainWindow public: MainWindow(QWidget *parent = nullptr); ~MainWindow(); + void updateMainWidget(); private: Ui::MainWindow *ui; + QBasicTimer timer; + + void timerEvent(QTimerEvent*) override; }; #endif // MAINWINDOW_H diff --git a/editor/mainwindow.ui b/editor/mainwindow.ui index 2154ca0..04b9e1a 100644 --- a/editor/mainwindow.ui +++ b/editor/mainwindow.ui @@ -16,7 +16,7 @@ - +