Project

General

Profile

« Previous | Next » 

Revision 4bfffdd5

Added by Leszek Koltunski 12 months ago

build for API 34.

View differences:

build.gradle
1 1
apply plugin: 'com.android.application'
2 2

  
3 3
android {
4
    compileSdkVersion 32
4
    compileSdkVersion 34
5 5

  
6 6
    defaultConfig {
7 7
        applicationId "org.distorted.examples"
8 8
        minSdkVersion 21
9
        targetSdkVersion 32
9
        targetSdkVersion 34
10 10
        versionCode 1
11 11
        versionName "1.0"
12 12
    }
......
24 24
    api project(':distorted-library-opengl')
25 25
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
26 26
    implementation 'androidx.legacy:legacy-support-v13:1.0.0'
27
    implementation 'com.google.android.material:material:1.8.0'
27
    implementation 'com.google.android.material:material:1.9.0'
28 28
    implementation project(path: ':distorted-library-object')
29 29
    implementation project(path: ':distorted-component-jsons')
30 30
}
src/main/java/org/distorted/examples/TableOfContents.java
77 77
import org.distorted.examples.predeform.PredeformActivity;
78 78
import org.distorted.examples.singlemesh.SingleMeshActivity;
79 79
import org.distorted.examples.meshfile.MeshFileActivity;
80
import org.distorted.examples.polymesh.PolymeshActivity;
80 81

  
81 82
///////////////////////////////////////////////////////////////////////////////////////////////////
82 83

  
......
130 131
    SINGLEMESH        (R.drawable.icon_example_singlemesh      , R.string.example_singlemesh           , R.string.example_singlemesh_subtitle           ,            SingleMeshActivity.class),
131 132
    MESHFILE          (R.drawable.icon_example_meshfile        , R.string.example_meshfile           , R.string.example_meshfile_subtitle           ,            MeshFileActivity.class),
132 133
    FLATBLUR2         (R.drawable.icon_example_flatblur        , R.string.example_flatblur         , R.string.example_flatblur_subtitle         , FlatBlur2Activity.class ),
134
    POLYMESH          (R.drawable.icon_example_wip             , R.string.example_polymesh         , R.string.example_polymesh_subtitle         , PolymeshActivity.class ),
133 135
    ;
134 136

  
135 137
    final int icon, title, subtitle;
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
19 19

  
20 20
package org.distorted.examples.meshfile;
21 21

  
22
import android.app.ActivityManager;
23 22
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25 23
import android.content.res.Resources;
26 24
import android.graphics.Bitmap;
27 25
import android.graphics.Canvas;
......
267 265
    private void createPolygon()
268 266
      {
269 267
      float A = 0.5f;
270
      float B = 0.1f;
268
      float B = 0.5f;
271 269

  
272
      int extraIndex    = 2;
273
      int extraVertices = 2;
274
      int numBands      = 2;
270
      int extraIndex    = 0;
271
      int extraVertices = 0;
272
      int numBands      = 3;
275 273

  
276 274
      float[] vertices = new float[] { -A,-A, A,-A, A,A, -A,A };
277 275
      float[] bands = new float[2*numBands];
src/main/java/org/distorted/examples/polymesh/PolymeshActivity.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.polymesh;
21

  
22
import android.app.Activity;
23
import android.opengl.GLSurfaceView;
24
import android.os.Bundle;
25
import android.view.View;
26
import android.widget.Button;
27
import android.widget.Toast;
28

  
29
import org.distorted.examples.R;
30
import org.distorted.library.main.DistortedLibrary;
31

  
32
///////////////////////////////////////////////////////////////////
33

  
34
public class PolymeshActivity extends Activity
35
    {
36
    private static final int COLOR_PRESSED   = 0xff0000ff;
37
    private static final int COLOR_UNPRESSED = 0x888888ff;
38
    private static final String SHOWED_TOAST = "showed_toast";
39

  
40
    private Button mAbort, mChroma, mTrans, mSink, mBubble, mSwirl;
41
   
42
///////////////////////////////////////////////////////////////////
43
    @Override
44
    protected void onCreate(Bundle savedState) 
45
      {
46
      super.onCreate(savedState);
47
      DistortedLibrary.onCreate();
48
      setContentView(R.layout.movingeffectslayout);
49
      
50
      mAbort = findViewById(R.id.movingeffectsAbort);
51
      mChroma= findViewById(R.id.movingeffectsChroma);
52
      mTrans = findViewById(R.id.movingeffectsTrans);
53
      mSink  = findViewById(R.id.movingeffectsSink);
54
      mBubble= findViewById(R.id.movingeffectsBubble);
55
      mSwirl = findViewById(R.id.movingeffectsSwirl);
56
      
57
      mAbort.setBackgroundColor(COLOR_PRESSED);
58
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
59
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
60
      mSink.setBackgroundColor(COLOR_UNPRESSED);
61
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
62
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
63
     
64
      if ( savedState== null || !savedState.getBoolean(SHOWED_TOAST, false))
65
         {
66
         Toast.makeText(this, R.string.example_movingeffects_toast , Toast.LENGTH_LONG).show();
67
         }   
68
      }
69

  
70
///////////////////////////////////////////////////////////////////
71

  
72
    @Override
73
    protected void onPause()
74
      {
75
      Abort(null);
76

  
77
      super.onPause();
78
      GLSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
79
      view.onPause();
80
      DistortedLibrary.onPause();
81
      }
82

  
83
///////////////////////////////////////////////////////////////////
84

  
85
    @Override
86
    protected void onResume() 
87
      {
88
      super.onResume();
89
      GLSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
90
      view.onResume();
91
      }
92

  
93
///////////////////////////////////////////////////////////////////
94

  
95
    @Override
96
    public void onStop()
97
      {
98
      super.onStop();
99
      }
100

  
101
///////////////////////////////////////////////////////////////////
102
    @Override
103
    public void onDestroy()
104
      {
105
      DistortedLibrary.onDestroy();
106
      super.onDestroy();
107
      }     
108
   
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
    
111
    @Override
112
    protected void onSaveInstanceState (Bundle outState)
113
      {
114
      outState.putBoolean(SHOWED_TOAST, true);
115
      }
116
     
117
///////////////////////////////////////////////////////////////////
118
    
119
    public void Bubble(View v)
120
      {
121
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
122
      view.Bubble();
123
      
124
      mAbort.setBackgroundColor(COLOR_UNPRESSED);
125
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
126
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
127
      mSink.setBackgroundColor(COLOR_UNPRESSED);
128
      mBubble.setBackgroundColor(COLOR_PRESSED);
129
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
130
      }     
131
    
132
///////////////////////////////////////////////////////////////////
133

  
134
    public void Sink(View v)
135
      {
136
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
137
      view.Sink();
138
      
139
      mAbort.setBackgroundColor(COLOR_UNPRESSED);
140
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
141
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
142
      mSink.setBackgroundColor(COLOR_PRESSED);
143
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
144
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
145
      }       
146

  
147
///////////////////////////////////////////////////////////////////
148
    
149
    public void Transparency(View v)
150
      {
151
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
152
      view.Transparency();
153
      
154
      mAbort.setBackgroundColor(COLOR_UNPRESSED);
155
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
156
      mTrans.setBackgroundColor(COLOR_PRESSED);
157
      mSink.setBackgroundColor(COLOR_UNPRESSED);
158
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
159
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
160
      }     
161
    
162
///////////////////////////////////////////////////////////////////
163

  
164
    public void Chroma(View v)
165
      {
166
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
167
      view.Chroma();
168
      
169
      mAbort.setBackgroundColor(COLOR_UNPRESSED);
170
      mChroma.setBackgroundColor(COLOR_PRESSED);
171
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
172
      mSink.setBackgroundColor(COLOR_UNPRESSED);
173
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
174
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
175
      }       
176

  
177
///////////////////////////////////////////////////////////////////
178

  
179
    public void Swirl(View v)
180
      {
181
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
182
      view.Swirl();
183
      
184
      mAbort.setBackgroundColor(COLOR_UNPRESSED);
185
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
186
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
187
      mSink.setBackgroundColor(COLOR_UNPRESSED);
188
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
189
      mSwirl.setBackgroundColor(COLOR_PRESSED);
190
      }       
191
    
192
///////////////////////////////////////////////////////////////////
193

  
194
    public void Abort(View v)
195
      {
196
      PolymeshSurfaceView view = findViewById(R.id.movingeffectsSurfaceView);
197
      view.Abort();
198
      
199
      mAbort.setBackgroundColor(COLOR_PRESSED);
200
      mChroma.setBackgroundColor(COLOR_UNPRESSED);
201
      mTrans.setBackgroundColor(COLOR_UNPRESSED);
202
      mSink.setBackgroundColor(COLOR_UNPRESSED);
203
      mBubble.setBackgroundColor(COLOR_UNPRESSED);
204
      mSwirl.setBackgroundColor(COLOR_UNPRESSED);
205
      }
206
}
src/main/java/org/distorted/examples/polymesh/PolymeshRenderer.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.polymesh;
21

  
22
import android.content.res.Resources;
23
import android.graphics.Bitmap;
24
import android.graphics.Canvas;
25
import android.graphics.Paint;
26
import android.graphics.Paint.Style;
27
import android.opengl.GLSurfaceView;
28

  
29
import org.distorted.library.effect.Effect;
30
import org.distorted.library.effect.EffectType;
31
import org.distorted.library.effect.FragmentEffectAlpha;
32
import org.distorted.library.effect.FragmentEffectChroma;
33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectDeform;
35
import org.distorted.library.effect.VertexEffectScale;
36
import org.distorted.library.effect.VertexEffectSink;
37
import org.distorted.library.effect.VertexEffectSwirl;
38
import org.distorted.library.main.DistortedEffects;
39
import org.distorted.library.main.DistortedLibrary;
40
import org.distorted.library.main.DistortedScreen;
41
import org.distorted.library.main.DistortedTexture;
42
import org.distorted.library.mesh.MeshSquare;
43
import org.distorted.library.type.Static3D;
44

  
45
import java.io.InputStream;
46

  
47
import javax.microedition.khronos.egl.EGLConfig;
48
import javax.microedition.khronos.opengles.GL10;
49

  
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

  
52
class PolymeshRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
53
   {  
54
   private final PolymeshSurfaceView mView;
55
   private final DistortedEffects mEffects;
56
   private final DistortedTexture mTexture;
57
   private final DistortedScreen mScreen;
58
   private final Static3D mScaleMatrix, mScaleVertex;
59
   private final Paint mPaint;
60
   private final Resources mResources;
61

  
62
   private MeshSquare mMesh;
63
   private Canvas mCanvas;
64
   private Bitmap mBitmap;
65
   private int texW, texH;
66
   private boolean mRefresh;
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
   PolymeshRenderer(PolymeshSurfaceView v)
71
     {
72
     mView = v;
73
     mResources = v.getResources();
74

  
75
     mPaint = new Paint();
76
     mPaint.setAntiAlias(true);
77
     mPaint.setFakeBoldText(true);
78
     mPaint.setStyle(Style.FILL);
79

  
80
     mEffects= new DistortedEffects();
81
     mScreen = new DistortedScreen();
82
     mTexture= new DistortedTexture();
83
     mRefresh= true;
84

  
85
     mScaleMatrix = new Static3D(1,1,1);
86
     mScaleVertex = new Static3D(1,1,1);
87
     mEffects.apply( new MatrixEffectScale(mScaleMatrix));
88
     mEffects.apply( new VertexEffectScale(mScaleVertex));
89
     }
90

  
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

  
93
   private void drawBackground()
94
     {
95
     int NW, NH;
96

  
97
     if( texH<texW )
98
       {
99
       NH = 10;
100
       NW = NH*texW/texH;
101
       }
102
     else
103
       {
104
       NW = 10;
105
       NH = NW*texH/texW;
106
       }
107

  
108
     mPaint.setColor(0xff008800);
109
     mCanvas.drawRect(0, 0, texW, texH, mPaint);
110
     mPaint.setColor(0xffffffff);
111
         
112
     for(int i=0; i<=NH ; i++ ) mCanvas.drawRect( 0, texH*i/NH -2,  texW,  texH*i/NH + 2, mPaint);
113
     for(int i=0; i<=NW ; i++ ) mCanvas.drawRect( texW*i/NW - 2, 0, texW*i/NW + 2,  texH, mPaint);
114
     }
115
   
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
   void apply(Effect effect)
119
     {
120
     mEffects.abortByType(EffectType.VERTEX);
121
     mEffects.abortByType(EffectType.FRAGMENT);
122

  
123
     mEffects.apply( new VertexEffectScale(mScaleVertex));
124

  
125
     if( effect!=null ) mEffects.apply(effect);
126
     }
127

  
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

  
130
   void setRefresh()
131
     {
132
     mRefresh = true;
133
     }
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
   public void onDrawFrame(GL10 glUnused)
138
     {
139
     long time = System.currentTimeMillis();
140

  
141
     if (mView.getCurrentEffect() == PolymeshSurfaceView.EFFECT_POINTS && mRefresh )
142
       {
143
       drawBackground();
144
       mView.drawCurve(mCanvas,time);
145
       mTexture.setTexture(mBitmap);
146
       mRefresh = false;
147
       }
148

  
149
     mScreen.render(time);
150
     }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
155
     {
156
     texW = width;
157
     texH = height;
158

  
159
     mScaleMatrix.set(width,width,width);
160
     mScaleVertex.set(1.0f, (float)texH/texW, 1.0f);
161

  
162
     mBitmap  = Bitmap.createBitmap(texW,texH, Bitmap.Config.ARGB_8888);
163
     mCanvas  = new Canvas(mBitmap);
164

  
165
     if( mMesh!=null ) mMesh.markForDeletion();
166
     mMesh = new MeshSquare(80,80*texH/texW);
167

  
168
     mScreen.detachAll();
169
     mScreen.attach(mTexture,mEffects,mMesh);
170
     mScreen.resize(texW, texH);
171
     mView.onSurfaceChanged(texW,texH);
172

  
173
     mRefresh = true;
174
     }
175

  
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

  
178
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
179
     {
180
     VertexEffectScale.enable();
181
     VertexEffectSwirl.enable();
182
     VertexEffectDeform.enable();
183
     VertexEffectSink.enable();
184
     FragmentEffectChroma.enable();
185
     FragmentEffectAlpha.enable();
186

  
187
     DistortedLibrary.onSurfaceCreated(this);
188
     }
189

  
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

  
192
   public void distortedException(Exception ex)
193
     {
194
     android.util.Log.e("MovingEffects", ex.getMessage() );
195
     }
196

  
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

  
199
   public InputStream localFile(int fileID)
200
      {
201
      return mResources.openRawResource(fileID);
202
      }
203

  
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

  
206
   public void logMessage(String message)
207
      {
208
      android.util.Log.e("MovingEffects", message );
209
      }
210
}
src/main/java/org/distorted/examples/polymesh/PolymeshSurfaceView.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.polymesh;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.graphics.Paint.Style;
28
import android.opengl.GLSurfaceView;
29
import android.util.AttributeSet;
30
import android.view.MotionEvent;
31

  
32
import org.distorted.library.effect.FragmentEffectAlpha;
33
import org.distorted.library.effect.FragmentEffectChroma;
34
import org.distorted.library.effect.VertexEffectDeform;
35
import org.distorted.library.effect.VertexEffectSink;
36
import org.distorted.library.effect.VertexEffectSwirl;
37
import org.distorted.library.type.Dynamic3D;
38
import org.distorted.library.type.Static1D;
39
import org.distorted.library.type.Static3D;
40
import org.distorted.library.type.Static4D;
41

  
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

  
44
public class PolymeshSurfaceView extends GLSurfaceView
45
    {
46
    private static final int LOOP_TIME = 5000;
47
    private static final int NUM_POINTS= 100;
48

  
49
    public static final int EFFECT_POINTS=0;
50
    public static final int EFFECT_BUBBLE=1;
51
    public static final int EFFECT_SINK  =2;
52
    public static final int EFFECT_TRANS =3;
53
    public static final int EFFECT_CHROMA=4;
54
    public static final int EFFECT_SWIRL =5;
55

  
56
    private static final Object lock = new Object();
57

  
58
    private Dynamic3D mCenter;
59
    private Paint mPaint;
60
    private int moving;
61
    private int mScrWidth, mScrHeight;
62
    private long mTime = 0;
63
    
64
    private int mCurrEffect;
65
    private int mSize1, mSize2;
66
    private Static3D mDeform;
67
    private Static1D mRadius;
68

  
69
    private PolymeshRenderer mRenderer;
70

  
71
    private VertexEffectDeform mEffectDeform;
72
    private VertexEffectSink mEffectSink;
73
    private VertexEffectSwirl mEffectSwirl;
74
    private FragmentEffectChroma mEffectChroma;
75
    private FragmentEffectAlpha mEffectAlpha;
76

  
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
    
79
    public PolymeshSurfaceView(Context context, AttributeSet attrs)
80
      {
81
      super(context, attrs);
82

  
83
      mCurrEffect=EFFECT_POINTS;
84
      mPaint = new Paint();
85
      mPaint.setStyle(Style.FILL);
86
      moving = -1;
87
      
88
      mCenter = new Dynamic3D(LOOP_TIME,0.0f);
89
      mDeform = new Static3D(0,0,0.15f);
90
      mRadius = new Static1D(0);
91

  
92
      if(!isInEditMode())
93
        {
94
        mRenderer = new PolymeshRenderer(this);
95

  
96
        setFocusable(true);
97
        setFocusableInTouchMode(true);
98
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
99
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
100
        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
101
        setRenderer(mRenderer);
102

  
103
        Static3D regionFrag = new Static3D(0.15f,0.15f,0.15f);
104
        Static4D regionVert = new Static4D(0,0,0,0.15f);
105

  
106
        mEffectDeform  = new VertexEffectDeform  ( mDeform          , mRadius, mCenter, regionVert);
107
        mEffectSink    = new VertexEffectSink    (new Static1D(10)  , mCenter, regionVert);
108
        mEffectSwirl   = new VertexEffectSwirl   (new Static1D(30)  , mCenter, regionVert);
109
        mEffectAlpha   = new FragmentEffectAlpha (new Static1D(0.5f), mCenter, regionFrag, true);
110
        mEffectChroma  = new FragmentEffectChroma(new Static1D(0.5f), new Static3D(1,0,0), mCenter, regionFrag, true);
111
        }
112
      }
113

  
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

  
116
    public void onSurfaceChanged(int width,int height)
117
      {
118
      int max = Math.max(width, height);
119

  
120
      mScrWidth  = width;
121
      mScrHeight = height;
122

  
123
      mRadius.set(max/2);
124

  
125
      mSize1 = max/200;
126
      mSize2 = max/80;
127
      }
128

  
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

  
131
    public int getCurrentEffect()
132
      {
133
      return mCurrEffect;
134
      }
135
    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137
    
138
    public void Bubble()
139
      {
140
      if( mCurrEffect==EFFECT_BUBBLE ) return;     
141
      
142
      synchronized(lock)
143
        {
144
        mRenderer.apply(mEffectDeform);
145
        mCurrEffect = EFFECT_BUBBLE;
146
        }
147
      }
148

  
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

  
151
    public void Sink()
152
      {
153
      if( mCurrEffect==EFFECT_SINK ) return; 
154
         
155
      synchronized(lock)
156
        {
157
        mRenderer.apply(mEffectSink);
158
        mCurrEffect = EFFECT_SINK;
159
        }
160
      }
161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
    public void Chroma()
165
      {
166
      if( mCurrEffect==EFFECT_CHROMA ) return;
167
         
168
      synchronized(lock)
169
        {
170
        mRenderer.apply(mEffectChroma);
171
        mCurrEffect = EFFECT_CHROMA;
172
        }
173
      }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
    public void Transparency()
178
      {
179
      if( mCurrEffect==EFFECT_TRANS ) return;   
180
      
181
      synchronized(lock)
182
        {
183
        mRenderer.apply(mEffectAlpha);
184
        mCurrEffect = EFFECT_TRANS;
185
        }
186
      }
187

  
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

  
190
    public void Swirl()
191
      {
192
      if( mCurrEffect==EFFECT_SWIRL ) return;   
193
      
194
      synchronized(lock)
195
        {
196
        mRenderer.apply(mEffectSwirl);
197
        mCurrEffect = EFFECT_SWIRL;
198
        }
199
      }
200
    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

  
203
    public void Abort()
204
      {
205
      synchronized(lock)
206
        {
207
        mRenderer.apply(null);
208
        mCenter.removeAll();
209
        mCenter.resetToBeginning();
210
        mCurrEffect = EFFECT_POINTS;
211
        mRenderer.setRefresh();
212
        }
213
      }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
 
217
    public void drawCurve(Canvas c, long time)
218
      {
219
      synchronized(lock)
220
        {  
221
        int len = mCenter.getNumPoints();
222

  
223
        float[] drawCoord = new float[3];
224
        Static3D cu;
225

  
226
        if( len>=2 )
227
          {
228
          final float step = (float)LOOP_TIME/(NUM_POINTS+1);
229

  
230
          for(int i=0; i<NUM_POINTS; i++)
231
            {
232
            mPaint.setColor( 0xffffffff );
233
            mCenter.get( drawCoord, 0, (long)(i*step), 0 );
234
            c.drawCircle( (drawCoord[0]+0.5f)*mScrWidth, 0.5f*mScrHeight-drawCoord[1]*mScrWidth, mSize1, mPaint );
235
            }
236
          }
237

  
238
        mPaint.setColor(0xffff0000);
239
      
240
        for(int curr=0; curr<len; curr++)
241
          {       
242
          cu = mCenter.getPoint(curr);
243
          c.drawCircle( (cu.get0()+0.5f)*mScrWidth, 0.5f*mScrHeight-cu.get1()*mScrWidth, mSize2, mPaint);
244
          }
245
        
246
        if( time-mTime > LOOP_TIME ) mTime = time;
247
        }
248
      }
249
       
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251
    
252
    @Override
253
    public boolean onTouchEvent(MotionEvent event)
254
      {
255
      if( mCurrEffect!=EFFECT_POINTS ) return true;   
256

  
257
      float xDown = event.getX()/mScrWidth - 0.5f;
258
      float yDown = (0.5f*mScrHeight - event.getY())/mScrWidth;
259

  
260
      switch(event.getAction())
261
        {
262
        case MotionEvent.ACTION_DOWN: float gx, gy;
263
                                      Static3D dv;
264
                                      int len = mCenter.getNumPoints();
265
                                 
266
                                      for(int g=0; g<len; g++)
267
                                        {
268
                                        dv = mCenter.getPoint(g);
269
                                        gx = dv.get0();
270
                                        gy = dv.get1();
271

  
272
                                        float Z = mDeform.get2()/7;
273

  
274
                                        if( (xDown-gx)*(xDown-gx) + (yDown-gy)*(yDown-gy) < Z*Z )
275
                                          {
276
                                          moving = g;
277
                                          break;
278
                                          }
279
                                        }
280
                                      if( moving<0 )
281
                                        {
282
                                        synchronized(lock)
283
                                          {
284
                                          mCenter.add(new Static3D(xDown,yDown,0));
285
                                          }
286
                                        }
287
                                      mRenderer.setRefresh();
288
                                      break;
289
        case MotionEvent.ACTION_MOVE: if( moving>=0 )
290
                                        {
291
                                        mCenter.setPoint(moving, xDown, yDown, 0);
292
                                        }
293
                                      mRenderer.setRefresh();
294
                                      break;
295
        case MotionEvent.ACTION_UP  : moving = -1;
296
                                      break;
297
        }
298
      return true;
299
      }
300
  }
src/main/res/values/strings.xml
217 217
    <string name="example_meshfile_subtitle">Explore Distorted\'s own Mesh format, dmesh. Open .dmesh files and explore their contents.</string>
218 218
    <string name="example_flatblur">Flat Blur</string>
219 219
    <string name="example_flatblur_subtitle">Unit test to see two partially obstructing flat objects, one of them blurred.</string>
220
    <string name="example_polymesh">Polygon Mesh</string>
221
    <string name="example_polymesh_subtitle">Test to be able to generate various polygon meshes with different parameters.</string>
220 222

  
221 223
    <string name="example_movingeffects_toast">Click on \'RESET\' and define your path by touching the screen. Then click on one of the effects and see it move along your path.</string>
222 224
    <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>

Also available in: Unified diff