Skip to content

Commit cef9b5c

Browse files
author
Kenneth Lin
committed
More updates, more randomness, more TOOOOORNAAADDO!!!
1 parent 2aa07de commit cef9b5c

6 files changed

+50
-19
lines changed

src/DustcloudParticleSystem.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#include "DustcloudParticleSystem.h"
22

3-
#define NUM_PARTICLES_DUST 100
4-
#define DUST_CYCLE_SPEED -25.0
5-
#define DUST_ROT_SPEED -4.0
3+
#define NUM_PARTICLES_DUST 75
4+
#define DUST_CYCLE_SPEED -15.0
5+
#define DUST_ROT_SPEED -6.0
66

77
DustcloudParticleSystem::DustcloudParticleSystem(Tornado* tornado)
88
{

src/Tornado.cpp

+35-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ void Tornado::init()
3030
// Initialize an array of control points and widths...
3131
m_controlPoints = new vec3[NUM_CONTROL_POINTS];
3232
m_controlWidths = new float[NUM_CONTROL_POINTS];
33+
m_initWidths = new float[NUM_CONTROL_POINTS];
3334
float segmentSize = m_height/(NUM_CONTROL_POINTS - 1);
3435
for(int it = 0; it < NUM_CONTROL_POINTS; it++){
3536
float th = it * segmentSize;
@@ -38,14 +39,16 @@ void Tornado::init()
3839
m_controlPoints[it].setY(th);
3940
// width should be a function of height.
4041
// Should edit scale factor to match texture?
41-
m_controlWidths[it] = initWidth(th);
42+
m_initWidths[it] = initWidth(th);
43+
m_controlWidths[it] = m_initWidths[it];
4244
}
4345
}
4446

4547
Tornado::~Tornado()
4648
{
4749
delete[] m_controlPoints;
4850
delete[] m_controlWidths;
51+
delete[] m_initWidths;
4952
}
5053

5154
// Interpolate the tornado's spine position at a given world-space height.
@@ -111,8 +114,9 @@ float Tornado::initWidth(float height)
111114
return rv;
112115
}
113116

114-
#define TORNADO_RAND_SCALE 25.0
115-
#define TORNADO_MAX_TWIST 0.2
117+
#define TORNADO_RAND_SCALE 10.0
118+
#define TORNADO_MAX_TWIST 0.10
119+
#define TORNADO_MAX_DELTA 0.20
116120

117121
void Tornado::update(float dt)
118122
{
@@ -127,13 +131,34 @@ void Tornado::update(float dt)
127131
m_origin.setY(terrainHeight - TORNADO_SUB_GROUND);
128132
// Add a little random shake to the control points...
129133
for(int it = 0; it < NUM_CONTROL_POINTS; it++){
134+
// Shake control point position...
130135
vec3 rvec;
131-
double rx = TORNADO_RAND_SCALE/2.0 - (TORNADO_RAND_SCALE * dt * (double)rand() / RAND_MAX);
132-
double ry = TORNADO_RAND_SCALE/2.0 - (TORNADO_RAND_SCALE * dt * (double)rand() / RAND_MAX);
133-
rvec.setX(max(TORNADO_MAX_TWIST, min(-TORNADO_MAX_TWIST, rx)));
134-
rvec.setY(max(TORNADO_MAX_TWIST, min(-TORNADO_MAX_TWIST, ry)));
135-
rvec.setZ(0.0);
136-
//std::cout<<it<<": "<<rvec<<endl;
137-
//m_controlPoints[it] += rvec;
136+
double hprop = (double)it / (double)(NUM_CONTROL_POINTS - 1);
137+
double rx = dt * hprop * TORNADO_RAND_SCALE * randf(-1.0, 1.0);
138+
double ry = dt * hprop * TORNADO_RAND_SCALE * randf(-1.0, 1.0);
139+
rvec.setX(min(TORNADO_MAX_TWIST, max(-TORNADO_MAX_TWIST, rx)));
140+
rvec.setZ(min(TORNADO_MAX_TWIST, max(-TORNADO_MAX_TWIST, ry)));
141+
rvec.setY(0.0);
142+
// Shake control point widths...
143+
float rwf = dt * hprop * TORNADO_RAND_SCALE * 0.5;
144+
m_controlWidths[it] *= randf(1.0 - rwf, 1.0 + rwf);
145+
m_controlPoints[it] += rvec;
146+
}
147+
capControls();
148+
}
149+
150+
void Tornado::capControls()
151+
{
152+
for(int it = 0; it < NUM_CONTROL_POINTS; it++){
153+
double hprop = (double)it / (double)(NUM_CONTROL_POINTS - 1);
154+
double maxDelta = TORNADO_MAX_DELTA * hprop;
155+
double maxDT = maxDelta * 20.0;
156+
// Cap control point x and z...
157+
m_controlPoints[it].setX(min(maxDT, max(-maxDT, m_controlPoints[it].x())));
158+
m_controlPoints[it].setZ(min(maxDT, max(-maxDT, m_controlPoints[it].z())));
159+
// Cap control width...
160+
float minW = (1.0 - maxDelta) * m_initWidths[it];
161+
float maxW = (1.0 + maxDelta) * m_initWidths[it];
162+
m_controlWidths[it] = min(maxW, max(minW, m_controlWidths[it]));
138163
}
139164
}

src/Tornado.h

+3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@ class Tornado
3636
vec3 m_origin; // The point where the tornado hits the terrain height map.
3737
vec3* m_controlPoints; // An array of the control points needed for the tornado - these are offsets from origin!
3838
float* m_controlWidths; // The width of the tornado at each step!
39+
float* m_initWidths; // The original width of the tornado at each step!
3940
virtual void init(); // Part of both constructors.
4041
vec3 m_destination;
4142
float m_speed;
43+
private:
44+
void capControls(); // maintain outer bounds for comtrol points and control widths.
4245
};
4346

4447
#endif // TORNADO_H

src/TornadoParticleSystem.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void TornadoParticleSystem::updateParticle(Particle &particle, float dt)
8181
particle.position.setY(particle.position.y() - (m_cycleSpeed * dt * sterm));
8282
particle.position = getParticlePosition(&particle, particle.position.y());
8383
particle.size = getParticleSize(particle.position.y());
84-
particle.rotation = updateParticleRotation(particle.rotation, dt);
84+
particle.rotation = updateParticleRotation(&particle, dt);
8585
if(m_useOpacity){
8686
float oprop = sqrt(lprop);
8787
particle.opacity = (oprop * TORNADO_MAX_OPACITY) + (TORNADO_MIN_OPACITY * (1.0 - oprop));
@@ -104,8 +104,11 @@ float TornadoParticleSystem::getParticleSize(float yval)
104104
return m_tornado->interpWidth(yval);
105105
}
106106

107-
float TornadoParticleSystem::updateParticleRotation(float rot, float dt)
107+
float TornadoParticleSystem::updateParticleRotation(Particle* p, float dt)
108108
{
109-
return rot + (90.0 * dt);
109+
float rot = p->rotation;
110+
float hprop = (p->position.y() - m_tornado->getOrigin().y()) / m_tornado->getHeight();
111+
float rotFactor = (1.0 + hprop) * dt * randf(20.0, 25.0);
112+
return rot + rotFactor;
110113
}
111114

src/TornadoParticleSystem.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class TornadoParticleSystem : public ParticleSystem
2121
virtual void update(float dt);
2222
virtual vec3 getParticlePosition(Particle* p, float yval);
2323
virtual float getParticleSize(float yval);
24-
virtual float updateParticleRotation(float rot, float dt);
24+
virtual float updateParticleRotation(Particle* p, float dt);
2525
virtual void spawnParticle(Particle *particle);
2626
virtual void updateParticle(Particle& particle, float dt);
2727
};

src/scene.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ void Scene::initialize()
7474
Cloud* cloud = new Cloud(500);
7575
cloud->update(20);
7676
cloud->transform().translate(0, 80, 0);
77-
//sceneObjects_.push_back(cloud);
77+
sceneObjects_.push_back(cloud);
7878

7979
// Follower cloud
8080
follower_ = new Cloud(100);
@@ -86,7 +86,7 @@ void Scene::initialize()
8686
follower_->transform().translate(start.x(), start.y() + tornado_->getHeight(), start.z());
8787
follower_->setEmissionRate(4);
8888
follower_->setMaxParticleCount(40);
89-
//sceneObjects_.push_back(follower_);
89+
sceneObjects_.push_back(follower_);
9090
vec3 dest = {18, 0, 10};
9191
tornado_->setDestination(dest);
9292
TornadoParticleSystem* tPart = new TornadoParticleSystem(tornado_);

0 commit comments

Comments
 (0)