-
Notifications
You must be signed in to change notification settings - Fork 40
/
renderer.hpp
41 lines (35 loc) · 1.1 KB
/
renderer.hpp
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
40
41
#pragma once
#include "solver.hpp"
class Renderer
{
public:
explicit
Renderer(sf::RenderTarget& target)
: m_target{target}
{
}
void render(const Solver& solver) const
{
// Render constraint
const sf::Vector3f constraint = solver.getConstraint();
sf::CircleShape constraint_background{constraint.z};
constraint_background.setOrigin(constraint.z, constraint.z);
constraint_background.setFillColor(sf::Color::Black);
constraint_background.setPosition(constraint.x, constraint.y);
constraint_background.setPointCount(128);
m_target.draw(constraint_background);
// Render objects
sf::CircleShape circle{1.0f};
circle.setPointCount(32);
circle.setOrigin(1.0f, 1.0f);
const auto& objects = solver.getObjects();
for (const auto& obj : objects) {
circle.setPosition(obj.position);
circle.setScale(obj.radius, obj.radius);
circle.setFillColor(obj.color);
m_target.draw(circle);
}
}
private:
sf::RenderTarget& m_target;
};