-
Notifications
You must be signed in to change notification settings - Fork 0
/
WarpEffect.cpp
113 lines (89 loc) · 2.2 KB
/
WarpEffect.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "WarpEffect.h"
WarpEffect::WarpEffect(){
x = 0;
y = 0;
age = 0;
radius = 10;
active = false;
Clock = new sf::Clock();
Clock->Reset();
//lastTime = 0;
}
WarpEffect::WarpEffect(float intX, float intY){
x = intX;
y = intY;
age = 0;
radius = 10;
}
void WarpEffect::setAge(int mAge){
maxAge = mAge;
halfLife = maxAge/2;
}
void WarpEffect::setHalfLife(int mHalf){
halfLife = mHalf;
maxAge = halfLife * 2;
}
void WarpEffect::draw(float mX, float mY){
//dRadius = 1/x ?
//Radius = ln(abs(age)) + C
float X = x - mX + 400;
float Y = y - mY + 300;
//std::cout << "Age: " << age << std::endl;
if(!active){
return;
}
if(age>1500){
return;
}
float opacity;
radius = 5 * log(abs((age/5)-(halfLife/5))) + 4;
//opacity = 5/radius;
//if(opacity >= 1.0)
// opacity = 1;
opacity = -1/1500.0 * age + 1;
//std::cout << "op: " << opacity << std::endl;
//opacity = 1.0;
//std::cout << "Radius: " << radius << std::endl;
glColor4f(0.0, 0.1, 0.85, opacity);
glBegin(GL_LINE_LOOP);
for(float angle=0; angle<2*pi; angle+=.17){ //.17 ~= 10 degrees
glVertex2f(X + sin(angle) * radius, Y + cos(angle) * radius);
}
glEnd();
radius = 5 * log(abs(((age-100)/5)-(halfLife/5))) + 4;
glBegin(GL_LINE_LOOP);
for(float angle=0; angle<2*pi; angle+=.17){ //.17 ~= 10 degrees
glVertex2f(X + sin(angle) * (radius), Y + cos(angle) * (radius));
}
glEnd();
radius = 5 * log(abs(((age-300)/5)-(halfLife/5))) + 4;
glBegin(GL_LINE_LOOP);
for(float angle=0; angle<2*pi; angle+=.17){ //.17 ~= 10 degrees
glVertex2f(X + sin(angle) * (radius), Y + cos(angle) * (radius));
}
glEnd();
}
//void WarpEffect::incAge(Uint32 deltaTime){
void WarpEffect::incAge(){
//deltaTime = SDL_GetTicks() - lastTime;
//lastTime = SDL_GetTicks();
deltaTime = (Clock->GetElapsedTime() * 1000) - lastTime;
lastTime = Clock->GetElapsedTime() * 1000;
//std::cout << "deltaTime: " << deltaTime << std::endl;
age += deltaTime;
//std::cout << "age: " << age << std::endl;
}
void WarpEffect::initiate(float intX, float intY, int inHalfLife){
age = 0;
x = intX;
y = intY;
halfLife = inHalfLife;
maxAge = halfLife * 2;
active = true;
}
float WarpEffect::getX(){
return x;
}
float WarpEffect::getY(){
return y;
}