-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwind.cpp
61 lines (44 loc) · 1.38 KB
/
wind.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
#include "wind.h"
#include "texture.h"
#include "texturecache.h"
#include "particlematerial.h"
#include "drawcontext.h"
#include "camera.h"
Wind::Wind(float radius)
{
radius_ = radius;
Texture* texture = TextureCache::getInstance()->acquire("wind", TextureType::Texture2D);
setParticleTexture(texture);
setEmissionRate(10);
setMaxParticleCount(20);
}
void Wind::spawnParticle(Particle *particle)
{
float speed = randf(10, 20);
vec3 velocity = {randf(0, 1), 0, randf(0, 1)};
velocity *= speed;
particle->velocity = velocity;
float phi = randf(0, M_PI * 2);
float r = radius_ * randf(0.3, 1.0);
float x = cosf(phi) * r;
float y = 0;
float z = sinf(phi) * r;
particle->position = {x, y, z};
particle->maxLife = 10;
particle->size = randf(10, 50);
float scale = randf(0.6f, 0.8f);
particle->color = {scale, scale * 0.9, scale * 0.85};
particle->opacity = randf(0.05, 0.1);
}
void Wind::updateParticle(Particle &particle, float dt)
{
particle.position += particle.velocity * dt;
particle.opacity = randf(0.11, 0.13);
}
void Wind::renderGeometry(DrawContext &context)
{
ParticleSystem::renderGeometry(context);
transform().setToIdentity();
vec3 camPos = context.camera->position();
transform().translate(camPos.x(), camPos.y(), camPos.z());
}