minor fixes

main
Benjamin Kraft 1 year ago
parent 41180a7352
commit 9ccec44eb0
  1. 4
      src/GLWidget.cpp
  2. 2
      src/GLWidget.h
  3. 5
      src/MainWindow.cpp
  4. 2
      src/MainWindow.h
  5. 3
      src/Overlay.cpp
  6. 2
      src/Overlay.h
  7. 3
      src/Simulation.h
  8. 1
      src/main.cpp

@ -14,7 +14,7 @@ GLWidget::GLWidget(Simulation * simulation) : simulation(simulation) {
startTimer(1000 / 144); startTimer(1000 / 144);
overlay = new Overlay(simulation); overlay = new Overlay(simulation);
connect(simulation, &Simulation::layoutChanged, this, &GLWidget::uploadStaticDataToGPU); connect(simulation, &Simulation::layoutChanged, this, &GLWidget::uploadStaticDataToGPU);
connect(simulation, &Simulation::layoutChanged, overlay, &Overlay::fetchEnergyLimit); connect(simulation, &Simulation::layoutChanged, overlay, &Overlay::resetEnergyLimit);
connect(simulation, &Simulation::positionChanged, this, &GLWidget::changePosition); connect(simulation, &Simulation::positionChanged, this, &GLWidget::changePosition);
} }
@ -44,8 +44,6 @@ void GLWidget::initializeGL() {
uploadStaticDataToGPU(); uploadStaticDataToGPU();
overlay->init(); overlay->init();
std::cout << format().swapInterval() << std::endl;
} }
void GLWidget::paintGL() { void GLWidget::paintGL() {

@ -12,6 +12,7 @@ class Overlay;
class GLWidget : public QOpenGLWidget, protected QOpenGLExtraFunctions { class GLWidget : public QOpenGLWidget, protected QOpenGLExtraFunctions {
public: public:
explicit GLWidget(Simulation *); explicit GLWidget(Simulation *);
Overlay * overlay;
protected: protected:
void timerEvent(QTimerEvent* e) override; void timerEvent(QTimerEvent* e) override;
void initializeGL() override; void initializeGL() override;
@ -37,6 +38,5 @@ private:
bool showMasses; bool showMasses;
Simulation * simulation; Simulation * simulation;
Overlay * overlay;
static bool AnyDialogOpen(); static bool AnyDialogOpen();
}; };

@ -16,6 +16,7 @@
#include <QThread> #include <QThread>
#include <QCloseEvent> #include <QCloseEvent>
#include <QTimer> #include <QTimer>
#include "Overlay.h"
MainWindow::MainWindow() { MainWindow::MainWindow() {
simulationThread = new QThread(this); simulationThread = new QThread(this);
@ -328,6 +329,8 @@ QWidget * MainWindow::buildSimulationUI() {
}); });
substepsSlider = new Slider<>(substepsLabel, "Substeps: %d", &simulation->substeps); substepsSlider = new Slider<>(substepsLabel, "Substeps: %d", &simulation->substeps);
connect(gravitySlider, &QSlider::valueChanged, glWidget->overlay, &Overlay::resetEnergyLimit);
gravitySlider->setMaximum(3000); gravitySlider->setMaximum(3000);
timescaleSlider->setMinimum(1); timescaleSlider->setMinimum(1);
timescaleSlider->setMaximum(500); timescaleSlider->setMaximum(500);
@ -441,7 +444,7 @@ void MainWindow::add() {
void MainWindow::resetSimulationControl() { void MainWindow::resetSimulationControl() {
gravitySlider->setValue(981); gravitySlider->setValue(981);
timescaleSlider->setValue(100); timescaleSlider->setValue(100);
substepsSlider->setValue(5); substepsSlider->setValue(20);
} }
void MainWindow::toggleSimulation() { void MainWindow::toggleSimulation() {

@ -27,7 +27,7 @@ private:
std::vector<double> masses, lengths; std::vector<double> masses, lengths;
int segments = 0; int segments = 0;
int startingAngle = 90; int startingAngle = 135;
QColor color = Qt::white; QColor color = Qt::white;
bool multiple = false; bool multiple = false;
bool rainbow = false; bool rainbow = false;

@ -172,6 +172,7 @@ void Overlay::drawTexture(QImage *image) {
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
} }
void Overlay::fetchEnergyLimit() { void Overlay::resetEnergyLimit() {
simulation->updateEnergy();
energyLimit = simulation->kineticEnergy + simulation->potentialEnergy; energyLimit = simulation->kineticEnergy + simulation->potentialEnergy;
} }

@ -20,7 +20,7 @@ class Overlay : public QObject, protected QOpenGLExtraFunctions {
Simulation * simulation; Simulation * simulation;
double energyLimit = 0; double energyLimit = 0;
public slots: public slots:
void fetchEnergyLimit(); void resetEnergyLimit();
public: public:
explicit Overlay(Simulation *); explicit Overlay(Simulation *);
void init(); void init();

@ -29,6 +29,8 @@ public:
std::mutex pendulaMutex; std::mutex pendulaMutex;
FPS * ups; FPS * ups;
void updateEnergy();
signals: signals:
void layoutChanged(); void layoutChanged();
void positionChanged(); void positionChanged();
@ -38,7 +40,6 @@ public slots:
private slots: private slots:
void update(); void update();
private: private:
void updateEnergy();
QTimer * timer; QTimer * timer;
int updateInterval = 16; int updateInterval = 16;
}; };

@ -10,6 +10,7 @@ using namespace std::chrono;
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
QSurfaceFormat fmt = QSurfaceFormat::defaultFormat(); QSurfaceFormat fmt = QSurfaceFormat::defaultFormat();
fmt.setDepthBufferSize(24); fmt.setDepthBufferSize(24);
fmt.setSamples(8);
fmt.setSwapInterval(1); fmt.setSwapInterval(1);
fmt.setVersion(3, 3); fmt.setVersion(3, 3);
fmt.setProfile(QSurfaceFormat::CoreProfile); fmt.setProfile(QSurfaceFormat::CoreProfile);

Loading…
Cancel
Save