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