@@ -17,7 +17,6 @@ ParticleSystem::~ParticleSystem()
17
17
delete mesh_;
18
18
}
19
19
20
- // To Ken: This function can be ignored.
21
20
void ParticleSystem::renderGeometry (DrawContext &context)
22
21
{
23
22
update (context.deltaTime );
@@ -26,9 +25,25 @@ void ParticleSystem::renderGeometry(DrawContext &context)
26
25
return ;
27
26
}
28
27
28
+ Particles particles = particles_;
29
+
30
+ if (renderingOrder_ == RenderingOrder::Reversed) {
31
+ std::reverse (begin (particles), end (particles));
32
+ }
33
+ else if (renderingOrder_ == RenderingOrder::OldestFirst) {
34
+ std::sort (begin (particles), end (particles), [](const Particle& left, const Particle& right) {
35
+ return left.life > right.life ;
36
+ });
37
+ }
38
+ else if (renderingOrder_ == RenderingOrder::YoungestFirst) {
39
+ std::sort (begin (particles), end (particles), [](const Particle& left, const Particle& right) {
40
+ return left.life < right.life ;
41
+ });
42
+ }
43
+
29
44
VertexBufferDesc desc;
30
- desc.bufferData = particles_ .data ();
31
- desc.bufferSize = particles_ .size () * sizeof (Particle);
45
+ desc.bufferData = particles .data ();
46
+ desc.bufferSize = particles .size () * sizeof (Particle);
32
47
desc.vertexElementSizes = {3 , 1 , 1 , 3 , 1 };
33
48
desc.stride = sizeof (Particle);
34
49
@@ -79,7 +94,7 @@ void ParticleSystem::update(float dt)
79
94
80
95
void ParticleSystem::spawnParticle (Particle *particle)
81
96
{
82
-
97
+
83
98
}
84
99
85
100
void ParticleSystem::updateParticle (Particle &particle, float dt)
@@ -107,5 +122,16 @@ void ParticleSystem::setMaxParticleCount(int maxParticleCount)
107
122
maxParticleCount_ = maxParticleCount;
108
123
}
109
124
125
+ RenderingOrder ParticleSystem::renderingOrder () const
126
+ {
127
+ return renderingOrder_;
128
+ }
129
+
130
+ void ParticleSystem::setRenderingOrder (RenderingOrder renderingOrder)
131
+ {
132
+ renderingOrder_ = renderingOrder;
133
+ }
134
+
135
+
110
136
111
137
0 commit comments