-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollider.cpp
More file actions
26 lines (22 loc) · 1.23 KB
/
Copy pathcollider.cpp
File metadata and controls
26 lines (22 loc) · 1.23 KB
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
#include "collider.h"
void PlanCollider::render(QPainter *painter, const std::function<Vec2(const Vec2&)>& worldToView) {
Vec2 view_start = worldToView(this->position - 1000 * perpendicular(this->normal));
Vec2 view_end = worldToView(this->position + 1000 * perpendicular(this->normal));
//painter->drawLine(view_start[0], view_start[1], view_end[0], view_end[1]);
// Draw a polygon on the normal's opposite side, to represent the ground
// TO BE REFACTORED
Vec2 view_start_2 = worldToView(this->position - 1000 * perpendicular(this->normal) - 1000 * this->normal);
Vec2 view_end_2 = worldToView(this->position + 1000 * perpendicular(this->normal) - 1000 * this->normal);
QPointF points[4] = {
QPointF(view_start[0], view_start[1]),
QPointF(view_end[0], view_end[1]),
QPointF(view_end_2[0], view_end_2[1]),
QPointF(view_start_2[0], view_start_2[1])
};
painter->drawPolygon(points, 4);
}
void SphereCollider::render(QPainter *painter, const std::function<Vec2(const Vec2&)>& worldToView) {
Vec2 view_center = worldToView(this->center);
QRectF target(view_center[0]-this->radius,view_center[1]-this->radius, this->radius*2, this->radius*2);
painter->drawEllipse(target);
}