m2b-ar-tp2/main.cpp
2021-10-06 19:49:42 +02:00

52 lines
1.2 KiB
C++

// Basé sur :
// CC-BY Edouard.Thiel@univ-amu.fr - 22/01/2019
#include "princ.h"
#include "glarea.h"
#include "fish_painter.h"
#include "fish_schooling.h"
#include <QApplication>
#include <QTimer>
#include <QElapsedTimer>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Princ main_window;
FishSchooling schooling(20);
FishPainter fish_painter;
GLArea *glarea = main_window.glarea;
QObject::connect(glarea, &GLArea::onInit,
[&](QOpenGLExtraFunctions *glf) {
fish_painter.create(glf);
});
QObject::connect(glarea, &GLArea::onPaint,
[&](QOpenGLExtraFunctions *glf,
const QMatrix4x4 &projection,
const QMatrix4x4 &view) {
fish_painter.paint(glf, projection, view,
schooling.fishes);
});
QTimer timer;
timer.setInterval(1000. / 60);
QElapsedTimer elapsed_timer;
elapsed_timer.start();
qint64 old_chrono = 0;
QObject::connect(&timer, &QTimer::timeout, [&]() {
qint64 chrono = elapsed_timer.elapsed();
float dt = (chrono - old_chrono) / 1000.0f;
old_chrono = chrono;
schooling.animate(dt);
glarea->update();
});
timer.start();
main_window.show();
return app.exec();
}