-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGround.cpp
More file actions
31 lines (26 loc) · 766 Bytes
/
Ground.cpp
File metadata and controls
31 lines (26 loc) · 766 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
#include "Ground.h"
Ground::Ground() : start(Tmpl8::vec2(0, 0)), end(Tmpl8::vec2(0, 0)), color(0x000000) {
length = 0;
angle = 0;
middle = Tmpl8::vec2(0, 0);
id = 0;
}
Ground::Ground(Tmpl8::vec2 _start, Tmpl8::vec2 _end, Tmpl8::Pixel _color, int _id) {
start = _start;
end = _end;
color = _color;
id = _id;
Ground::ComputeProperties();
}
/// <summary>
/// Calculate the length, angle and middle of the ground.
/// </summary>
void Ground::ComputeProperties() {
length = sqrt(pow(end.x - start.x, 2) + pow(end.y - start.y, 2));
angle = atan2(end.y - start.y, end.x - start.x);
middle.x = (start.x + end.x) / 2;
middle.y = (start.y + end.y) / 2;
}
void Ground::Draw(Tmpl8::Surface* screen) {
screen->LineFill(start.x, start.y, end.x, end.y, color);
}