-
Notifications
You must be signed in to change notification settings - Fork 0
/
shadows.h
89 lines (65 loc) · 3.62 KB
/
shadows.h
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
#include <SFML/Graphics.hpp>
#pragma once
class Opaque{
public:
Opaque(){
position = Vector2f(0, 0);
size = Vector2f(0, 0);
}
Opaque(sf::Vector2f position1, sf::Vector2f size1) :
position(position1),
size(size1){};
sf::Vector2f position;
sf::Vector2f size;
};
float getLenght(Vector2f a){
return sqrt(a.x*a.x + a.y*a.y);
}
Vector2f norm(Vector2f a){
return a / getLenght(a);
}
void setShadow(std::vector<Opaque> &houses, std::vector<sf::ConvexShape> &trapezes, sf::Vector2f player){
// Clock clock1;
// Time time1 = clock1.getElapsedTime();
// std::cout << std::endl << "Shadow started 0: " << time1.asSeconds();
int shadowLength = 100000;
trapezes.clear();
// time1 = clock1.getElapsedTime();
// std::cout << "1: " << time1.asSeconds() << std::endl;
for(auto &i : houses){
sf::ConvexShape trapeze0;
sf::ConvexShape trapeze1;
sf::ConvexShape trapeze2;
sf::ConvexShape trapeze3;
trapeze0.setPointCount(4);
trapeze1.setPointCount(4);
trapeze2.setPointCount(4);
trapeze3.setPointCount(4);
trapeze0.setPoint(0, sf::Vector2f(i.position.x, i.position.y));
trapeze0.setPoint(1, sf::Vector2f(i.position.x, i.position.y) + norm(sf::Vector2f(i.position.x, i.position.y) - player) * (float)shadowLength);
trapeze0.setPoint(2, sf::Vector2f(i.position.x + i.size.x, i.position.y) + norm(sf::Vector2f(i.position.x + i.size.x, i.position.y) - player) * (float)shadowLength);
trapeze0.setPoint(3, sf::Vector2f(i.position.x + i.size.x, i.position.y));
trapeze1.setPoint(0, sf::Vector2f(i.position.x + i.size.x, i.position.y));
trapeze1.setPoint(1, sf::Vector2f(i.position.x + i.size.x, i.position.y) + norm(sf::Vector2f(i.position.x + i.size.x, i.position.y) - player) * (float)shadowLength);
trapeze1.setPoint(2, sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y) + norm(sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y) - player) * (float)shadowLength);
trapeze1.setPoint(3, sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y));
trapeze1.setPoint(0, sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y));
trapeze1.setPoint(1, sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y) + norm(sf::Vector2f(i.position.x + i.size.x, i.position.y + i.size.y) - player) * (float)shadowLength);
trapeze1.setPoint(2, sf::Vector2f(i.position.x, i.position.y + i.size.y) + norm(sf::Vector2f(i.position.x, i.position.y + i.size.y) - player) * (float)shadowLength);
trapeze1.setPoint(3, sf::Vector2f(i.position.x, i.position.y + i.size.y));
trapeze3.setPoint(0, sf::Vector2f(i.position.x, i.position.y + i.size.y));
trapeze3.setPoint(1, sf::Vector2f(i.position.x, i.position.y + i.size.y) + norm(sf::Vector2f(i.position.x, i.position.y + i.size.y) - player) * (float)shadowLength);
trapeze3.setPoint(2, sf::Vector2f(i.position.x, i.position.y) + norm(sf::Vector2f(i.position.x, i.position.y) - player) * (float)shadowLength);
trapeze3.setPoint(3, sf::Vector2f(i.position.x, i.position.y));
trapeze0.setFillColor(sf::Color(0, 0, 0, 255));
trapeze1.setFillColor(sf::Color(0, 0, 0, 255));
trapeze2.setFillColor(sf::Color(0, 0, 0, 255));
trapeze3.setFillColor(sf::Color(0, 0, 0, 255));
trapezes.push_back(trapeze0);
trapezes.push_back(trapeze1);
trapezes.push_back(trapeze2);
trapezes.push_back(trapeze3);
}
// time1 = clock1.getElapsedTime();
// std::cout << "2: " << time1.asSeconds() << std::endl;
}