-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlightsource.cpp
More file actions
67 lines (50 loc) · 1.6 KB
/
Copy pathlightsource.cpp
File metadata and controls
67 lines (50 loc) · 1.6 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
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
#include "lightsource.h"
bool lightSource::onLoad()
{
// Load the shader
if (!m_shader.loadFromFile("storm.vert", "blink.frag") || !shader.loadFromFile("storm.vert","blink.frag"))
return false;
return true;
}
void lightSource::onUpdate()
{
float time;
float radius;
for(QMap<int,QPoint>::iterator it = pos.begin()
; it != pos.end();it++){
time= timers.value(it.key()).elapsed();
int freq = 20;
radius = 100 + std::cos((time)/1000.*freq-PI)*100;
if(radius >=180){
radius = 0;
}
if(time < 2*PI/freq*1000){
m_shader.setParameter("storm_position" + QString::number(it.key()).toStdString(), it.value().x(), it.value().y());
m_shader.setParameter("storm_inner_radius"+ QString::number(it.key()).toStdString(), radius*3);
m_shader.setParameter("storm_total_radius"+ QString::number(it.key()).toStdString(), radius/2);
}else{
if(currentLight > it.key())
currentLight = it.key();
timers.remove(it.key());
pos.remove(it.key());
nbrLight--;
}
}
}
void lightSource::launch(float x, float y){
if(m_isLoaded){
if(nbrLight < 10){
QTime tmpTime;
tmpTime.start();
timers.insert(currentLight,tmpTime);
pos.insert(currentLight,QPoint(x,y));
currentLight++;
nbrLight++;
}
}
}
void lightSource::onDraw(sf::RenderTarget& target, sf::RenderStates states) const
{
states.shader = &m_shader;
target.draw(vArray, states);
}