1
|
|
2
|
package org.distorted.examples.effects3d;
|
3
|
|
4
|
import org.distorted.library.Distorted;
|
5
|
import org.distorted.examples.R;
|
6
|
|
7
|
import android.app.Activity;
|
8
|
import android.os.Bundle;
|
9
|
import android.opengl.GLSurfaceView;
|
10
|
import android.view.View;
|
11
|
import android.widget.LinearLayout;
|
12
|
import android.widget.SeekBar;
|
13
|
import android.widget.TextView;
|
14
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
15
|
|
16
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
17
|
|
18
|
public class Effects3DActivity extends Activity implements OnSeekBarChangeListener
|
19
|
{
|
20
|
public static final int MOVE =0;
|
21
|
public static final int SCALE =1;
|
22
|
public static final int ROTATE =2;
|
23
|
public static final int SHEAR =3;
|
24
|
|
25
|
private SeekBar bar;
|
26
|
private TextView textMove, textScale, textRotate, textShear;
|
27
|
private int moveX, moveY, moveZ;
|
28
|
private int scaleX, scaleY, scaleZ;
|
29
|
private int rotateX, rotateY, rotateZ, rotateA;
|
30
|
private int shearX, shearY, shearZ;
|
31
|
|
32
|
private int maxX, maxY, maxZ;
|
33
|
|
34
|
private float fmoveX, fmoveY, fmoveZ;
|
35
|
private float fscaleX, fscaleY, fscaleZ;
|
36
|
private float frotateX, frotateY, frotateZ, frotateA;
|
37
|
private float fshearX, fshearY, fshearZ;
|
38
|
|
39
|
private int[] effects = new int[4];
|
40
|
|
41
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42
|
|
43
|
@Override
|
44
|
protected void onCreate(Bundle icicle)
|
45
|
{
|
46
|
super.onCreate(icicle);
|
47
|
setContentView(R.layout.effects3dlayout);
|
48
|
Default(null);
|
49
|
}
|
50
|
|
51
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
52
|
|
53
|
public void Default(View view)
|
54
|
{
|
55
|
effects[0] = MOVE;
|
56
|
effects[1] = SCALE;
|
57
|
effects[2] = ROTATE;
|
58
|
effects[3] = SHEAR;
|
59
|
|
60
|
moveX = 50;
|
61
|
moveY = 50;
|
62
|
moveZ = 50;
|
63
|
|
64
|
scaleX = 50;
|
65
|
scaleY = 50;
|
66
|
scaleZ = 50;
|
67
|
|
68
|
rotateX = 100;
|
69
|
rotateY = 50;
|
70
|
rotateZ = 50;
|
71
|
rotateA = 50;
|
72
|
|
73
|
shearX = 50;
|
74
|
shearY = 50;
|
75
|
shearZ = 50;
|
76
|
|
77
|
addViews();
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
private void addViews()
|
83
|
{
|
84
|
LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
|
85
|
|
86
|
layout.removeAllViews();
|
87
|
|
88
|
View move = getLayoutInflater().inflate(R.layout.effects3dmove , null);
|
89
|
View scale = getLayoutInflater().inflate(R.layout.effects3dscale , null);
|
90
|
View rotate = getLayoutInflater().inflate(R.layout.effects3drotate , null);
|
91
|
View shear = getLayoutInflater().inflate(R.layout.effects3dshear , null);
|
92
|
|
93
|
for( int i=effects.length-1 ; i>=0 ; i-- )
|
94
|
{
|
95
|
switch(effects[i])
|
96
|
{
|
97
|
case MOVE : layout.addView(move , 0); break;
|
98
|
case SCALE : layout.addView(scale , 0); break;
|
99
|
case ROTATE: layout.addView(rotate , 0); break;
|
100
|
case SHEAR : layout.addView(shear , 0); break;
|
101
|
}
|
102
|
}
|
103
|
|
104
|
textMove = (TextView)findViewById(R.id.matrix3dmoveText);
|
105
|
textScale = (TextView)findViewById(R.id.matrix3dscaleText);
|
106
|
textRotate= (TextView)findViewById(R.id.matrix3drotateText);
|
107
|
textShear = (TextView)findViewById(R.id.matrix3dshearText);
|
108
|
|
109
|
setMoveText();
|
110
|
setScaleText();
|
111
|
setRotateText();
|
112
|
setShearText();
|
113
|
|
114
|
setBar(R.id.matrix3dmoveBar1, moveX);
|
115
|
setBar(R.id.matrix3dmoveBar2, moveY);
|
116
|
setBar(R.id.matrix3dmoveBar3, moveZ);
|
117
|
|
118
|
setBar(R.id.matrix3dscaleBar1, scaleX);
|
119
|
setBar(R.id.matrix3dscaleBar2, scaleY);
|
120
|
setBar(R.id.matrix3dscaleBar3, scaleZ);
|
121
|
|
122
|
setBar(R.id.matrix3drotateBar1, rotateX);
|
123
|
setBar(R.id.matrix3drotateBar2, rotateY);
|
124
|
setBar(R.id.matrix3drotateBar3, rotateZ);
|
125
|
setBar(R.id.matrix3drotateBar4, rotateA);
|
126
|
|
127
|
setBar(R.id.matrix3dshearBar1, shearX);
|
128
|
setBar(R.id.matrix3dshearBar2, shearY);
|
129
|
setBar(R.id.matrix3dshearBar3, shearZ);
|
130
|
|
131
|
Effects3DRenderer.setOrder(effects);
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
private void moveUp(int effect)
|
137
|
{
|
138
|
int len = effects.length-1;
|
139
|
int index = -1;
|
140
|
|
141
|
for(int i=0; i<=len; i++)
|
142
|
{
|
143
|
if( effects[i]==effect )
|
144
|
{
|
145
|
index=i;
|
146
|
break;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
if( index==0 )
|
151
|
{
|
152
|
for(int i=0; i<len; i++)
|
153
|
effects[i] = effects[i+1];
|
154
|
|
155
|
effects[len] = effect;
|
156
|
}
|
157
|
else if( index>0 )
|
158
|
{
|
159
|
effects[index] = effects[index-1];
|
160
|
effects[index-1] = effect;
|
161
|
}
|
162
|
|
163
|
addViews();
|
164
|
}
|
165
|
|
166
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167
|
|
168
|
public void ButtonMove(View v)
|
169
|
{
|
170
|
moveUp(MOVE);
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
public void ButtonScale(View v)
|
176
|
{
|
177
|
moveUp(SCALE);
|
178
|
}
|
179
|
|
180
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181
|
|
182
|
public void ButtonRotate(View v)
|
183
|
{
|
184
|
moveUp(ROTATE);
|
185
|
}
|
186
|
|
187
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188
|
|
189
|
public void ButtonShear(View v)
|
190
|
{
|
191
|
moveUp(SHEAR);
|
192
|
}
|
193
|
|
194
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195
|
|
196
|
private void setBar(int id, int value)
|
197
|
{
|
198
|
bar = (SeekBar)findViewById(id);
|
199
|
bar.setOnSeekBarChangeListener(this);
|
200
|
bar.setProgress(value);
|
201
|
}
|
202
|
|
203
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204
|
|
205
|
private void computeMove()
|
206
|
{
|
207
|
fmoveX = (moveX-50)*maxX/50.0f;
|
208
|
fmoveY = (moveY-50)*maxY/50.0f;
|
209
|
fmoveZ = (moveZ-50)*maxZ/50.0f;
|
210
|
|
211
|
Effects3DRenderer.setMove( fmoveX, fmoveY, fmoveZ);
|
212
|
}
|
213
|
|
214
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215
|
|
216
|
private void setMoveText()
|
217
|
{
|
218
|
fmoveX = ((int)(100*fmoveX))/100.0f;
|
219
|
fmoveY = ((int)(100*fmoveY))/100.0f;
|
220
|
fmoveZ = ((int)(100*fmoveZ))/100.0f;
|
221
|
|
222
|
textMove.setText("move("+fmoveX+" , "+fmoveY+" , "+fmoveZ+")");
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
private void computeScale()
|
228
|
{
|
229
|
fscaleX = (scaleX>50 ? 0.18f : 0.018f)*(scaleX-50)+1;
|
230
|
fscaleY = (scaleY>50 ? 0.18f : 0.018f)*(scaleY-50)+1;
|
231
|
fscaleZ = (scaleZ>50 ? 0.18f : 0.018f)*(scaleZ-50)+1;
|
232
|
|
233
|
Effects3DRenderer.setScale(fscaleX, fscaleY, fscaleZ);
|
234
|
}
|
235
|
|
236
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237
|
|
238
|
private void setScaleText()
|
239
|
{
|
240
|
fscaleX = ((int)(100*fscaleX))/100.0f;
|
241
|
fscaleY = ((int)(100*fscaleY))/100.0f;
|
242
|
fscaleZ = ((int)(100*fscaleZ))/100.0f;
|
243
|
|
244
|
textScale.setText("scale("+fscaleX+" , "+fscaleY+" , "+fscaleZ+")");
|
245
|
}
|
246
|
|
247
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248
|
|
249
|
private void computeRotate()
|
250
|
{
|
251
|
frotateX = (rotateX-50)/50.0f;
|
252
|
frotateY = (rotateY-50)/50.0f;
|
253
|
frotateZ = (rotateZ-50)/50.0f;
|
254
|
|
255
|
Effects3DRenderer.setRotate( frotateA, frotateX, frotateY, frotateZ );
|
256
|
}
|
257
|
|
258
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259
|
|
260
|
private void setRotateText()
|
261
|
{
|
262
|
frotateX = ((int)(100*frotateX))/100.0f;
|
263
|
frotateY = ((int)(100*frotateY))/100.0f;
|
264
|
frotateZ = ((int)(100*frotateZ))/100.0f;
|
265
|
|
266
|
frotateA = ((rotateA-50)*180)/50;
|
267
|
|
268
|
textRotate.setText("rotate( "+frotateA+" ("+frotateX+","+frotateY+","+frotateZ+") )");
|
269
|
}
|
270
|
|
271
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
272
|
|
273
|
private void computeShear()
|
274
|
{
|
275
|
fshearX = (shearX-50)/25.0f;
|
276
|
fshearY = (shearY-50)/25.0f;
|
277
|
fshearZ = (shearZ-50)/25.0f;
|
278
|
|
279
|
Effects3DRenderer.setShear( fshearX, fshearY, fshearZ );
|
280
|
}
|
281
|
|
282
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283
|
|
284
|
private void setShearText()
|
285
|
{
|
286
|
fshearX = ((int)(100*fshearX))/100.0f;
|
287
|
fshearY = ((int)(100*fshearY))/100.0f;
|
288
|
fshearZ = ((int)(100*fshearZ))/100.0f;
|
289
|
|
290
|
textShear.setText("shear("+fshearX+" , "+fshearY+" , "+fshearZ+")");
|
291
|
}
|
292
|
|
293
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
294
|
|
295
|
@Override
|
296
|
protected void onPause()
|
297
|
{
|
298
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView);
|
299
|
mView.onPause();
|
300
|
super.onPause();
|
301
|
}
|
302
|
|
303
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
304
|
|
305
|
@Override
|
306
|
protected void onResume()
|
307
|
{
|
308
|
super.onResume();
|
309
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView);
|
310
|
mView.onResume();
|
311
|
}
|
312
|
|
313
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
314
|
|
315
|
@Override
|
316
|
public void onWindowFocusChanged(boolean hasFocus)
|
317
|
{
|
318
|
super.onWindowFocusChanged(hasFocus);
|
319
|
|
320
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView);
|
321
|
|
322
|
maxX = mView.getWidth();
|
323
|
maxY = mView.getHeight();
|
324
|
maxZ = (maxX+maxY)/2;
|
325
|
}
|
326
|
|
327
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
328
|
|
329
|
@Override
|
330
|
protected void onDestroy()
|
331
|
{
|
332
|
Distorted.onDestroy();
|
333
|
super.onDestroy();
|
334
|
}
|
335
|
|
336
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337
|
|
338
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
339
|
{
|
340
|
switch (bar.getId())
|
341
|
{
|
342
|
case R.id.matrix3dmoveBar1 : moveX = progress; computeMove() ; setMoveText() ; break;
|
343
|
case R.id.matrix3dmoveBar2 : moveY = progress; computeMove() ; setMoveText() ; break;
|
344
|
case R.id.matrix3dmoveBar3 : moveZ = progress; computeMove() ; setMoveText() ; break;
|
345
|
|
346
|
case R.id.matrix3dscaleBar1 : scaleX= progress; computeScale() ; setScaleText() ; break;
|
347
|
case R.id.matrix3dscaleBar2 : scaleY= progress; computeScale() ; setScaleText() ; break;
|
348
|
case R.id.matrix3dscaleBar3 : scaleZ= progress; computeScale() ; setScaleText() ; break;
|
349
|
|
350
|
case R.id.matrix3drotateBar1: rotateX=progress; computeRotate(); setRotateText(); break;
|
351
|
case R.id.matrix3drotateBar2: rotateY=progress; computeRotate(); setRotateText(); break;
|
352
|
case R.id.matrix3drotateBar3: rotateZ=progress; computeRotate(); setRotateText(); break;
|
353
|
case R.id.matrix3drotateBar4: rotateA=progress; computeRotate(); setRotateText(); break;
|
354
|
|
355
|
case R.id.matrix3dshearBar1 : shearX= progress; computeShear() ; setShearText() ; break;
|
356
|
case R.id.matrix3dshearBar2 : shearY= progress; computeShear() ; setShearText() ; break;
|
357
|
case R.id.matrix3dshearBar3 : shearZ= progress; computeShear() ; setShearText() ; break;
|
358
|
}
|
359
|
}
|
360
|
|
361
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
362
|
|
363
|
public void onStartTrackingTouch(SeekBar bar) { }
|
364
|
|
365
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366
|
|
367
|
public void onStopTrackingTouch(SeekBar bar) { }
|
368
|
|
369
|
}
|