@@ -30,6 +30,7 @@ void Tornado::init()
30
30
// Initialize an array of control points and widths...
31
31
m_controlPoints = new vec3[NUM_CONTROL_POINTS];
32
32
m_controlWidths = new float [NUM_CONTROL_POINTS];
33
+ m_initWidths = new float [NUM_CONTROL_POINTS];
33
34
float segmentSize = m_height/(NUM_CONTROL_POINTS - 1 );
34
35
for (int it = 0 ; it < NUM_CONTROL_POINTS; it++){
35
36
float th = it * segmentSize;
@@ -38,14 +39,16 @@ void Tornado::init()
38
39
m_controlPoints[it].setY (th);
39
40
// width should be a function of height.
40
41
// 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];
42
44
}
43
45
}
44
46
45
47
Tornado::~Tornado ()
46
48
{
47
49
delete[] m_controlPoints;
48
50
delete[] m_controlWidths;
51
+ delete[] m_initWidths;
49
52
}
50
53
51
54
// Interpolate the tornado's spine position at a given world-space height.
@@ -111,8 +114,9 @@ float Tornado::initWidth(float height)
111
114
return rv;
112
115
}
113
116
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
116
120
117
121
void Tornado::update (float dt)
118
122
{
@@ -127,13 +131,34 @@ void Tornado::update(float dt)
127
131
m_origin.setY (terrainHeight - TORNADO_SUB_GROUND);
128
132
// Add a little random shake to the control points...
129
133
for (int it = 0 ; it < NUM_CONTROL_POINTS; it++){
134
+ // Shake control point position...
130
135
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]));
138
163
}
139
164
}
0 commit comments