31#include <Qt3DExtras/QForwardRenderer>
32#include <Qt3DExtras/QOrbitCameraController>
33#include <Qt3DExtras/Qt3DWindow>
34#include <Qt3DRender/QCamera>
52 class Display :
public Qt3DExtras::Qt3DWindow {
61 QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform>,
62 QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform>,
63 QPointer<Qt3DCore::QEntity>, QPointer<Qt3DCore::QTransform>>;
69 explicit Display(
const Configuration::SimulationConfig& config)
75 defaultFrameGraph()->setClearColor(QColor(0, 0, 0));
78 camera()->lens()->setPerspectiveProjection(45., 16. / 9., 0.1,
80 camera()->setPosition(QVector3D(0, 0, 820));
81 camera()->setViewCenter(QVector3D(0, 0, 0));
82 rootEntity_ = std::make_unique<Qt3DCore::QEntity>();
113 new Qt3DExtras::QOrbitCameraController(
rootEntity_.get());
142 void updateFrame(
const Model::Vector3dVec& positions,
143 const Model::QuaterniondVec& quaternions,
144 const Model::Vector3dVec& torques,
145 const Model::Vector3dVec& alphas,
146 std::size_t iteration);
215 Qt3DCore::QEntity* parent,
const QColor& colour,
float radius,
226 const Model::Vector3d& vector,
227 double scaleFactor)
const;
Runs the physics simulation in a separate thread to keep the UI responsive.
void updatedBodyData(const Vector3dVec &positions, const QuaterniondVec &quaternions, const Vector3dVec &torques, const Vector3dVec &alphas, std::size_t iteration)
Emitted after each simulation step with the updated state of all bodies.
void startSimulation()
Starts the simulation loop.
void performSingleStep()
Performs a single step of the physics simulation and emits the results.
void simulationFinished()
Emitted when the simulation has completed all iterations.
A 32-bit Permuted Congruential Generator (pcg32).
Manages the Qt3D window, scene setup, and the main simulation loop.
void cleanup()
Performs cleanup actions, such as printing profiling reports.
std::unique_ptr< Qt3DCore::QEntity > rootEntity_
The root entity for the 3D scene.
std::size_t maxIterations_
Maximum number of iterations.
void createSpheres(Rng::Pcg32 &gen)
Create and set up the spherical bodies in the scene.
std::pair< Qt3DCore::QEntity *, Qt3DCore::QTransform * > createArrowEntity(Qt3DCore::QEntity *parent, const QColor &colour, float radius, float length)
Creates a 3D arrow entity for vector visualization.
bool cleanupCalled_
Flag to track if cleanup has already been called. This prevents cleanup from being called multiple ti...
~Display() override
Destructor to ensure worker thread is cleaned up.
QPointer< Model::PhysicsWorker > physicsWorker_
The worker object running the simulation. Uses QPointer for safety: it becomes nullptr if the object ...
void simulationFinished()
Emitted when the simulation has run for n_iter iterations.
std::tuple< QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform >, QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform >, QPointer< Qt3DCore::QEntity >, QPointer< Qt3DCore::QTransform > > BodyInformations
A tuple to hold the Qt-specific components for a single rendered body.
std::size_t iterationCount_
The current iteration count.
QTimer * simulationTimer_
Timer to drive the simulation loop. Reused timer that triggers physics steps automatically.
void updateFrame(const Model::Vector3dVec &positions, const Model::QuaterniondVec &quaternions, const Model::Vector3dVec &torques, const Model::Vector3dVec &alphas, std::size_t iteration)
Slot to receive updated data from the physics worker and update the scene.
QPointer< Qt3DExtras::QOrbitCameraController > camController_
Mouse camera controller.
void createScene(unsigned int seed)
Set up the scene.
QThread * physicsThread_
The thread where the physics worker runs. Created with 'this' as parent, so Qt manages its lifetime.
void runSimulation()
Starts the physics simulation by starting the worker thread.
bool showAlphaArrow_
Flag to display angular acceleration vectors in the UI.
void updateVectorArrow(Qt3DCore::QTransform *arrowTransform, const Model::Vector3d &vector, double scaleFactor) const
Updates the transform of an arrow entity to represent a 3D vector.
bool showTorqueArrow_
Flag to display torque vectors in the UI.
std::vector< BodyInformations > bodies_
List of spheres representing bodies. This list differs from the actual physical bodies in the simulat...
Display(const Configuration::SimulationConfig &config)
Initialise the 3D window and set up the scene.
A minimal C++ implementation of the PCG32 random number generator.
Worker object to run the physics simulation in a separate thread.