Project

General

Profile

Download (19.4 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / effects3d / Effects3DActivity.java @ fe7fe83e

1 08f92d82 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 76a81b6a Leszek Koltunski
package org.distorted.examples.effects3d;
21 08f92d82 Leszek Koltunski
22
import android.app.Activity;
23 9167cfd4 Leszek Koltunski
import android.graphics.Bitmap;
24
import android.graphics.BitmapFactory;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27 08f92d82 Leszek Koltunski
import android.opengl.GLSurfaceView;
28
import android.os.Bundle;
29 fe7fe83e Leszek Koltunski
import android.support.design.widget.TabLayout;
30
import android.support.v4.view.ViewPager;
31 d40cfeb2 Leszek Koltunski
import android.view.Gravity;
32 08f92d82 Leszek Koltunski
import android.view.View;
33 50ac40a6 Leszek Koltunski
import android.widget.AdapterView;
34
import android.widget.ArrayAdapter;
35 d40cfeb2 Leszek Koltunski
import android.widget.Button;
36 0ab55f0c Leszek Koltunski
import android.widget.CheckBox;
37 08f92d82 Leszek Koltunski
import android.widget.LinearLayout;
38 d40cfeb2 Leszek Koltunski
import android.widget.NumberPicker;
39 50ac40a6 Leszek Koltunski
import android.widget.Spinner;
40 d40cfeb2 Leszek Koltunski
import android.widget.TableRow;
41 08f92d82 Leszek Koltunski
42
import org.distorted.examples.R;
43 a418b421 Leszek Koltunski
import org.distorted.library.effect.EffectType;
44 01782e85 Leszek Koltunski
import org.distorted.library.main.Distorted;
45
import org.distorted.library.main.MeshCubes;
46
import org.distorted.library.main.MeshFlat;
47
import org.distorted.library.main.MeshObject;
48
import org.distorted.library.main.DistortedTexture;
49
import org.distorted.library.main.DistortedEffects;
50 56cbe1cf Leszek Koltunski
51 9167cfd4 Leszek Koltunski
import java.io.IOException;
52
import java.io.InputStream;
53 08f92d82 Leszek Koltunski
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55
56 76a81b6a Leszek Koltunski
public class Effects3DActivity extends Activity
57 fe7fe83e Leszek Koltunski
                               implements View.OnClickListener, AdapterView.OnItemSelectedListener
58 d40cfeb2 Leszek Koltunski
  {
59 50ac40a6 Leszek Koltunski
  private static final int COLOR_OFF = 0xffffe81f;
60
  private static final int COLOR_ON  = 0xff0000ff;
61 bfcf419a Leszek Koltunski
  private static final int COLOR_INAC= 0xff00ff00;
62 50ac40a6 Leszek Koltunski
63 56cbe1cf Leszek Koltunski
  private int mNumCols = 10;
64
  private int mNumRows = 10;
65 b3b2c6cf leszek
  private int mNumSlic =  1;
66 2e755580 Leszek Koltunski
  private boolean mGridInitialized;
67 b3b2c6cf leszek
  private NumberPicker mColsPicker, mRowsPicker, mSlicPicker;
68 50ac40a6 Leszek Koltunski
  private boolean[] mShape;
69 f6d884d5 Leszek Koltunski
  private DistortedTexture mTexture;
70 b01acdaf Leszek Koltunski
  private MeshObject mMesh;
71 bcc8e016 Leszek Koltunski
  private int mObjectType;
72 cdc515b9 Leszek Koltunski
  private int mBitmapID;
73
  private Bitmap mBitmap;
74 bfcf419a Leszek Koltunski
  private LinearLayout mLay;
75 d40cfeb2 Leszek Koltunski
76 334c13fa Leszek Koltunski
  private float mCenterX, mCenterY, mCenterZ;
77 6f779cd4 Leszek Koltunski
  private float mRegionX, mRegionY, mRegionR;
78 fe7fe83e Leszek Koltunski
  private DistortedEffects mEffects;
79
  private ViewPager mViewPager;
80
  private Effects3DTabViewPager mPager;
81 24991bc2 Leszek Koltunski
82 0ab55f0c Leszek Koltunski
  private static boolean mShowCenter = true;
83
  private static boolean mShowRegion = true;
84
  private static boolean mShowNormal = true;
85 bddd4b2d Leszek Koltunski
  private static boolean mUseOIT     = false;
86 0ab55f0c Leszek Koltunski
87 08f92d82 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
88 56cbe1cf Leszek Koltunski
89 d40cfeb2 Leszek Koltunski
  @Override
90
  protected void onCreate(Bundle savedState)
91
    {
92
    super.onCreate(savedState);
93
94 50ac40a6 Leszek Koltunski
    setContentView(R.layout.objectpickerlayout);
95 d40cfeb2 Leszek Koltunski
96 bddd4b2d Leszek Koltunski
    mLay = findViewById(R.id.objectpicker_buttongrid);
97 bfcf419a Leszek Koltunski
98 bddd4b2d Leszek Koltunski
    mColsPicker = findViewById(R.id.objectpicker_cols);
99
    mRowsPicker = findViewById(R.id.objectpicker_rows);
100
    mSlicPicker = findViewById(R.id.objectpicker_slices);
101 d40cfeb2 Leszek Koltunski
102 9758b1ec Leszek Koltunski
    mColsPicker.setMaxValue(40);
103 d40cfeb2 Leszek Koltunski
    mColsPicker.setMinValue( 0);
104 9758b1ec Leszek Koltunski
    mRowsPicker.setMaxValue(40);
105 d40cfeb2 Leszek Koltunski
    mRowsPicker.setMinValue( 0);
106 b3b2c6cf leszek
    mSlicPicker.setMaxValue(40);
107
    mSlicPicker.setMinValue( 0);
108 d40cfeb2 Leszek Koltunski
109
    mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
110 bfcf419a Leszek Koltunski
         {
111
         @Override
112
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
113
           {
114
           setGrid();
115
           }
116
         });
117 d40cfeb2 Leszek Koltunski
118
    mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
119 bfcf419a Leszek Koltunski
         {
120
         @Override
121
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
122
           {
123
           setGrid();
124
           }
125
         });
126 d40cfeb2 Leszek Koltunski
127 b3b2c6cf leszek
    mSlicPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
128
         {
129
         @Override
130
         public void onValueChange(NumberPicker picker, int oldVal, int newVal)
131
           {
132
           mNumSlic = mSlicPicker.getValue();
133
           }
134
         });
135
136 50ac40a6 Leszek Koltunski
    mObjectType = 0;
137 2e755580 Leszek Koltunski
    mGridInitialized = false;
138 d40cfeb2 Leszek Koltunski
139 bddd4b2d Leszek Koltunski
    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
140 50ac40a6 Leszek Koltunski
    typeSpinner.setOnItemSelectedListener(this);
141 d40cfeb2 Leszek Koltunski
142 bfcf419a Leszek Koltunski
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
143 d40cfeb2 Leszek Koltunski
144 bcc8e016 Leszek Koltunski
    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
145
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
146
    typeSpinner.setAdapter(adapterType);
147
148 bddd4b2d Leszek Koltunski
    Spinner bitmapSpinner  = findViewById(R.id.objectpicker_spinnerBitmap);
149 bcc8e016 Leszek Koltunski
    bitmapSpinner.setOnItemSelectedListener(this);
150
151 bfcf419a Leszek Koltunski
    String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
152
                                           "Texture: Squares", "Texture: Bean", "Texture: Lisa" };
153 bcc8e016 Leszek Koltunski
154
    ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
155
    adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
156
    bitmapSpinner.setAdapter(adapterBitmap);
157 d40cfeb2 Leszek Koltunski
    }
158
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
161 50ac40a6 Leszek Koltunski
  private void setGrid()
162 d40cfeb2 Leszek Koltunski
    {
163 2e755580 Leszek Koltunski
    mGridInitialized = true;
164
165 bfcf419a Leszek Koltunski
    mNumCols = mColsPicker.getValue();
166
    mNumRows = mRowsPicker.getValue();
167 d40cfeb2 Leszek Koltunski
168 bfcf419a Leszek Koltunski
    int width = mLay.getWidth();
169
    int height= mLay.getHeight();
170 57ba16f3 Leszek Koltunski
    int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
171
    int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
172 d40cfeb2 Leszek Koltunski
    int size= w<h ? w:h;
173 57ba16f3 Leszek Koltunski
    int pad = size<20 ? 1 : size/20;
174 d40cfeb2 Leszek Koltunski
175 bfcf419a Leszek Koltunski
    mLay.removeAllViews();
176 d40cfeb2 Leszek Koltunski
177
    mShape = new boolean[mNumRows*mNumCols];
178
179 56cbe1cf Leszek Koltunski
    TableRow.LayoutParams p = new TableRow.LayoutParams();
180 d40cfeb2 Leszek Koltunski
181
    p.rightMargin  = pad;
182
    p.leftMargin   = pad;
183
    p.topMargin    = pad;
184
    p.bottomMargin = pad;
185
    p.height       = size;
186
    p.width        = size;
187
188
    for (int rows=0; rows<mNumRows; rows++)
189 08f92d82 Leszek Koltunski
      {
190 d40cfeb2 Leszek Koltunski
      TableRow tr = new TableRow(this);
191
      tr.setGravity(Gravity.CENTER);
192
193
      for(int cols=0; cols<mNumCols; cols++)
194
        {
195
        Button b = new Button(this);
196
        b.setOnClickListener(this);
197
        b.setId(rows*mNumCols+cols);
198
        b.setLayoutParams(p);
199 bfcf419a Leszek Koltunski
        b.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
200 d40cfeb2 Leszek Koltunski
        tr.addView(b, p);
201 bcc8e016 Leszek Koltunski
        mShape[rows*mNumCols+cols] = true;
202 d40cfeb2 Leszek Koltunski
        }
203
204 bfcf419a Leszek Koltunski
      mLay.addView(tr);
205 d40cfeb2 Leszek Koltunski
      }
206
    }
207
208 50ac40a6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210 f6d884d5 Leszek Koltunski
  public DistortedTexture getTexture()
211 50ac40a6 Leszek Koltunski
    {
212 f6d884d5 Leszek Koltunski
    return mTexture;
213
    }
214
215 e8b6aa95 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
216
217 7fca6741 Leszek Koltunski
  public MeshObject getMesh()
218 e8b6aa95 Leszek Koltunski
    {
219 b01acdaf Leszek Koltunski
    return mMesh;
220 e8b6aa95 Leszek Koltunski
    }
221
222 d40cfeb2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
223
224 9167cfd4 Leszek Koltunski
  public Bitmap getBitmap()
225 d40cfeb2 Leszek Koltunski
    {
226 cdc515b9 Leszek Koltunski
    if( mBitmap==null )
227 9167cfd4 Leszek Koltunski
      {
228 cdc515b9 Leszek Koltunski
      if( mBitmapID!=-1)
229 9167cfd4 Leszek Koltunski
        {
230 cdc515b9 Leszek Koltunski
        InputStream is = getResources().openRawResource(mBitmapID);
231
232 9167cfd4 Leszek Koltunski
        try
233
          {
234 cdc515b9 Leszek Koltunski
          mBitmap = BitmapFactory.decodeStream(is);
235
          }
236
        finally
237
          {
238
          try
239
            {
240
            is.close();
241
            }
242
          catch(IOException e) { }
243 9167cfd4 Leszek Koltunski
          }
244
        }
245 cdc515b9 Leszek Koltunski
      else
246
        {
247 0ab55f0c Leszek Koltunski
        final int W = 64*mNumCols;
248
        final int H = 64*mNumRows;
249 9167cfd4 Leszek Koltunski
250 cdc515b9 Leszek Koltunski
        Paint paint = new Paint();
251
        mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
252
        Canvas canvas = new Canvas(mBitmap);
253 9167cfd4 Leszek Koltunski
254 cdc515b9 Leszek Koltunski
        paint.setAntiAlias(true);
255
        paint.setTextAlign(Paint.Align.CENTER);
256
        paint.setColor(0xff008800);
257
        paint.setStyle(Paint.Style.FILL);
258
        canvas.drawRect(0, 0, W, H, paint);
259
        paint.setColor(0xffffffff);
260 9167cfd4 Leszek Koltunski
261 0ab55f0c Leszek Koltunski
        for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
262
        for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W,  H*i/mNumRows+1, paint);
263 9167cfd4 Leszek Koltunski
        }
264
      }
265
266 cdc515b9 Leszek Koltunski
    return mBitmap;
267 d40cfeb2 Leszek Koltunski
    }
268
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
271 56cbe1cf Leszek Koltunski
  public void onClick(View view)
272 d40cfeb2 Leszek Koltunski
    {
273 bfcf419a Leszek Koltunski
    if( mObjectType!=1 )
274
      {
275
      Button tmp = (Button)view;
276
      int id = tmp.getId();
277
      mShape[id] = !mShape[id];
278
      tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
279
      }
280
    }
281
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
284
  private void uncheckAll()
285
    {
286
    TableRow tr;
287
    Button butt;
288
289
    for (int row=0; row<mNumRows; row++)
290
      {
291
      tr = (TableRow)mLay.getChildAt(row);
292
293
      for(int col=0; col<mNumCols; col++)
294
        {
295
        butt = (Button)tr.getVirtualChildAt(col);
296
        butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
297
        mShape[row*mNumCols+col] = true;
298
        }
299
      }
300 bcc8e016 Leszek Koltunski
    }
301
302 6f779cd4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
303
304
  public void setRegion(float x, float y, float r)
305
    {
306
    mRegionX = x;
307 24991bc2 Leszek Koltunski
    mRegionY =-y;
308 6f779cd4 Leszek Koltunski
    mRegionR = r;
309
310 bddd4b2d Leszek Koltunski
    Effects3DSurfaceView view = findViewById(R.id.effects3dSurfaceView);
311 6f779cd4 Leszek Koltunski
    view.getRenderer().setRegion(mRegionX, mRegionY, mRegionR);
312
    }
313
314 950511ed Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
315
316 334c13fa Leszek Koltunski
  public void setCenter(float x, float y, float z)
317 950511ed Leszek Koltunski
    {
318
    mCenterX = x;
319
    mCenterY = y;
320 334c13fa Leszek Koltunski
    mCenterZ = z;
321 950511ed Leszek Koltunski
322 bddd4b2d Leszek Koltunski
    Effects3DSurfaceView view = findViewById(R.id.effects3dSurfaceView);
323 334c13fa Leszek Koltunski
    view.getRenderer().setCenter( mCenterX, mCenterY, mCenterZ );
324 950511ed Leszek Koltunski
    }
325
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
328
  public float getCenterX()
329
    {
330
    return mCenterX;
331
    }
332
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334
335
  public float getCenterY()
336
    {
337
    return mCenterY;
338
    }
339
340 334c13fa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
341
342
  public float getCenterZ()
343
    {
344
    return mCenterZ;
345
    }
346
347 6f779cd4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
348
349
  public float getRegionX()
350
    {
351
    return mRegionX;
352
    }
353
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
356
  public float getRegionY()
357
    {
358
    return mRegionY;
359
    }
360
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362
363
  public float getRegionR()
364
    {
365
    return mRegionR;
366
    }
367
368 bcc8e016 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
369 50ac40a6 Leszek Koltunski
370 bfcf419a Leszek Koltunski
  public void Create(View v)
371 bcc8e016 Leszek Koltunski
    {
372 d76638f1 leszek
    DistortedEffects.setMax(EffectType.VERTEX ,20);    // those have to be called before
373
    DistortedEffects.setMax(EffectType.FRAGMENT,3);    // any DistortedEffect get created!
374 a98db446 Leszek Koltunski
375 50ac40a6 Leszek Koltunski
    if( mObjectType==1 )
376
      {
377 bfcf419a Leszek Koltunski
      mMesh = new MeshFlat(mNumCols,mNumRows);
378 50ac40a6 Leszek Koltunski
      }
379
    else
380
      {
381 bfcf419a Leszek Koltunski
      String str = "";
382 50ac40a6 Leszek Koltunski
383 bfcf419a Leszek Koltunski
      for(int i=0; i<mNumRows*mNumCols; i++)
384
        str += mShape[i] ? "1" : "0";
385 50ac40a6 Leszek Koltunski
386 b3b2c6cf leszek
      mMesh = new MeshCubes(mNumCols, str, mNumSlic);
387 50ac40a6 Leszek Koltunski
      }
388 bcc8e016 Leszek Koltunski
389 0ab55f0c Leszek Koltunski
    mMesh.setShowNormals(mShowNormal);
390 bfcf419a Leszek Koltunski
    mTexture= new DistortedTexture(mNumCols,mNumRows);
391 fe7fe83e Leszek Koltunski
    mEffects= new DistortedEffects();
392 bcc8e016 Leszek Koltunski
393 bfcf419a Leszek Koltunski
    final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
394 bcc8e016 Leszek Koltunski
395 bfcf419a Leszek Koltunski
    setContentView(view);
396 bcc8e016 Leszek Koltunski
397 fe7fe83e Leszek Koltunski
    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);
402 bfcf419a Leszek Koltunski
403 98c04ab8 leszek
    resetData();
404 d40cfeb2 Leszek Koltunski
    }
405
406 50ac40a6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
407
408
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
409
    {
410
    switch(parent.getId())
411
      {
412 bfcf419a Leszek Koltunski
      case R.id.objectpicker_spinnerType  : if( mObjectType!=pos )
413
                                              {
414
                                              mObjectType = pos;
415
                                              uncheckAll();
416
                                              }
417 56cbe1cf Leszek Koltunski
                                            break;
418 bcc8e016 Leszek Koltunski
      case R.id.objectpicker_spinnerBitmap: switch(pos)
419
                                              {
420 cdc515b9 Leszek Koltunski
                                              case 0: mBitmapID = -1        ; break;
421
                                              case 1: mBitmapID = R.raw.face; break;
422
                                              case 2: mBitmapID = R.raw.dog ; break;
423
                                              case 3: mBitmapID = R.raw.cat ; break;
424
                                              case 4: mBitmapID = R.raw.grid; break;
425
                                              case 5: mBitmapID = R.raw.bean; break;
426
                                              case 6: mBitmapID = R.raw.monalisa; break;
427 bcc8e016 Leszek Koltunski
                                              }
428
                                            break;
429 50ac40a6 Leszek Koltunski
      }
430
    }
431
432
///////////////////////////////////////////////////////////////////////////////////////////////////
433
434
  public void onNothingSelected(AdapterView<?> parent)
435
    {
436
    }
437
438 d40cfeb2 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
439
440 56cbe1cf Leszek Koltunski
  public int getWidth()
441 d40cfeb2 Leszek Koltunski
    {
442 f6d884d5 Leszek Koltunski
    return mTexture==null ? 0: mTexture.getWidth();
443 d40cfeb2 Leszek Koltunski
    }
444 08f92d82 Leszek Koltunski
445
///////////////////////////////////////////////////////////////////////////////////////////////////
446
447 56cbe1cf Leszek Koltunski
  public int getHeight()
448 d40cfeb2 Leszek Koltunski
    {
449 f6d884d5 Leszek Koltunski
    return mTexture==null ? 0: mTexture.getHeight();
450 d40cfeb2 Leszek Koltunski
    }
451 08f92d82 Leszek Koltunski
452 334c13fa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
453
454
  public int getDepth()
455
    {
456 b01acdaf Leszek Koltunski
    return mTexture==null ? 0: mTexture.getDepth(mMesh);
457 334c13fa Leszek Koltunski
    }
458
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
461
  public int getScreenWidth()
462
    {
463
    return 0;
464
    }
465
466 08f92d82 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
467
468 fe7fe83e Leszek Koltunski
  void resetData()
469 d40cfeb2 Leszek Koltunski
    {
470 950511ed Leszek Koltunski
    mCenterX = 0.5f*getWidth();
471
    mCenterY = 0.5f*getHeight();
472 6f779cd4 Leszek Koltunski
    mRegionX = 0;
473
    mRegionY = 0;
474
    mRegionR = getWidth()/2;
475 47833473 Leszek Koltunski
476 bddd4b2d Leszek Koltunski
    Effects3DSurfaceView view = findViewById(R.id.effects3dSurfaceView);
477 fe7fe83e Leszek Koltunski
    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);
483 6f779cd4 Leszek Koltunski
    }
484
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486
// 'second screen' methods
487 fe7fe83e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
488 6f779cd4 Leszek Koltunski
489 fe7fe83e Leszek Koltunski
  public DistortedEffects getEffects()
490 794e6c4f Leszek Koltunski
    {
491 fe7fe83e Leszek Koltunski
    return mEffects;
492
    }
493 950511ed Leszek Koltunski
494 fe7fe83e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
495 98c04ab8 leszek
496 fe7fe83e Leszek Koltunski
  public void newEffect(View v)
497
    {
498
    mPager.newEffect(v,mViewPager.getCurrentItem());
499 d2337a3a Leszek Koltunski
    }
500
501
///////////////////////////////////////////////////////////////////////////////////////////////////
502
503 56cbe1cf Leszek Koltunski
  public void removeAll(View v)
504 d2337a3a Leszek Koltunski
    {
505 fe7fe83e Leszek Koltunski
    mPager.removeAll(v,mViewPager.getCurrentItem());
506 d2337a3a Leszek Koltunski
    }
507
508 de82c8b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
509
510
  public void remove(View v)
511
    {
512 fe7fe83e Leszek Koltunski
    mPager.remove(v,mViewPager.getCurrentItem());
513 de82c8b7 Leszek Koltunski
    }
514
515 0ab55f0c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
516
517 fe7fe83e Leszek Koltunski
  boolean getShowCenter()
518
    {
519
    return mShowCenter;
520
    }
521 0ab55f0c Leszek Koltunski
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523
524 fe7fe83e Leszek Koltunski
  boolean getShowRegion()
525
    {
526
    return mShowRegion;
527
    }
528 0ab55f0c Leszek Koltunski
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530
531 fe7fe83e Leszek Koltunski
  public void showCenter(View view)
532
    {
533
    CheckBox box = (CheckBox)view;
534
    mShowCenter = box.isChecked();
535 0ab55f0c Leszek Koltunski
536 fe7fe83e Leszek Koltunski
    Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
537
    sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
538
    }
539 0ab55f0c Leszek Koltunski
540
///////////////////////////////////////////////////////////////////////////////////////////////////
541
542 fe7fe83e Leszek Koltunski
  public void showRegion(View view)
543
    {
544
    CheckBox box = (CheckBox)view;
545
    mShowRegion = box.isChecked();
546 0ab55f0c Leszek Koltunski
547 fe7fe83e Leszek Koltunski
    Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
548
    sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
549
    }
550 0ab55f0c Leszek Koltunski
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552
553 fe7fe83e Leszek Koltunski
  public void showNormal(View view)
554
    {
555
    CheckBox box = (CheckBox)view;
556
    mShowNormal = box.isChecked();
557 0ab55f0c Leszek Koltunski
558 fe7fe83e Leszek Koltunski
    if ( mMesh!=null )
559
      {
560
      mMesh.setShowNormals(mShowNormal);
561 0ab55f0c Leszek Koltunski
      }
562 fe7fe83e Leszek Koltunski
    }
563 0ab55f0c Leszek Koltunski
564 bddd4b2d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
565
566 fe7fe83e Leszek Koltunski
  public void triggerOIT(View view)
567
    {
568
    CheckBox box = (CheckBox)view;
569
    mUseOIT = box.isChecked();
570 bddd4b2d Leszek Koltunski
571 fe7fe83e Leszek Koltunski
    Effects3DSurfaceView sv = findViewById(R.id.effects3dSurfaceView);
572
    sv.getRenderer().useOIT(mUseOIT);
573
    }
574 bddd4b2d Leszek Koltunski
575 08f92d82 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
576 d40cfeb2 Leszek Koltunski
// Overrides
577 fe7fe83e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
578 d40cfeb2 Leszek Koltunski
579
  @Override
580
  protected void onPause()
581
    {
582 bddd4b2d Leszek Koltunski
    GLSurfaceView mView = findViewById(R.id.effects3dSurfaceView);
583 d40cfeb2 Leszek Koltunski
    if( mView!=null ) mView.onPause();
584 b0ebdf5e Leszek Koltunski
585
    Distorted.onPause();
586 d40cfeb2 Leszek Koltunski
    super.onPause();
587
    }
588 08f92d82 Leszek Koltunski
589
///////////////////////////////////////////////////////////////////////////////////////////////////
590
    
591 d40cfeb2 Leszek Koltunski
  @Override
592
  protected void onResume()
593
    {
594
    super.onResume();
595 bddd4b2d Leszek Koltunski
    GLSurfaceView mView = findViewById(R.id.effects3dSurfaceView);
596 d40cfeb2 Leszek Koltunski
    if( mView!=null ) mView.onResume();
597
    }
598 08f92d82 Leszek Koltunski
599
///////////////////////////////////////////////////////////////////////////////////////////////////
600
    
601 d40cfeb2 Leszek Koltunski
  @Override
602
  public void onWindowFocusChanged(boolean hasFocus)
603
    {
604
    super.onWindowFocusChanged(hasFocus);
605
606 bfcf419a Leszek Koltunski
    mColsPicker.setValue(mNumCols);
607
    mRowsPicker.setValue(mNumRows);
608 b3b2c6cf leszek
    mSlicPicker.setValue(mNumSlic);
609 bfcf419a Leszek Koltunski
610 2e755580 Leszek Koltunski
    if( !mGridInitialized ) setGrid();
611 d40cfeb2 Leszek Koltunski
    }
612 08f92d82 Leszek Koltunski
613
///////////////////////////////////////////////////////////////////////////////////////////////////
614
    
615 d40cfeb2 Leszek Koltunski
  @Override
616
  protected void onDestroy()
617
    {
618
    Distorted.onDestroy();
619
    super.onDestroy();
620
    }
621 08f92d82 Leszek Koltunski
622 d40cfeb2 Leszek Koltunski
  }