Revision 318dd77b
Added by Leszek Koltunski over 5 years ago
src/main/java/org/distorted/examples/wind/WindEffectsManager.java | ||
---|---|---|
35 | 35 |
|
36 | 36 |
class WindEffectsManager |
37 | 37 |
{ |
38 |
private static final long TIME_TO_GET_UP = 400; // time it takes for the max wind to |
|
39 |
// make the flag horizontal (milliseconds) |
|
40 |
private static final long TIME_TO_FALL_DOWN =2000; // time it takes for the flag to |
|
41 |
// fall back down if no wind (milliseconds) |
|
42 |
private long lastTime; |
|
43 |
private float mWind; |
|
38 | 44 |
private int mHeight, mWidth; |
39 | 45 |
|
40 | 46 |
private Static3D shearFactor; |
... | ... | |
46 | 52 |
private Dynamic5D windDynamic2; |
47 | 53 |
private Static5D windFactor31, windFactor32; |
48 | 54 |
private Dynamic5D windDynamic3; |
55 |
private Static5D windFactor41, windFactor42; |
|
56 |
private Dynamic5D windDynamic4; |
|
49 | 57 |
|
50 | 58 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 59 |
|
52 | 60 |
WindEffectsManager(DistortedTexture texture) |
53 | 61 |
{ |
62 |
lastTime = 0; |
|
63 |
|
|
54 | 64 |
mHeight = texture.getHeight(); |
55 | 65 |
mWidth = texture.getWidth(); |
56 | 66 |
|
... | ... | |
81 | 91 |
windDynamic3.add(windFactor32); |
82 | 92 |
windDynamic3.setMode(Dynamic.MODE_JUMP); |
83 | 93 |
windDynamic3.setAccessMode(Dynamic.ACCESS_SEQUENTIAL); |
94 |
|
|
95 |
windFactor41 = new Static5D(mHeight/10,mHeight/5,-180, 0, 0); |
|
96 |
windFactor42 = new Static5D(mHeight/10,mHeight/5,+180, 0, 0); |
|
97 |
windDynamic4 = new Dynamic5D(1000,0.0f); |
|
98 |
windDynamic4.add(windFactor41); |
|
99 |
windDynamic4.add(windFactor42); |
|
100 |
windDynamic4.setMode(Dynamic.MODE_JUMP); |
|
101 |
windDynamic4.setAccessMode(Dynamic.ACCESS_SEQUENTIAL); |
|
84 | 102 |
} |
85 | 103 |
|
86 | 104 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 | 105 |
|
88 |
void apply(DistortedEffects effects, int wind)
|
|
106 |
void apply(DistortedEffects effects) |
|
89 | 107 |
{ |
90 |
Static3D midLeft = new Static3D(0,mHeight/2,0); |
|
91 |
Static3D midRight = new Static3D(mWidth,mHeight/2,0); |
|
108 |
Static3D midLeft = new Static3D(0,mHeight/2,0); |
|
109 |
Static3D midRight = new Static3D(mWidth,mHeight/2,0); |
|
110 |
Static3D tadRight = new Static3D(3*mWidth/4,mHeight/2,0); |
|
92 | 111 |
Static4D windRegion = new Static4D(0,0,0,mHeight); |
93 | 112 |
|
94 |
setWind(wind);
|
|
113 |
setWind(0);
|
|
95 | 114 |
|
96 | 115 |
effects.apply( new MatrixEffectShear(shearFactor,midLeft) ); |
97 | 116 |
effects.apply( new MatrixEffectScale(scaleFactor) ); |
... | ... | |
99 | 118 |
effects.apply( new VertexEffectWave(windDynamic1, midRight, windRegion) ); |
100 | 119 |
effects.apply( new VertexEffectWave(windDynamic2, midRight, windRegion) ); |
101 | 120 |
effects.apply( new VertexEffectWave(windDynamic3, midRight, windRegion) ); |
121 |
effects.apply( new VertexEffectWave(windDynamic4, tadRight, windRegion) ); |
|
102 | 122 |
} |
103 | 123 |
|
104 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
105 | 125 |
|
106 |
synchronized void setWind(int wind)
|
|
126 |
private void setWind(int wind)
|
|
107 | 127 |
{ |
108 |
float tanAngle = (wind-50)/50.0f;
|
|
128 |
mWind = wind;
|
|
109 | 129 |
|
130 |
float tanAngle = (wind-50)/50.0f; |
|
110 | 131 |
shearFactor.set2(tanAngle); |
111 | 132 |
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle)); |
112 |
windDynamic1.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE); |
|
113 |
windDynamic2.setDuration( wind > 0 ? 80000/wind : Long.MAX_VALUE); |
|
114 |
windDynamic3.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE); |
|
115 | 133 |
|
116 |
float waveA = (mHeight/(20.0f-0.15f*wind)); |
|
117 |
windFactor21.set1(waveA); |
|
118 |
windFactor22.set1(waveA); |
|
134 |
windDynamic1.setDuration( wind > 0 ? 900 + 10000/wind : Long.MAX_VALUE); |
|
135 |
windDynamic2.setDuration( wind > 0 ? 720 + 8000/wind : Long.MAX_VALUE); |
|
136 |
windDynamic3.setDuration( wind > 0 ? 900 + 10000/wind : Long.MAX_VALUE); |
|
137 |
|
|
138 |
float wave2 = mHeight*( 0.05f + 0.002f*wind); |
|
139 |
windFactor21.set1(wave2); |
|
140 |
windFactor22.set1(wave2); |
|
141 |
|
|
142 |
float wave3 = (mHeight/(wind+5.0f)); |
|
143 |
windFactor31.set1(wave3); |
|
144 |
windFactor32.set1(wave3); |
|
145 |
|
|
146 |
float wave4 = (mHeight*(wind*(100-wind)/50000.0f)); |
|
147 |
windFactor41.set1(wave4); |
|
148 |
windFactor42.set1(wave4); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
|
|
153 |
synchronized void increaseWind(long currTime) |
|
154 |
{ |
|
155 |
if( lastTime>0 ) |
|
156 |
{ |
|
157 |
long diff = currTime-lastTime; |
|
158 |
float diffWind = (100.0f*diff/TIME_TO_GET_UP); |
|
159 |
|
|
160 |
mWind += diffWind; |
|
161 |
if( mWind>100.0f ) mWind=100.0f; |
|
162 |
|
|
163 |
setWind( (int)mWind ); |
|
164 |
} |
|
165 |
|
|
166 |
lastTime = currTime; |
|
167 |
} |
|
168 |
|
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
synchronized void decreaseWind(long currTime) |
|
172 |
{ |
|
173 |
if( lastTime>0 ) |
|
174 |
{ |
|
175 |
long diff = currTime-lastTime; |
|
176 |
float diffWind = (100.0f*diff/TIME_TO_FALL_DOWN); |
|
177 |
|
|
178 |
mWind -= diffWind; |
|
179 |
if( mWind<0.0f ) mWind=0.0f; |
|
119 | 180 |
|
120 |
float waveB = (mHeight/(wind+5.0f)); |
|
121 |
windFactor31.set1(waveB); |
|
122 |
windFactor32.set1(waveB); |
|
181 |
setWind( (int)mWind ); |
|
182 |
} |
|
183 |
|
|
184 |
lastTime = currTime; |
|
123 | 185 |
} |
186 |
|
|
187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 | 188 |
} |
Also available in: Unified diff
Some improvements to the Wind app - still does not look very realistic though :(