Revision 21819119
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/examples/wind/WindEffectsManager.java | ||
---|---|---|
22 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
23 | 23 |
|
24 | 24 |
import org.distorted.library.DistortedObject; |
25 |
import org.distorted.library.type.Dynamic3D; |
|
26 |
import org.distorted.library.type.Static3D; |
|
25 | 27 |
|
26 | 28 |
class WindEffectsManager |
27 | 29 |
{ |
30 |
private Static3D shearFactor; |
|
31 |
private Dynamic3D shearDynamic; |
|
32 |
private Static3D scaleFactor; |
|
33 |
private Dynamic3D scaleDynamic; |
|
28 | 34 |
|
29 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
30 | 36 |
|
31 |
void apply(DistortedObject obj, int wind)
|
|
37 |
WindEffectsManager()
|
|
32 | 38 |
{ |
39 |
shearFactor = new Static3D(0,0,0); |
|
40 |
shearDynamic= new Dynamic3D(); |
|
41 |
shearDynamic.add(shearFactor); |
|
33 | 42 |
|
43 |
scaleFactor = new Static3D(1,1,1); |
|
44 |
scaleDynamic= new Dynamic3D(); |
|
45 |
scaleDynamic.add(scaleFactor); |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
synchronized void apply(DistortedObject obj, int wind) |
|
51 |
{ |
|
52 |
Static3D center = new Static3D(0,obj.getHeight()/2,0); |
|
53 |
setWind(wind); |
|
54 |
|
|
55 |
obj.shear(shearDynamic,center); |
|
56 |
obj.scale(scaleDynamic); |
|
57 |
} |
|
58 |
|
|
59 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
60 |
|
|
61 |
synchronized void setWind(int wind) |
|
62 |
{ |
|
63 |
float tanAngle = (wind-50)/50.0f; |
|
64 |
|
|
65 |
shearFactor.set2(tanAngle); |
|
66 |
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle)); |
|
34 | 67 |
} |
35 | 68 |
} |
src/main/java/org/distorted/examples/wind/WindRenderer.java | ||
---|---|---|
46 | 46 |
private DistortedObject mObject; |
47 | 47 |
private WindEffectsManager mEffects; |
48 | 48 |
private int mObjWidth, mObjHeight; |
49 |
private int mWind; |
|
49 | 50 |
|
50 | 51 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
51 | 52 |
|
... | ... | |
64 | 65 |
|
65 | 66 |
void setWind(int wind) |
66 | 67 |
{ |
67 |
mEffects.apply(mObject,wind); |
|
68 |
mWind = wind; |
|
69 |
mEffects.setWind(mWind); |
|
68 | 70 |
} |
69 | 71 |
|
70 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
82 | 84 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
83 | 85 |
{ |
84 | 86 |
mObject.abortEffects(EffectTypes.MATRIX); |
87 |
mObject.abortEffects(EffectTypes.VERTEX); |
|
88 |
mObject.abortEffects(EffectTypes.FRAGMENT); |
|
89 |
|
|
85 | 90 |
float factor = 0.8f*(width<height? width:height)/mObjWidth; |
86 | 91 |
|
87 | 92 |
mObject.move( new Static3D( (width-factor*mObjWidth)/2 + width/8 , (height-factor*mObjHeight)/2 -height/4 , 0) ); |
... | ... | |
93 | 98 |
|
94 | 99 |
mObject.rotate(angle, axis, center); |
95 | 100 |
|
101 |
mEffects.apply(mObject, mWind); |
|
102 |
|
|
96 | 103 |
Distorted.onSurfaceChanged(width, height); |
97 | 104 |
} |
98 | 105 |
|
Also available in: Unified diff
Progress with Wind