Revision b041d424
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/examples/bean/BeanRenderer.java | ||
---|---|---|
57 | 57 |
{ |
58 | 58 |
mView = v; |
59 | 59 |
|
60 |
pLeft = new Static2D(100, 199);
|
|
60 |
pLeft = new Static2D(106, 192);
|
|
61 | 61 |
pRight= new Static2D(230, 150); |
62 | 62 |
|
63 | 63 |
rLeft = new Static4D(-9,-31,35,35); |
64 | 64 |
rRight= new Static4D(-9,-31,35,35); |
65 | 65 |
|
66 |
dLeft = new Dynamic3D(1500,0.0f);
|
|
67 |
dRight= new Dynamic3D(1500,0.0f);
|
|
66 |
dLeft = new Dynamic3D(2000,0.0f);
|
|
67 |
dRight= new Dynamic3D(2000,0.0f);
|
|
68 | 68 |
|
69 | 69 |
Static3D p1 = new Static3D( 0, 0, 0); |
70 |
Static3D p2 = new Static3D(-10,-34, 0);
|
|
70 |
Static3D p2 = new Static3D(-10,-30, 0);
|
|
71 | 71 |
|
72 | 72 |
dLeft.add(p1); |
73 | 73 |
dLeft.add(p1); |
... | ... | |
143 | 143 |
bmpHeight = bitmap.getHeight(); |
144 | 144 |
bmpWidth = bitmap.getWidth(); |
145 | 145 |
|
146 |
mBean = new DistortedBitmap(bitmap, 9);
|
|
146 |
mBean = new DistortedBitmap(bitmap, 30);
|
|
147 | 147 |
mBean.distort(dLeft , pLeft , rLeft ); |
148 | 148 |
mBean.distort(dRight, pRight, rRight); |
149 | 149 |
|
src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java | ||
---|---|---|
57 | 57 |
private int moving; |
58 | 58 |
private int mDuration; |
59 | 59 |
private int mPosition; |
60 |
private long mDiffTime, mLastTime; |
|
60 | 61 |
private float mNoise0, mNoise1, mNoise2; |
61 | 62 |
|
62 | 63 |
private int mSize1, mSize2, mSizeT, mAvg; |
... | ... | |
89 | 90 |
mNoise0 = 0.0f; |
90 | 91 |
mNoise1 = 0.0f; |
91 | 92 |
mNoise2 = 0.0f; |
93 |
mDiffTime = -1; |
|
94 |
mLastTime = -1; |
|
92 | 95 |
|
93 | 96 |
di1D = new Dynamic1D(mDuration,0.0f); |
94 | 97 |
p1N = new Static1D(mNoise0); |
... | ... | |
193 | 196 |
public void drawCurve(Canvas c, long time) |
194 | 197 |
{ |
195 | 198 |
if ( ++mPosition >= NUM_POINTS ) mPosition=0; |
196 |
|
|
199 |
|
|
200 |
if( mLastTime<0 ) |
|
201 |
{ |
|
202 |
mLastTime = time; |
|
203 |
} |
|
204 |
else |
|
205 |
{ |
|
206 |
mDiffTime = time - mLastTime; |
|
207 |
} |
|
208 |
|
|
197 | 209 |
synchronized(lock) |
198 | 210 |
{ |
199 | 211 |
switch(currentDim) |
... | ... | |
203 | 215 |
default : drawCurve3D(c,time); break; |
204 | 216 |
} |
205 | 217 |
} |
218 |
|
|
219 |
mLastTime = time; |
|
206 | 220 |
} |
207 | 221 |
|
208 | 222 |
/////////////////////////////////////////////////////////////////// |
... | ... | |
227 | 241 |
|
228 | 242 |
if( len>=2 ) |
229 | 243 |
{ |
230 |
di1D.interpolateMain(mPoints,3*mPosition, time); |
|
244 |
di1D.interpolateMain(mPoints,3*mPosition, time, mDiffTime);
|
|
231 | 245 |
|
232 | 246 |
for(int i=0; i<NUM_POINTS; i++) |
233 | 247 |
{ |
... | ... | |
263 | 277 |
|
264 | 278 |
if( len>=2 ) |
265 | 279 |
{ |
266 |
di2D.interpolateMain(mPoints,3*mPosition, time); |
|
280 |
di2D.interpolateMain(mPoints,3*mPosition, time, mDiffTime);
|
|
267 | 281 |
|
268 | 282 |
for(int i=0; i<NUM_POINTS; i++) |
269 | 283 |
{ |
... | ... | |
299 | 313 |
|
300 | 314 |
if( len>=2 ) |
301 | 315 |
{ |
302 |
di3D.interpolateMain(mPoints, 3*mPosition, time); |
|
316 |
di3D.interpolateMain(mPoints, 3*mPosition, time, mDiffTime);
|
|
303 | 317 |
|
304 | 318 |
for(int i=0; i<NUM_POINTS; i++) |
305 | 319 |
{ |
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.Dynamic; |
|
25 | 26 |
import org.distorted.library.type.Dynamic3D; |
27 |
import org.distorted.library.type.Dynamic5D; |
|
26 | 28 |
import org.distorted.library.type.Static3D; |
29 |
import org.distorted.library.type.Static4D; |
|
30 |
import org.distorted.library.type.Static5D; |
|
27 | 31 |
|
28 | 32 |
class WindEffectsManager |
29 | 33 |
{ |
30 |
private Static3D shearFactor; |
|
34 |
private Static3D shearFactor;
|
|
31 | 35 |
private Dynamic3D shearDynamic; |
32 |
private Static3D scaleFactor; |
|
36 |
private Static3D scaleFactor;
|
|
33 | 37 |
private Dynamic3D scaleDynamic; |
38 |
private Static3D deformForce; |
|
39 |
private Static5D windFactor1, windFactor2; |
|
40 |
private Dynamic5D windDynamic; |
|
34 | 41 |
|
35 | 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
36 | 43 |
|
37 |
WindEffectsManager() |
|
44 |
WindEffectsManager(DistortedObject obj)
|
|
38 | 45 |
{ |
46 |
int h = obj.getHeight(); |
|
47 |
int w = obj.getWidth(); |
|
48 |
|
|
39 | 49 |
shearFactor = new Static3D(0,0,0); |
40 | 50 |
shearDynamic= new Dynamic3D(); |
41 | 51 |
shearDynamic.add(shearFactor); |
... | ... | |
43 | 53 |
scaleFactor = new Static3D(1,1,1); |
44 | 54 |
scaleDynamic= new Dynamic3D(); |
45 | 55 |
scaleDynamic.add(scaleFactor); |
56 |
|
|
57 |
deformForce = new Static3D(w/3,0,0); |
|
58 |
|
|
59 |
windFactor1 = new Static5D(h/10,h/5, 180, 0, 90); |
|
60 |
windFactor2 = new Static5D(h/10,h/5,-180, 0, 90); |
|
61 |
windDynamic = new Dynamic5D(1000,0.0f); |
|
62 |
windDynamic.add(windFactor1); |
|
63 |
windDynamic.add(windFactor2); |
|
64 |
windDynamic.setMode(Dynamic.MODE_JUMP); |
|
46 | 65 |
} |
47 | 66 |
|
48 | 67 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
49 | 68 |
|
50 | 69 |
synchronized void apply(DistortedObject obj, int wind) |
51 | 70 |
{ |
52 |
Static3D center = new Static3D(0,obj.getHeight()/2,0); |
|
71 |
int h = obj.getHeight(); |
|
72 |
int w = obj.getWidth(); |
|
73 |
|
|
74 |
Static3D midLeft = new Static3D(0,h/2,0); |
|
75 |
Static3D midRight = new Static3D(w,h/2,0); |
|
76 |
Static4D windRegion = new Static4D(0,0,w,h); |
|
77 |
|
|
53 | 78 |
setWind(wind); |
54 | 79 |
|
55 |
obj.shear(shearDynamic,center);
|
|
80 |
obj.shear(shearDynamic,midLeft);
|
|
56 | 81 |
obj.scale(scaleDynamic); |
82 |
obj.deform(deformForce,midRight); |
|
83 |
obj.wave(windDynamic, midRight, windRegion); |
|
57 | 84 |
} |
58 | 85 |
|
59 | 86 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
64 | 91 |
|
65 | 92 |
shearFactor.set2(tanAngle); |
66 | 93 |
scaleFactor.set1(1/(float)Math.sqrt(1+tanAngle*tanAngle)); |
94 |
windDynamic.setDuration( wind > 0 ? 100000/wind : Long.MAX_VALUE); |
|
67 | 95 |
} |
68 | 96 |
} |
src/main/java/org/distorted/examples/wind/WindRenderer.java | ||
---|---|---|
55 | 55 |
mView = view; |
56 | 56 |
|
57 | 57 |
mObject = new DistortedCubes(50,30,10,false); |
58 |
mEffects = new WindEffectsManager(); |
|
58 |
mEffects = new WindEffectsManager(mObject);
|
|
59 | 59 |
|
60 | 60 |
mObjWidth = mObject.getWidth(); |
61 | 61 |
mObjHeight= mObject.getHeight(); |
... | ... | |
83 | 83 |
|
84 | 84 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
85 | 85 |
{ |
86 |
mObject.abortEffects(EffectTypes.MATRIX); |
|
87 |
mObject.abortEffects(EffectTypes.VERTEX); |
|
88 |
mObject.abortEffects(EffectTypes.FRAGMENT); |
|
86 |
mObject.abortAllEffects(); |
|
89 | 87 |
|
90 |
float factor = 0.8f*(width<height? width:height)/mObjWidth;
|
|
88 |
float factor = ( (float)(width<height? width:height) )/(mObjHeight + 1.4f*mObjWidth);
|
|
91 | 89 |
|
92 |
mObject.move( new Static3D( (width-factor*mObjWidth)/2 + width/8 , (height-factor*mObjHeight)/2 -height/4 , 0) );
|
|
90 |
mObject.move( new Static3D( factor*mObjHeight*0.58f , factor*mObjHeight*0.08f , 0) );
|
|
93 | 91 |
mObject.scale(factor); |
94 | 92 |
|
95 | 93 |
Static1D angle = new Static1D(-45); |
Also available in: Unified diff
Minor details