-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.h
More file actions
39 lines (32 loc) · 877 Bytes
/
Copy pathobject.h
File metadata and controls
39 lines (32 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#ifndef OBJECT_H
#define OBJECT_H
#include "particle.h"
#include <QtGui/qpainter.h>
#include <QColor>
class Object
{
public:
Object() = default;
template <typename... Particles>
Object(QColor color, Particles&&... particles)
: color(color)
{
(addParticle(std::make_unique<Particle>(particles)), ...);
computeMass();
}
float mass;
QColor color;
std::vector<std::unique_ptr<Particle>> particles;
inline void addParticle(std::unique_ptr<Particle> particle) { particles.push_back(std::move(particle)); }
void render(QPainter *painter, const std::function<Vec2(const Vec2&)>& worldToView);
private:
void computeMass() {
mass = 0;
for (const auto& particle : particles) {
if (particle) {
mass += particle->mass;
}
}
}
};
#endif // OBJECT_H