Revision 398fb2ee
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java | ||
---|---|---|
57 | 57 |
|
58 | 58 |
private static final Object lock = new Object(); |
59 | 59 |
|
60 |
private Dynamic3D di3D;
|
|
61 |
private Static4D dr;
|
|
62 |
private Dynamic4D mRegion; |
|
60 |
private Dynamic3D mCenterVertex;
|
|
61 |
private Static4D mRegionVertex;
|
|
62 |
private Dynamic4D mRegionFragment;
|
|
63 | 63 |
|
64 | 64 |
private Paint mPaint; |
65 | 65 |
private int moving; |
... | ... | |
67 | 67 |
|
68 | 68 |
private int mCurrEffect; |
69 | 69 |
private int mSize1, mSize2, mSizeR; |
70 |
private int mMax;
|
|
70 |
private Static3D mDistort;
|
|
71 | 71 |
|
72 | 72 |
private MovingEffectsRenderer mRenderer; |
73 | 73 |
|
... | ... | |
88 | 88 |
mPaint.setStyle(Style.FILL); |
89 | 89 |
moving = -1; |
90 | 90 |
|
91 |
di3D = new Dynamic3D(LOOP_TIME,0.0f); |
|
92 |
mRegion = new Dynamic4D(LOOP_TIME,0.0f); |
|
91 |
mCenterVertex = new Dynamic3D(LOOP_TIME,0.0f); |
|
92 |
mRegionFragment = new Dynamic4D(LOOP_TIME,0.0f); |
|
93 |
mRegionVertex = new Static4D(0,0,0,0); |
|
94 |
mDistort = new Static3D(0,0,0); |
|
93 | 95 |
|
94 | 96 |
mRenderer = new MovingEffectsRenderer(this); |
95 | 97 |
|
... | ... | |
100 | 102 |
setRenderer(mRenderer); |
101 | 103 |
} |
102 | 104 |
|
103 |
mEffectDistort = new VertexEffectDistort(new Static3D(0,0,mMax/10) , di3D, dr);
|
|
104 |
mEffectSink = new VertexEffectSink(new Static1D(10), di3D, dr);
|
|
105 |
mEffectSwirl = new VertexEffectSwirl( new Static1D(30), di3D, dr);
|
|
106 |
mEffectAlpha = new FragmentEffectAlpha(new Static1D(0.5f), mRegion, true); |
|
107 |
mEffectChroma = new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0), mRegion, true); |
|
105 |
mEffectDistort = new VertexEffectDistort( mDistort , mCenterVertex, mRegionVertex);
|
|
106 |
mEffectSink = new VertexEffectSink(new Static1D(10), mCenterVertex, mRegionVertex);
|
|
107 |
mEffectSwirl = new VertexEffectSwirl( new Static1D(30), mCenterVertex, mRegionVertex);
|
|
108 |
mEffectAlpha = new FragmentEffectAlpha(new Static1D(0.5f), mRegionFragment, true);
|
|
109 |
mEffectChroma = new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0), mRegionFragment, true);
|
|
108 | 110 |
} |
109 | 111 |
|
110 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 113 |
|
112 | 114 |
public void onSurfaceChanged(int width,int height) |
113 | 115 |
{ |
114 |
mMax = width>height ? width:height;
|
|
116 |
int max = width>height ? width:height;
|
|
115 | 117 |
|
116 |
mSize1 = mMax/200;
|
|
117 |
mSize2 = mMax/80;
|
|
118 |
mSizeR = mMax/6;
|
|
118 |
mSize1 = max/200; |
|
119 |
mSize2 = max/80; |
|
120 |
mSizeR = max/6; |
|
119 | 121 |
|
120 |
dr = new Static4D(0,0, mSizeR,mSizeR); |
|
122 |
mRegionVertex.set(0,0, mSizeR,mSizeR); |
|
123 |
mDistort.set3(max/10); |
|
121 | 124 |
} |
122 | 125 |
|
123 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
216 | 219 |
DistortedEffects q = mRenderer.getEffects(); |
217 | 220 |
q.abortByType(EffectType.VERTEX); |
218 | 221 |
q.abortByType(EffectType.FRAGMENT); |
219 |
di3D.removeAll();
|
|
220 |
mRegion.removeAll(); |
|
222 |
mCenterVertex.removeAll();
|
|
223 |
mRegionFragment.removeAll();
|
|
221 | 224 |
mCurrEffect = EFFECT_POINTS; |
222 | 225 |
mRenderer.setRefresh(); |
223 | 226 |
} |
... | ... | |
229 | 232 |
{ |
230 | 233 |
synchronized(lock) |
231 | 234 |
{ |
232 |
int len = di3D.getNumPoints();
|
|
235 |
int len = mCenterVertex.getNumPoints();
|
|
233 | 236 |
|
234 | 237 |
float[] drawCoord = new float[3]; |
235 | 238 |
Static3D cu; |
... | ... | |
241 | 244 |
for(int i=0; i<NUM_POINTS; i++) |
242 | 245 |
{ |
243 | 246 |
mPaint.setColor( 0xffffffff ); |
244 |
di3D.interpolateMain( drawCoord, 0, (long)(i*step) );
|
|
247 |
mCenterVertex.interpolateMain( drawCoord, 0, (long)(i*step) );
|
|
245 | 248 |
c.drawCircle(drawCoord[0], drawCoord[1], mSize1, mPaint ); |
246 | 249 |
} |
247 | 250 |
} |
... | ... | |
250 | 253 |
|
251 | 254 |
for(int curr=0; curr<len; curr++) |
252 | 255 |
{ |
253 |
cu = di3D.getPoint(curr);
|
|
256 |
cu = mCenterVertex.getPoint(curr);
|
|
254 | 257 |
c.drawCircle(cu.getX(), cu.getY(), mSize2, mPaint); |
255 | 258 |
} |
256 | 259 |
|
... | ... | |
273 | 276 |
|
274 | 277 |
float gx, gy; |
275 | 278 |
Static2D dv; |
276 |
int len = di3D.getNumPoints();
|
|
279 |
int len = mCenterVertex.getNumPoints();
|
|
277 | 280 |
|
278 | 281 |
for(int g=0; g<len; g++) |
279 | 282 |
{ |
280 |
dv = di3D.getPoint(g);
|
|
283 |
dv = mCenterVertex.getPoint(g);
|
|
281 | 284 |
gx = dv.getX(); |
282 | 285 |
gy = dv.getY(); |
283 |
|
|
284 |
if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (mMax*mMax)/100 ) |
|
286 |
|
|
287 |
float Z = mDistort.getZ()/10; |
|
288 |
|
|
289 |
if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < Z*Z ) |
|
285 | 290 |
{ |
286 | 291 |
moving = g; |
287 | 292 |
break; |
... | ... | |
291 | 296 |
{ |
292 | 297 |
synchronized(lock) |
293 | 298 |
{ |
294 |
di3D.add(new Static3D(xDown,yDown,0));
|
|
295 |
mRegion.add(new Static4D(xDown,yDown,mSizeR,mSizeR)); |
|
299 |
mCenterVertex.add(new Static3D(xDown,yDown,0));
|
|
300 |
mRegionFragment.add(new Static4D(xDown,yDown,mSizeR,mSizeR));
|
|
296 | 301 |
} |
297 | 302 |
} |
298 | 303 |
mRenderer.setRefresh(); |
... | ... | |
302 | 307 |
xDown = (int)event.getX(); |
303 | 308 |
yDown = (int)event.getY(); |
304 | 309 |
|
305 |
di3D.setPoint(moving, xDown, yDown, 0);
|
|
306 |
mRegion.setPoint(moving, xDown, yDown, mSizeR, mSizeR); |
|
310 |
mCenterVertex.setPoint(moving, xDown, yDown, 0);
|
|
311 |
mRegionFragment.setPoint(moving, xDown, yDown, mSizeR, mSizeR);
|
|
307 | 312 |
} |
308 | 313 |
mRenderer.setRefresh(); |
309 | 314 |
break; |
Also available in: Unified diff
Fix Moving Effects APP. Now 23 out of 31 APPs work.