-
Notifications
You must be signed in to change notification settings - Fork 0
/
Particle.cpp
187 lines (160 loc) · 3.17 KB
/
Particle.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "Particle.h"
Particle::Particle()
{
}
Particle::Particle(sf::Vector2f pPosition, sf::Vector2f pVelocity, float pAngle, float pAngularVelocity, int pTTL, float pSize, sf::Color pColor, DrawType pDrawType) :
mPosition(pPosition),
mVelocity(pVelocity),
mAngle(pAngle),
mAngularVelocity(pAngularVelocity),
mTTL(pTTL),
maxTTL(pTTL),
mSize(pSize),
mColor(pColor),
mDrawType(pDrawType)
{
}
Particle::~Particle(void)
{
}
void Particle::Update()
{
mColor.a = (255/maxTTL) * mTTL;
mTTL--;
mPosition += mVelocity;
mAngle += mAngularVelocity;
}
void Particle::Draw(sf::RenderWindow* pWindow, float pInterpolation)
{
if (mDrawType == eRANDOM) mDrawType = newDrawType();
switch (mDrawType)
{
case(eRECTANGLE):
DrawRectangles(pWindow, pInterpolation);
break;
case(eCIRCLE):
DrawCircles(pWindow, pInterpolation);
break;
default:
DrawCircles(pWindow, pInterpolation, mDrawType);
break;
}
}
void Particle::DrawRectangles(sf::RenderWindow* pWindow, float pInterpolation)
{
mRectangle.setPosition(mPosition + (mVelocity * pInterpolation));
mRectangle.setSize(sf::Vector2f(mSize,mSize * 2));
mRectangle.setFillColor(mColor);
mRectangle.setRotation(mAngle);
pWindow->draw(mRectangle);
}
void Particle::DrawCircles(sf::RenderWindow* pWindow, float pInterpolation, DrawType pDrawType)
{
mCircle.setPosition(mPosition + (mVelocity * pInterpolation));
mCircle.setRadius(mSize);
mCircle.setPointCount(12);
switch (pDrawType)
{
case(eTRIANGLE):
mCircle.setPointCount(3);
break;
case(eSQUARE):
mCircle.setPointCount(4);
break;
case(ePENTAGON):
mCircle.setPointCount(5);
break;
case(eOCTAGON):
mCircle.setPointCount(8);
break;
case(eCIRCLE):
break;
default:
mCircle.setRadius(1);
}
mCircle.setFillColor(mColor);
mCircle.setRotation(mAngle);
pWindow->draw(mCircle);
}
void Particle::setPosition(sf::Vector2f pPosition)
{
mPosition = pPosition;
}
sf::Vector2f Particle::getPosition()
{
return mPosition;
}
void Particle::setVelocity(sf::Vector2f pVelocity)
{
mVelocity = pVelocity;
}
void Particle::changeVelocity(sf::Vector2f pVelocity)
{
mVelocity += pVelocity;
}
sf::Vector2f Particle::getVelocity()
{
return mVelocity;
}
void Particle::setAngle( float pAngle)
{
mAngle = pAngle;
}
float Particle::getAngle()
{
return mAngle;
}
void Particle::setAnglularVelocity(float pAngVel)
{
mAngularVelocity = pAngVel;
}
float Particle::getAngularVelocity()
{
return mAngularVelocity;
}
void Particle::setColor(sf::Color pColor)
{
mColor = pColor;
}
sf::Color Particle::getColor()
{
return mColor;
}
void Particle::setSize(float pSize)
{
mSize = pSize;
}
float Particle::getSize()
{
return mSize;
}
void Particle::setTTL(int pTTL)
{
mTTL = pTTL;
}
int Particle::getTTL()
{
return mTTL;
}
void Particle::setDrawType(DrawType pDrawType)
{
mDrawType = pDrawType;
}
DrawType Particle::getDrawType()
{
return mDrawType;
}
float RandomFloat(float pA, float pB) {
float random = ((float) rand()) / (float) RAND_MAX;
float diff = pB - pA;
float r = random * diff;
return pA + r;
}
int RandomInt (int pA, int pB)
{
return pA + (rand() % (int)(pB - pA + 1));
}
DrawType newDrawType()
{
return (DrawType)RandomInt(0,7);
}