-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugDraw.cpp
90 lines (76 loc) · 2.69 KB
/
DebugDraw.cpp
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "DebugDraw.hpp"
DebugDraw::DebugDraw(sf::RenderTarget& target)
: mTarget(target)
{
}
void DebugDraw::draw(const Aabb& aabb, const sf::Vector2f position, sf::Color color)
{
sf::RectangleShape shape(aabb.getSize());
shape.setPosition(position);
shape.setFillColor(sf::Color::Transparent);
shape.setOutlineColor(color);
shape.setOutlineThickness(1.0f);
mTarget.draw(shape);
}
void DebugDraw::draw(const Circle& circle, const sf::Vector2f position, sf::Color color)
{
sf::CircleShape shape(circle.getRadius());
shape.setOrigin(circle.getRadius(), circle.getRadius());
shape.setPosition(position);
shape.setFillColor(sf::Color::Transparent);
shape.setOutlineColor(color);
shape.setOutlineThickness(1.0f);
mTarget.draw(shape);
}
void DebugDraw::draw(const Ray& ray, const sf::Vector2f position, sf::Color color)
{
sf::Vector2f direction = ray.getDirection() * ray.getLength();
sf::Vertex line[] = {
sf::Vertex(position, color),
sf::Vertex(position + direction, color),
};
mTarget.draw(line, 2, sf::Lines);
}
void DebugDraw::draw(const Manifold& manifold, sf::Color color)
{
if (manifold.colliding)
{
sf::Vector2f normal = manifold.normal * manifold.depth;
sf::Vertex point[] = {
sf::Vertex(manifold.contact, sf::Color::Red),
};
sf::Vertex line[] = {
sf::Vertex(manifold.contact, color),
sf::Vertex(manifold.contact + normal, color),
};
mTarget.draw(line, 2, sf::Lines);
mTarget.draw(point, 1, sf::Points);
}
}
void DebugDraw::draw(const Raycast& raycast, sf::Color color)
{
if (raycast.hit)
{
sf::Vector2f normal = raycast.normal * 10.0f;
sf::Vertex point[] = {
sf::Vertex(raycast.contact, sf::Color::Red),
};
sf::Vertex line[] = {
sf::Vertex(raycast.contact, color),
sf::Vertex(raycast.contact + normal, color),
};
mTarget.draw(line, 2, sf::Lines);
mTarget.draw(point, 1, sf::Points);
}
}
void DebugDraw::draw(const Shape& shape, const sf::Vector2f position, sf::Color color)
{
if (shape.getType() == Type::Aabb)
{
draw(castShape<Aabb>(shape), position, color);
}
else if (shape.getType() == Type::Circle)
{
draw(castShape<Circle>(shape), position, color);
}
}