Project

General

Profile

« Previous | Next » 

Revision 9c5b5cb6

Added by Leszek Koltunski almost 8 years ago

Improce the 'Check' App.

View differences:

src/main/java/org/distorted/examples/check/CheckActivity.java
38 38
         {
39 39
         @Override
40 40
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
41
           { 
41
           {
42 42
           maxV = newVal;
43 43
           }
44 44
         });
......
47 47
         {
48 48
         @Override
49 49
         public void onValueChange(NumberPicker picker, int oldVal, int newVal) 
50
           { 
50
           {
51 51
           maxF = newVal;
52 52
           }
53 53
         });
......
91 91
      {
92 92
      super.onWindowFocusChanged(hasFocus);
93 93

  
94
      mVPicker.setValue(1);
94
      maxF = 1;
95
      maxV = 2;
96

  
97
      mVPicker.setValue(2);
95 98
      mFPicker.setValue(1);
96 99
      }
97 100

  
src/main/java/org/distorted/examples/check/CheckRenderer.java
12 12
import org.distorted.library.Distorted;
13 13
import org.distorted.library.DistortedBitmap;
14 14
import org.distorted.library.EffectTypes;
15
import org.distorted.library.Float1D;
15 16
import org.distorted.library.Float2D;
16 17
import org.distorted.library.Float3D;
18
import org.distorted.library.Float4D;
19
import org.distorted.library.Interpolator1D;
20
import org.distorted.library.Interpolator2D;
17 21

  
18 22
import android.app.AlertDialog;
19 23
import android.content.Context;
......
29 33
{
30 34
    private GLSurfaceView mView;
31 35
    private DistortedBitmap mSuccess;
32
    private Float2D pUp, pDown;
33
    private Float3D vUp, vDown;
34
    
35 36
    private int bmpHeight, bmpWidth;
36
    
37

  
37 38
    public static String compilationResult;
38 39
    public static String compilationTitle;
39
    
40

  
40 41
///////////////////////////////////////////////////////////////////////////////////////////////////
41 42

  
42 43
    public CheckRenderer(GLSurfaceView view) 
43 44
      { 
44 45
      mView = view;
45
    
46

  
46 47
      Distorted.setMaxVertex(CheckActivity.getMaxV());
47 48
      Distorted.setMaxFragment(CheckActivity.getMaxF());
48 49
      }
......
85 86
      {  
86 87
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.success);
87 88
      Bitmap bitmap;
88
        
89
      try 
89

  
90
      try
90 91
        {
91 92
        bitmap = BitmapFactory.decodeStream(is);
92 93
        } 
......
97 98
          is.close();
98 99
          } 
99 100
        catch(IOException e) { }
100
        }  
101
      
101
        }
102

  
103
      mSuccess = new DistortedBitmap(bitmap, 30);
104

  
102 105
      bmpHeight = bitmap.getHeight();
103 106
      bmpWidth  = bitmap.getWidth();
104
       
105
      pDown = new Float2D(bmpWidth/2,        0);
106
      pUp   = new Float2D(bmpWidth/2,bmpHeight);
107
      
108
      vUp   = new Float3D( 0,+bmpHeight,0);
109
      vDown = new Float3D( 0,-bmpHeight,0);
110
      
111
      mSuccess = new DistortedBitmap(bitmap, 30);  
112
      mSuccess.deform(  vUp,   pUp, 2000, 0.0f);
107

  
108
      // Try adding 2 Vertex Effects to the Bitmap.
109
      // This will fail if we have set maxVertexEffects to something < 2.
110
      //
111
      // Even if adding some of the Effects fails, the App will still start - you just won't see
112
      // the effects that failed to add.
113
      Float2D pDown   = new Float2D(bmpWidth/2,   0);
114
      Float3D vDown   = new Float3D( 0,-bmpHeight,0);
115
      Float4D mRegion = new Float4D( 0, 0, 40 ,40 );
116

  
117
      Interpolator2D mPoint = new Interpolator2D();
118
      mPoint.setCount(0.0f);
119
      mPoint.setDuration(2000);
120
      mPoint.add(new Float2D(        0, bmpHeight/2));
121
      mPoint.add(new Float2D( bmpWidth, bmpHeight/2));
122

  
123
      mSuccess.swirl( 30, mRegion, mPoint );
113 124
      mSuccess.deform(vDown, pDown, 2000, 0.0f);
114
      
125

  
126
      // Now try adding 1 Fragment Effect. Likewise, will fail if maxFragmentEffects is <1.
127
      Float3D color = new Float3D(1,0,0);
128
      Interpolator1D inter = new Interpolator1D();
129
      inter.setCount(0.0f);
130
      inter.setDuration(2000);
131
      inter.add(new Float1D(0));
132
      inter.add(new Float1D(1));
133

  
134
      mSuccess.chroma(inter, color, null, new Float2D(0,0) );
135

  
115 136
      try
116 137
        {
117 138
        Distorted.onSurfaceCreated(mView.getContext());
118 139
        }
119 140
      catch(Exception ex)
120 141
        {
142
        // We have failed to compile or link shaders - probably too many effects.
143
        // (each effect adds a certain number of Uniforms to the shader and there
144
        // can only be a limited number of those )
145

  
121 146
        compilationTitle = ex.getClass().getSimpleName();
122 147
        compilationResult= ex.getMessage();
123 148
      
src/main/java/org/distorted/examples/movingeffects/MovingEffectsSurfaceView.java
169 169
        {
170 170
        MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.VERTEX);
171 171
        MovingEffectsRenderer.mBackground.abortEffects(EffectTypes.FRAGMENT);
172
        MovingEffectsRenderer.mBackground.swirl(30, dr, di2D, 0, 0.5f);  
172
        MovingEffectsRenderer.mBackground.swirl(30, dr, di2D);
173 173
        mCurrEffect = EFFECT_SWIRL;
174 174
        }
175 175
      }

Also available in: Unified diff