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.effects3d;
|
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.view.Gravity;
|
30
|
import android.view.View;
|
31
|
import android.widget.AdapterView;
|
32
|
import android.widget.ArrayAdapter;
|
33
|
import android.widget.Button;
|
34
|
import android.widget.CheckBox;
|
35
|
import android.widget.LinearLayout;
|
36
|
import android.widget.NumberPicker;
|
37
|
import android.widget.Spinner;
|
38
|
import android.widget.TableRow;
|
39
|
|
40
|
import org.distorted.examples.R;
|
41
|
import org.distorted.library.main.Distorted;
|
42
|
import org.distorted.library.main.MeshCubes;
|
43
|
import org.distorted.library.main.MeshFlat;
|
44
|
import org.distorted.library.main.MeshObject;
|
45
|
import org.distorted.library.main.DistortedTexture;
|
46
|
import org.distorted.library.main.DistortedEffects;
|
47
|
import org.distorted.library.EffectNames;
|
48
|
import org.distorted.library.EffectTypes;
|
49
|
|
50
|
import java.io.IOException;
|
51
|
import java.io.InputStream;
|
52
|
import java.util.ArrayList;
|
53
|
|
54
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
55
|
|
56
|
public class Effects3DActivity extends Activity
|
57
|
implements View.OnClickListener,
|
58
|
AdapterView.OnItemSelectedListener
|
59
|
{
|
60
|
private static final int COLOR_OFF = 0xffffe81f;
|
61
|
private static final int COLOR_ON = 0xff0000ff;
|
62
|
private static final int COLOR_INAC= 0xff00ff00;
|
63
|
|
64
|
private int mNumCols = 10;
|
65
|
private int mNumRows = 10;
|
66
|
private int mNumSlic = 1;
|
67
|
private boolean mGridInitialized;
|
68
|
private NumberPicker mColsPicker, mRowsPicker, mSlicPicker;
|
69
|
private boolean[] mShape;
|
70
|
private DistortedTexture mTexture;
|
71
|
private DistortedEffects mEffects;
|
72
|
private MeshObject mMesh;
|
73
|
private int mObjectType;
|
74
|
private int mBitmapID;
|
75
|
private Bitmap mBitmap;
|
76
|
private LinearLayout mLay;
|
77
|
|
78
|
private ArrayList<Effects3DEffect> mList;
|
79
|
private int mEffectAdd;
|
80
|
private float mCenterX, mCenterY, mCenterZ;
|
81
|
private float mRegionX, mRegionY, mRegionR;
|
82
|
|
83
|
private EffectNames[] mEffectNames;
|
84
|
|
85
|
private static boolean mSupportsRegion;
|
86
|
private static boolean mSupportsCenter;
|
87
|
|
88
|
private static boolean mShowCenter = true;
|
89
|
private static boolean mShowRegion = true;
|
90
|
private static boolean mShowNormal = true;
|
91
|
|
92
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
93
|
|
94
|
@Override
|
95
|
protected void onCreate(Bundle savedState)
|
96
|
{
|
97
|
super.onCreate(savedState);
|
98
|
|
99
|
mList = new ArrayList<>();
|
100
|
|
101
|
createEffectNames();
|
102
|
|
103
|
setContentView(R.layout.objectpickerlayout);
|
104
|
|
105
|
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
106
|
|
107
|
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
|
108
|
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
|
109
|
mSlicPicker = (NumberPicker)findViewById(R.id.objectpicker_slices);
|
110
|
|
111
|
mColsPicker.setMaxValue(40);
|
112
|
mColsPicker.setMinValue( 0);
|
113
|
mRowsPicker.setMaxValue(40);
|
114
|
mRowsPicker.setMinValue( 0);
|
115
|
mSlicPicker.setMaxValue(40);
|
116
|
mSlicPicker.setMinValue( 0);
|
117
|
|
118
|
mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
|
119
|
{
|
120
|
@Override
|
121
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
|
122
|
{
|
123
|
setGrid();
|
124
|
}
|
125
|
});
|
126
|
|
127
|
mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
|
128
|
{
|
129
|
@Override
|
130
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
|
131
|
{
|
132
|
setGrid();
|
133
|
}
|
134
|
});
|
135
|
|
136
|
mSlicPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
|
137
|
{
|
138
|
@Override
|
139
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
|
140
|
{
|
141
|
mNumSlic = mSlicPicker.getValue();
|
142
|
}
|
143
|
});
|
144
|
|
145
|
mObjectType = 0;
|
146
|
mGridInitialized = false;
|
147
|
|
148
|
Spinner typeSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerType);
|
149
|
typeSpinner.setOnItemSelectedListener(this);
|
150
|
|
151
|
String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
|
152
|
|
153
|
ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
|
154
|
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
155
|
typeSpinner.setAdapter(adapterType);
|
156
|
|
157
|
Spinner bitmapSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerBitmap);
|
158
|
bitmapSpinner.setOnItemSelectedListener(this);
|
159
|
|
160
|
String[] objectBitmap = new String[] { "Texture: Grid", "Texture: Girl", "Texture: Dog", "Texture: Cat",
|
161
|
"Texture: Squares", "Texture: Bean", "Texture: Lisa" };
|
162
|
|
163
|
ArrayAdapter<String> adapterBitmap = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectBitmap);
|
164
|
adapterBitmap.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
165
|
bitmapSpinner.setAdapter(adapterBitmap);
|
166
|
}
|
167
|
|
168
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
169
|
|
170
|
private void createEffectNames()
|
171
|
{
|
172
|
EffectTypes type1 = EffectTypes.FRAGMENT;
|
173
|
EffectTypes type2 = EffectTypes.VERTEX;
|
174
|
|
175
|
EffectNames[] names = EffectNames.values();
|
176
|
|
177
|
int numEffects=0;
|
178
|
|
179
|
for(int i=0; i<names.length; i++)
|
180
|
if( names[i].getType() == type1 || names[i].getType() == type2 ) numEffects++;
|
181
|
|
182
|
mEffectNames = new EffectNames[numEffects];
|
183
|
|
184
|
numEffects=0;
|
185
|
|
186
|
for(int i=0; i<names.length; i++)
|
187
|
if( names[i].getType() == type1 || names[i].getType() == type2 )
|
188
|
{
|
189
|
mEffectNames[numEffects++] = names[i];
|
190
|
}
|
191
|
}
|
192
|
|
193
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
194
|
|
195
|
private void setGrid()
|
196
|
{
|
197
|
mGridInitialized = true;
|
198
|
|
199
|
mNumCols = mColsPicker.getValue();
|
200
|
mNumRows = mRowsPicker.getValue();
|
201
|
|
202
|
int width = mLay.getWidth();
|
203
|
int height= mLay.getHeight();
|
204
|
int w = mNumCols>0 ? (int)( 0.9f*width / mNumCols) : 0;
|
205
|
int h = mNumRows>0 ? (int)( 0.9f*height/ mNumRows) : 0;
|
206
|
int size= w<h ? w:h;
|
207
|
int pad = size<20 ? 1 : size/20;
|
208
|
|
209
|
mLay.removeAllViews();
|
210
|
|
211
|
mShape = new boolean[mNumRows*mNumCols];
|
212
|
|
213
|
TableRow.LayoutParams p = new TableRow.LayoutParams();
|
214
|
|
215
|
p.rightMargin = pad;
|
216
|
p.leftMargin = pad;
|
217
|
p.topMargin = pad;
|
218
|
p.bottomMargin = pad;
|
219
|
p.height = size;
|
220
|
p.width = size;
|
221
|
|
222
|
for (int rows=0; rows<mNumRows; rows++)
|
223
|
{
|
224
|
TableRow tr = new TableRow(this);
|
225
|
tr.setGravity(Gravity.CENTER);
|
226
|
|
227
|
for(int cols=0; cols<mNumCols; cols++)
|
228
|
{
|
229
|
Button b = new Button(this);
|
230
|
b.setOnClickListener(this);
|
231
|
b.setId(rows*mNumCols+cols);
|
232
|
b.setLayoutParams(p);
|
233
|
b.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
|
234
|
tr.addView(b, p);
|
235
|
mShape[rows*mNumCols+cols] = true;
|
236
|
}
|
237
|
|
238
|
mLay.addView(tr);
|
239
|
}
|
240
|
}
|
241
|
|
242
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243
|
|
244
|
public DistortedTexture getTexture()
|
245
|
{
|
246
|
return mTexture;
|
247
|
}
|
248
|
|
249
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
250
|
|
251
|
public DistortedEffects getEffects()
|
252
|
{
|
253
|
return mEffects;
|
254
|
}
|
255
|
|
256
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
257
|
|
258
|
public MeshObject getMesh()
|
259
|
{
|
260
|
return mMesh;
|
261
|
}
|
262
|
|
263
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
264
|
|
265
|
public void setSupportsRegion(boolean supports)
|
266
|
{
|
267
|
mSupportsRegion = supports;
|
268
|
}
|
269
|
|
270
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271
|
|
272
|
public void setSupportsCenter(boolean supports)
|
273
|
{
|
274
|
mSupportsCenter = supports;
|
275
|
}
|
276
|
|
277
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278
|
|
279
|
public Bitmap getBitmap()
|
280
|
{
|
281
|
if( mBitmap==null )
|
282
|
{
|
283
|
if( mBitmapID!=-1)
|
284
|
{
|
285
|
InputStream is = getResources().openRawResource(mBitmapID);
|
286
|
|
287
|
try
|
288
|
{
|
289
|
mBitmap = BitmapFactory.decodeStream(is);
|
290
|
}
|
291
|
finally
|
292
|
{
|
293
|
try
|
294
|
{
|
295
|
is.close();
|
296
|
}
|
297
|
catch(IOException e) { }
|
298
|
}
|
299
|
}
|
300
|
else
|
301
|
{
|
302
|
final int W = 64*mNumCols;
|
303
|
final int H = 64*mNumRows;
|
304
|
|
305
|
Paint paint = new Paint();
|
306
|
mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
|
307
|
Canvas canvas = new Canvas(mBitmap);
|
308
|
|
309
|
paint.setAntiAlias(true);
|
310
|
paint.setTextAlign(Paint.Align.CENTER);
|
311
|
paint.setColor(0xff008800);
|
312
|
paint.setStyle(Paint.Style.FILL);
|
313
|
canvas.drawRect(0, 0, W, H, paint);
|
314
|
paint.setColor(0xffffffff);
|
315
|
|
316
|
for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
|
317
|
for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W, H*i/mNumRows+1, paint);
|
318
|
}
|
319
|
}
|
320
|
|
321
|
return mBitmap;
|
322
|
}
|
323
|
|
324
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
325
|
|
326
|
public void onClick(View view)
|
327
|
{
|
328
|
if( mObjectType!=1 )
|
329
|
{
|
330
|
Button tmp = (Button)view;
|
331
|
int id = tmp.getId();
|
332
|
mShape[id] = !mShape[id];
|
333
|
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
|
334
|
}
|
335
|
}
|
336
|
|
337
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
338
|
|
339
|
private void uncheckAll()
|
340
|
{
|
341
|
TableRow tr;
|
342
|
Button butt;
|
343
|
|
344
|
for (int row=0; row<mNumRows; row++)
|
345
|
{
|
346
|
tr = (TableRow)mLay.getChildAt(row);
|
347
|
|
348
|
for(int col=0; col<mNumCols; col++)
|
349
|
{
|
350
|
butt = (Button)tr.getVirtualChildAt(col);
|
351
|
butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
|
352
|
mShape[row*mNumCols+col] = true;
|
353
|
}
|
354
|
}
|
355
|
}
|
356
|
|
357
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
358
|
|
359
|
public void setRegion(float x, float y, float r)
|
360
|
{
|
361
|
mRegionX = x;
|
362
|
mRegionY =-y;
|
363
|
mRegionR = r;
|
364
|
|
365
|
Effects3DSurfaceView view = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
366
|
view.getRenderer().setRegion(mRegionX, mRegionY, mRegionR);
|
367
|
}
|
368
|
|
369
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
370
|
|
371
|
public void setCenter(float x, float y, float z)
|
372
|
{
|
373
|
mCenterX = x;
|
374
|
mCenterY = y;
|
375
|
mCenterZ = z;
|
376
|
|
377
|
Effects3DSurfaceView view = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
378
|
view.getRenderer().setCenter( mCenterX, mCenterY, mCenterZ );
|
379
|
}
|
380
|
|
381
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
382
|
|
383
|
public float getCenterX()
|
384
|
{
|
385
|
return mCenterX;
|
386
|
}
|
387
|
|
388
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389
|
|
390
|
public float getCenterY()
|
391
|
{
|
392
|
return mCenterY;
|
393
|
}
|
394
|
|
395
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
396
|
|
397
|
public float getCenterZ()
|
398
|
{
|
399
|
return mCenterZ;
|
400
|
}
|
401
|
|
402
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
403
|
|
404
|
public float getRegionX()
|
405
|
{
|
406
|
return mRegionX;
|
407
|
}
|
408
|
|
409
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
410
|
|
411
|
public float getRegionY()
|
412
|
{
|
413
|
return mRegionY;
|
414
|
}
|
415
|
|
416
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
417
|
|
418
|
public float getRegionR()
|
419
|
{
|
420
|
return mRegionR;
|
421
|
}
|
422
|
|
423
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
424
|
|
425
|
public void Create(View v)
|
426
|
{
|
427
|
DistortedEffects.setMaxVertex(20); // those have to be called before
|
428
|
DistortedEffects.setMaxFragment(3); // any DistortedEffect get created!
|
429
|
|
430
|
if( mObjectType==1 )
|
431
|
{
|
432
|
mMesh = new MeshFlat(mNumCols,mNumRows);
|
433
|
}
|
434
|
else
|
435
|
{
|
436
|
String str = "";
|
437
|
|
438
|
for(int i=0; i<mNumRows*mNumCols; i++)
|
439
|
str += mShape[i] ? "1" : "0";
|
440
|
|
441
|
mMesh = new MeshCubes(mNumCols, str, mNumSlic);
|
442
|
}
|
443
|
|
444
|
mMesh.setShowNormals(mShowNormal);
|
445
|
|
446
|
mEffects= new DistortedEffects();
|
447
|
mTexture= new DistortedTexture(mNumCols,mNumRows);
|
448
|
|
449
|
final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
|
450
|
|
451
|
setContentView(view);
|
452
|
|
453
|
String[] effects = new String[mEffectNames.length];
|
454
|
|
455
|
for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name();
|
456
|
|
457
|
Spinner effectSpinner = (Spinner)findViewById(R.id.effects3dspinner );
|
458
|
effectSpinner.setOnItemSelectedListener(this);
|
459
|
|
460
|
ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects);
|
461
|
adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
462
|
effectSpinner.setAdapter(adapterEffect);
|
463
|
|
464
|
resetData();
|
465
|
|
466
|
mEffectAdd = 0;
|
467
|
}
|
468
|
|
469
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
470
|
|
471
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
472
|
{
|
473
|
switch(parent.getId())
|
474
|
{
|
475
|
case R.id.objectpicker_spinnerType : if( mObjectType!=pos )
|
476
|
{
|
477
|
mObjectType = pos;
|
478
|
uncheckAll();
|
479
|
}
|
480
|
break;
|
481
|
case R.id.objectpicker_spinnerBitmap: switch(pos)
|
482
|
{
|
483
|
case 0: mBitmapID = -1 ; break;
|
484
|
case 1: mBitmapID = R.raw.face; break;
|
485
|
case 2: mBitmapID = R.raw.dog ; break;
|
486
|
case 3: mBitmapID = R.raw.cat ; break;
|
487
|
case 4: mBitmapID = R.raw.grid; break;
|
488
|
case 5: mBitmapID = R.raw.bean; break;
|
489
|
case 6: mBitmapID = R.raw.monalisa; break;
|
490
|
}
|
491
|
break;
|
492
|
case R.id.effects3dspinner : mEffectAdd = pos;
|
493
|
break;
|
494
|
}
|
495
|
}
|
496
|
|
497
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498
|
|
499
|
public void onNothingSelected(AdapterView<?> parent)
|
500
|
{
|
501
|
}
|
502
|
|
503
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
504
|
|
505
|
public int getWidth()
|
506
|
{
|
507
|
return mTexture==null ? 0: mTexture.getWidth();
|
508
|
}
|
509
|
|
510
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
511
|
|
512
|
public int getHeight()
|
513
|
{
|
514
|
return mTexture==null ? 0: mTexture.getHeight();
|
515
|
}
|
516
|
|
517
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
518
|
|
519
|
public int getDepth()
|
520
|
{
|
521
|
return mTexture==null ? 0: mTexture.getDepth(mMesh);
|
522
|
}
|
523
|
|
524
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
525
|
|
526
|
public int getScreenWidth()
|
527
|
{
|
528
|
return 0;
|
529
|
}
|
530
|
|
531
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
532
|
|
533
|
private void resetData()
|
534
|
{
|
535
|
mCenterX = 0.5f*getWidth();
|
536
|
mCenterY = 0.5f*getHeight();
|
537
|
mRegionX = 0;
|
538
|
mRegionY = 0;
|
539
|
mRegionR = getWidth()/2;
|
540
|
|
541
|
mSupportsRegion =false;
|
542
|
mSupportsCenter =false;
|
543
|
|
544
|
Effects3DSurfaceView view = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
545
|
view.getRenderer().showRegionAndCenter(false,false);
|
546
|
}
|
547
|
|
548
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
549
|
// 'second screen' methods
|
550
|
|
551
|
public void newEffect(View v)
|
552
|
{
|
553
|
Effects3DEffect eff = new Effects3DEffect(mEffectNames[mEffectAdd], this);
|
554
|
mList.add(eff);
|
555
|
|
556
|
LinearLayout layout = (LinearLayout)findViewById(R.id.effects3dlayout);
|
557
|
View view = eff.createView();
|
558
|
layout.addView(view);
|
559
|
|
560
|
if( mSupportsCenter )
|
561
|
{
|
562
|
View center = eff.createCenter();
|
563
|
layout.addView(center);
|
564
|
}
|
565
|
|
566
|
if( mSupportsRegion )
|
567
|
{
|
568
|
View region = eff.createRegion();
|
569
|
layout.addView(region);
|
570
|
}
|
571
|
|
572
|
eff.apply(mEffects);
|
573
|
|
574
|
boolean show = (mEffectNames[mEffectAdd].getType()==EffectTypes.VERTEX);
|
575
|
Effects3DSurfaceView sv = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
576
|
sv.getRenderer().showRegionAndCenter( (show && mShowRegion) , (show && mShowCenter) );
|
577
|
}
|
578
|
|
579
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
580
|
|
581
|
public void removeAll(View v)
|
582
|
{
|
583
|
mList.clear();
|
584
|
LinearLayout layout = (LinearLayout)findViewById(R.id.effects3dlayout);
|
585
|
layout.removeAllViews();
|
586
|
mEffects.abortEffects(EffectTypes.VERTEX);
|
587
|
mEffects.abortEffects(EffectTypes.FRAGMENT);
|
588
|
|
589
|
resetData();
|
590
|
|
591
|
Effects3DSurfaceView view = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
592
|
Effects3DRenderer renderer= view.getRenderer();
|
593
|
|
594
|
renderer.setCenter( mCenterX, mCenterY, mCenterZ );
|
595
|
renderer.setRegion( mRegionX, mRegionY, mRegionR );
|
596
|
renderer.mQuat1.set(0,0,0,1);
|
597
|
renderer.mQuat2.set(0,0,0,1);
|
598
|
}
|
599
|
|
600
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
601
|
|
602
|
public void remove(View v)
|
603
|
{
|
604
|
for(Effects3DEffect effect: mList)
|
605
|
{
|
606
|
if( effect.thisView(v) )
|
607
|
{
|
608
|
LinearLayout layout = (LinearLayout)findViewById(R.id.effects3dlayout);
|
609
|
View view;
|
610
|
|
611
|
view = effect.getEffect();
|
612
|
if( view!=null ) layout.removeView(view);
|
613
|
view = effect.getCenter();
|
614
|
if( view!=null ) layout.removeView(view);
|
615
|
view = effect.getRegion();
|
616
|
if( view!=null ) layout.removeView(view);
|
617
|
|
618
|
mEffects.abortEffect(effect.getId());
|
619
|
mList.remove(effect);
|
620
|
|
621
|
resetData();
|
622
|
|
623
|
break;
|
624
|
}
|
625
|
}
|
626
|
}
|
627
|
|
628
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
629
|
|
630
|
boolean getShowCenter()
|
631
|
{
|
632
|
return mShowCenter;
|
633
|
}
|
634
|
|
635
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
636
|
|
637
|
boolean getShowRegion()
|
638
|
{
|
639
|
return mShowRegion;
|
640
|
}
|
641
|
|
642
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
643
|
|
644
|
public void showCenter(View view)
|
645
|
{
|
646
|
CheckBox box = (CheckBox)view;
|
647
|
mShowCenter = box.isChecked();
|
648
|
|
649
|
Effects3DSurfaceView sv = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
650
|
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
|
651
|
}
|
652
|
|
653
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
654
|
|
655
|
public void showRegion(View view)
|
656
|
{
|
657
|
CheckBox box = (CheckBox)view;
|
658
|
mShowRegion = box.isChecked();
|
659
|
|
660
|
Effects3DSurfaceView sv = (Effects3DSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
661
|
sv.getRenderer().showRegionAndCenter(mShowRegion,mShowCenter);
|
662
|
}
|
663
|
|
664
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
665
|
|
666
|
public void showNormal(View view)
|
667
|
{
|
668
|
CheckBox box = (CheckBox)view;
|
669
|
mShowNormal = box.isChecked();
|
670
|
|
671
|
if ( mMesh!=null )
|
672
|
{
|
673
|
mMesh.setShowNormals(mShowNormal);
|
674
|
}
|
675
|
}
|
676
|
|
677
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
678
|
// Overrides
|
679
|
|
680
|
@Override
|
681
|
protected void onPause()
|
682
|
{
|
683
|
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
684
|
if( mView!=null ) mView.onPause();
|
685
|
|
686
|
Distorted.onPause();
|
687
|
super.onPause();
|
688
|
}
|
689
|
|
690
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
691
|
|
692
|
@Override
|
693
|
protected void onResume()
|
694
|
{
|
695
|
super.onResume();
|
696
|
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.effects3dSurfaceView);
|
697
|
if( mView!=null ) mView.onResume();
|
698
|
}
|
699
|
|
700
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
701
|
|
702
|
@Override
|
703
|
public void onWindowFocusChanged(boolean hasFocus)
|
704
|
{
|
705
|
super.onWindowFocusChanged(hasFocus);
|
706
|
|
707
|
mColsPicker.setValue(mNumCols);
|
708
|
mRowsPicker.setValue(mNumRows);
|
709
|
mSlicPicker.setValue(mNumSlic);
|
710
|
|
711
|
if( !mGridInitialized ) setGrid();
|
712
|
}
|
713
|
|
714
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
715
|
|
716
|
@Override
|
717
|
protected void onDestroy()
|
718
|
{
|
719
|
Distorted.onDestroy();
|
720
|
super.onDestroy();
|
721
|
}
|
722
|
|
723
|
}
|