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