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.vertex3d;
|
21
|
|
22
|
import android.app.Activity;
|
23
|
import android.opengl.GLSurfaceView;
|
24
|
import android.os.Bundle;
|
25
|
import android.view.View;
|
26
|
import android.widget.LinearLayout;
|
27
|
import android.widget.SeekBar;
|
28
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
29
|
import android.widget.TextView;
|
30
|
|
31
|
import org.distorted.examples.R;
|
32
|
import org.distorted.library.Distorted;
|
33
|
import org.distorted.library.EffectNames;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
public class Vertex3DActivity extends Activity implements OnSeekBarChangeListener
|
38
|
{
|
39
|
private SeekBar bar;
|
40
|
private TextView textDeform, textDistort, textSink, textSwirl;
|
41
|
private int deformX, deformY, deformZ;
|
42
|
private int distortX, distortY, distortZ;
|
43
|
private int sinkA;
|
44
|
private int swirlA;
|
45
|
|
46
|
private int maxX, maxY, maxZ;
|
47
|
|
48
|
private float fdeformX, fdeformY, fdeformZ;
|
49
|
private float fdistortX, fdistortY, fdistortZ;
|
50
|
private float fsinkA;
|
51
|
private float fswirlA;
|
52
|
|
53
|
private EffectNames[] effects = new EffectNames[4];
|
54
|
|
55
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
56
|
|
57
|
@Override
|
58
|
protected void onCreate(Bundle icicle)
|
59
|
{
|
60
|
super.onCreate(icicle);
|
61
|
setContentView(R.layout.vertex3dlayout);
|
62
|
Default(null);
|
63
|
}
|
64
|
|
65
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66
|
|
67
|
public void Default(View view)
|
68
|
{
|
69
|
effects[0] = EffectNames.DEFORM;
|
70
|
effects[1] = EffectNames.DISTORT;
|
71
|
effects[2] = EffectNames.SINK;
|
72
|
effects[3] = EffectNames.SWIRL;
|
73
|
|
74
|
deformX = 50;
|
75
|
deformY = 50;
|
76
|
deformZ = 50;
|
77
|
|
78
|
distortX = 50;
|
79
|
distortY = 50;
|
80
|
distortZ = 50;
|
81
|
|
82
|
sinkA = 50;
|
83
|
swirlA = 50;
|
84
|
|
85
|
addViews();
|
86
|
}
|
87
|
|
88
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
89
|
|
90
|
private void addViews()
|
91
|
{
|
92
|
LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout);
|
93
|
|
94
|
layout.removeAllViews();
|
95
|
|
96
|
View deform = getLayoutInflater().inflate(R.layout.vertex3ddeform , null);
|
97
|
View distort= getLayoutInflater().inflate(R.layout.vertex3ddistort, null);
|
98
|
View sink = getLayoutInflater().inflate(R.layout.vertex3dsink , null);
|
99
|
View swirl = getLayoutInflater().inflate(R.layout.vertex3dswirl , null);
|
100
|
|
101
|
for( int i=effects.length-1 ; i>=0 ; i-- )
|
102
|
{
|
103
|
switch(effects[i])
|
104
|
{
|
105
|
case DEFORM : layout.addView(deform , 0); break;
|
106
|
case DISTORT: layout.addView(distort, 0); break;
|
107
|
case SINK : layout.addView(sink , 0); break;
|
108
|
case SWIRL : layout.addView(swirl , 0); break;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
textDeform = (TextView)findViewById(R.id.vertex3ddeformText);
|
113
|
textDistort= (TextView)findViewById(R.id.vertex3ddistortText);
|
114
|
textSink = (TextView)findViewById(R.id.vertex3dsinkText);
|
115
|
textSwirl = (TextView)findViewById(R.id.vertex3dswirlText);
|
116
|
|
117
|
setDeformText();
|
118
|
setDistortText();
|
119
|
setSinkText();
|
120
|
setSwirlText();
|
121
|
|
122
|
setBar(R.id.vertex3ddeformBar1, deformX);
|
123
|
setBar(R.id.vertex3ddeformBar2, deformY);
|
124
|
setBar(R.id.vertex3ddeformBar3, deformZ);
|
125
|
|
126
|
setBar(R.id.vertex3ddistortBar1, distortX);
|
127
|
setBar(R.id.vertex3ddistortBar2, distortY);
|
128
|
setBar(R.id.vertex3ddistortBar3, distortZ);
|
129
|
|
130
|
setBar(R.id.vertex3dsinkBar1, sinkA);
|
131
|
|
132
|
setBar(R.id.vertex3dswirlBar1, swirlA);
|
133
|
|
134
|
Vertex3DRenderer.setOrder(effects);
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
private void moveUp(EffectNames name)
|
140
|
{
|
141
|
int len = effects.length-1;
|
142
|
int index = -1;
|
143
|
|
144
|
for(int i=0; i<=len; i++)
|
145
|
{
|
146
|
if( effects[i]==name )
|
147
|
{
|
148
|
index=i;
|
149
|
break;
|
150
|
}
|
151
|
}
|
152
|
|
153
|
if( index==0 )
|
154
|
{
|
155
|
for(int i=0; i<len; i++)
|
156
|
effects[i] = effects[i+1];
|
157
|
|
158
|
effects[len] = name;
|
159
|
}
|
160
|
else if( index>0 )
|
161
|
{
|
162
|
effects[index] = effects[index-1];
|
163
|
effects[index-1] = name;
|
164
|
}
|
165
|
|
166
|
addViews();
|
167
|
}
|
168
|
|
169
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
170
|
|
171
|
public void ButtonDeform(View v)
|
172
|
{
|
173
|
moveUp(EffectNames.DEFORM);
|
174
|
}
|
175
|
|
176
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
177
|
|
178
|
public void ButtonDistort(View v)
|
179
|
{
|
180
|
moveUp(EffectNames.DISTORT);
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
public void ButtonSink(View v)
|
186
|
{
|
187
|
moveUp(EffectNames.SINK);
|
188
|
}
|
189
|
|
190
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191
|
|
192
|
public void ButtonSwirl(View v)
|
193
|
{
|
194
|
moveUp(EffectNames.SWIRL);
|
195
|
}
|
196
|
|
197
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198
|
|
199
|
private void setBar(int id, int value)
|
200
|
{
|
201
|
bar = (SeekBar)findViewById(id);
|
202
|
bar.setOnSeekBarChangeListener(this);
|
203
|
bar.setProgress(value);
|
204
|
}
|
205
|
|
206
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
207
|
|
208
|
private void computeDeform()
|
209
|
{
|
210
|
fdeformX = (deformX-50)*maxX/50.0f;
|
211
|
fdeformY = (deformY-50)*maxY/50.0f;
|
212
|
fdeformZ = (deformZ-50)*maxZ/50.0f;
|
213
|
|
214
|
Vertex3DRenderer.setDeform( fdeformX, fdeformY, fdeformZ );
|
215
|
}
|
216
|
|
217
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
218
|
|
219
|
private void setDeformText()
|
220
|
{
|
221
|
fdeformX = ((int)(100*fdeformX))/100.0f;
|
222
|
fdeformY = ((int)(100*fdeformY))/100.0f;
|
223
|
fdeformZ = ((int)(100*fdeformZ))/100.0f;
|
224
|
|
225
|
textDeform.setText("deform("+fdeformX+" , "+fdeformY+" , "+fdeformZ+")");
|
226
|
}
|
227
|
|
228
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
229
|
|
230
|
private void computeDistort()
|
231
|
{
|
232
|
fdistortX = (distortX-50)*maxX/50.0f;
|
233
|
fdistortY = (distortY-50)*maxY/50.0f;
|
234
|
fdistortZ = (distortZ-50)*maxZ/50.0f;
|
235
|
|
236
|
Vertex3DRenderer.setDistort(fdistortX, fdistortY, fdistortZ);
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
|
241
|
private void setDistortText()
|
242
|
{
|
243
|
fdistortX = ((int)(100*fdistortX))/100.0f;
|
244
|
fdistortY = ((int)(100*fdistortY))/100.0f;
|
245
|
fdistortZ = ((int)(100*fdistortZ))/100.0f;
|
246
|
|
247
|
textDistort.setText("distort("+fdistortX+" , "+fdistortY+" , "+fdistortZ+")");
|
248
|
}
|
249
|
|
250
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
251
|
|
252
|
private void computeSink()
|
253
|
{
|
254
|
fsinkA = (sinkA>= 50 ? sinkA-49 : 1/(51-sinkA));
|
255
|
|
256
|
Vertex3DRenderer.setSink( fsinkA );
|
257
|
}
|
258
|
|
259
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
260
|
|
261
|
private void setSinkText()
|
262
|
{
|
263
|
fsinkA = ((int)(100*fsinkA))/100.0f;
|
264
|
|
265
|
textSink.setText("sink("+fsinkA+")");
|
266
|
}
|
267
|
|
268
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269
|
|
270
|
private void computeSwirl()
|
271
|
{
|
272
|
fswirlA = (swirlA-50)*3.6f;
|
273
|
|
274
|
Vertex3DRenderer.setSwirl( fswirlA );
|
275
|
}
|
276
|
|
277
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
278
|
|
279
|
private void setSwirlText()
|
280
|
{
|
281
|
fswirlA = ((int)(100*fswirlA))/100.0f;
|
282
|
|
283
|
textSwirl.setText("swirl("+fswirlA+")");
|
284
|
}
|
285
|
|
286
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
287
|
|
288
|
@Override
|
289
|
protected void onPause()
|
290
|
{
|
291
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.vertex3dSurfaceView);
|
292
|
mView.onPause();
|
293
|
super.onPause();
|
294
|
}
|
295
|
|
296
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
297
|
|
298
|
@Override
|
299
|
protected void onResume()
|
300
|
{
|
301
|
super.onResume();
|
302
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.vertex3dSurfaceView);
|
303
|
mView.onResume();
|
304
|
}
|
305
|
|
306
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
307
|
|
308
|
@Override
|
309
|
public void onWindowFocusChanged(boolean hasFocus)
|
310
|
{
|
311
|
super.onWindowFocusChanged(hasFocus);
|
312
|
|
313
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.vertex3dSurfaceView);
|
314
|
|
315
|
maxX = mView.getWidth();
|
316
|
maxY = mView.getHeight();
|
317
|
maxZ = (maxX+maxY)/2;
|
318
|
}
|
319
|
|
320
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
321
|
|
322
|
@Override
|
323
|
protected void onDestroy()
|
324
|
{
|
325
|
Distorted.onDestroy();
|
326
|
super.onDestroy();
|
327
|
}
|
328
|
|
329
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330
|
|
331
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
332
|
{
|
333
|
switch (bar.getId())
|
334
|
{
|
335
|
case R.id.vertex3ddeformBar1 : deformX= progress; computeDeform() ; setDeformText() ; break;
|
336
|
case R.id.vertex3ddeformBar2 : deformY= progress; computeDeform() ; setDeformText() ; break;
|
337
|
case R.id.vertex3ddeformBar3 : deformZ= progress; computeDeform() ; setDeformText() ; break;
|
338
|
|
339
|
case R.id.vertex3ddistortBar1 : distortX= progress; computeDistort(); setDistortText() ; break;
|
340
|
case R.id.vertex3ddistortBar2 : distortY= progress; computeDistort(); setDistortText() ; break;
|
341
|
case R.id.vertex3ddistortBar3 : distortZ= progress; computeDistort(); setDistortText() ; break;
|
342
|
|
343
|
case R.id.vertex3dsinkBar1 : sinkA = progress; computeSink() ; setSinkText() ; break;
|
344
|
|
345
|
case R.id.vertex3dswirlBar1 : swirlA = progress; computeSwirl() ; setSwirlText() ; break;
|
346
|
}
|
347
|
}
|
348
|
|
349
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
350
|
|
351
|
public void onStartTrackingTouch(SeekBar bar) { }
|
352
|
|
353
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
354
|
|
355
|
public void onStopTrackingTouch(SeekBar bar) { }
|
356
|
|
357
|
}
|