Revision 97dadfe5
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java | ||
---|---|---|
29 | 29 |
import android.util.AttributeSet; |
30 | 30 |
|
31 | 31 |
import org.distorted.library.EffectTypes; |
32 |
import org.distorted.library.type.Dynamic1D; |
|
33 | 32 |
import org.distorted.library.type.Dynamic2D; |
34 |
import org.distorted.library.type.Dynamic3D; |
|
35 | 33 |
import org.distorted.library.type.Dynamic4D; |
36 | 34 |
import org.distorted.library.type.Static1D; |
37 | 35 |
import org.distorted.library.type.Static2D; |
... | ... | |
43 | 41 |
public class MovingEffectsSurfaceView extends GLSurfaceView |
44 | 42 |
{ |
45 | 43 |
private static final int LOOP_TIME = 5000; |
46 |
private static final int NUM_INTERPOLATIONS= 100;
|
|
44 |
private static final int NUM_POINTS= 100;
|
|
47 | 45 |
|
48 | 46 |
public static final int EFFECT_POINTS=0; |
49 | 47 |
public static final int EFFECT_BUBBLE=1; |
... | ... | |
51 | 49 |
public static final int EFFECT_TRANS =3; |
52 | 50 |
public static final int EFFECT_CHROMA=4; |
53 | 51 |
public static final int EFFECT_SWIRL =5; |
54 |
|
|
55 |
private static MovingEffectsRenderer mRenderer; |
|
56 |
|
|
57 |
private static int xDown,yDown; |
|
58 |
private static int mScrW, mScrH; |
|
59 | 52 |
|
60 | 53 |
private static Dynamic2D di2D; |
61 | 54 |
private static Static4D dr; |
... | ... | |
63 | 56 |
|
64 | 57 |
private static Paint mPaint; |
65 | 58 |
private static int moving; |
66 |
private static Object lock = new Object(); |
|
59 |
private static final Object lock = new Object();
|
|
67 | 60 |
private static long mTime = 0; |
68 | 61 |
|
69 | 62 |
private static int mCurrEffect; |
70 |
|
|
63 |
private static int mSize1, mSize2, mSizeR; |
|
64 |
private static int mMax; |
|
65 |
|
|
71 | 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
72 | 67 |
|
73 | 68 |
public MovingEffectsSurfaceView(Context c, AttributeSet attrs) |
... | ... | |
81 | 76 |
|
82 | 77 |
di2D = new Dynamic2D(LOOP_TIME,0.0f); |
83 | 78 |
mRegion = new Dynamic4D(LOOP_TIME,0.0f); |
84 |
dr = new Static4D(0,0,60,60); |
|
85 | 79 |
|
86 | 80 |
if(!isInEditMode()) |
87 | 81 |
{ |
... | ... | |
95 | 89 |
setEGLConfigChooser(8, 8, 8, 8, 16, 0); |
96 | 90 |
} |
97 | 91 |
|
98 |
mRenderer = new MovingEffectsRenderer(this); |
|
92 |
MovingEffectsRenderer mRenderer = new MovingEffectsRenderer(this);
|
|
99 | 93 |
setRenderer(mRenderer); |
100 | 94 |
} |
101 | 95 |
} |
102 | 96 |
|
103 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
104 | 98 |
|
105 |
public static void setScreenSize(int width, int height)
|
|
99 |
public static void onSurfaceChanged(int width,int height)
|
|
106 | 100 |
{ |
107 |
mScrW = width; |
|
108 |
mScrH = height; |
|
101 |
mMax = width>height ? width:height; |
|
102 |
|
|
103 |
mSize1 = mMax/200; |
|
104 |
mSize2 = mMax/80; |
|
105 |
mSizeR = mMax/6; |
|
106 |
|
|
107 |
dr = new Static4D(0,0, mSizeR,mSizeR); |
|
109 | 108 |
} |
110 | 109 |
|
111 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
125 | 124 |
{ |
126 | 125 |
MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.VERTEX); |
127 | 126 |
MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.FRAGMENT); |
128 |
MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,30) , di2D, dr);
|
|
127 |
MovingEffectsRenderer.mBackground.distort( new Static3D(0,0,mMax/10) , di2D, dr);
|
|
129 | 128 |
mCurrEffect = EFFECT_BUBBLE; |
130 | 129 |
} |
131 | 130 |
} |
... | ... | |
211 | 210 |
synchronized(lock) |
212 | 211 |
{ |
213 | 212 |
int len = di2D.getNumPoints(); |
213 |
|
|
214 | 214 |
float[] drawCoord = new float[2]; |
215 | 215 |
Static2D cu; |
216 |
int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_INTERPOLATIONS/LOOP_TIME) : 0;
|
|
216 |
int lit = mTime> 0 ? (int)((float)(time-mTime)*NUM_POINTS/LOOP_TIME) : 0;
|
|
217 | 217 |
|
218 | 218 |
if( len>=2 ) |
219 | 219 |
{ |
220 |
for(int i=0; i<NUM_INTERPOLATIONS; i++) |
|
220 |
float step = (float)LOOP_TIME/(NUM_POINTS+1); |
|
221 |
|
|
222 |
for(int i=0; i<NUM_POINTS; i++) |
|
221 | 223 |
{ |
222 |
int color = i<=lit ? 0xff - (lit -i)*0xff/(NUM_INTERPOLATIONS-1)
|
|
223 |
: 0xff - (lit+NUM_INTERPOLATIONS-i)*0xff/(NUM_INTERPOLATIONS-1);
|
|
224 |
int color = i<=lit ? 0xff - (lit -i)*0xff/(NUM_POINTS-1)
|
|
225 |
: 0xff - (lit+NUM_POINTS-i)*0xff/(NUM_POINTS-1);
|
|
224 | 226 |
|
225 | 227 |
mPaint.setColor( 0xffffff + ((color&0xff)<<24) ); |
226 |
di2D.interpolate( drawCoord, 0, (float)i/NUM_INTERPOLATIONS);
|
|
227 |
c.drawCircle(drawCoord[0], drawCoord[1], 2.0f, mPaint );
|
|
228 |
di2D.interpolateMain( drawCoord, 0, (long)(i*step) );
|
|
229 |
c.drawCircle(drawCoord[0], drawCoord[1], mSize1, mPaint );
|
|
228 | 230 |
} |
229 | 231 |
} |
230 | 232 |
|
... | ... | |
233 | 235 |
for(int curr=0; curr<len; curr++) |
234 | 236 |
{ |
235 | 237 |
cu = di2D.getPoint(curr); |
236 |
c.drawCircle(cu.getX(), cu.getY(), 5.0f, mPaint);
|
|
238 |
c.drawCircle(cu.getX(), cu.getY(), mSize2, mPaint);
|
|
237 | 239 |
} |
238 | 240 |
|
239 | 241 |
if( time-mTime > LOOP_TIME ) mTime = time; |
... | ... | |
245 | 247 |
@Override public boolean onTouchEvent(MotionEvent event) |
246 | 248 |
{ |
247 | 249 |
if( mCurrEffect!=EFFECT_POINTS ) return true; |
248 |
|
|
250 |
|
|
251 |
int xDown, yDown; |
|
252 |
|
|
249 | 253 |
switch(event.getAction()) |
250 | 254 |
{ |
251 |
case MotionEvent.ACTION_DOWN: xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW;
|
|
252 |
yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH;
|
|
255 |
case MotionEvent.ACTION_DOWN: xDown = (int)event.getX();
|
|
256 |
yDown = (int)event.getY(); |
|
253 | 257 |
|
254 | 258 |
float gx, gy; |
255 | 259 |
Static2D dv; |
... | ... | |
261 | 265 |
gx = dv.getX(); |
262 | 266 |
gy = dv.getY(); |
263 | 267 |
|
264 |
if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (MovingEffectsRenderer.BHEI*MovingEffectsRenderer.BHEI)/100 )
|
|
268 |
if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < (mMax*mMax)/100 )
|
|
265 | 269 |
{ |
266 | 270 |
moving = g; |
267 | 271 |
break; |
... | ... | |
272 | 276 |
synchronized(lock) |
273 | 277 |
{ |
274 | 278 |
di2D.add(new Static2D(xDown,yDown)); |
275 |
mRegion.add(new Static4D(xDown,yDown,60,60));
|
|
279 |
mRegion.add(new Static4D(xDown,yDown,mSizeR,mSizeR));
|
|
276 | 280 |
} |
277 | 281 |
} |
278 | 282 |
break; |
279 | 283 |
case MotionEvent.ACTION_MOVE: if( moving>=0 ) |
280 | 284 |
{ |
281 |
xDown = (int)event.getX()*MovingEffectsRenderer.BWID/mScrW; |
|
282 |
yDown = (int)event.getY()*MovingEffectsRenderer.BHEI/mScrH; |
|
285 |
xDown = (int)event.getX(); |
|
286 |
yDown = (int)event.getY(); |
|
287 |
|
|
283 | 288 |
di2D.setPoint(moving, xDown, yDown); |
284 |
mRegion.setPoint(moving, xDown, yDown, 60, 60);
|
|
289 |
mRegion.setPoint(moving, xDown, yDown, mSizeR, mSizeR);
|
|
285 | 290 |
} |
286 | 291 |
break; |
287 | 292 |
case MotionEvent.ACTION_UP : moving = -1; |
Also available in: Unified diff
1. Attempt to deal with unstable Orthonormal Base in Dynamic class (so far unsuccessful)
2. Improvements to the 'Dynamic' (and by necessity, 'MovingEffects') applications (to be able to debug the previous)