Project

General

Profile

« Previous | Next » 

Revision 77a500b3

Added by Leszek Koltunski over 5 years ago

Progress with Inflate (building block of postprocessing effects: the proper way of marking a halo around a Mesh)
'Inflate' app testing the machanism. MeshFlat appears to be working, now we only need to fill up the per-vertex Inflate vector in the MeshCubes.

View differences:

src/main/AndroidManifest.xml
50 50
        <activity android:name=".stencil.StencilActivity"/>
51 51
        <activity android:name=".glow.GlowActivity"/>
52 52
        <activity android:name=".movingglow.MovingGlowActivity"/>
53
        <activity android:name=".inflate.InflateActivity"/>
54
        <activity android:name=".inflate.InflateActivity2"/>
53 55
    </application>
54 56
</manifest>
src/main/java/org/distorted/examples/TableOfContents.java
68 68
import org.distorted.examples.stencil.StencilActivity;
69 69
import org.distorted.examples.glow.GlowActivity;
70 70
import org.distorted.examples.movingglow.MovingGlowActivity;
71
import org.distorted.examples.inflate.InflateActivity;
71 72

  
72 73
///////////////////////////////////////////////////////////////////////////////////////////////////
73 74

  
......
396 397
      activityMapping.put(i++, MovingGlowActivity.class);
397 398
   }
398 399

  
400
   {
401
   final Map<String, Object> item = new HashMap<>();
402
   item.put(ITEM_IMAGE, R.drawable.icon_example_wip);
403
   item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_inflate));
404
   item.put(ITEM_SUBTITLE, getText(R.string.example_inflate_subtitle));
405
   data.add(item);
406
   activityMapping.put(i++, InflateActivity.class);
407
   }
408

  
399 409
   final SimpleAdapter dataAdapter = new SimpleAdapter(this, data, R.layout.toc_item, new String[] {ITEM_IMAGE, ITEM_TITLE, ITEM_SUBTITLE}, new int[] {R.id.Image, R.id.Title, R.id.SubTitle});
400 410
   setListAdapter(dataAdapter);  
401 411
      
src/main/java/org/distorted/examples/inflate/InflateActivity.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.inflate;
21

  
22
import android.app.Activity;
23
import android.content.Intent;
24
import android.os.Bundle;
25
import android.view.Gravity;
26
import android.view.View;
27
import android.widget.AdapterView;
28
import android.widget.ArrayAdapter;
29
import android.widget.Button;
30
import android.widget.LinearLayout;
31
import android.widget.NumberPicker;
32
import android.widget.Spinner;
33
import android.widget.TableRow;
34

  
35
import org.distorted.examples.R;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39
public class InflateActivity extends Activity
40
                               implements View.OnClickListener, AdapterView.OnItemSelectedListener
41
  {
42
  private static final int COLOR_OFF = 0xffffe81f;
43
  private static final int COLOR_ON  = 0xff0000ff;
44
  private static final int COLOR_INAC= 0xff00ff00;
45

  
46
  private int mNumCols = 1;
47
  private int mNumRows = 1;
48
  private int mNumSlic = 1;
49
  private boolean mGridInitialized;
50
  private NumberPicker mColsPicker, mRowsPicker, mSlicPicker;
51
  private boolean[] mShape;
52
  private int mObjectType;
53
  private int mBitmapID;
54
  private LinearLayout mLay;
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
  @Override
59
  protected void onCreate(Bundle savedState)
60
    {
61
    super.onCreate(savedState);
62

  
63
    setContentView(R.layout.objectpickerlayout);
64

  
65
    mLay = findViewById(R.id.objectpicker_buttongrid);
66

  
67
    mColsPicker = findViewById(R.id.objectpicker_cols);
68
    mRowsPicker = findViewById(R.id.objectpicker_rows);
69
    mSlicPicker = findViewById(R.id.objectpicker_slices);
70

  
71
    mColsPicker.setMaxValue(40);
72
    mColsPicker.setMinValue( 0);
73
    mRowsPicker.setMaxValue(40);
74
    mRowsPicker.setMinValue( 0);
75
    mSlicPicker.setMaxValue(40);
76
    mSlicPicker.setMinValue( 0);
77

  
78
    mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
79
         {
80
         @Override
81
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
82
           {
83
           setGrid();
84
           }
85
         });
86

  
87
    mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
88
         {
89
         @Override
90
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
91
           {
92
           setGrid();
93
           }
94
         });
95

  
96
    mSlicPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
97
         {
98
         @Override
99
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
100
           {
101
           mNumSlic = mSlicPicker.getValue();
102
           }
103
         });
104

  
105
    mObjectType = 0;
106
    mGridInitialized = false;
107

  
108
    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
109
    typeSpinner.setOnItemSelectedListener(this);
110

  
111
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
112

  
113
    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
114
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
115
    typeSpinner.setAdapter(adapterType);
116

  
117
    Spinner bitmapSpinner  = findViewById(R.id.objectpicker_spinnerBitmap);
118
    bitmapSpinner.setOnItemSelectedListener(this);
119

  
120
    String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
121
                                           "Texture: Squares", "Texture: Bean", "Texture: Lisa" };
122

  
123
    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
124
    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
125
    bitmapSpinner.setAdapter(adapterBitmap);
126
    }
127

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

  
130
  private void setGrid()
131
    {
132
    mGridInitialized = true;
133

  
134
    mNumCols = mColsPicker.getValue();
135
    mNumRows = mRowsPicker.getValue();
136

  
137
    int width = mLay.getWidth();
138
    int height= mLay.getHeight();
139
    int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
140
    int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
141
    int size= w<h ? w:h;
142
    int pad = size<20 ? 1 : size/20;
143

  
144
    mLay.removeAllViews();
145

  
146
    mShape = new boolean[mNumRows*mNumCols];
147

  
148
    TableRow.LayoutParams p = new TableRow.LayoutParams();
149

  
150
    p.rightMargin  = pad;
151
    p.leftMargin   = pad;
152
    p.topMargin    = pad;
153
    p.bottomMargin = pad;
154
    p.height       = size;
155
    p.width        = size;
156

  
157
    for (int rows=0; rows<mNumRows; rows++)
158
      {
159
      TableRow tr = new TableRow(this);
160
      tr.setGravity(Gravity.CENTER);
161

  
162
      for(int cols=0; cols<mNumCols; cols++)
163
        {
164
        Button b = new Button(this);
165
        b.setOnClickListener(this);
166
        b.setId(rows*mNumCols+cols);
167
        b.setLayoutParams(p);
168
        b.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
169
        tr.addView(b, p);
170
        mShape[rows*mNumCols+cols] = true;
171
        }
172

  
173
      mLay.addView(tr);
174
      }
175
    }
176

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

  
179
  public void onClick(View view)
180
    {
181
    if( mObjectType!=1 )
182
      {
183
      Button tmp = (Button)view;
184
      int id = tmp.getId();
185
      mShape[id] = !mShape[id];
186
      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
187
      }
188
    }
189

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

  
192
  private void uncheckAll()
193
    {
194
    TableRow tr;
195
    Button butt;
196

  
197
    for (int row=0; row<mNumRows; row++)
198
      {
199
      tr = (TableRow)mLay.getChildAt(row);
200

  
201
      for(int col=0; col<mNumCols; col++)
202
        {
203
        butt = (Button)tr.getVirtualChildAt(col);
204
        butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
205
        mShape[row*mNumCols+col] = true;
206
        }
207
      }
208
    }
209

  
210
///////////////////////////////////////////////////////////////////////////////////////////////////
211

  
212
  public void Create(View v)
213
    {
214
    Intent mainInt = new Intent( getApplicationContext(), InflateActivity2.class);
215
    Bundle b = new Bundle();
216

  
217
    b.putInt("type", mObjectType);
218
    b.putInt("cols", mNumCols);
219
    b.putInt("rows", mNumRows);
220
    b.putInt("slices", mNumSlic);
221
    b.putInt("bitmap", mBitmapID);
222

  
223
    if( mObjectType==1 )
224
      {
225
      b.putString("string", "");
226
      }
227
    else
228
      {
229
      String str = "";
230

  
231
      for(int i=0; i<mNumRows*mNumCols; i++)
232
        str += mShape[i] ? "1" : "0";
233

  
234
      b.putString("string", str);
235
      }
236

  
237
    mainInt.putExtras(b);
238
    startActivity(mainInt);
239
    }
240

  
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

  
243
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
244
    {
245
    switch(parent.getId())
246
      {
247
      case R.id.objectpicker_spinnerType  : if( mObjectType!=pos )
248
                                              {
249
                                              mObjectType = pos;
250
                                              uncheckAll();
251
                                              }
252
                                            break;
253
      case R.id.objectpicker_spinnerBitmap: switch(pos)
254
                                              {
255
                                              case 0: mBitmapID = -1        ; break;
256
                                              case 1: mBitmapID = R.raw.face; break;
257
                                              case 2: mBitmapID = R.raw.dog ; break;
258
                                              case 3: mBitmapID = R.raw.cat ; break;
259
                                              case 4: mBitmapID = R.raw.grid; break;
260
                                              case 5: mBitmapID = R.raw.bean; break;
261
                                              case 6: mBitmapID = R.raw.monalisa; break;
262
                                              }
263
                                            break;
264
      }
265
    }
266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

  
269
  public void onNothingSelected(AdapterView<?> parent)
270
    {
271
    }
272

  
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274
// Overrides
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276

  
277
  @Override
278
  public void onWindowFocusChanged(boolean hasFocus)
279
    {
280
    super.onWindowFocusChanged(hasFocus);
281

  
282
    mColsPicker.setValue(mNumCols);
283
    mRowsPicker.setValue(mNumRows);
284
    mSlicPicker.setValue(mNumSlic);
285

  
286
    if( !mGridInitialized ) setGrid();
287
    }
288
  }
src/main/java/org/distorted/examples/inflate/InflateActivity2.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.inflate;
21

  
22
import android.app.Activity;
23
import android.graphics.Bitmap;
24
import android.graphics.BitmapFactory;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.opengl.GLSurfaceView;
28
import android.os.Bundle;
29
import android.widget.SeekBar;
30
import android.widget.TextView;
31

  
32
import org.distorted.examples.R;
33
import org.distorted.library.main.Distorted;
34
import org.distorted.library.main.DistortedTexture;
35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshCubes;
37
import org.distorted.library.mesh.MeshFlat;
38

  
39
import java.io.IOException;
40
import java.io.InputStream;
41

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

  
44
public class InflateActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener
45
{
46
    private DistortedTexture mTexture;
47
    private MeshBase mMesh;
48
    private TextView mTextLevel;
49
    private int mBitmapID;
50
    private Bitmap mBitmap;
51
    private int mNumCols;
52
    private int mNumRows;
53
    private int mNumSlic;
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56
    
57
    @Override
58
    protected void onPause() 
59
      {
60
      GLSurfaceView mView = this.findViewById(R.id.inflateSurfaceView);
61
      if( mView!=null ) mView.onPause();
62

  
63
      Distorted.onPause();
64
      super.onPause();
65
      }
66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68
    
69
    @Override
70
    protected void onResume() 
71
      {
72
      super.onResume();
73
      
74
      GLSurfaceView mView = this.findViewById(R.id.inflateSurfaceView);
75
      if( mView!=null ) mView.onResume();  
76
      }
77
    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79
    
80
    @Override
81
    protected void onDestroy() 
82
      {
83
      Distorted.onDestroy();  
84
      super.onDestroy();
85
      }
86
 
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

  
89
    @Override
90
    protected void onCreate(Bundle savedState)
91
      {
92
      super.onCreate(savedState);
93

  
94
      Bundle b = getIntent().getExtras();
95

  
96
      String str     = b.getString("string");
97
      int objectType = b.getInt("type");
98
      mNumCols       = b.getInt("cols");
99
      mNumRows       = b.getInt("rows");
100
      mNumSlic       = b.getInt("slices");
101
      mBitmapID      = b.getInt("bitmap");
102

  
103
      if( objectType==1 ) mMesh = new MeshFlat(mNumCols,mNumRows);
104
      else                mMesh = new MeshCubes(mNumCols, str, mNumSlic);
105

  
106
      mTexture= new DistortedTexture(mNumCols,mNumRows);
107

  
108
      setContentView(R.layout.inflatelayout);
109

  
110
      mTextLevel = (TextView)findViewById(R.id.inflateText);
111
      SeekBar levelBar = findViewById(R.id.inflateLevel);
112
      levelBar.setOnSeekBarChangeListener(this);
113

  
114
      InflateSurfaceView view = this.findViewById(R.id.inflateSurfaceView);
115
      float level = view.getRenderer().setLevel(50);
116
      mTextLevel.setText(getString(R.string.inflate_placeholder, level));
117
      levelBar.setProgress(50);
118
      }
119

  
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

  
123
    public Bitmap getBitmap()
124
      {
125
      if( mBitmap==null )
126
        {
127
        if( mBitmapID!=-1)
128
          {
129
          InputStream is = getResources().openRawResource(mBitmapID);
130

  
131
          try
132
            {
133
            mBitmap = BitmapFactory.decodeStream(is);
134
            }
135
          finally
136
            {
137
            try
138
              {
139
              is.close();
140
              }
141
            catch(IOException e) { }
142
            }
143
          }
144
        else
145
          {
146
          final int W = 64*mNumCols;
147
          final int H = 64*mNumRows;
148

  
149
          Paint paint = new Paint();
150
          mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
151
          Canvas canvas = new Canvas(mBitmap);
152

  
153
          paint.setAntiAlias(true);
154
          paint.setTextAlign(Paint.Align.CENTER);
155
          paint.setColor(0xff008800);
156
          paint.setStyle(Paint.Style.FILL);
157
          canvas.drawRect(0, 0, W, H, paint);
158
          paint.setColor(0xffffffff);
159

  
160
          for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
161
          for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W,  H*i/mNumRows+1, paint);
162
          }
163
        }
164

  
165
      return mBitmap;
166
      }
167

  
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

  
170
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
171
      {
172
      switch (bar.getId())
173
        {
174
        case R.id.inflateLevel: InflateSurfaceView view = this.findViewById(R.id.inflateSurfaceView);
175
                                float level = view.getRenderer().setLevel(progress);
176
                                mTextLevel.setText(getString(R.string.inflate_placeholder, level));
177
                                break;
178
        }
179
      }
180

  
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

  
183
    public void onStartTrackingTouch(SeekBar bar) { }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
    public void onStopTrackingTouch(SeekBar bar)  { }
188

  
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

  
191
    public DistortedTexture getTexture()
192
      {
193
      return mTexture;
194
      }
195

  
196
///////////////////////////////////////////////////////////////////////////////////////////////////
197

  
198
    public MeshBase getMesh()
199
      {
200
      return mMesh;
201
      }
202
}
src/main/java/org/distorted/examples/inflate/InflateRenderer.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.inflate;
21

  
22
import android.opengl.GLSurfaceView;
23

  
24
import org.distorted.library.effect.MatrixEffectMove;
25
import org.distorted.library.effect.MatrixEffectQuaternion;
26
import org.distorted.library.effect.MatrixEffectScale;
27
import org.distorted.library.main.Distorted;
28
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedScreen;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.type.DynamicQuat;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35

  
36
import javax.microedition.khronos.egl.EGLConfig;
37
import javax.microedition.khronos.opengles.GL10;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
class InflateRenderer implements GLSurfaceView.Renderer
42
{
43
    private GLSurfaceView mView;
44
    private DistortedTexture mTexture;
45
    private DistortedEffects mEffects;
46
    private MeshBase mMesh;
47
    private DistortedScreen mScreen;
48
    private int mObjWidth, mObjHeight, mObjDepth;
49
    private Static3D mMove, mScale, mCenter;
50

  
51
    Static4D mQuat1, mQuat2;
52
    int mScreenMin;
53

  
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

  
56
    InflateRenderer(GLSurfaceView v)
57
      {
58
      mView = v;
59

  
60
      mMove = new Static3D(0,0,0);
61
      mScale= new Static3D(1,1,1);
62
      mCenter=new Static3D(0,0,0);
63

  
64
      InflateActivity2 act = (InflateActivity2)v.getContext();
65

  
66
      mTexture = act.getTexture();
67
      mMesh    = act.getMesh();
68

  
69
      mObjWidth = mTexture.getWidth();
70
      mObjHeight= mTexture.getHeight();
71
      mObjDepth = mTexture.getDepth(mMesh);
72

  
73
      mQuat1 = new Static4D(0,0,0,1);  // unity
74
      mQuat2 = new Static4D(0,0,0,1);  // quaternions
75
      
76
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
77
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
78

  
79
      quatInt1.add(mQuat1);
80
      quatInt2.add(mQuat2);
81

  
82
      mEffects = new DistortedEffects();
83
      mEffects.apply( new MatrixEffectMove(mMove) );
84
      mEffects.apply( new MatrixEffectScale(mScale));
85
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, mCenter) );
86
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, mCenter) );
87

  
88
      mScreen = new DistortedScreen();
89
      mScreen.glClearColor(1.0f,1.0f,1.0f,0.0f);
90
      }
91

  
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
   
94
    public void onDrawFrame(GL10 glUnused) 
95
      {
96
      mScreen.render( System.currentTimeMillis() );
97
      }
98

  
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
    
101
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
102
      {
103
      mScreenMin = width<height ? width:height;
104
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.75f*height)/mObjHeight :  (0.75f*width)/mObjWidth;
105
      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
106
      mScale.set(factor,factor,factor);
107
      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );
108
      mScreen.resize(width, height);
109
      }
110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
    float setLevel(int level)
114
      {
115
      float inflateLevel = (level-50)/50.0f;
116
      mMesh.setInflate(inflateLevel);
117

  
118
      return inflateLevel;
119
      }
120

  
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122
    
123
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
124
      {
125
      InflateActivity2 act = (InflateActivity2)mView.getContext();
126

  
127
      mTexture.setTexture( act.getBitmap() );
128

  
129
      mScreen.detachAll();
130
      mScreen.attach(mTexture,mEffects,mMesh);
131

  
132
      try
133
        {
134
        Distorted.onCreate(mView.getContext());
135
        }
136
      catch(Exception ex)
137
        {
138
        android.util.Log.e("Inflate", ex.getMessage() );
139
        }
140
      }
141
}
src/main/java/org/distorted/examples/inflate/InflateSurfaceView.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.inflate;
21

  
22
import android.app.ActivityManager;
23
import android.content.Context;
24
import android.content.pm.ConfigurationInfo;
25
import android.opengl.GLSurfaceView;
26
import android.util.AttributeSet;
27
import android.view.MotionEvent;
28
import android.widget.Toast;
29

  
30
import org.distorted.examples.R;
31

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

  
34
class InflateSurfaceView extends GLSurfaceView
35
{
36
    private int mX, mY;
37
    private InflateRenderer mRenderer;
38
	
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40
   
41
    public InflateSurfaceView(Context context, AttributeSet attrs)
42
      {
43
      super(context,attrs);
44
    
45
      mX = -1;
46
      mY = -1;
47
      
48
      if(!isInEditMode())
49
        {
50
        mRenderer = new InflateRenderer(this);
51
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
52
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
53
        setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
54
        setRenderer(mRenderer);
55
        Toast.makeText(context, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show();
56
        }
57
      }
58

  
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60

  
61
    public InflateRenderer getRenderer()
62
      {
63
      return mRenderer;
64
      }
65

  
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67
    
68
    @Override public boolean onTouchEvent(MotionEvent event) 
69
      {
70
      int action = event.getAction();
71
      int x = (int)event.getX();
72
      int y = (int)event.getY();
73
           
74
      switch(action)
75
         {
76
         case MotionEvent.ACTION_DOWN: mX = x;
77
                                       mY = y;
78
                                       break;
79
                                       
80
         case MotionEvent.ACTION_MOVE: if( mX>=0 && mY>= 0 )
81
                                         {
82
                                         float px = mY-y;
83
                                         float py = mX-x;
84
                                         float pz = 0;
85
                                         float plen = (float)Math.sqrt(px*px + py*py + pz*pz);
86
                                         
87
                                         if( plen>0 )
88
                                           {
89
                                           px /= plen;
90
                                           py /= plen;
91
                                           pz /= plen;
92

  
93
                                           float cosA = (float)Math.cos(plen*3.14f/mRenderer.mScreenMin);
94
                                           float sinA = (float)Math.sqrt(1-cosA*cosA);
95
                                         
96
                                           mRenderer.mQuat1.set(px*sinA, py*sinA, pz*sinA, cosA);
97
                                           }
98
                                         }                             
99
                                       break;
100
                                       
101
         case MotionEvent.ACTION_UP  : mX = -1;
102
                                       mY = -1;
103
        	                           
104
                                       float qx = mRenderer.mQuat1.get1();
105
                                       float qy = mRenderer.mQuat1.get2();
106
                                       float qz = mRenderer.mQuat1.get3();
107
                                       float qw = mRenderer.mQuat1.get4();
108

  
109
                                       float rx = mRenderer.mQuat2.get1();
110
                                       float ry = mRenderer.mQuat2.get2();
111
                                       float rz = mRenderer.mQuat2.get3();
112
                                       float rw = mRenderer.mQuat2.get4();
113

  
114
                                       // This is quaternion multiplication. (tx,ty,tz,tw)
115
                                       // is now equal to (qx,qy,qz,qw)*(rx,ry,rz,rw)
116
                                       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
117
                                       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
118
                                       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
119
                                       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
120

  
121
                                       // The point of this is so that there are always
122
                                       // exactly 2 quaternions: Quat1 representing the rotation
123
                                       // accumulating only since the last screen touch, and Quat2
124
                                       // which remembers the combined effect of all previous
125
                                       // swipes.
126
                                       // We cannot be accumulating an ever-growing list of quaternions
127
                                       // and add a new one every time user swipes the screen - there
128
                                       // is a limited number of slots in the EffectQueueMatrix!
129
                                       mRenderer.mQuat1.set(0f, 0f, 0f, 1f);
130
                                       mRenderer.mQuat2.set(tx, ty, tz, tw);
131
                                       
132
                                       break;
133
         }
134
             
135
      return true;
136
      }
137
         
138
}
139

  
src/main/res/layout/inflatelayout.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
    android:layout_width="fill_parent"
4
    android:layout_height="fill_parent"
5
    android:gravity="center_horizontal"
6
    android:orientation="vertical" >
7

  
8
    <org.distorted.examples.inflate.InflateSurfaceView
9
        android:id="@+id/inflateSurfaceView"
10
        android:layout_width="match_parent"
11
        android:layout_height="0dp"
12
        android:layout_weight="1.00" />
13

  
14
    <LinearLayout
15
        android:id="@+id/linearLayout"
16
        android:layout_width="fill_parent"
17
        android:layout_height="wrap_content"
18
        android:gravity="center|fill_horizontal"
19
        android:orientation="horizontal"
20
        android:background="@color/blue">
21

  
22
        <TextView
23
            android:id="@+id/inflateText"
24
            android:layout_width="0dp"
25
            android:layout_height="wrap_content"
26
            android:layout_weight="0.3"
27
            android:paddingLeft="10dp"
28
            android:text="@string/inflate" />
29

  
30
        <SeekBar
31
            android:id="@+id/inflateLevel"
32
            android:layout_weight="0.7"
33
            android:layout_width="0dp"
34
            android:layout_height="50dp"
35
            android:paddingLeft="10dp"
36
            android:paddingRight="10dp" />
37

  
38
    </LinearLayout>
39

  
40
</LinearLayout>
src/main/res/values/strings.xml
75 75
    <string name="screen">Screen</string>
76 76
    <string name="framebuffer">Framebuffer</string>
77 77
    <string name="matrixautomatic">Automatic Matrix Effects</string>
78
    <string name="inflate">Inflate</string>
78 79

  
79 80
    <string name="quality0">Highest</string>
80 81
    <string name="quality1">High</string>
......
104 105
    <string name="blur_placeholder">Blur: %1$d</string>
105 106
    <string name="glow_radius_placeholder">Radius: %1$d</string>
106 107
    <string name="glow_alpha_placeholder">Alpha: %1$.2f</string>
108
    <string name="inflate_placeholder">Inflate: %1$.2f</string>
107 109

  
108 110
    <string name="example_monalisa">Mona Lisa</string>
109 111
    <string name="example_monalisa_subtitle">The basics of Distortions.</string>
......
173 175
    <string name="example_glow_subtitle">Leaf glowing with light.</string>
174 176
    <string name="example_moving_glow">Glow Effect</string>
175 177
    <string name="example_moving_glow_subtitle">See moving objects glowing with light.</string>
176
    <string name="example_mali">Debug Mali GPU</string>
177
    <string name="example_mali_subtitle">Self-contained app to try and debug issues on Mali GPU</string>
178
    <string name="example_inflate">Debug Inflating the Mesh</string>
179
    <string name="example_inflate_subtitle">Just a test appliacation for the developers of the library to test the Inflate mechanism.</string>
178 180

  
179 181
    <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>
180 182
    <string name="example_rotate_toast">Rotate the scene by swiping the screen</string>

Also available in: Unified diff