Revision fe7fe83e
Added by Leszek Koltunski almost 6 years ago
src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java | ||
---|---|---|
26 | 26 |
import android.graphics.Paint; |
27 | 27 |
import android.opengl.GLSurfaceView; |
28 | 28 |
import android.os.Bundle; |
29 |
import android.support.design.widget.TabLayout; |
|
30 |
import android.support.v4.view.ViewPager; |
|
29 | 31 |
import android.view.Gravity; |
30 | 32 |
import android.view.View; |
31 | 33 |
import android.widget.AdapterView; |
... | ... | |
38 | 40 |
import android.widget.TableRow; |
39 | 41 |
|
40 | 42 |
import org.distorted.examples.R; |
41 |
import org.distorted.library.effect.EffectName; |
|
42 | 43 |
import org.distorted.library.effect.EffectType; |
43 | 44 |
import org.distorted.library.main.Distorted; |
44 | 45 |
import org.distorted.library.main.MeshCubes; |
... | ... | |
49 | 50 |
|
50 | 51 |
import java.io.IOException; |
51 | 52 |
import java.io.InputStream; |
52 |
import java.util.ArrayList; |
|
53 | 53 |
|
54 | 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
55 | 55 |
|
56 | 56 |
public class Effects3DActivity extends Activity |
57 |
implements View.OnClickListener, |
|
58 |
AdapterView.OnItemSelectedListener |
|
57 |
implements View.OnClickListener, AdapterView.OnItemSelectedListener |
|
59 | 58 |
{ |
60 | 59 |
private static final int COLOR_OFF = 0xffffe81f; |
61 | 60 |
private static final int COLOR_ON = 0xff0000ff; |
... | ... | |
68 | 67 |
private NumberPicker mColsPicker, mRowsPicker, mSlicPicker; |
69 | 68 |
private boolean[] mShape; |
70 | 69 |
private DistortedTexture mTexture; |
71 |
private DistortedEffects mEffects; |
|
72 | 70 |
private MeshObject mMesh; |
73 | 71 |
private int mObjectType; |
74 | 72 |
private int mBitmapID; |
75 | 73 |
private Bitmap mBitmap; |
76 | 74 |
private LinearLayout mLay; |
77 | 75 |
|
78 |
private ArrayList<Effects3DEffect> mList; |
|
79 |
private int mEffectAdd; |
|
80 | 76 |
private float mCenterX, mCenterY, mCenterZ; |
81 | 77 |
private float mRegionX, mRegionY, mRegionR; |
82 |
|
|
83 |
private EffectName[] mEffectNames; |
|
84 |
|
|
85 |
private static boolean mSupportsRegion; |
|
86 |
private static boolean mSupportsCenter; |
|
78 |
private DistortedEffects mEffects; |
|
79 |
private ViewPager mViewPager; |
|
80 |
private Effects3DTabViewPager mPager; |
|
87 | 81 |
|
88 | 82 |
private static boolean mShowCenter = true; |
89 | 83 |
private static boolean mShowRegion = true; |
... | ... | |
97 | 91 |
{ |
98 | 92 |
super.onCreate(savedState); |
99 | 93 |
|
100 |
mList = new ArrayList<>(); |
|
101 |
|
|
102 |
createEffectNames(); |
|
103 |
|
|
104 | 94 |
setContentView(R.layout.objectpickerlayout); |
105 | 95 |
|
106 | 96 |
mLay = findViewById(R.id.objectpicker_buttongrid); |
... | ... | |
166 | 156 |
bitmapSpinner.setAdapter(adapterBitmap); |
167 | 157 |
} |
168 | 158 |
|
169 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
170 |
|
|
171 |
private void createEffectNames() |
|
172 |
{ |
|
173 |
EffectType type1 = EffectType.FRAGMENT; |
|
174 |
EffectType type2 = EffectType.VERTEX; |
|
175 |
|
|
176 |
EffectName[] names = EffectName.values(); |
|
177 |
|
|
178 |
int numEffects=0; |
|
179 |
|
|
180 |
for(int i=0; i<names.length; i++) |
|
181 |
if( names[i].getType() == type1 || names[i].getType() == type2 ) numEffects++; |
|
182 |
|
|
183 |
mEffectNames = new EffectName[numEffects]; |
|
184 |
|
|
185 |
numEffects=0; |
|
186 |
|
|
187 |
for(int i=0; i<names.length; i++) |
|
188 |
if( names[i].getType() == type1 || names[i].getType() == type2 ) |
|
189 |
{ |
|
190 |
mEffectNames[numEffects++] = names[i]; |
|
191 |
} |
|
192 |
} |
|
193 |
|
|
194 | 159 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
195 | 160 |
|
196 | 161 |
private void setGrid() |
... | ... | |
247 | 212 |
return mTexture; |
248 | 213 |
} |
249 | 214 |
|
250 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
251 |
|
|
252 |
public DistortedEffects getEffects() |
|
253 |
{ |
|
254 |
return mEffects; |
|
255 |
} |
|
256 |
|
|
257 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
258 | 216 |
|
259 | 217 |
public MeshObject getMesh() |
... | ... | |
261 | 219 |
return mMesh; |
262 | 220 |
} |
263 | 221 |
|
264 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
265 |
|
|
266 |
public void setSupportsRegion(boolean supports) |
|
267 |
{ |
|
268 |
mSupportsRegion = supports; |
|
269 |
} |
|
270 |
|
|
271 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
272 |
|
|
273 |
public void setSupportsCenter(boolean supports) |
|
274 |
{ |
|
275 |
mSupportsCenter = supports; |
|
276 |
} |
|
277 |
|
|
278 | 222 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
279 | 223 |
|
280 | 224 |
public Bitmap getBitmap() |
... | ... | |
443 | 387 |
} |
444 | 388 |
|
445 | 389 |
mMesh.setShowNormals(mShowNormal); |
446 |
|
|
447 |
mEffects= new DistortedEffects(); |
|
448 | 390 |
mTexture= new DistortedTexture(mNumCols,mNumRows); |
391 |
mEffects= new DistortedEffects(); |
|
449 | 392 |
|
450 | 393 |
final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null); |
451 | 394 |
|
452 | 395 |
setContentView(view); |
453 | 396 |
|
454 |
String[] effects = new String[mEffectNames.length]; |
|
455 |
|
|
456 |
for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name(); |
|
457 |
|
|
458 |
Spinner effectSpinner = findViewById(R.id.effects3dspinner ); |
|
459 |
effectSpinner.setOnItemSelectedListener(this); |
|
460 |
|
|
461 |
ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects); |
|
462 |
adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
463 |
effectSpinner.setAdapter(adapterEffect); |
|
397 |
mViewPager = findViewById(R.id.effects3d_viewpager); |
|
398 |
mPager = new Effects3DTabViewPager(this, getFragmentManager() ); |
|
399 |
mViewPager.setAdapter(mPager); |
|
400 |
TabLayout tabLayout = findViewById(R.id.effects3d_sliding_tabs); |
|
401 |
tabLayout.setupWithViewPager(mViewPager); |
|
464 | 402 |
|
465 | 403 |
resetData(); |
466 |
|
|
467 |
mEffectAdd = 0; |
|
468 | 404 |
} |
469 | 405 |
|
470 | 406 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
490 | 426 |
case 6: mBitmapID = R.raw.monalisa; break; |
491 | 427 |
} |
492 | 428 |
break; |
493 |
case R.id.effects3dspinner : mEffectAdd = pos; |
|
494 |
break; |
|
495 | 429 |
} |
496 | 430 |
} |
497 | 431 |
|
... | ... | |
531 | 465 |
|
532 | 466 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
533 | 467 |
|
534 |
private void resetData()
|
|
468 |
void resetData() |
|
535 | 469 |
{ |
536 | 470 |
mCenterX = 0.5f*getWidth(); |
537 | 471 |
mCenterY = 0.5f*getHeight(); |
... | ... | |
539 | 473 |
mRegionY = 0; |
540 | 474 |
mRegionR = getWidth()/2; |
541 | 475 |
|
542 |
mSupportsRegion =false; |
|
543 |
mSupportsCenter =false; |
|
544 |
|
|
545 | 476 |
Effects3DSurfaceView view = findViewById(R.id.effects3dSurfaceView); |
546 |
view.getRenderer().showRegionAndCenter(false,false); |
|
477 |
Effects3DRenderer renderer= view.getRenderer(); |
|
478 |
|
|
479 |
renderer.setCenter( mCenterX, mCenterY, mCenterZ ); |
|
480 |
renderer.setRegion( mRegionX, mRegionY, mRegionR ); |
|
481 |
renderer.mQuat1.set(0,0,0,1); |
|
482 |
renderer.mQuat2.set(0,0,0,1); |
|
547 | 483 |
} |
548 | 484 |
|
549 | 485 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
550 | 486 |
// 'second screen' methods |
487 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
551 | 488 |
|
552 |
public void newEffect(View v)
|
|
489 |
public DistortedEffects getEffects()
|
|
553 | 490 |
{ |
554 |
Effects3DEffect eff = new Effects3DEffect(mEffectNames[mEffectAdd], this); |
|
555 |
mList.add(eff); |
|
556 |
|
|
557 |
LinearLayout layout = findViewById(R.id.effects3dlayout); |
|
558 |
View view = eff.createView(); |
|
559 |
layout.addView(view); |
|
560 |
|
|
561 |
if( mSupportsCenter ) |
|
562 |
{ |
|
563 |
View center = eff.createCenter(); |
|
564 |
layout.addView(center); |
|
565 |
} |
|
566 |
|
|
567 |
if( mSupportsRegion ) |
|
568 |
{ |
|
569 |
View region = eff.createRegion(); |
|
570 |
layout.addView(region); |
|
571 |
} |
|
491 |
return mEffects; |
|
492 |
} |
|
572 | 493 |
|
573 |
eff.apply(mEffects);
|
|
494 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
574 | 495 |
|
575 |
boolean show = (mEffectNames[mEffectAdd].getType()==EffectType.VERTEX);
|
|
576 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
|
|
577 |
sv.getRenderer().showRegionAndCenter( (show && mShowRegion) , (show && mShowCenter) );
|
|
496 |
public void newEffect(View v)
|
|
497 |
{
|
|
498 |
mPager.newEffect(v,mViewPager.getCurrentItem());
|
|
578 | 499 |
} |
579 | 500 |
|
580 | 501 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
581 | 502 |
|
582 | 503 |
public void removeAll(View v) |
583 | 504 |
{ |
584 |
mList.clear(); |
|
585 |
LinearLayout layout = findViewById(R.id.effects3dlayout); |
|
586 |
layout.removeAllViews(); |
|
587 |
mEffects.abortByType(EffectType.VERTEX); |
|
588 |
mEffects.abortByType(EffectType.FRAGMENT); |
|
589 |
|
|
590 |
resetData(); |
|
591 |
|
|
592 |
Effects3DSurfaceView view = findViewById(R.id.effects3dSurfaceView); |
|
593 |
Effects3DRenderer renderer= view.getRenderer(); |
|
594 |
|
|
595 |
renderer.setCenter( mCenterX, mCenterY, mCenterZ ); |
|
596 |
renderer.setRegion( mRegionX, mRegionY, mRegionR ); |
|
597 |
renderer.mQuat1.set(0,0,0,1); |
|
598 |
renderer.mQuat2.set(0,0,0,1); |
|
505 |
mPager.removeAll(v,mViewPager.getCurrentItem()); |
|
599 | 506 |
} |
600 | 507 |
|
601 | 508 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
602 | 509 |
|
603 | 510 |
public void remove(View v) |
604 | 511 |
{ |
605 |
for(Effects3DEffect effect: mList) |
|
606 |
{ |
|
607 |
if( effect.thisView(v) ) |
|
608 |
{ |
|
609 |
LinearLayout layout = findViewById(R.id.effects3dlayout); |
|
610 |
View view; |
|
611 |
|
|
612 |
view = effect.getEffect(); |
|
613 |
if( view!=null ) layout.removeView(view); |
|
614 |
view = effect.getCenter(); |
|
615 |
if( view!=null ) layout.removeView(view); |
|
616 |
view = effect.getRegion(); |
|
617 |
if( view!=null ) layout.removeView(view); |
|
618 |
|
|
619 |
mEffects.abortById(effect.getId()); |
|
620 |
mList.remove(effect); |
|
621 |
|
|
622 |
resetData(); |
|
623 |
|
|
624 |
break; |
|
625 |
} |
|
626 |
} |
|
512 |
mPager.remove(v,mViewPager.getCurrentItem()); |
|
627 | 513 |
} |
628 | 514 |
|
629 | 515 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
630 | 516 |
|
631 |
boolean getShowCenter()
|
|
632 |
{
|
|
633 |
return mShowCenter;
|
|
634 |
}
|
|
517 |
boolean getShowCenter() |
|
518 |
{ |
|
519 |
return mShowCenter; |
|
520 |
} |
|
635 | 521 |
|
636 | 522 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
637 | 523 |
|
638 |
boolean getShowRegion()
|
|
639 |
{
|
|
640 |
return mShowRegion;
|
|
641 |
}
|
|
524 |
boolean getShowRegion() |
|
525 |
{ |
|
526 |
return mShowRegion; |
|
527 |
} |
|
642 | 528 |
|
643 | 529 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
644 | 530 |
|
645 |
public void showCenter(View view)
|
|
646 |
{
|
|
647 |
CheckBox box = (CheckBox)view;
|
|
648 |
mShowCenter = box.isChecked();
|
|
531 |
public void showCenter(View view) |
|
532 |
{ |
|
533 |
CheckBox box = (CheckBox)view; |
|
534 |
mShowCenter = box.isChecked(); |
|
649 | 535 |
|
650 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
|
|
651 |
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
|
|
652 |
}
|
|
536 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView); |
|
537 |
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter); |
|
538 |
} |
|
653 | 539 |
|
654 | 540 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
655 | 541 |
|
656 |
public void showRegion(View view)
|
|
657 |
{
|
|
658 |
CheckBox box = (CheckBox)view;
|
|
659 |
mShowRegion = box.isChecked();
|
|
542 |
public void showRegion(View view) |
|
543 |
{ |
|
544 |
CheckBox box = (CheckBox)view; |
|
545 |
mShowRegion = box.isChecked(); |
|
660 | 546 |
|
661 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
|
|
662 |
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
|
|
663 |
}
|
|
547 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView); |
|
548 |
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter); |
|
549 |
} |
|
664 | 550 |
|
665 | 551 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
666 | 552 |
|
667 |
public void showNormal(View view)
|
|
668 |
{
|
|
669 |
CheckBox box = (CheckBox)view;
|
|
670 |
mShowNormal = box.isChecked();
|
|
553 |
public void showNormal(View view) |
|
554 |
{ |
|
555 |
CheckBox box = (CheckBox)view; |
|
556 |
mShowNormal = box.isChecked(); |
|
671 | 557 |
|
672 |
if ( mMesh!=null ) |
|
673 |
{ |
|
674 |
mMesh.setShowNormals(mShowNormal); |
|
675 |
} |
|
558 |
if ( mMesh!=null ) |
|
559 |
{ |
|
560 |
mMesh.setShowNormals(mShowNormal); |
|
676 | 561 |
} |
562 |
} |
|
677 | 563 |
|
678 | 564 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
679 | 565 |
|
680 |
public void triggerOIT(View view)
|
|
681 |
{
|
|
682 |
CheckBox box = (CheckBox)view;
|
|
683 |
mUseOIT = box.isChecked();
|
|
566 |
public void triggerOIT(View view) |
|
567 |
{ |
|
568 |
CheckBox box = (CheckBox)view; |
|
569 |
mUseOIT = box.isChecked(); |
|
684 | 570 |
|
685 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
|
|
686 |
sv.getRenderer().useOIT(mUseOIT);
|
|
687 |
}
|
|
571 |
Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView); |
|
572 |
sv.getRenderer().useOIT(mUseOIT); |
|
573 |
} |
|
688 | 574 |
|
689 | 575 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
690 | 576 |
// Overrides |
577 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
691 | 578 |
|
692 | 579 |
@Override |
693 | 580 |
protected void onPause() |
Also available in: Unified diff
Overhaul of the Effects3D generic test app.
Still not perfect (the 'postprocess' tab does not work; things crash when we rotate)