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.dynamic;
|
21
|
|
22
|
import org.distorted.library.main.Distorted;
|
23
|
import org.distorted.library.type.Dynamic1D;
|
24
|
import org.distorted.examples.R;
|
25
|
|
26
|
import android.app.Activity;
|
27
|
import android.opengl.GLSurfaceView;
|
28
|
import android.os.Bundle;
|
29
|
import android.view.View;
|
30
|
import android.widget.SeekBar;
|
31
|
import android.widget.TextView;
|
32
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
33
|
|
34
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
35
|
|
36
|
public class DynamicActivity extends Activity implements OnSeekBarChangeListener
|
37
|
{
|
38
|
private TextView textD, textN;
|
39
|
private int p0,p1,p2;
|
40
|
private int mDim, mMode;
|
41
|
|
42
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
43
|
@Override
|
44
|
protected void onCreate(Bundle savedState)
|
45
|
{
|
46
|
super.onCreate(savedState);
|
47
|
setContentView(R.layout.dynamicslayout);
|
48
|
|
49
|
textD = (TextView)findViewById(R.id.dynamicTextDuration);
|
50
|
textN = (TextView)findViewById(R.id.dynamicTextNoise);
|
51
|
|
52
|
p0=p1=p2=0;
|
53
|
mDim = DynamicSurfaceView.DIM_2D;
|
54
|
mMode= Dynamic1D.MODE_LOOP;
|
55
|
|
56
|
SeekBar barD = (SeekBar)findViewById(R.id.dynamicSeekDuration);
|
57
|
barD.setOnSeekBarChangeListener(this);
|
58
|
SeekBar bar0 = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
|
59
|
bar0.setOnSeekBarChangeListener(this);
|
60
|
SeekBar bar1 = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
|
61
|
bar1.setOnSeekBarChangeListener(this);
|
62
|
SeekBar bar2 = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
|
63
|
bar2.setOnSeekBarChangeListener(this);
|
64
|
|
65
|
if( savedState==null )
|
66
|
{
|
67
|
barD.setProgress(50);
|
68
|
bar0.setProgress(0);
|
69
|
bar1.setProgress(0);
|
70
|
bar2.setProgress(0);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
@Override
|
76
|
protected void onResume()
|
77
|
{
|
78
|
super.onResume();
|
79
|
|
80
|
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
81
|
view.onResume();
|
82
|
}
|
83
|
|
84
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
85
|
@Override
|
86
|
protected void onPause()
|
87
|
{
|
88
|
GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
89
|
view.onPause();
|
90
|
|
91
|
Distorted.onPause();
|
92
|
super.onPause();
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
@Override
|
97
|
public void onStop()
|
98
|
{
|
99
|
super.onStop();
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
@Override
|
104
|
public void onDestroy()
|
105
|
{
|
106
|
Distorted.onDestroy();
|
107
|
super.onDestroy();
|
108
|
}
|
109
|
|
110
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
111
|
|
112
|
public void Loop(View v)
|
113
|
{
|
114
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
115
|
view.setMode(Dynamic1D.MODE_LOOP);
|
116
|
mMode = Dynamic1D.MODE_LOOP;
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
public void Path(View v)
|
122
|
{
|
123
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
124
|
view.setMode(Dynamic1D.MODE_PATH);
|
125
|
mMode = Dynamic1D.MODE_PATH;
|
126
|
}
|
127
|
|
128
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129
|
|
130
|
public void Jump(View v)
|
131
|
{
|
132
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
133
|
view.setMode(Dynamic1D.MODE_JUMP);
|
134
|
mMode = Dynamic1D.MODE_JUMP;
|
135
|
}
|
136
|
|
137
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138
|
|
139
|
public void Dim1D(View v)
|
140
|
{
|
141
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
142
|
view.setDimension(DynamicSurfaceView.DIM_1D);
|
143
|
mDim = DynamicSurfaceView.DIM_1D;
|
144
|
}
|
145
|
|
146
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
147
|
|
148
|
public void Dim2D(View v)
|
149
|
{
|
150
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
151
|
view.setDimension(DynamicSurfaceView.DIM_2D);
|
152
|
mDim = DynamicSurfaceView.DIM_2D;
|
153
|
}
|
154
|
|
155
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
156
|
|
157
|
public void Dim3DXY(View v)
|
158
|
{
|
159
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
160
|
view.setDimension(DynamicSurfaceView.DIM_3DXY);
|
161
|
mDim = DynamicSurfaceView.DIM_3DXY;
|
162
|
}
|
163
|
|
164
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165
|
|
166
|
public void Dim3DXZ(View v)
|
167
|
{
|
168
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
169
|
view.setDimension(DynamicSurfaceView.DIM_3DXZ);
|
170
|
mDim = DynamicSurfaceView.DIM_3DXZ;
|
171
|
}
|
172
|
|
173
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174
|
|
175
|
@Override
|
176
|
public void onSaveInstanceState(Bundle savedInstanceState)
|
177
|
{
|
178
|
super.onSaveInstanceState(savedInstanceState);
|
179
|
|
180
|
savedInstanceState.putInt("dim" , mDim );
|
181
|
savedInstanceState.putInt("mode", mMode);
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
|
186
|
@Override
|
187
|
public void onRestoreInstanceState(Bundle savedInstanceState)
|
188
|
{
|
189
|
super.onRestoreInstanceState(savedInstanceState);
|
190
|
|
191
|
mDim = savedInstanceState.getInt("dim");
|
192
|
mMode= savedInstanceState.getInt("mode");
|
193
|
|
194
|
switch(mDim)
|
195
|
{
|
196
|
case DynamicSurfaceView.DIM_1D : Dim1D(null) ; break;
|
197
|
case DynamicSurfaceView.DIM_2D : Dim2D(null) ; break;
|
198
|
case DynamicSurfaceView.DIM_3DXY: Dim3DXY(null); break;
|
199
|
case DynamicSurfaceView.DIM_3DXZ: Dim3DXZ(null); break;
|
200
|
}
|
201
|
|
202
|
switch(mMode)
|
203
|
{
|
204
|
case Dynamic1D.MODE_JUMP: Jump(null); break;
|
205
|
case Dynamic1D.MODE_PATH: Path(null); break;
|
206
|
case Dynamic1D.MODE_LOOP: Loop(null); break;
|
207
|
}
|
208
|
}
|
209
|
|
210
|
///////////////////////////////////////////////////////////////////
|
211
|
|
212
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
213
|
{
|
214
|
DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
|
215
|
int id = bar.getId();
|
216
|
|
217
|
if( id == R.id.dynamicSeekDuration )
|
218
|
{
|
219
|
float v = progress*200;
|
220
|
int i = (int)(v/100);
|
221
|
float t = i/10.0f;
|
222
|
view.setDuration((int)v);
|
223
|
textD.setText("Duration: "+(int)t+" s");
|
224
|
}
|
225
|
else
|
226
|
{
|
227
|
switch(id)
|
228
|
{
|
229
|
case R.id.dynamicSeekNoise0 : p0 = progress; break;
|
230
|
case R.id.dynamicSeekNoise1 : p1 = progress; break;
|
231
|
case R.id.dynamicSeekNoise2 : p2 = progress; break;
|
232
|
}
|
233
|
|
234
|
view.setNoise(p0/100.0f,p1/100.0f,p2/100.0f);
|
235
|
textN.setText("Noise: "+(p0/100.f)+" "+(p1/100.f)+" "+(p2/100.f));
|
236
|
}
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////
|
240
|
|
241
|
public void onStartTrackingTouch(SeekBar bar) { }
|
242
|
|
243
|
///////////////////////////////////////////////////////////////////
|
244
|
|
245
|
public void onStopTrackingTouch(SeekBar bar) { }
|
246
|
|
247
|
///////////////////////////////////////////////////////////////////
|
248
|
// end of file
|
249
|
}
|