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.
 
 
 
 

45 lines
778 B

#include <vector>
#include <cstdint>
#include <QObject>
#include <chrono>
#include "Pendulum.h"
#include <semaphore>
using namespace std::chrono;
class QTimer;
class FPS;
class Simulation : public QObject {
Q_OBJECT
public:
explicit Simulation();
double sizeMeters = 50;
double gravity {};
double timescale {};
int substeps {};
double potentialEnergy = 0, kineticEnergy = 0;
bool isPlaying = false;
std::vector<Pendulum *> pendula;
std::binary_semaphore semaphore = std::binary_semaphore(1);
FPS * ups;
void updateEnergy();
signals:
void layoutChanged();
void positionChanged();
public slots:
void clearPendula();
void addPendula(const std::vector<Pendulum *> &add);
private slots:
void update();
private:
QTimer * timer;
int updateInterval = 16;
};