-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
98 lines (86 loc) · 1.99 KB
/
main.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
91
92
93
94
95
96
97
98
#include <iostream>
#include <SFML/Graphics.hpp>
#include "segment.h"
#include "Wall.h"
#include "Ray.h"
#define WIDTH 900
#define HEIGHT 800
int main()
{
srand(time(0));
sf::ContextSettings settings;
settings.antialiasingLevel = 8;
sf::RenderWindow window(sf::VideoMode(WIDTH,HEIGHT), "2D-RayCasting", sf::Style::Titlebar | sf::Style::Close, settings);
Wall wallsInit(WIDTH,HEIGHT);
Ray lightRays;
bool isKeyRpressed = false;
bool isRightPressed = false;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
switch (event.type)
{
case sf::Event::Closed:
{
window.close();
}
break;
case sf::Event::Resized:
{
sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
window.setView(sf::View(visibleArea));
}
break;
case sf::Event::KeyPressed:
{
switch (event.key.code)
{
case sf::Keyboard::R:
{
if (isKeyRpressed)
isKeyRpressed = false;
else
isKeyRpressed = true;
}
default:
break;
}
}
case sf::Event::MouseButtonPressed:
{
switch (event.mouseButton.button) {
case sf::Mouse::Left:
{
}
break;
case sf::Mouse::Right:
{
if (isRightPressed)
isRightPressed = false;
else
isRightPressed = true;
}
break;
}
}
break;
}
}
window.clear();
wallsInit.drawWalls(window);
sf::Vector2f mousePos = sf::Vector2f(sf::Mouse::getPosition(window));
lightRays.initRays(Vector2f(mousePos.x, mousePos.y), wallsInit.getWallsVector());
lightRays.calculateHit(wallsInit.getWallsVector());
if (isKeyRpressed)
lightRays.drawRays(window);
if (isRightPressed)
{
lightRays.fillArea(window);
}
lightRays.clearRayVector();
window.display();
}
return 0;
}