-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrain.cpp
64 lines (46 loc) · 1.49 KB
/
rain.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
#include "rain.h"
#include "texture.h"
#include "texturecache.h"
#include "particlematerial.h"
#include "drawcontext.h"
#include "camera.h"
Rain::Rain(float radius)
{
radius_ = radius;
Texture* texture = TextureCache::getInstance()->acquire("rain", TextureType::Texture2D);
setParticleTexture(texture);
setEmissionRate(4000);
setMaxParticleCount(20000);
ParticleMaterial* material = static_cast<ParticleMaterial *>(material_);
material->setLengthScale(12);
}
void Rain::spawnParticle(Particle *particle)
{
float speed = randf(60, 100);
vec3 velocity = {randf(0, 0.05), -1, randf(0, 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 = 2;
particle->size = 0.08;
float scale = randf(0.6f, 0.8f);
particle->color = {scale, scale * 0.9, scale * 0.80};
particle->opacity = randf(0.4, 0.7);
}
void Rain::updateParticle(Particle &particle, float dt)
{
particle.position += particle.velocity * dt;
particle.opacity = randf(0.4, 0.7);
}
void Rain::renderGeometry(DrawContext &context)
{
ParticleSystem::renderGeometry(context);
transform().setToIdentity();
vec3 camPos = context.camera->position();
transform().translate(camPos.x(), camPos.y() + 50, camPos.z());
}