-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloud.cpp
68 lines (46 loc) · 1.46 KB
/
cloud.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
#include "cloud.h"
#include "texture.h"
#include "texturecache.h"
#include "particlematerial.h"
Cloud::Cloud(float radius)
{
radius_ = radius;
Texture* texture = TextureCache::getInstance()->acquire("cloud1", TextureType::Texture2D);
setParticleTexture(texture);
setEmissionRate(10);
setMaxParticleCount(1000);
setRenderingOrder(RenderingOrder::YoungestFirst);
ParticleMaterial* material = static_cast<ParticleMaterial *>(material_);
material->setHorizontal(true);
}
void Cloud::spawnParticle(Particle *particle)
{
float speed = randf(2, 10);
vec3 velocity = {0, 0, 1};
velocity *= speed;
particle->velocity = velocity;
float phi = randf(0, M_PI * 2);
float r = radius_ * randf();
float x = cosf(phi) * r;
float y = randf() * 10;
float z = sinf(phi) * r;
particle->position = {x, y, z};
particle->angularSpeed = randf(2, 15);
particle->maxLife = 20;
particle->size = randf(50, 150);
float scale = randf(0.55, 0.6f);
particle->color = {scale, scale, scale};
particle->opacity = 0;
}
void Cloud::updateParticle(Particle &particle, float dt)
{
particle.position += particle.velocity * dt;
particle.rotation += particle.angularSpeed * dt;
float x = particle.life / particle.maxLife;
if (x < 0.5) {
particle.opacity = x;
}
else {
particle.opacity = 1 - x;
}
}