-
Notifications
You must be signed in to change notification settings - Fork 1
/
Common.cpp
38 lines (32 loc) · 1.3 KB
/
Common.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
#include "Common.hpp"
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>
#include <array>
std::array<sf::Vector2f, 6> swift::getTrianglesFromVector(sf::Vector2f vec) {
std::array<sf::Vector2f, 6> returnValue = std::array<sf::Vector2f, 6>();
/// Triangle 1
returnValue[0] = {0, 0}; /// Top Left
returnValue[1] = {vec.x, 0}; /// Top Right
returnValue[2] = {0, vec.y}; /// Bottom Left
/// Triangle 2
returnValue[3] = {vec.x, 0}; /// Top Right
returnValue[4] = vec; /// Bottom Right
returnValue[5] = {0, vec.y}; /// Bottom Left
return returnValue;
}
std::array<sf::Vector2f, 6> swift::getTrianglesFromRect(sf::FloatRect vec) {
std::array<sf::Vector2f, 6> returnValue = std::array<sf::Vector2f, 6>();
/// Triangle 1
returnValue[0] = {0, 0}; /// Top Left
returnValue[1] = {vec.width, 0}; /// Top Right
returnValue[2] = {0, vec.height}; /// Bottom Left
/// Triangle 2
returnValue[3] = {vec.width, 0}; /// Top Right
returnValue[4] = {vec.width, vec.height}; /// Bottom Right
returnValue[5] = {0, vec.height}; /// Bottom Left
for( int i = 0; i < 6; i++ ) {
returnValue[i].x += vec.left;
returnValue[i].y += vec.top;
}
return returnValue;
}