Revision 56cbe1cf
Added by Leszek Koltunski over 8 years ago
src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java | ||
---|---|---|
268 | 268 |
mSeekID[2] = seek[2].getId(); |
269 | 269 |
mSeekID[3] = seek[3].getId(); |
270 | 270 |
break; |
271 |
default: android.util.Log.e("Fragment3DEffect", "dimension "+mDimension+" not supported!");
|
|
271 |
default: android.util.Log.e("Vertex3DEffect", "dimension "+mDimension+" not supported!");
|
|
272 | 272 |
return null; |
273 | 273 |
} |
274 | 274 |
|
src/main/java/org/distorted/examples/vertex3d/Vertex3DActivity.java | ||
---|---|---|
29 | 29 |
import android.widget.Button; |
30 | 30 |
import android.widget.LinearLayout; |
31 | 31 |
import android.widget.NumberPicker; |
32 |
import android.widget.SeekBar; |
|
33 |
import android.widget.SeekBar.OnSeekBarChangeListener; |
|
34 | 32 |
import android.widget.Spinner; |
35 | 33 |
import android.widget.TableRow; |
36 |
import android.widget.TextView; |
|
37 | 34 |
|
38 | 35 |
import org.distorted.examples.R; |
39 | 36 |
import org.distorted.library.Distorted; |
... | ... | |
41 | 38 |
import org.distorted.library.DistortedCubes; |
42 | 39 |
import org.distorted.library.DistortedObject; |
43 | 40 |
import org.distorted.library.EffectNames; |
41 |
import org.distorted.library.EffectTypes; |
|
42 |
import org.distorted.library.type.Dynamic1D; |
|
43 |
import org.distorted.library.type.Dynamic2D; |
|
44 |
import org.distorted.library.type.Dynamic3D; |
|
45 |
import org.distorted.library.type.Dynamic4D; |
|
46 |
|
|
47 |
import java.util.ArrayList; |
|
44 | 48 |
|
45 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
46 | 50 |
|
47 | 51 |
public class Vertex3DActivity extends Activity |
48 |
implements OnSeekBarChangeListener, |
|
49 |
View.OnClickListener, |
|
52 |
implements View.OnClickListener, |
|
50 | 53 |
AdapterView.OnItemSelectedListener |
51 | 54 |
{ |
52 | 55 |
private static final int COLOR_OFF = 0xffffe81f; |
... | ... | |
56 | 59 |
|
57 | 60 |
// fields needed for the first 'pick-a-shape' screen |
58 | 61 |
// |
59 |
private int mNumCols = 3;
|
|
60 |
private int mNumRows = 3;
|
|
62 |
private int mNumCols = 10;
|
|
63 |
private int mNumRows = 10;
|
|
61 | 64 |
private NumberPicker mColsPicker, mRowsPicker; |
62 |
private LinearLayout mLay; |
|
63 | 65 |
private boolean[] mShape; |
64 | 66 |
private DistortedObject mObject; |
65 | 67 |
private int mObjectType; |
66 | 68 |
private int mBitmap; |
67 | 69 |
|
68 |
// fields needed for the second 'apply vertex effects' screen |
|
69 |
// |
|
70 |
private SeekBar bar; |
|
71 |
private TextView textDeform, textDistort, textSink, textSwirl, textCenter; |
|
72 |
private int deformX, deformY, deformZ; |
|
73 |
private int distortX, distortY, distortZ; |
|
74 |
private int sinkA; |
|
75 |
private int swirlA; |
|
76 |
private int centerX, centerY; |
|
77 |
|
|
78 |
private float fdeformX, fdeformY, fdeformZ; |
|
79 |
private float fdistortX, fdistortY, fdistortZ; |
|
80 |
private float fsinkA; |
|
81 |
private float fswirlA; |
|
82 |
private float fcenterX, fcenterY; |
|
83 |
private EffectNames[] effects = new EffectNames[4]; |
|
84 |
|
|
70 |
private ArrayList<Vertex3DEffect> mEffects; |
|
71 |
private int mEffectAdd; |
|
85 | 72 |
|
86 | 73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
87 |
|
|
74 |
|
|
88 | 75 |
@Override |
89 | 76 |
protected void onCreate(Bundle savedState) |
90 | 77 |
{ |
91 | 78 |
super.onCreate(savedState); |
92 | 79 |
|
80 |
mEffects = new ArrayList<>(); |
|
81 |
|
|
93 | 82 |
setContentView(R.layout.objectpickerlayout); |
94 | 83 |
|
95 | 84 |
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols); |
96 | 85 |
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows); |
97 | 86 |
|
98 |
mColsPicker.setMaxValue(10);
|
|
87 |
mColsPicker.setMaxValue(15);
|
|
99 | 88 |
mColsPicker.setMinValue( 0); |
100 |
mRowsPicker.setMaxValue(10);
|
|
89 |
mRowsPicker.setMaxValue(15);
|
|
101 | 90 |
mRowsPicker.setMinValue( 0); |
102 | 91 |
|
103 | 92 |
mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() |
... | ... | |
145 | 134 |
|
146 | 135 |
private void setGrid() |
147 | 136 |
{ |
148 |
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
|
137 |
LinearLayout lay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
|
149 | 138 |
|
150 |
int width = mLay.getWidth();
|
|
151 |
int height= mLay.getHeight();
|
|
139 |
int width = lay.getWidth();
|
|
140 |
int height= lay.getHeight();
|
|
152 | 141 |
int w = mNumCols>0 ? (width / mNumCols) -10 : 0; |
153 | 142 |
int h = mNumRows>0 ? (height/ mNumRows) -10 : 0; |
154 | 143 |
int size= w<h ? w:h; |
155 | 144 |
int pad = size/20; |
156 | 145 |
|
157 |
mLay.removeAllViews();
|
|
146 |
lay.removeAllViews();
|
|
158 | 147 |
|
159 | 148 |
mShape = new boolean[mNumRows*mNumCols]; |
160 | 149 |
|
161 |
TableRow.LayoutParams p = new android.widget.TableRow.LayoutParams();
|
|
150 |
TableRow.LayoutParams p = new TableRow.LayoutParams(); |
|
162 | 151 |
|
163 | 152 |
p.rightMargin = pad; |
164 | 153 |
p.leftMargin = pad; |
... | ... | |
183 | 172 |
mShape[rows*mNumCols+cols] = true; |
184 | 173 |
} |
185 | 174 |
|
186 |
mLay.addView(tr);
|
|
175 |
lay.addView(tr);
|
|
187 | 176 |
} |
188 | 177 |
} |
189 | 178 |
|
... | ... | |
196 | 185 |
|
197 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
198 | 187 |
|
199 |
public void onClick(View view)
|
|
188 |
public int getBitmap()
|
|
200 | 189 |
{ |
201 |
Button tmp = (Button)view; |
|
202 |
int id = tmp.getId(); |
|
203 |
mShape[id] = !mShape[id]; |
|
204 |
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF); |
|
190 |
return mBitmap; |
|
205 | 191 |
} |
206 | 192 |
|
207 | 193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
208 | 194 |
|
209 |
public int getBitmap()
|
|
195 |
public void onClick(View view)
|
|
210 | 196 |
{ |
211 |
return mBitmap; |
|
197 |
Button tmp = (Button)view; |
|
198 |
int id = tmp.getId(); |
|
199 |
mShape[id] = !mShape[id]; |
|
200 |
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF); |
|
212 | 201 |
} |
213 | 202 |
|
214 | 203 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 204 |
|
216 | 205 |
public void Continue(View v) |
217 | 206 |
{ |
207 |
firstScreen = false; |
|
208 |
|
|
218 | 209 |
if( mObjectType==1 ) |
219 | 210 |
{ |
220 |
firstScreen = false; |
|
221 | 211 |
mObject = new DistortedBitmap(100,100,mNumCols); |
222 |
setContentView(R.layout.vertex3dlayout); |
|
223 |
Default(null); |
|
212 |
setVertexView(); |
|
224 | 213 |
} |
225 | 214 |
else |
226 | 215 |
{ |
... | ... | |
250 | 239 |
|
251 | 240 |
mObject = new DistortedCubes(mNumCols, str, 10); |
252 | 241 |
|
253 |
setContentView(R.layout.vertex3dlayout); |
|
254 |
Default(null); |
|
242 |
setVertexView(); |
|
255 | 243 |
} |
256 | 244 |
|
257 | 245 |
|
... | ... | |
261 | 249 |
{ |
262 | 250 |
switch(parent.getId()) |
263 | 251 |
{ |
264 |
case R.id.objectpicker_spinnerType : mObjectType = pos; break; |
|
252 |
case R.id.objectpicker_spinnerType : mObjectType = pos; |
|
253 |
break; |
|
265 | 254 |
case R.id.objectpicker_spinnerBitmap: switch(pos) |
266 | 255 |
{ |
267 | 256 |
case 0: mBitmap = R.raw.face; break; |
... | ... | |
270 | 259 |
case 3: mBitmap = R.raw.grid; break; |
271 | 260 |
} |
272 | 261 |
break; |
262 |
case R.id.vertex3dspinner : mEffectAdd = pos; |
|
263 |
break; |
|
273 | 264 |
} |
274 | 265 |
} |
275 | 266 |
|
... | ... | |
280 | 271 |
} |
281 | 272 |
|
282 | 273 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
283 |
// 'second screen' methods |
|
284 | 274 |
|
285 |
public void Default(View view)
|
|
275 |
public int getWidth()
|
|
286 | 276 |
{ |
287 |
effects[0] = EffectNames.DEFORM; |
|
288 |
effects[1] = EffectNames.DISTORT; |
|
289 |
effects[2] = EffectNames.SINK; |
|
290 |
effects[3] = EffectNames.SWIRL; |
|
291 |
|
|
292 |
deformX = 50; |
|
293 |
deformY = 50; |
|
294 |
deformZ = 50; |
|
295 |
|
|
296 |
distortX = 50; |
|
297 |
distortY = 50; |
|
298 |
distortZ = 50; |
|
299 |
|
|
300 |
sinkA = 50; |
|
301 |
swirlA = 50; |
|
302 |
|
|
303 |
centerX = 50; |
|
304 |
centerY = 50; |
|
305 |
|
|
306 |
textCenter = (TextView)findViewById(R.id.vertex3dcenterText); |
|
307 |
computeCenter(); |
|
308 |
setCenterText(); |
|
309 |
|
|
310 |
setBar(R.id.vertex3dcenterX, centerX); |
|
311 |
setBar(R.id.vertex3dcenterY, centerY); |
|
312 |
|
|
313 |
addViews(); |
|
314 |
} |
|
315 |
|
|
316 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
317 |
|
|
318 |
private void addViews() |
|
319 |
{ |
|
320 |
LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout); |
|
321 |
|
|
322 |
layout.removeAllViews(); |
|
323 |
|
|
324 |
View deform = getLayoutInflater().inflate(R.layout.vertex3ddeform , null); |
|
325 |
View distort= getLayoutInflater().inflate(R.layout.vertex3ddistort, null); |
|
326 |
View sink = getLayoutInflater().inflate(R.layout.vertex3dsink , null); |
|
327 |
View swirl = getLayoutInflater().inflate(R.layout.vertex3dswirl , null); |
|
328 |
|
|
329 |
for( int i=effects.length-1 ; i>=0 ; i-- ) |
|
330 |
{ |
|
331 |
switch(effects[i]) |
|
332 |
{ |
|
333 |
case DEFORM : layout.addView(deform , 0); break; |
|
334 |
case DISTORT: layout.addView(distort, 0); break; |
|
335 |
case SINK : layout.addView(sink , 0); break; |
|
336 |
case SWIRL : layout.addView(swirl , 0); break; |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
textDeform = (TextView)findViewById(R.id.vertex3ddeformText); |
|
341 |
textDistort= (TextView)findViewById(R.id.vertex3ddistortText); |
|
342 |
textSink = (TextView)findViewById(R.id.vertex3dsinkText); |
|
343 |
textSwirl = (TextView)findViewById(R.id.vertex3dswirlText); |
|
344 |
|
|
345 |
setDeformText(); |
|
346 |
setDistortText(); |
|
347 |
setSinkText(); |
|
348 |
setSwirlText(); |
|
349 |
|
|
350 |
setBar(R.id.vertex3ddeformBar1, deformX); |
|
351 |
setBar(R.id.vertex3ddeformBar2, deformY); |
|
352 |
setBar(R.id.vertex3ddeformBar3, deformZ); |
|
353 |
|
|
354 |
setBar(R.id.vertex3ddistortBar1, distortX); |
|
355 |
setBar(R.id.vertex3ddistortBar2, distortY); |
|
356 |
setBar(R.id.vertex3ddistortBar3, distortZ); |
|
357 |
|
|
358 |
setBar(R.id.vertex3dsinkBar1, sinkA); |
|
359 |
|
|
360 |
setBar(R.id.vertex3dswirlBar1, swirlA); |
|
361 |
|
|
362 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
363 |
view.getRenderer().setOrder(effects); |
|
364 |
} |
|
365 |
|
|
366 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
367 |
|
|
368 |
private void moveUp(EffectNames name) |
|
369 |
{ |
|
370 |
int len = effects.length-1; |
|
371 |
int index = -1; |
|
372 |
|
|
373 |
for(int i=0; i<=len; i++) |
|
374 |
{ |
|
375 |
if( effects[i]==name ) |
|
376 |
{ |
|
377 |
index=i; |
|
378 |
break; |
|
379 |
} |
|
380 |
} |
|
381 |
|
|
382 |
if( index==0 ) |
|
383 |
{ |
|
384 |
for(int i=0; i<len; i++) |
|
385 |
effects[i] = effects[i+1]; |
|
386 |
|
|
387 |
effects[len] = name; |
|
388 |
} |
|
389 |
else if( index>0 ) |
|
390 |
{ |
|
391 |
effects[index] = effects[index-1]; |
|
392 |
effects[index-1] = name; |
|
393 |
} |
|
394 |
|
|
395 |
addViews(); |
|
396 |
} |
|
397 |
|
|
398 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
399 |
|
|
400 |
public void ButtonDeform(View v) |
|
401 |
{ |
|
402 |
moveUp(EffectNames.DEFORM); |
|
277 |
return mObject==null ? 0: mObject.getWidth(); |
|
403 | 278 |
} |
404 | 279 |
|
405 | 280 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
406 | 281 |
|
407 |
public void ButtonDistort(View v)
|
|
282 |
public int getHeight()
|
|
408 | 283 |
{ |
409 |
moveUp(EffectNames.DISTORT);
|
|
284 |
return mObject==null ? 0: mObject.getHeight();
|
|
410 | 285 |
} |
411 | 286 |
|
412 | 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
288 |
// 'second screen' methods |
|
413 | 289 |
|
414 |
public void ButtonSink(View v) |
|
415 |
{ |
|
416 |
moveUp(EffectNames.SINK); |
|
417 |
} |
|
418 |
|
|
419 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
420 |
|
|
421 |
public void ButtonSwirl(View v) |
|
422 |
{ |
|
423 |
moveUp(EffectNames.SWIRL); |
|
424 |
} |
|
425 |
|
|
426 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
427 |
|
|
428 |
private void setBar(int id, int value) |
|
429 |
{ |
|
430 |
bar = (SeekBar)findViewById(id); |
|
431 |
bar.setOnSeekBarChangeListener(this); |
|
432 |
bar.setProgress(value); |
|
433 |
} |
|
434 |
|
|
435 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
436 |
|
|
437 |
private void computeDeform() |
|
438 |
{ |
|
439 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
440 |
Vertex3DRenderer renderer = view.getRenderer(); |
|
441 |
|
|
442 |
fdeformX = (deformX-50)*renderer.mScreenMin/200.0f; |
|
443 |
fdeformY = (deformY-50)*renderer.mScreenMin/200.0f; |
|
444 |
fdeformZ = (deformZ-50)*renderer.mScreenMin/200.0f; |
|
445 |
|
|
446 |
renderer.setDeform( fdeformX, fdeformY, fdeformZ ); |
|
447 |
} |
|
448 |
|
|
449 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
450 |
|
|
451 |
private void setDeformText() |
|
452 |
{ |
|
453 |
fdeformX = ((int)(100*fdeformX))/100.0f; |
|
454 |
fdeformY = ((int)(100*fdeformY))/100.0f; |
|
455 |
fdeformZ = ((int)(100*fdeformZ))/100.0f; |
|
456 |
|
|
457 |
textDeform.setText("deform("+fdeformX+" , "+fdeformY+" , "+fdeformZ+")"); |
|
458 |
} |
|
459 |
|
|
460 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
461 |
|
|
462 |
private void computeDistort() |
|
463 |
{ |
|
464 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
465 |
Vertex3DRenderer renderer = view.getRenderer(); |
|
466 |
|
|
467 |
fdistortX = (distortX-50)*renderer.mScreenMin/200.0f; |
|
468 |
fdistortY = (distortY-50)*renderer.mScreenMin/200.0f; |
|
469 |
fdistortZ = (distortZ-50)*renderer.mScreenMin/200.0f; |
|
470 |
|
|
471 |
renderer.setDistort(fdistortX, fdistortY, fdistortZ); |
|
472 |
} |
|
473 |
|
|
474 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
475 |
|
|
476 |
private void setDistortText() |
|
477 |
{ |
|
478 |
fdistortX = ((int)(100*fdistortX))/100.0f; |
|
479 |
fdistortY = ((int)(100*fdistortY))/100.0f; |
|
480 |
fdistortZ = ((int)(100*fdistortZ))/100.0f; |
|
481 |
|
|
482 |
textDistort.setText("distort("+fdistortX+" , "+fdistortY+" , "+fdistortZ+")"); |
|
483 |
} |
|
484 |
|
|
485 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
486 |
|
|
487 |
private void computeSink() |
|
488 |
{ |
|
489 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
490 |
|
|
491 |
fsinkA = (sinkA>= 50 ? 0.18f*sinkA-8.0f : 0.018f*sinkA + 0.1f); |
|
492 |
|
|
493 |
view.getRenderer().setSink( fsinkA ); |
|
494 |
} |
|
495 |
|
|
496 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
497 |
|
|
498 |
private void setSinkText() |
|
499 |
{ |
|
500 |
fsinkA = ((int)(100*fsinkA))/100.0f; |
|
501 |
|
|
502 |
textSink.setText("sink("+fsinkA+")"); |
|
503 |
} |
|
504 |
|
|
505 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
506 |
|
|
507 |
private void computeSwirl() |
|
508 |
{ |
|
509 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
510 |
|
|
511 |
fswirlA = (swirlA-50)*3.6f; |
|
512 |
|
|
513 |
view.getRenderer().setSwirl( fswirlA ); |
|
514 |
} |
|
515 |
|
|
516 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
517 |
|
|
518 |
private void setSwirlText() |
|
290 |
private void setVertexView() |
|
519 | 291 |
{ |
520 |
fswirlA = ((int)(100*fswirlA))/100.0f;
|
|
292 |
final View view = getLayoutInflater().inflate(R.layout.vertex3dlayout, null);
|
|
521 | 293 |
|
522 |
textSwirl.setText("swirl("+fswirlA+")"); |
|
523 |
} |
|
294 |
setContentView(view); |
|
524 | 295 |
|
525 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
296 |
String[] effects = new String[] { "DISTORT", |
|
297 |
"DEFORM", |
|
298 |
"SINK", |
|
299 |
"SWIRL" }; |
|
526 | 300 |
|
527 |
private void computeCenter() |
|
528 |
{ |
|
529 |
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView); |
|
301 |
Spinner effectSpinner = (Spinner)findViewById(R.id.vertex3dspinner ); |
|
302 |
effectSpinner.setOnItemSelectedListener(this); |
|
530 | 303 |
|
531 |
fcenterX = centerX; |
|
532 |
fcenterY = centerY; |
|
304 |
ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects); |
|
305 |
adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
306 |
effectSpinner.setAdapter(adapterEffect); |
|
533 | 307 |
|
534 |
view.getRenderer().setCenter( fcenterX, fcenterY );
|
|
308 |
mEffectAdd = 0;
|
|
535 | 309 |
} |
536 | 310 |
|
537 | 311 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
538 | 312 |
|
539 |
private void setCenterText()
|
|
313 |
public void newEffect(View v)
|
|
540 | 314 |
{ |
541 |
fcenterX = ((int)(100*fcenterX))/100.0f; |
|
542 |
fcenterY = ((int)(100*fcenterY))/100.0f; |
|
315 |
EffectNames name; |
|
543 | 316 |
|
544 |
textCenter.setText("center("+fcenterX+","+fcenterY+")"); |
|
545 |
} |
|
317 |
switch(mEffectAdd) |
|
318 |
{ |
|
319 |
case 0 : name = EffectNames.DISTORT; break; |
|
320 |
case 1 : name = EffectNames.DEFORM ; break; |
|
321 |
case 2 : name = EffectNames.SINK ; break; |
|
322 |
case 3 : name = EffectNames.SWIRL ; break; |
|
323 |
default: return; |
|
324 |
} |
|
546 | 325 |
|
547 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
326 |
Vertex3DEffect eff = new Vertex3DEffect(name, this); |
|
327 |
mEffects.add(eff); |
|
548 | 328 |
|
549 |
public float getCenterX() |
|
550 |
{ |
|
551 |
return fcenterX; |
|
329 |
LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout); |
|
330 |
View view = eff.createView(); |
|
331 |
layout.addView(view); |
|
332 |
View center = eff.createCenter(); |
|
333 |
layout.addView(center); |
|
334 |
View region = eff.createRegion(); |
|
335 |
layout.addView(region); |
|
336 |
|
|
337 |
Dynamic1D dyn1 = eff.getDyn1(); |
|
338 |
Dynamic2D cent = eff.getCenter(); |
|
339 |
Dynamic3D dyn3 = eff.getDyn3(); |
|
340 |
Dynamic4D regi = eff.getRegion(); |
|
341 |
|
|
342 |
switch(mEffectAdd) |
|
343 |
{ |
|
344 |
case 0: mObject.distort(dyn3, cent, regi); break; |
|
345 |
case 1: mObject.deform (dyn3, cent ); break; |
|
346 |
case 2: mObject.sink (dyn1, cent, regi); break; |
|
347 |
case 3: mObject.swirl (dyn1, cent, regi); break; |
|
348 |
} |
|
552 | 349 |
} |
553 | 350 |
|
554 | 351 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
555 | 352 |
|
556 |
public float getCenterY()
|
|
353 |
public void removeAll(View v)
|
|
557 | 354 |
{ |
558 |
return fcenterY; |
|
355 |
mEffects.clear(); |
|
356 |
LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout); |
|
357 |
layout.removeAllViews(); |
|
358 |
mObject.abortEffects(EffectTypes.VERTEX); |
|
559 | 359 |
} |
560 | 360 |
|
561 | 361 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
601 | 401 |
Distorted.onDestroy(); |
602 | 402 |
super.onDestroy(); |
603 | 403 |
} |
604 |
|
|
605 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
606 |
|
|
607 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
608 |
{ |
|
609 |
switch (bar.getId()) |
|
610 |
{ |
|
611 |
case R.id.vertex3dcenterX : centerX = progress; computeCenter() ; setCenterText() ; break; |
|
612 |
case R.id.vertex3dcenterY : centerY = progress; computeCenter() ; setCenterText() ; break; |
|
613 |
case R.id.vertex3ddeformBar1 : deformX = progress; computeDeform() ; setDeformText() ; break; |
|
614 |
case R.id.vertex3ddeformBar2 : deformY = progress; computeDeform() ; setDeformText() ; break; |
|
615 |
case R.id.vertex3ddeformBar3 : deformZ = progress; computeDeform() ; setDeformText() ; break; |
|
616 |
case R.id.vertex3ddistortBar1 : distortX= progress; computeDistort(); setDistortText() ; break; |
|
617 |
case R.id.vertex3ddistortBar2 : distortY= progress; computeDistort(); setDistortText() ; break; |
|
618 |
case R.id.vertex3ddistortBar3 : distortZ= progress; computeDistort(); setDistortText() ; break; |
|
619 |
case R.id.vertex3dsinkBar1 : sinkA = progress; computeSink() ; setSinkText() ; break; |
|
620 |
case R.id.vertex3dswirlBar1 : swirlA = progress; computeSwirl() ; setSwirlText() ; break; |
|
621 |
} |
|
622 |
} |
|
623 |
|
|
624 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
625 |
|
|
626 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
627 |
|
|
628 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
629 | 404 |
|
630 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
631 | 405 |
} |
src/main/java/org/distorted/examples/vertex3d/Vertex3DEffect.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
2 |
// Copyright 2016 Leszek Koltunski // |
|
3 |
// // |
|
4 |
// This file is part of Distorted. // |
|
5 |
// // |
|
6 |
// Distorted is free software: you can redistribute it and/or modify // |
|
7 |
// it under the terms of the GNU General Public License as published by // |
|
8 |
// the Free Software Foundation, either version 2 of the License, or // |
|
9 |
// (at your option) any later version. // |
|
10 |
// // |
|
11 |
// Distorted is distributed in the hope that it will be useful, // |
|
12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
|
13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
|
14 |
// GNU General Public License for more details. // |
|
15 |
// // |
|
16 |
// You should have received a copy of the GNU General Public License // |
|
17 |
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
19 |
|
|
20 |
package org.distorted.examples.vertex3d; |
|
21 |
|
|
22 |
import android.view.View; |
|
23 |
import android.widget.SeekBar; |
|
24 |
import android.widget.TextView; |
|
25 |
|
|
26 |
import org.distorted.examples.R; |
|
27 |
import org.distorted.library.EffectNames; |
|
28 |
import org.distorted.library.type.Dynamic1D; |
|
29 |
import org.distorted.library.type.Dynamic2D; |
|
30 |
import org.distorted.library.type.Dynamic3D; |
|
31 |
import org.distorted.library.type.Dynamic4D; |
|
32 |
import org.distorted.library.type.Static1D; |
|
33 |
import org.distorted.library.type.Static2D; |
|
34 |
import org.distorted.library.type.Static3D; |
|
35 |
import org.distorted.library.type.Static4D; |
|
36 |
|
|
37 |
import java.lang.ref.WeakReference; |
|
38 |
|
|
39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
40 |
|
|
41 |
public class Vertex3DEffect implements SeekBar.OnSeekBarChangeListener |
|
42 |
{ |
|
43 |
private WeakReference<Vertex3DActivity> mAct; |
|
44 |
|
|
45 |
private EffectNames mName; |
|
46 |
private int[] mInter; |
|
47 |
private int[] mInterRegion; |
|
48 |
private int[] mInterCenter; |
|
49 |
private int[] mSeekID; |
|
50 |
private int[] mSeekRegionID; |
|
51 |
private int[] mSeekCenterID; |
|
52 |
private int mDimension; |
|
53 |
private TextView mText,mTextRegion,mTextCenter; |
|
54 |
|
|
55 |
private Dynamic1D mDyn1; |
|
56 |
private Dynamic3D mDyn3; |
|
57 |
private Static1D mSta1; |
|
58 |
private Static3D mSta3; |
|
59 |
private Dynamic4D mRegionDyn; |
|
60 |
private Static4D mRegionSta; |
|
61 |
private Dynamic2D mCenterDyn; |
|
62 |
private Static2D mCenterSta; |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
private void fillCenterStatics() |
|
67 |
{ |
|
68 |
Vertex3DActivity act = mAct.get(); |
|
69 |
|
|
70 |
float x = (mInterCenter[0]*0.014f - 0.2f)*act.getWidth(); |
|
71 |
float y = (mInterCenter[1]*0.014f - 0.2f)*act.getHeight(); |
|
72 |
mCenterSta.set(x,y); |
|
73 |
} |
|
74 |
|
|
75 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
76 |
|
|
77 |
private void setDefaultCenterInter() |
|
78 |
{ |
|
79 |
mInterCenter[0] = 50; |
|
80 |
mInterCenter[1] = 50; |
|
81 |
} |
|
82 |
|
|
83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
84 |
|
|
85 |
private void setCenterText() |
|
86 |
{ |
|
87 |
int f0 = (int)mCenterSta.getX(); |
|
88 |
int f1 = (int)mCenterSta.getY(); |
|
89 |
|
|
90 |
mTextCenter.setText("center ("+f0+","+f1+")"); |
|
91 |
} |
|
92 |
|
|
93 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
94 |
|
|
95 |
private void fillRegionStatics() |
|
96 |
{ |
|
97 |
Vertex3DActivity act = mAct.get(); |
|
98 |
|
|
99 |
float factorX = act.getWidth() / 100.0f; |
|
100 |
float factorY = act.getHeight()/ 100.0f; |
|
101 |
|
|
102 |
float x = (mInterRegion[0]-50)*factorX; |
|
103 |
float y = (mInterRegion[1]-50)*factorY; |
|
104 |
float rx = mInterRegion[2] *factorX; |
|
105 |
float ry = mInterRegion[3] *factorY; |
|
106 |
|
|
107 |
mRegionSta.set(x,y,rx,ry); |
|
108 |
} |
|
109 |
|
|
110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
111 |
|
|
112 |
private void setDefaultRegionInter() |
|
113 |
{ |
|
114 |
mInterRegion[0] = 50; |
|
115 |
mInterRegion[1] = 50; |
|
116 |
mInterRegion[2] = 50; |
|
117 |
mInterRegion[3] = 50; |
|
118 |
} |
|
119 |
|
|
120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
121 |
|
|
122 |
private void setRegionText() |
|
123 |
{ |
|
124 |
int f0 = (int)mRegionSta.getX(); |
|
125 |
int f1 = (int)mRegionSta.getY(); |
|
126 |
int f2 = (int)mRegionSta.getZ(); |
|
127 |
int f3 = (int)mRegionSta.getW(); |
|
128 |
|
|
129 |
mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")"); |
|
130 |
} |
|
131 |
|
|
132 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
133 |
|
|
134 |
private void fillStatics() |
|
135 |
{ |
|
136 |
switch(mName) |
|
137 |
{ |
|
138 |
case DISTORT: |
|
139 |
case DEFORM : Vertex3DActivity act = mAct.get(); |
|
140 |
float l = act.getWidth()/50.0f; |
|
141 |
float x = (mInter[0]-50)*l; |
|
142 |
float y = (mInter[1]-50)*l; |
|
143 |
float z = (mInter[2]-50)*l; |
|
144 |
mSta3.set(x,y,z); |
|
145 |
break; |
|
146 |
case SINK : mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f); |
|
147 |
break; |
|
148 |
case SWIRL : mSta1.set( 3.6f*(mInter[0]-50) ); |
|
149 |
break; |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
private void setDefaultInter() |
|
156 |
{ |
|
157 |
switch(mName) |
|
158 |
{ |
|
159 |
case DISTORT: |
|
160 |
case DEFORM : mInter[0] = 50; |
|
161 |
mInter[1] = 50; |
|
162 |
mInter[2] = 50; |
|
163 |
break; |
|
164 |
case SINK : |
|
165 |
case SWIRL : mInter[0] = 50; |
|
166 |
break; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 |
|
|
172 |
private void setText() |
|
173 |
{ |
|
174 |
String text = mName.name(); |
|
175 |
|
|
176 |
if( mName==EffectNames.DISTORT || mName==EffectNames.DEFORM) |
|
177 |
{ |
|
178 |
int f1 = (int)mSta3.getX(); |
|
179 |
int f2 = (int)mSta3.getY(); |
|
180 |
int f3 = (int)mSta3.getZ(); |
|
181 |
text += " ("+f1+","+f2+","+f3+")"; |
|
182 |
} |
|
183 |
else |
|
184 |
{ |
|
185 |
float f1 = ((int)(mSta1.getX()*100))/100.0f; |
|
186 |
text += " ("+f1+")"; |
|
187 |
} |
|
188 |
|
|
189 |
mText.setText(text); |
|
190 |
} |
|
191 |
|
|
192 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
193 |
|
|
194 |
public Vertex3DEffect(EffectNames name, Vertex3DActivity act) |
|
195 |
{ |
|
196 |
mAct = new WeakReference<>(act); |
|
197 |
mName = name; |
|
198 |
|
|
199 |
if( mName==EffectNames.SINK || mName==EffectNames.SWIRL ) |
|
200 |
{ |
|
201 |
mDimension = 1; |
|
202 |
mDyn1 = new Dynamic1D(); |
|
203 |
mSta1 = new Static1D(0); |
|
204 |
mDyn1.add(mSta1); |
|
205 |
mDyn3 = null; |
|
206 |
} |
|
207 |
else |
|
208 |
{ |
|
209 |
mDimension = 3; |
|
210 |
mDyn3 = new Dynamic3D(); |
|
211 |
mSta3 = new Static3D(0,0,0); |
|
212 |
mDyn3.add(mSta3); |
|
213 |
mDyn1 = null; |
|
214 |
} |
|
215 |
|
|
216 |
mInter = new int[mDimension]; |
|
217 |
mSeekID= new int[mDimension]; |
|
218 |
|
|
219 |
mInterRegion = new int[4]; |
|
220 |
mSeekRegionID= new int[4]; |
|
221 |
mRegionDyn = new Dynamic4D(); |
|
222 |
mRegionSta = new Static4D(0,0,0,0); |
|
223 |
mRegionDyn.add(mRegionSta); |
|
224 |
|
|
225 |
mInterCenter = new int[2]; |
|
226 |
mSeekCenterID= new int[2]; |
|
227 |
mCenterDyn = new Dynamic2D(); |
|
228 |
mCenterSta = new Static2D(0,0); |
|
229 |
mCenterDyn.add(mCenterSta); |
|
230 |
} |
|
231 |
|
|
232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
233 |
|
|
234 |
public Dynamic1D getDyn1() |
|
235 |
{ |
|
236 |
return mDyn1; |
|
237 |
} |
|
238 |
|
|
239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
240 |
|
|
241 |
public Dynamic3D getDyn3() |
|
242 |
{ |
|
243 |
return mDyn3; |
|
244 |
} |
|
245 |
|
|
246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 |
|
|
248 |
public Dynamic4D getRegion() |
|
249 |
{ |
|
250 |
return mRegionDyn; |
|
251 |
} |
|
252 |
|
|
253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
254 |
|
|
255 |
public Dynamic2D getCenter() |
|
256 |
{ |
|
257 |
return mCenterDyn; |
|
258 |
} |
|
259 |
|
|
260 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
261 |
|
|
262 |
public View createView() |
|
263 |
{ |
|
264 |
View effect; |
|
265 |
SeekBar[] seek = new SeekBar[mDimension]; |
|
266 |
|
|
267 |
Vertex3DActivity act = mAct.get(); |
|
268 |
|
|
269 |
switch(mDimension) |
|
270 |
{ |
|
271 |
case 1 : effect = act.getLayoutInflater().inflate(R.layout.effect1d, null); |
|
272 |
mText = (TextView)effect.findViewById(R.id.effect1dText); |
|
273 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect1dbar1); |
|
274 |
mSeekID[0] = seek[0].getId(); |
|
275 |
break; |
|
276 |
case 2 : effect = act.getLayoutInflater().inflate(R.layout.effect2d, null); |
|
277 |
mText = (TextView)effect.findViewById(R.id.effect2dText); |
|
278 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect2dbar1); |
|
279 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect2dbar2); |
|
280 |
mSeekID[0] = seek[0].getId(); |
|
281 |
mSeekID[1] = seek[1].getId(); |
|
282 |
break; |
|
283 |
case 3 : effect = act.getLayoutInflater().inflate(R.layout.effect3d, null); |
|
284 |
mText = (TextView)effect.findViewById(R.id.effect3dText); |
|
285 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect3dbar1); |
|
286 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect3dbar2); |
|
287 |
seek[2] = (SeekBar)effect.findViewById(R.id.effect3dbar3); |
|
288 |
mSeekID[0] = seek[0].getId(); |
|
289 |
mSeekID[1] = seek[1].getId(); |
|
290 |
mSeekID[2] = seek[2].getId(); |
|
291 |
break; |
|
292 |
case 4 : effect = act.getLayoutInflater().inflate(R.layout.effect4d, null); |
|
293 |
mText = (TextView)effect.findViewById(R.id.effect4dText); |
|
294 |
seek[0] = (SeekBar)effect.findViewById(R.id.effect4dbar1); |
|
295 |
seek[1] = (SeekBar)effect.findViewById(R.id.effect4dbar2); |
|
296 |
seek[2] = (SeekBar)effect.findViewById(R.id.effect4dbar3); |
|
297 |
seek[3] = (SeekBar)effect.findViewById(R.id.effect4dbar4); |
|
298 |
mSeekID[0] = seek[0].getId(); |
|
299 |
mSeekID[1] = seek[1].getId(); |
|
300 |
mSeekID[2] = seek[2].getId(); |
|
301 |
mSeekID[3] = seek[3].getId(); |
|
302 |
break; |
|
303 |
default: android.util.Log.e("Vertex3DEffect", "dimension "+mDimension+" not supported!"); |
|
304 |
return null; |
|
305 |
} |
|
306 |
|
|
307 |
setDefaultInter(); |
|
308 |
fillStatics(); |
|
309 |
setText(); |
|
310 |
|
|
311 |
for(int i=0; i<mDimension; i++) |
|
312 |
{ |
|
313 |
seek[i].setOnSeekBarChangeListener(this); |
|
314 |
seek[i].setProgress( mInter[i] ); |
|
315 |
} |
|
316 |
|
|
317 |
return effect; |
|
318 |
} |
|
319 |
|
|
320 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
321 |
|
|
322 |
public View createRegion() |
|
323 |
{ |
|
324 |
Vertex3DActivity act = mAct.get(); |
|
325 |
|
|
326 |
View region = act.getLayoutInflater().inflate(R.layout.effectregion, null); |
|
327 |
|
|
328 |
SeekBar[] seek = new SeekBar[4]; |
|
329 |
|
|
330 |
seek[0] = (SeekBar)region.findViewById(R.id.effectRegionBarX ); |
|
331 |
seek[1] = (SeekBar)region.findViewById(R.id.effectRegionBarY ); |
|
332 |
seek[2] = (SeekBar)region.findViewById(R.id.effectRegionBarRX); |
|
333 |
seek[3] = (SeekBar)region.findViewById(R.id.effectRegionBarRY); |
|
334 |
|
|
335 |
mSeekRegionID[0] = seek[0].getId(); |
|
336 |
mSeekRegionID[1] = seek[1].getId(); |
|
337 |
mSeekRegionID[2] = seek[2].getId(); |
|
338 |
mSeekRegionID[3] = seek[3].getId(); |
|
339 |
|
|
340 |
mTextRegion = (TextView)region.findViewById(R.id.effectRegionText); |
|
341 |
|
|
342 |
setDefaultRegionInter(); |
|
343 |
fillRegionStatics(); |
|
344 |
setRegionText(); |
|
345 |
|
|
346 |
for(int i=0; i<4; i++) |
|
347 |
{ |
|
348 |
seek[i].setOnSeekBarChangeListener(this); |
|
349 |
seek[i].setProgress( mInterRegion[i] ); |
|
350 |
} |
|
351 |
|
|
352 |
return region; |
|
353 |
} |
|
354 |
|
|
355 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
356 |
|
|
357 |
public View createCenter() |
|
358 |
{ |
|
359 |
Vertex3DActivity act = mAct.get(); |
|
360 |
|
|
361 |
View center = act.getLayoutInflater().inflate(R.layout.effectcenter, null); |
|
362 |
|
|
363 |
SeekBar[] seek = new SeekBar[2]; |
|
364 |
|
|
365 |
seek[0] = (SeekBar)center.findViewById(R.id.effectCenterBarX ); |
|
366 |
seek[1] = (SeekBar)center.findViewById(R.id.effectCenterBarY ); |
|
367 |
|
|
368 |
mSeekCenterID[0] = seek[0].getId(); |
|
369 |
mSeekCenterID[1] = seek[1].getId(); |
|
370 |
|
|
371 |
mTextCenter = (TextView)center.findViewById(R.id.effectCenterText); |
|
372 |
|
|
373 |
setDefaultCenterInter(); |
|
374 |
fillCenterStatics(); |
|
375 |
setCenterText(); |
|
376 |
|
|
377 |
for(int i=0; i<2; i++) |
|
378 |
{ |
|
379 |
seek[i].setOnSeekBarChangeListener(this); |
|
380 |
seek[i].setProgress( mInterCenter[i] ); |
|
381 |
} |
|
382 |
|
|
383 |
return center; |
|
384 |
} |
|
385 |
|
|
386 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
387 |
|
|
388 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
389 |
{ |
|
390 |
if ( mDimension>=1 && bar.getId()==mSeekID[0] ) |
|
391 |
{ |
|
392 |
mInter[0] = progress; |
|
393 |
fillStatics(); |
|
394 |
setText(); |
|
395 |
} |
|
396 |
if ( mDimension>=2 && bar.getId()==mSeekID[1] ) |
|
397 |
{ |
|
398 |
mInter[1] = progress; |
|
399 |
fillStatics(); |
|
400 |
setText(); |
|
401 |
} |
|
402 |
if ( mDimension>=3 && bar.getId()==mSeekID[2] ) |
|
403 |
{ |
|
404 |
mInter[2] = progress; |
|
405 |
fillStatics(); |
|
406 |
setText(); |
|
407 |
} |
|
408 |
if ( mDimension>=4 && bar.getId()==mSeekID[3] ) |
|
409 |
{ |
|
410 |
mInter[3] = progress; |
|
411 |
fillStatics(); |
|
412 |
setText(); |
|
413 |
} |
|
414 |
|
|
415 |
if( bar.getId() == mSeekRegionID[0] ) |
|
416 |
{ |
|
417 |
mInterRegion[0] = progress; |
|
418 |
fillRegionStatics(); |
|
419 |
setRegionText(); |
|
420 |
} |
|
421 |
if( bar.getId() == mSeekRegionID[1] ) |
|
422 |
{ |
|
423 |
mInterRegion[1] = progress; |
|
424 |
fillRegionStatics(); |
|
425 |
setRegionText(); |
|
426 |
} |
|
427 |
if( bar.getId() == mSeekRegionID[2] ) |
|
428 |
{ |
|
429 |
mInterRegion[2] = progress; |
|
430 |
fillRegionStatics(); |
|
431 |
setRegionText(); |
|
432 |
} |
|
433 |
if( bar.getId() == mSeekRegionID[3] ) |
|
434 |
{ |
|
435 |
mInterRegion[3] = progress; |
|
436 |
fillRegionStatics(); |
|
437 |
setRegionText(); |
|
438 |
} |
|
439 |
|
|
440 |
if( bar.getId() == mSeekCenterID[0] ) |
|
441 |
{ |
|
442 |
mInterCenter[0] = progress; |
|
443 |
fillCenterStatics(); |
|
444 |
setCenterText(); |
|
445 |
} |
|
446 |
if( bar.getId() == mSeekCenterID[1] ) |
|
447 |
{ |
|
448 |
mInterCenter[1] = progress; |
|
449 |
fillCenterStatics(); |
|
450 |
setCenterText(); |
|
451 |
} |
|
452 |
} |
|
453 |
|
|
454 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
455 |
|
|
456 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
457 |
|
|
458 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
459 |
|
|
460 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
461 |
} |
src/main/java/org/distorted/examples/vertex3d/Vertex3DRenderer.java | ||
---|---|---|
27 | 27 |
import org.distorted.examples.R; |
28 | 28 |
import org.distorted.library.Distorted; |
29 | 29 |
import org.distorted.library.DistortedBitmap; |
30 |
import org.distorted.library.DistortedCubes; |
|
31 | 30 |
import org.distorted.library.DistortedObject; |
32 |
import org.distorted.library.EffectNames; |
|
33 | 31 |
import org.distorted.library.EffectTypes; |
34 |
import org.distorted.library.type.Dynamic1D; |
|
35 |
import org.distorted.library.type.Dynamic2D; |
|
36 |
import org.distorted.library.type.Dynamic3D; |
|
37 | 32 |
import org.distorted.library.type.DynamicQuat; |
38 |
import org.distorted.library.type.Static1D; |
|
39 |
import org.distorted.library.type.Static2D; |
|
40 | 33 |
import org.distorted.library.type.Static3D; |
41 | 34 |
import org.distorted.library.type.Static4D; |
42 | 35 |
|
... | ... | |
50 | 43 |
|
51 | 44 |
class Vertex3DRenderer implements GLSurfaceView.Renderer |
52 | 45 |
{ |
53 |
private static final int SIZE = 100; |
|
54 |
|
|
55 | 46 |
private GLSurfaceView mView; |
56 | 47 |
private DistortedObject mObject; |
57 |
private DistortedBitmap mCenter; |
|
58 |
private float mFactorCen, mFactorObj; |
|
59 |
|
|
48 |
private DistortedBitmap mBackground; |
|
60 | 49 |
private int mObjWidth, mObjHeight; |
61 |
|
|
62 | 50 |
private DynamicQuat mQuatInt1, mQuatInt2; |
63 |
|
|
64 |
private EffectNames[] order; |
|
65 |
|
|
66 |
private Dynamic2D mCenterInter; |
|
67 |
private Dynamic3D mDeformInter, mDistortInter, mMoveInter; |
|
68 |
private Dynamic1D mSinkInter, mSwirlInter; |
|
69 |
|
|
70 |
private Static2D mCenterPoint; |
|
71 |
private Static3D mDeformPoint, mDistortPoint, mMovePoint; |
|
72 |
private Static1D mSinkPoint, mSwirlPoint; |
|
73 |
|
|
74 | 51 |
Static4D mQuat1, mQuat2; |
75 | 52 |
int mScreenMin; |
76 | 53 |
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
public void setDeform(float x, float y, float z) |
|
80 |
{ |
|
81 |
mDeformPoint.set(x, y, z); |
|
82 |
} |
|
83 |
|
|
84 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
85 |
|
|
86 |
public void setDistort(float x, float y, float z) |
|
87 |
{ |
|
88 |
mDistortPoint.set(x, y, z); |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public void setSink(float s) |
|
94 |
{ |
|
95 |
mSinkPoint.set(s); |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public void setSwirl(float s) |
|
101 |
{ |
|
102 |
mSwirlPoint.set(s); |
|
103 |
} |
|
104 |
|
|
105 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
106 |
|
|
107 |
public void setCenter(float x, float y) |
|
108 |
{ |
|
109 |
x = (0.012f*x-0.1f)*mObjWidth; |
|
110 |
y = (0.012f*y-0.1f)*mObjHeight; |
|
111 |
|
|
112 |
mCenterPoint.set(x,y); |
|
113 |
mMovePoint.set(mFactorObj*x,mFactorObj*y,0); |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public void setOrder(EffectNames[] effects) |
|
119 |
{ |
|
120 |
order = effects; |
|
121 |
setVertexEffects(); |
|
122 |
} |
|
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
public void setVertexEffects() |
|
127 |
{ |
|
128 |
mObject.abortEffects(EffectTypes.VERTEX); |
|
129 |
|
|
130 |
for( int i=0; i<=order.length-1 ; i++ ) |
|
131 |
{ |
|
132 |
switch(order[i]) |
|
133 |
{ |
|
134 |
case DEFORM : mObject.deform( mDeformInter , mCenterInter) ; break; |
|
135 |
case DISTORT: mObject.distort(mDistortInter, mCenterInter) ; break; |
|
136 |
case SINK : mObject.sink( mSinkInter , mCenterInter) ; break; |
|
137 |
case SWIRL : mObject.swirl( mSwirlInter , mCenterInter) ; break; |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
|
|
142 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
143 | 55 |
|
144 | 56 |
public Vertex3DRenderer(GLSurfaceView v) |
145 | 57 |
{ |
146 | 58 |
mView = v; |
147 | 59 |
|
148 |
mObject = ((Vertex3DActivity)v.getContext()).getObject(); |
|
149 |
mCenter = new DistortedBitmap(SIZE, SIZE, 1);
|
|
60 |
mObject = ((Vertex3DActivity)v.getContext()).getObject();
|
|
61 |
mBackground = new DistortedBitmap(100, 100, 1);
|
|
150 | 62 |
|
151 | 63 |
mObjWidth = mObject.getWidth(); |
152 | 64 |
mObjHeight= mObject.getHeight(); |
153 | 65 |
|
154 |
mCenterPoint = new Static2D(0,0); |
|
155 |
mMovePoint = new Static3D(0,0,0); |
|
156 |
mDeformPoint = new Static3D(0,0,0); |
|
157 |
mDistortPoint= new Static3D(1,1,1); |
|
158 |
mSwirlPoint = new Static1D(0); |
|
159 |
mSinkPoint = new Static1D(1); |
|
160 |
|
|
161 |
mCenterInter = new Dynamic2D(); |
|
162 |
mDeformInter = new Dynamic3D(); |
|
163 |
mDistortInter = new Dynamic3D(); |
|
164 |
mMoveInter = new Dynamic3D(); |
|
165 |
mSwirlInter = new Dynamic1D(); |
|
166 |
mSinkInter = new Dynamic1D(); |
|
167 |
|
|
168 |
mCenterInter.add(mCenterPoint); |
|
169 |
mMoveInter.add(mMovePoint); |
|
170 |
mDeformInter.add(mDeformPoint); |
|
171 |
mDistortInter.add(mDistortPoint); |
|
172 |
mSwirlInter.add(mSwirlPoint); |
|
173 |
mSinkInter.add(mSinkPoint); |
|
174 |
|
|
175 | 66 |
mQuat1 = new Static4D(0,0,0,1); // unity |
176 | 67 |
mQuat2 = new Static4D(0,0,0,1); // quaternions |
177 | 68 |
|
... | ... | |
183 | 74 |
} |
184 | 75 |
|
185 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 |
|
|
187 |
public void onDrawFrame(GL10 glUnused)
|
|
77 |
|
|
78 |
public void onDrawFrame(GL10 glUnused) |
|
188 | 79 |
{ |
189 | 80 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
190 | 81 |
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); |
191 | 82 |
|
192 | 83 |
long time = System.currentTimeMillis(); |
193 | 84 |
|
85 |
mBackground.draw(time); |
|
194 | 86 |
mObject.draw(time); |
195 |
mCenter.draw(time); |
|
196 | 87 |
} |
197 | 88 |
|
198 | 89 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
199 |
|
|
200 |
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
90 |
|
|
91 |
public void onSurfaceChanged(GL10 glUnused, int width, int height) |
|
201 | 92 |
{ |
202 | 93 |
mScreenMin = width<height ? width:height; |
203 | 94 |
|
204 | 95 |
mObject.abortEffects(EffectTypes.MATRIX); |
205 |
mCenter.abortEffects(EffectTypes.MATRIX); |
|
206 |
|
|
207 |
int centerSize = mCenter.getWidth(); |
|
96 |
mBackground.abortEffects(EffectTypes.MATRIX); |
|
97 |
float factorObj; |
|
208 | 98 |
|
209 | 99 |
if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object |
210 | 100 |
{ |
211 |
mFactorObj = (0.70f*height)/mObjHeight; |
|
212 |
mFactorCen = (0.15f*height)/centerSize; |
|
101 |
factorObj = (0.80f*height)/mObjHeight; |
|
213 | 102 |
} |
214 | 103 |
else |
215 | 104 |
{ |
216 |
mFactorObj = (0.70f*width)/mObjWidth; |
|
217 |
mFactorCen = (0.15f*width)/centerSize; |
|
105 |
factorObj = (0.80f*width)/mObjWidth; |
|
218 | 106 |
} |
219 | 107 |
|
220 |
Vertex3DActivity act = (Vertex3DActivity)mView.getContext(); |
|
221 |
float cX = act.getCenterX(); |
|
222 |
float cY = act.getCenterY(); |
|
223 |
|
|
224 |
cX = (0.012f*cX-0.1f)*mObjWidth; |
|
225 |
cY = (0.012f*cY-0.1f)*mObjHeight; |
|
226 |
|
|
227 |
mMovePoint.set(cX*mFactorObj,cY*mFactorObj,0); |
|
228 |
|
|
229 | 108 |
Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0); |
230 | 109 |
|
231 |
mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
|
|
232 |
mObject.scale(mFactorObj);
|
|
110 |
mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
|
|
111 |
mObject.scale(factorObj);
|
|
233 | 112 |
mObject.quaternion(mQuatInt1, rotateObj); |
234 | 113 |
mObject.quaternion(mQuatInt2, rotateObj); |
235 | 114 |
|
236 |
Static3D rotateCen = new Static3D(width/2,height/2, 0); |
|
115 |
int backgroundSize = mBackground.getWidth(); |
|
116 |
float factorBackX = ((float)width)/backgroundSize; |
|
117 |
float factorBackY = ((float)height)/backgroundSize; |
|
237 | 118 |
|
238 |
mCenter.quaternion(mQuatInt1, rotateCen); |
|
239 |
mCenter.quaternion(mQuatInt2, rotateCen); |
|
240 |
mCenter.move( new Static3D( (width -mFactorCen*centerSize-mFactorObj*mObjWidth )/2 , |
|
241 |
(height-mFactorCen*centerSize-mFactorObj*mObjHeight)/2 , 10) ); |
|
242 |
mCenter.move(mMoveInter); |
|
243 |
mCenter.scale(mFactorCen); |
|
119 |
mBackground.move(new Static3D( -width/2, -height/2,-factorObj*(mObjWidth+mObjHeight)/2) ); |
|
120 |
mBackground.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) ); |
|
244 | 121 |
|
245 |
setVertexEffects(); |
|
246 |
|
|
247 |
Distorted.onSurfaceChanged(width, height); |
|
122 |
Distorted.onSurfaceChanged(width, height); |
|
248 | 123 |
} |
249 | 124 |
|
250 | 125 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
251 |
|
|
252 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
126 |
|
|
127 |
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) |
|
253 | 128 |
{ |
254 | 129 |
Vertex3DActivity act = (Vertex3DActivity)mView.getContext(); |
255 | 130 |
|
256 | 131 |
InputStream is1 = act.getResources().openRawResource(act.getBitmap()); |
257 |
InputStream is2 = act.getResources().openRawResource(R.raw.center);
|
|
132 |
InputStream is2 = act.getResources().openRawResource(R.raw.water);
|
|
258 | 133 |
|
259 | 134 |
Bitmap bitmap1,bitmap2; |
260 | 135 |
|
... | ... | |
274 | 149 |
} |
275 | 150 |
|
276 | 151 |
mObject.setBitmap(bitmap1); |
277 |
mCenter.setBitmap(bitmap2);
|
|
278 |
|
|
152 |
mBackground.setBitmap(bitmap2)
|
|
153 |
; |
|
279 | 154 |
try |
280 | 155 |
{ |
281 | 156 |
Distorted.onSurfaceCreated(mView.getContext()); |
... | ... | |
285 | 160 |
android.util.Log.e("Vertex3D", ex.getMessage() ); |
286 | 161 |
} |
287 | 162 |
} |
288 |
} |
|
163 |
} |
src/main/res/layout/effectcenter.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:id="@+id/effectCenterLayout" |
|
4 |
android:layout_width="match_parent" |
|
5 |
android:layout_height="wrap_content" |
|
6 |
android:orientation="vertical"> |
|
7 |
|
|
8 |
<TextView |
|
9 |
android:id="@+id/effectCenterText" |
|
10 |
android:layout_width="wrap_content" |
|
11 |
android:layout_height="wrap_content" |
|
12 |
android:layout_marginEnd="5dp" |
|
13 |
android:layout_marginStart="5dp" |
|
14 |
android:layout_marginTop="3dp" |
|
15 |
/> |
|
16 |
|
|
17 |
<LinearLayout |
|
18 |
android:orientation="horizontal" |
|
19 |
android:layout_width="match_parent" |
|
20 |
android:layout_height="match_parent"> |
|
21 |
|
|
22 |
<SeekBar |
|
23 |
android:id="@+id/effectCenterBarX" |
|
24 |
android:layout_width="wrap_content" |
|
25 |
android:layout_height="wrap_content" |
|
26 |
android:layout_marginEnd="5dp" |
|
27 |
android:layout_marginLeft="5dp" |
|
28 |
android:layout_marginRight="5dp" |
|
29 |
android:layout_weight="0.5"/> |
|
30 |
|
|
31 |
<SeekBar |
|
32 |
android:id="@+id/effectCenterBarY" |
|
33 |
android:layout_width="wrap_content" |
|
34 |
android:layout_height="wrap_content" |
|
35 |
android:layout_marginEnd="5dp" |
|
36 |
android:layout_marginLeft="5dp" |
|
37 |
android:layout_marginRight="5dp" |
|
38 |
android:layout_weight="0.5"/> |
|
39 |
|
|
40 |
</LinearLayout> |
|
41 |
|
|
42 |
</LinearLayout> |
src/main/res/layout/vertex3ddeform.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:id="@+id/vertex3dRowDeform" |
|
4 |
android:orientation="horizontal" |
|
5 |
android:layout_width="match_parent" |
|
6 |
android:layout_height="wrap_content" |
|
7 |
> |
|
8 |
|
|
9 |
<LinearLayout |
|
10 |
android:layout_width="0dp" |
|
11 |
android:layout_height="match_parent" |
|
12 |
android:layout_weight="0.70" |
|
13 |
android:orientation="vertical" > |
|
14 |
|
|
15 |
<TextView |
|
16 |
android:id="@+id/vertex3ddeformText" |
|
17 |
android:layout_width="wrap_content" |
|
18 |
android:layout_height="wrap_content" |
|
19 |
android:layout_marginEnd="5dp" |
|
20 |
android:layout_marginStart="5dp" |
|
21 |
android:layout_marginTop="3dp" |
|
22 |
/> |
|
23 |
|
|
24 |
<SeekBar |
|
25 |
android:id="@+id/vertex3ddeformBar1" |
|
26 |
android:layout_width="fill_parent" |
|
27 |
android:layout_height="wrap_content" |
|
28 |
android:layout_gravity="end" |
|
29 |
android:layout_marginEnd="5dp" |
|
30 |
android:layout_marginLeft="5dp" |
|
31 |
android:layout_marginRight="5dp" /> |
|
32 |
|
|
33 |
<SeekBar |
|
34 |
android:id="@+id/vertex3ddeformBar2" |
|
35 |
android:layout_width="fill_parent" |
|
36 |
android:layout_height="wrap_content" |
|
37 |
android:layout_gravity="end" |
|
38 |
android:layout_marginEnd="5dp" |
|
39 |
android:layout_marginLeft="5dp" |
|
40 |
android:layout_marginRight="5dp" /> |
|
41 |
|
|
42 |
<SeekBar |
|
43 |
android:id="@+id/vertex3ddeformBar3" |
|
44 |
android:layout_width="fill_parent" |
|
45 |
android:layout_height="wrap_content" |
|
46 |
android:layout_gravity="end" |
|
47 |
android:layout_marginEnd="5dp" |
|
48 |
android:layout_marginLeft="5dp" |
|
49 |
android:layout_marginRight="5dp" /> |
|
50 |
|
|
51 |
</LinearLayout> |
|
52 |
|
|
53 |
<Button |
|
54 |
android:id="@+id/vertex3dUpDeform" |
|
55 |
android:layout_width="60dp" |
|
56 |
android:layout_height="fill_parent" |
|
57 |
android:onClick="ButtonDeform" |
|
58 |
android:text="@string/Up" /> |
|
59 |
|
|
60 |
</LinearLayout> |
src/main/res/layout/vertex3ddistort.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
|
|
3 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
4 |
android:id="@+id/vertex3dRowDistort" |
|
5 |
android:layout_width="match_parent" |
|
6 |
android:layout_height="wrap_content" |
|
7 |
android:orientation="horizontal" |
|
8 |
> |
|
9 |
|
|
10 |
<LinearLayout |
|
11 |
android:layout_width="0dp" |
|
12 |
android:layout_height="wrap_content" |
|
13 |
android:layout_weight="0.8" |
|
14 |
android:orientation="vertical" > |
|
15 |
|
|
16 |
<TextView |
|
17 |
android:id="@+id/vertex3ddistortText" |
|
18 |
android:layout_width="wrap_content" |
|
19 |
android:layout_height="wrap_content" |
|
20 |
android:layout_marginEnd="5dp" |
|
21 |
android:layout_marginStart="5dp" |
|
22 |
android:layout_marginTop="3dp" |
|
23 |
/> |
|
24 |
|
|
25 |
<SeekBar |
|
26 |
android:id="@+id/vertex3ddistortBar1" |
|
27 |
android:layout_width="fill_parent" |
|
28 |
android:layout_height="wrap_content" |
|
29 |
android:layout_marginEnd="5dp" |
|
30 |
android:layout_marginLeft="5dp" |
|
31 |
android:layout_marginRight="5dp" /> |
|
32 |
|
|
33 |
<SeekBar |
|
34 |
android:id="@+id/vertex3ddistortBar2" |
|
35 |
android:layout_width="fill_parent" |
|
36 |
android:layout_height="wrap_content" |
|
37 |
android:layout_marginEnd="5dp" |
|
38 |
android:layout_marginLeft="5dp" |
|
39 |
android:layout_marginRight="5dp" /> |
|
40 |
|
|
41 |
<SeekBar |
|
42 |
android:id="@+id/vertex3ddistortBar3" |
|
43 |
android:layout_width="fill_parent" |
|
44 |
android:layout_height="wrap_content" |
|
45 |
android:layout_marginEnd="5dp" |
|
46 |
android:layout_marginLeft="5dp" |
|
47 |
android:layout_marginRight="5dp" /> |
|
48 |
|
|
49 |
</LinearLayout> |
|
50 |
|
|
51 |
<Button |
|
52 |
android:id="@+id/vertex3dUpDistort" |
|
53 |
android:layout_width="60dp" |
Also available in: Unified diff
Re-write Vertex3D to provide similar functionality to Fragment3D (displaying the center and region bitmaps still missing)