Simulate thousands of n-Pendula (up to 32) with Position Based Dynamics
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
#include <vector>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <QObject>
|
|
|
|
#include <chrono>
|
|
|
|
#include <mutex>
|
|
|
|
#include "Pendulum.h"
|
|
|
|
|
|
|
|
using namespace std::chrono;
|
|
|
|
|
|
|
|
class QPainter;
|
|
|
|
class QTimer;
|
|
|
|
|
|
|
|
class Simulation : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
explicit Simulation();
|
|
|
|
|
|
|
|
double size = 50;
|
|
|
|
|
|
|
|
double gravity {};
|
|
|
|
double timescale {};
|
|
|
|
int substeps {};
|
|
|
|
|
|
|
|
bool isPlaying = false;
|
|
|
|
|
|
|
|
std::mutex pendulaMutex;
|
|
|
|
signals:
|
|
|
|
void layoutChanged(const std::vector<Pendulum *> *newPendula);
|
|
|
|
void positionChanged(const std::vector<Pendulum *> *changedPendula);
|
|
|
|
public slots:
|
|
|
|
void clearPendula();
|
|
|
|
void addPendula(const std::vector<Pendulum *> &add);
|
|
|
|
private slots:
|
|
|
|
void update();
|
|
|
|
private:
|
|
|
|
QTimer * timer;
|
|
|
|
int updateInterval = 17;
|
|
|
|
std::vector<Pendulum *> pendula;
|
|
|
|
time_point<system_clock> lastUpdate;
|
|
|
|
};
|