0
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
| |
#include "stdafx.h"
#include "AirstreamFilter.h"
#define DAMPING 0.95
#define MASS 30.0
#define SPRING_CONSTANT 0.2
#define BLOWING_INTERVEL 30
AirstreamFilter::AirstreamFilter(){
dirX = nextDirX = 0;
dirY = nextDirY = 0;
srcY = nextSrcY = 0;
timer = 0;
damp = DAMPING;
mass = MASS;
k = SPRING_CONSTANT;
velx = 0.0;
vely = 0.0;
velsrcy = 0.0;
accel = 0;
force = 0;
wind_dir = 0; wind_speed = 0;
srand( time( NULL ) );
}
void AirstreamFilter::sync( float wind_dir, float wind_spped ){
this->wind_dir = wind_dir;
this->wind_speed = wind_spped;
}
void AirstreamFilter::update(){
if( timer++ > BLOWING_INTERVEL ){
nextDirX = ((float)rand()/RAND_MAX-0.5+wind_dir)*1024;
nextDirY = ((float)rand()/RAND_MAX-0.5)*768;
nextSrcY = (float)rand()/RAND_MAX*768;
timer = 0;
}
force = -k * ( dirX - nextDirX ); accel = force/mass; velx = damp * ( velx + accel );
dirX += velx;
force = -k * ( dirY - nextDirY ); accel = force/mass; vely = damp * ( vely + accel );
dirY += vely;
force = -k * ( srcY - nextSrcY ); accel = force/mass; velsrcy = damp * ( vely + accel );
srcY += velsrcy;
}
void AirstreamFilter::mappingTo( CellSet* cellset ){
int x, y, i, j;
float alpha = 0, beta = 0;
float windsrc_pow = 0.02*wind_speed; float windsrc_pow_b = windsrc_pow*0.8;
if( wind_dir >= 0 ){
for( y = 0; y < cellset->hdiv; y++ ){
i = y*cellset->wdiv;
alpha = (1-(float)abs(srcY-cellset->cells_a[i].ypos)/768)+0.3;
alpha = (alpha*alpha) * windsrc_pow;
beta = (1-(float)abs(srcY-cellset->cells_b[i].ypos)/768)+0.3;
beta = (beta*beta) * windsrc_pow_b;
cellset->cells_a[i].next( dirX*alpha, dirY*alpha );
cellset->cells_b[i].next( dirX*beta, dirY*beta );
}
for( y = 0; y < cellset->hdiv; y++ ){
for( x = cellset->wdiv-1; x >= 1; x-- ){
i = x+y*cellset->wdiv;
j = (x-1)+y*cellset->wdiv;
cellset->cells_a[i].next( cellset->cells_a[j].nextx, cellset->cells_a[j].nexty );
cellset->cells_b[i].next( cellset->cells_b[j].nextx, cellset->cells_b[j].nexty );
}
}
}
else{
for( y = 0; y < cellset->hdiv; y++ ){
i = (cellset->wdiv-1)+y*cellset->wdiv;
alpha = (1-(float)abs(srcY-cellset->cells_a[i].ypos)/768)+0.3;
alpha = (alpha*alpha) * windsrc_pow;
beta = (1-(float)abs(srcY-cellset->cells_b[i].ypos)/768)+0.3;
beta = (beta*beta) * windsrc_pow_b;
cellset->cells_a[i].next( dirX*alpha, dirY*alpha );
cellset->cells_b[i].next( dirX*beta, dirY*beta );
}
for( y = 0; y < cellset->hdiv; y++ ){
for( x = 0; x < cellset->wdiv-1; x++ ){
i = x+y*cellset->wdiv;
j = (x+1)+y*cellset->wdiv;
cellset->cells_a[i].next( cellset->cells_a[j].nextx, cellset->cells_a[j].nexty );
cellset->cells_b[i].next( cellset->cells_b[j].nextx, cellset->cells_b[j].nexty );
}
}
}
}
|