1 |
08f92d82
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
d40cfeb2
|
Leszek Koltunski
|
import android.view.Gravity;
|
26 |
08f92d82
|
Leszek Koltunski
|
import android.view.View;
|
27 |
50ac40a6
|
Leszek Koltunski
|
import android.widget.AdapterView;
|
28 |
|
|
import android.widget.ArrayAdapter;
|
29 |
d40cfeb2
|
Leszek Koltunski
|
import android.widget.Button;
|
30 |
08f92d82
|
Leszek Koltunski
|
import android.widget.LinearLayout;
|
31 |
d40cfeb2
|
Leszek Koltunski
|
import android.widget.NumberPicker;
|
32 |
08f92d82
|
Leszek Koltunski
|
import android.widget.SeekBar;
|
33 |
|
|
import android.widget.SeekBar.OnSeekBarChangeListener;
|
34 |
50ac40a6
|
Leszek Koltunski
|
import android.widget.Spinner;
|
35 |
d40cfeb2
|
Leszek Koltunski
|
import android.widget.TableRow;
|
36 |
08f92d82
|
Leszek Koltunski
|
import android.widget.TextView;
|
37 |
|
|
|
38 |
|
|
import org.distorted.examples.R;
|
39 |
|
|
import org.distorted.library.Distorted;
|
40 |
50ac40a6
|
Leszek Koltunski
|
import org.distorted.library.DistortedBitmap;
|
41 |
|
|
import org.distorted.library.DistortedCubes;
|
42 |
|
|
import org.distorted.library.DistortedObject;
|
43 |
08f92d82
|
Leszek Koltunski
|
import org.distorted.library.EffectNames;
|
44 |
|
|
|
45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
46 |
|
|
|
47 |
50ac40a6
|
Leszek Koltunski
|
public class Vertex3DActivity extends Activity
|
48 |
|
|
implements OnSeekBarChangeListener,
|
49 |
|
|
View.OnClickListener,
|
50 |
|
|
AdapterView.OnItemSelectedListener
|
51 |
d40cfeb2
|
Leszek Koltunski
|
{
|
52 |
50ac40a6
|
Leszek Koltunski
|
private static final int COLOR_OFF = 0xffffe81f;
|
53 |
|
|
private static final int COLOR_ON = 0xff0000ff;
|
54 |
|
|
|
55 |
d40cfeb2
|
Leszek Koltunski
|
private boolean firstScreen;
|
56 |
|
|
|
57 |
|
|
// fields needed for the first 'pick-a-shape' screen
|
58 |
|
|
//
|
59 |
50ac40a6
|
Leszek Koltunski
|
private int mNumCols = 3;
|
60 |
|
|
private int mNumRows = 3;
|
61 |
d40cfeb2
|
Leszek Koltunski
|
private NumberPicker mColsPicker, mRowsPicker;
|
62 |
|
|
private LinearLayout mLay;
|
63 |
50ac40a6
|
Leszek Koltunski
|
private boolean[] mShape;
|
64 |
d40cfeb2
|
Leszek Koltunski
|
|
65 |
|
|
// fields needed for the second 'apply vertex effects' screen
|
66 |
|
|
//
|
67 |
|
|
private SeekBar bar;
|
68 |
794e6c4f
|
Leszek Koltunski
|
private TextView textDeform, textDistort, textSink, textSwirl, textCenter;
|
69 |
d40cfeb2
|
Leszek Koltunski
|
private int deformX, deformY, deformZ;
|
70 |
|
|
private int distortX, distortY, distortZ;
|
71 |
|
|
private int sinkA;
|
72 |
|
|
private int swirlA;
|
73 |
794e6c4f
|
Leszek Koltunski
|
private int centerX, centerY;
|
74 |
d40cfeb2
|
Leszek Koltunski
|
|
75 |
|
|
private float fdeformX, fdeformY, fdeformZ;
|
76 |
|
|
private float fdistortX, fdistortY, fdistortZ;
|
77 |
|
|
private float fsinkA;
|
78 |
|
|
private float fswirlA;
|
79 |
794e6c4f
|
Leszek Koltunski
|
private float fcenterX, fcenterY;
|
80 |
|
|
|
81 |
50ac40a6
|
Leszek Koltunski
|
private DistortedObject mObject;
|
82 |
|
|
|
83 |
d40cfeb2
|
Leszek Koltunski
|
private EffectNames[] effects = new EffectNames[4];
|
84 |
50ac40a6
|
Leszek Koltunski
|
private int mObjectType;
|
85 |
|
|
|
86 |
08f92d82
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
87 |
|
|
|
88 |
d40cfeb2
|
Leszek Koltunski
|
@Override
|
89 |
|
|
protected void onCreate(Bundle savedState)
|
90 |
|
|
{
|
91 |
|
|
super.onCreate(savedState);
|
92 |
|
|
|
93 |
50ac40a6
|
Leszek Koltunski
|
setContentView(R.layout.objectpickerlayout);
|
94 |
d40cfeb2
|
Leszek Koltunski
|
|
95 |
50ac40a6
|
Leszek Koltunski
|
mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
|
96 |
d40cfeb2
|
Leszek Koltunski
|
|
97 |
50ac40a6
|
Leszek Koltunski
|
mColsPicker = (NumberPicker)findViewById(R.id.objectpicker_cols);
|
98 |
|
|
mRowsPicker = (NumberPicker)findViewById(R.id.objectpicker_rows);
|
99 |
d40cfeb2
|
Leszek Koltunski
|
|
100 |
|
|
mColsPicker.setMaxValue(10);
|
101 |
|
|
mColsPicker.setMinValue( 0);
|
102 |
|
|
mRowsPicker.setMaxValue(10);
|
103 |
|
|
mRowsPicker.setMinValue( 0);
|
104 |
|
|
|
105 |
|
|
mColsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
|
106 |
08f92d82
|
Leszek Koltunski
|
{
|
107 |
d40cfeb2
|
Leszek Koltunski
|
@Override
|
108 |
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
|
109 |
|
|
{
|
110 |
|
|
setGrid();
|
111 |
|
|
}
|
112 |
|
|
});
|
113 |
|
|
|
114 |
|
|
mRowsPicker.setOnValueChangedListener(new NumberPicker.OnValueChangeListener()
|
115 |
|
|
{
|
116 |
|
|
@Override
|
117 |
|
|
public void onValueChange(NumberPicker picker, int oldVal, int newVal)
|
118 |
|
|
{
|
119 |
|
|
setGrid();
|
120 |
|
|
}
|
121 |
|
|
});
|
122 |
|
|
|
123 |
|
|
firstScreen = true;
|
124 |
|
|
|
125 |
50ac40a6
|
Leszek Koltunski
|
mObjectType = 0;
|
126 |
d40cfeb2
|
Leszek Koltunski
|
|
127 |
50ac40a6
|
Leszek Koltunski
|
Spinner typeSpinner = (Spinner)findViewById(R.id.objectpicker_spinnerType);
|
128 |
|
|
typeSpinner.setOnItemSelectedListener(this);
|
129 |
d40cfeb2
|
Leszek Koltunski
|
|
130 |
50ac40a6
|
Leszek Koltunski
|
String[] objectType = new String[] {"DistortedCubes", "DistortedBitmap"};
|
131 |
d40cfeb2
|
Leszek Koltunski
|
|
132 |
50ac40a6
|
Leszek Koltunski
|
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
|
133 |
|
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
134 |
|
|
typeSpinner.setAdapter(adapter);
|
135 |
d40cfeb2
|
Leszek Koltunski
|
}
|
136 |
|
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
|
139 |
50ac40a6
|
Leszek Koltunski
|
private void setGrid()
|
140 |
d40cfeb2
|
Leszek Koltunski
|
{
|
141 |
|
|
mNumCols = mColsPicker.getValue();
|
142 |
|
|
mNumRows = mRowsPicker.getValue();
|
143 |
|
|
|
144 |
|
|
int width = mLay.getWidth();
|
145 |
|
|
int height= mLay.getHeight();
|
146 |
|
|
int w = mNumCols>0 ? (width / mNumCols) -10 : 0;
|
147 |
|
|
int h = mNumRows>0 ? (height/ mNumRows) -10 : 0;
|
148 |
|
|
int size= w<h ? w:h;
|
149 |
|
|
int pad = size/20;
|
150 |
|
|
|
151 |
|
|
mLay.removeAllViews();
|
152 |
|
|
|
153 |
|
|
mShape = new boolean[mNumRows*mNumCols];
|
154 |
|
|
|
155 |
|
|
TableRow.LayoutParams p = new android.widget.TableRow.LayoutParams();
|
156 |
|
|
|
157 |
|
|
p.rightMargin = pad;
|
158 |
|
|
p.leftMargin = pad;
|
159 |
|
|
p.topMargin = pad;
|
160 |
|
|
p.bottomMargin = pad;
|
161 |
|
|
p.height = size;
|
162 |
|
|
p.width = size;
|
163 |
|
|
|
164 |
|
|
for (int rows=0; rows<mNumRows; rows++)
|
165 |
08f92d82
|
Leszek Koltunski
|
{
|
166 |
d40cfeb2
|
Leszek Koltunski
|
TableRow tr = new TableRow(this);
|
167 |
|
|
tr.setGravity(Gravity.CENTER);
|
168 |
|
|
|
169 |
|
|
for(int cols=0; cols<mNumCols; cols++)
|
170 |
|
|
{
|
171 |
|
|
Button b = new Button(this);
|
172 |
|
|
b.setOnClickListener(this);
|
173 |
|
|
b.setId(rows*mNumCols+cols);
|
174 |
|
|
b.setLayoutParams(p);
|
175 |
|
|
b.setBackgroundColor(COLOR_OFF);
|
176 |
|
|
tr.addView(b, p);
|
177 |
|
|
mShape[rows*mNumCols+cols] = false;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
|
|
mLay.addView(tr);
|
181 |
|
|
}
|
182 |
|
|
}
|
183 |
|
|
|
184 |
50ac40a6
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185 |
|
|
|
186 |
|
|
public DistortedObject getObject()
|
187 |
|
|
{
|
188 |
|
|
return mObject;
|
189 |
|
|
}
|
190 |
|
|
|
191 |
d40cfeb2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192 |
|
|
|
193 |
|
|
public void onClick(View view)
|
194 |
|
|
{
|
195 |
|
|
Button tmp = (Button)view;
|
196 |
|
|
int id = tmp.getId();
|
197 |
|
|
mShape[id] = !mShape[id];
|
198 |
|
|
tmp.setBackgroundColor(mShape[id] ? COLOR_ON:COLOR_OFF);
|
199 |
|
|
}
|
200 |
|
|
|
201 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
|
|
|
203 |
50ac40a6
|
Leszek Koltunski
|
public void Create(View v)
|
204 |
d40cfeb2
|
Leszek Koltunski
|
{
|
205 |
|
|
firstScreen = false;
|
206 |
50ac40a6
|
Leszek Koltunski
|
|
207 |
|
|
if( mObjectType==1 )
|
208 |
|
|
{
|
209 |
|
|
mObject = new DistortedBitmap(100,100,mNumCols);
|
210 |
|
|
}
|
211 |
|
|
else
|
212 |
|
|
{
|
213 |
|
|
String str = "";
|
214 |
|
|
|
215 |
|
|
for(int i=0; i<mNumRows*mNumCols; i++)
|
216 |
|
|
str += mShape[i] ? "1" : "0";
|
217 |
|
|
|
218 |
|
|
mObject = new DistortedCubes(mNumCols, str, 10);
|
219 |
|
|
}
|
220 |
|
|
|
221 |
d40cfeb2
|
Leszek Koltunski
|
setContentView(R.layout.vertex3dlayout);
|
222 |
|
|
Default(null);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
50ac40a6
|
Leszek Koltunski
|
|
226 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
227 |
|
|
|
228 |
|
|
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
|
229 |
|
|
{
|
230 |
|
|
switch(parent.getId())
|
231 |
|
|
{
|
232 |
|
|
case R.id.objectpicker_spinnerType: mObjectType = pos; break;
|
233 |
|
|
}
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237 |
|
|
|
238 |
|
|
public void onNothingSelected(AdapterView<?> parent)
|
239 |
|
|
{
|
240 |
|
|
}
|
241 |
|
|
|
242 |
d40cfeb2
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
243 |
|
|
// 'second screen' methods
|
244 |
|
|
|
245 |
|
|
public void Default(View view)
|
246 |
|
|
{
|
247 |
|
|
effects[0] = EffectNames.DEFORM;
|
248 |
|
|
effects[1] = EffectNames.DISTORT;
|
249 |
|
|
effects[2] = EffectNames.SINK;
|
250 |
|
|
effects[3] = EffectNames.SWIRL;
|
251 |
08f92d82
|
Leszek Koltunski
|
|
252 |
d40cfeb2
|
Leszek Koltunski
|
deformX = 50;
|
253 |
|
|
deformY = 50;
|
254 |
|
|
deformZ = 50;
|
255 |
e2d8ea1d
|
Leszek Koltunski
|
|
256 |
d40cfeb2
|
Leszek Koltunski
|
distortX = 50;
|
257 |
|
|
distortY = 50;
|
258 |
|
|
distortZ = 50;
|
259 |
e2d8ea1d
|
Leszek Koltunski
|
|
260 |
d40cfeb2
|
Leszek Koltunski
|
sinkA = 50;
|
261 |
|
|
swirlA = 50;
|
262 |
e2d8ea1d
|
Leszek Koltunski
|
|
263 |
d2337a3a
|
Leszek Koltunski
|
centerX = 50;
|
264 |
|
|
centerY = 50;
|
265 |
794e6c4f
|
Leszek Koltunski
|
|
266 |
|
|
textCenter = (TextView)findViewById(R.id.vertex3dcenterText);
|
267 |
d2337a3a
|
Leszek Koltunski
|
computeCenter();
|
268 |
794e6c4f
|
Leszek Koltunski
|
setCenterText();
|
269 |
|
|
|
270 |
|
|
setBar(R.id.vertex3dcenterX, centerX);
|
271 |
|
|
setBar(R.id.vertex3dcenterY, centerY);
|
272 |
|
|
|
273 |
d40cfeb2
|
Leszek Koltunski
|
addViews();
|
274 |
|
|
}
|
275 |
08f92d82
|
Leszek Koltunski
|
|
276 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277 |
|
|
|
278 |
d40cfeb2
|
Leszek Koltunski
|
private void addViews()
|
279 |
|
|
{
|
280 |
|
|
LinearLayout layout = (LinearLayout)findViewById(R.id.vertex3dlayout);
|
281 |
08f92d82
|
Leszek Koltunski
|
|
282 |
d40cfeb2
|
Leszek Koltunski
|
layout.removeAllViews();
|
283 |
08f92d82
|
Leszek Koltunski
|
|
284 |
d40cfeb2
|
Leszek Koltunski
|
View deform = getLayoutInflater().inflate(R.layout.vertex3ddeform , null);
|
285 |
|
|
View distort= getLayoutInflater().inflate(R.layout.vertex3ddistort, null);
|
286 |
|
|
View sink = getLayoutInflater().inflate(R.layout.vertex3dsink , null);
|
287 |
|
|
View swirl = getLayoutInflater().inflate(R.layout.vertex3dswirl , null);
|
288 |
08f92d82
|
Leszek Koltunski
|
|
289 |
d40cfeb2
|
Leszek Koltunski
|
for( int i=effects.length-1 ; i>=0 ; i-- )
|
290 |
|
|
{
|
291 |
|
|
switch(effects[i])
|
292 |
08f92d82
|
Leszek Koltunski
|
{
|
293 |
d40cfeb2
|
Leszek Koltunski
|
case DEFORM : layout.addView(deform , 0); break;
|
294 |
|
|
case DISTORT: layout.addView(distort, 0); break;
|
295 |
|
|
case SINK : layout.addView(sink , 0); break;
|
296 |
|
|
case SWIRL : layout.addView(swirl , 0); break;
|
297 |
08f92d82
|
Leszek Koltunski
|
}
|
298 |
d40cfeb2
|
Leszek Koltunski
|
}
|
299 |
08f92d82
|
Leszek Koltunski
|
|
300 |
d40cfeb2
|
Leszek Koltunski
|
textDeform = (TextView)findViewById(R.id.vertex3ddeformText);
|
301 |
|
|
textDistort= (TextView)findViewById(R.id.vertex3ddistortText);
|
302 |
|
|
textSink = (TextView)findViewById(R.id.vertex3dsinkText);
|
303 |
|
|
textSwirl = (TextView)findViewById(R.id.vertex3dswirlText);
|
304 |
08f92d82
|
Leszek Koltunski
|
|
305 |
d40cfeb2
|
Leszek Koltunski
|
setDeformText();
|
306 |
|
|
setDistortText();
|
307 |
|
|
setSinkText();
|
308 |
|
|
setSwirlText();
|
309 |
08f92d82
|
Leszek Koltunski
|
|
310 |
d40cfeb2
|
Leszek Koltunski
|
setBar(R.id.vertex3ddeformBar1, deformX);
|
311 |
|
|
setBar(R.id.vertex3ddeformBar2, deformY);
|
312 |
|
|
setBar(R.id.vertex3ddeformBar3, deformZ);
|
313 |
08f92d82
|
Leszek Koltunski
|
|
314 |
d40cfeb2
|
Leszek Koltunski
|
setBar(R.id.vertex3ddistortBar1, distortX);
|
315 |
|
|
setBar(R.id.vertex3ddistortBar2, distortY);
|
316 |
|
|
setBar(R.id.vertex3ddistortBar3, distortZ);
|
317 |
08f92d82
|
Leszek Koltunski
|
|
318 |
d40cfeb2
|
Leszek Koltunski
|
setBar(R.id.vertex3dsinkBar1, sinkA);
|
319 |
e2d8ea1d
|
Leszek Koltunski
|
|
320 |
d40cfeb2
|
Leszek Koltunski
|
setBar(R.id.vertex3dswirlBar1, swirlA);
|
321 |
e2d8ea1d
|
Leszek Koltunski
|
|
322 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
323 |
|
|
view.getRenderer().setOrder(effects);
|
324 |
d40cfeb2
|
Leszek Koltunski
|
}
|
325 |
08f92d82
|
Leszek Koltunski
|
|
326 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
327 |
|
|
|
328 |
d40cfeb2
|
Leszek Koltunski
|
private void moveUp(EffectNames name)
|
329 |
|
|
{
|
330 |
|
|
int len = effects.length-1;
|
331 |
|
|
int index = -1;
|
332 |
08f92d82
|
Leszek Koltunski
|
|
333 |
d40cfeb2
|
Leszek Koltunski
|
for(int i=0; i<=len; i++)
|
334 |
|
|
{
|
335 |
|
|
if( effects[i]==name )
|
336 |
08f92d82
|
Leszek Koltunski
|
{
|
337 |
d40cfeb2
|
Leszek Koltunski
|
index=i;
|
338 |
|
|
break;
|
339 |
08f92d82
|
Leszek Koltunski
|
}
|
340 |
d40cfeb2
|
Leszek Koltunski
|
}
|
341 |
08f92d82
|
Leszek Koltunski
|
|
342 |
d40cfeb2
|
Leszek Koltunski
|
if( index==0 )
|
343 |
|
|
{
|
344 |
|
|
for(int i=0; i<len; i++)
|
345 |
|
|
effects[i] = effects[i+1];
|
346 |
08f92d82
|
Leszek Koltunski
|
|
347 |
d40cfeb2
|
Leszek Koltunski
|
effects[len] = name;
|
348 |
08f92d82
|
Leszek Koltunski
|
}
|
349 |
d40cfeb2
|
Leszek Koltunski
|
else if( index>0 )
|
350 |
|
|
{
|
351 |
|
|
effects[index] = effects[index-1];
|
352 |
|
|
effects[index-1] = name;
|
353 |
|
|
}
|
354 |
|
|
|
355 |
|
|
addViews();
|
356 |
|
|
}
|
357 |
08f92d82
|
Leszek Koltunski
|
|
358 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
|
|
|
360 |
d40cfeb2
|
Leszek Koltunski
|
public void ButtonDeform(View v)
|
361 |
|
|
{
|
362 |
|
|
moveUp(EffectNames.DEFORM);
|
363 |
|
|
}
|
364 |
08f92d82
|
Leszek Koltunski
|
|
365 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366 |
|
|
|
367 |
d40cfeb2
|
Leszek Koltunski
|
public void ButtonDistort(View v)
|
368 |
|
|
{
|
369 |
|
|
moveUp(EffectNames.DISTORT);
|
370 |
|
|
}
|
371 |
08f92d82
|
Leszek Koltunski
|
|
372 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
373 |
|
|
|
374 |
d40cfeb2
|
Leszek Koltunski
|
public void ButtonSink(View v)
|
375 |
|
|
{
|
376 |
|
|
moveUp(EffectNames.SINK);
|
377 |
|
|
}
|
378 |
08f92d82
|
Leszek Koltunski
|
|
379 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
380 |
|
|
|
381 |
d40cfeb2
|
Leszek Koltunski
|
public void ButtonSwirl(View v)
|
382 |
|
|
{
|
383 |
|
|
moveUp(EffectNames.SWIRL);
|
384 |
|
|
}
|
385 |
08f92d82
|
Leszek Koltunski
|
|
386 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
387 |
|
|
|
388 |
d40cfeb2
|
Leszek Koltunski
|
private void setBar(int id, int value)
|
389 |
|
|
{
|
390 |
|
|
bar = (SeekBar)findViewById(id);
|
391 |
|
|
bar.setOnSeekBarChangeListener(this);
|
392 |
|
|
bar.setProgress(value);
|
393 |
|
|
}
|
394 |
08f92d82
|
Leszek Koltunski
|
|
395 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
396 |
|
|
|
397 |
d40cfeb2
|
Leszek Koltunski
|
private void computeDeform()
|
398 |
|
|
{
|
399 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
400 |
|
|
Vertex3DRenderer renderer = view.getRenderer();
|
401 |
08f92d82
|
Leszek Koltunski
|
|
402 |
d2337a3a
|
Leszek Koltunski
|
fdeformX = (deformX-50)*renderer.mScreenMin/200.0f;
|
403 |
|
|
fdeformY = (deformY-50)*renderer.mScreenMin/200.0f;
|
404 |
|
|
fdeformZ = (deformZ-50)*renderer.mScreenMin/200.0f;
|
405 |
|
|
|
406 |
|
|
renderer.setDeform( fdeformX, fdeformY, fdeformZ );
|
407 |
d40cfeb2
|
Leszek Koltunski
|
}
|
408 |
08f92d82
|
Leszek Koltunski
|
|
409 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
410 |
|
|
|
411 |
d40cfeb2
|
Leszek Koltunski
|
private void setDeformText()
|
412 |
|
|
{
|
413 |
|
|
fdeformX = ((int)(100*fdeformX))/100.0f;
|
414 |
|
|
fdeformY = ((int)(100*fdeformY))/100.0f;
|
415 |
|
|
fdeformZ = ((int)(100*fdeformZ))/100.0f;
|
416 |
08f92d82
|
Leszek Koltunski
|
|
417 |
d40cfeb2
|
Leszek Koltunski
|
textDeform.setText("deform("+fdeformX+" , "+fdeformY+" , "+fdeformZ+")");
|
418 |
|
|
}
|
419 |
08f92d82
|
Leszek Koltunski
|
|
420 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
421 |
|
|
|
422 |
d40cfeb2
|
Leszek Koltunski
|
private void computeDistort()
|
423 |
|
|
{
|
424 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
425 |
|
|
Vertex3DRenderer renderer = view.getRenderer();
|
426 |
|
|
|
427 |
|
|
fdistortX = (distortX-50)*renderer.mScreenMin/200.0f;
|
428 |
|
|
fdistortY = (distortY-50)*renderer.mScreenMin/200.0f;
|
429 |
|
|
fdistortZ = (distortZ-50)*renderer.mScreenMin/200.0f;
|
430 |
08f92d82
|
Leszek Koltunski
|
|
431 |
d2337a3a
|
Leszek Koltunski
|
renderer.setDistort(fdistortX, fdistortY, fdistortZ);
|
432 |
d40cfeb2
|
Leszek Koltunski
|
}
|
433 |
08f92d82
|
Leszek Koltunski
|
|
434 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
435 |
|
|
|
436 |
d40cfeb2
|
Leszek Koltunski
|
private void setDistortText()
|
437 |
|
|
{
|
438 |
|
|
fdistortX = ((int)(100*fdistortX))/100.0f;
|
439 |
|
|
fdistortY = ((int)(100*fdistortY))/100.0f;
|
440 |
|
|
fdistortZ = ((int)(100*fdistortZ))/100.0f;
|
441 |
08f92d82
|
Leszek Koltunski
|
|
442 |
d40cfeb2
|
Leszek Koltunski
|
textDistort.setText("distort("+fdistortX+" , "+fdistortY+" , "+fdistortZ+")");
|
443 |
|
|
}
|
444 |
08f92d82
|
Leszek Koltunski
|
|
445 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
446 |
|
|
|
447 |
d40cfeb2
|
Leszek Koltunski
|
private void computeSink()
|
448 |
|
|
{
|
449 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
450 |
|
|
|
451 |
e642b4aa
|
Leszek Koltunski
|
fsinkA = (sinkA>= 50 ? 0.18f*sinkA-8.0f : 0.018f*sinkA + 0.1f);
|
452 |
08f92d82
|
Leszek Koltunski
|
|
453 |
d2337a3a
|
Leszek Koltunski
|
view.getRenderer().setSink( fsinkA );
|
454 |
d40cfeb2
|
Leszek Koltunski
|
}
|
455 |
08f92d82
|
Leszek Koltunski
|
|
456 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
457 |
|
|
|
458 |
d40cfeb2
|
Leszek Koltunski
|
private void setSinkText()
|
459 |
|
|
{
|
460 |
|
|
fsinkA = ((int)(100*fsinkA))/100.0f;
|
461 |
08f92d82
|
Leszek Koltunski
|
|
462 |
d40cfeb2
|
Leszek Koltunski
|
textSink.setText("sink("+fsinkA+")");
|
463 |
|
|
}
|
464 |
08f92d82
|
Leszek Koltunski
|
|
465 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
466 |
|
|
|
467 |
d40cfeb2
|
Leszek Koltunski
|
private void computeSwirl()
|
468 |
|
|
{
|
469 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
470 |
|
|
|
471 |
d40cfeb2
|
Leszek Koltunski
|
fswirlA = (swirlA-50)*3.6f;
|
472 |
08f92d82
|
Leszek Koltunski
|
|
473 |
d2337a3a
|
Leszek Koltunski
|
view.getRenderer().setSwirl( fswirlA );
|
474 |
d40cfeb2
|
Leszek Koltunski
|
}
|
475 |
08f92d82
|
Leszek Koltunski
|
|
476 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
477 |
|
|
|
478 |
d40cfeb2
|
Leszek Koltunski
|
private void setSwirlText()
|
479 |
|
|
{
|
480 |
|
|
fswirlA = ((int)(100*fswirlA))/100.0f;
|
481 |
e2d8ea1d
|
Leszek Koltunski
|
|
482 |
d40cfeb2
|
Leszek Koltunski
|
textSwirl.setText("swirl("+fswirlA+")");
|
483 |
|
|
}
|
484 |
794e6c4f
|
Leszek Koltunski
|
|
485 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
486 |
|
|
|
487 |
|
|
private void computeCenter()
|
488 |
|
|
{
|
489 |
d2337a3a
|
Leszek Koltunski
|
Vertex3DSurfaceView view = (Vertex3DSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
490 |
794e6c4f
|
Leszek Koltunski
|
|
491 |
d2337a3a
|
Leszek Koltunski
|
fcenterX = centerX;
|
492 |
|
|
fcenterY = centerY;
|
493 |
|
|
|
494 |
|
|
view.getRenderer().setCenter( fcenterX, fcenterY );
|
495 |
794e6c4f
|
Leszek Koltunski
|
}
|
496 |
|
|
|
497 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
498 |
|
|
|
499 |
|
|
private void setCenterText()
|
500 |
|
|
{
|
501 |
|
|
fcenterX = ((int)(100*fcenterX))/100.0f;
|
502 |
|
|
fcenterY = ((int)(100*fcenterY))/100.0f;
|
503 |
|
|
|
504 |
|
|
textCenter.setText("center("+fcenterX+","+fcenterY+")");
|
505 |
|
|
}
|
506 |
|
|
|
507 |
d2337a3a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
508 |
|
|
|
509 |
|
|
public float getCenterX()
|
510 |
|
|
{
|
511 |
|
|
return fcenterX;
|
512 |
|
|
}
|
513 |
|
|
|
514 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
515 |
|
|
|
516 |
|
|
public float getCenterY()
|
517 |
|
|
{
|
518 |
|
|
return fcenterY;
|
519 |
|
|
}
|
520 |
|
|
|
521 |
08f92d82
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
522 |
d40cfeb2
|
Leszek Koltunski
|
// Overrides
|
523 |
|
|
|
524 |
|
|
@Override
|
525 |
|
|
protected void onPause()
|
526 |
|
|
{
|
527 |
|
|
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
528 |
|
|
if( mView!=null ) mView.onPause();
|
529 |
|
|
super.onPause();
|
530 |
|
|
}
|
531 |
08f92d82
|
Leszek Koltunski
|
|
532 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
533 |
|
|
|
534 |
d40cfeb2
|
Leszek Koltunski
|
@Override
|
535 |
|
|
protected void onResume()
|
536 |
|
|
{
|
537 |
|
|
super.onResume();
|
538 |
|
|
GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.vertex3dSurfaceView);
|
539 |
|
|
if( mView!=null ) mView.onResume();
|
540 |
|
|
}
|
541 |
08f92d82
|
Leszek Koltunski
|
|
542 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
543 |
|
|
|
544 |
d40cfeb2
|
Leszek Koltunski
|
@Override
|
545 |
|
|
public void onWindowFocusChanged(boolean hasFocus)
|
546 |
|
|
{
|
547 |
|
|
super.onWindowFocusChanged(hasFocus);
|
548 |
|
|
|
549 |
|
|
if( firstScreen )
|
550 |
|
|
{
|
551 |
|
|
mColsPicker.setValue(mNumCols);
|
552 |
|
|
mRowsPicker.setValue(mNumRows);
|
553 |
|
|
|
554 |
|
|
if( hasFocus ) setGrid();
|
555 |
|
|
}
|
556 |
|
|
}
|
557 |
08f92d82
|
Leszek Koltunski
|
|
558 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
559 |
|
|
|
560 |
d40cfeb2
|
Leszek Koltunski
|
@Override
|
561 |
|
|
protected void onDestroy()
|
562 |
|
|
{
|
563 |
|
|
Distorted.onDestroy();
|
564 |
|
|
super.onDestroy();
|
565 |
|
|
}
|
566 |
08f92d82
|
Leszek Koltunski
|
|
567 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
568 |
|
|
|
569 |
d40cfeb2
|
Leszek Koltunski
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
570 |
|
|
{
|
571 |
|
|
switch (bar.getId())
|
572 |
08f92d82
|
Leszek Koltunski
|
{
|
573 |
794e6c4f
|
Leszek Koltunski
|
case R.id.vertex3dcenterX : centerX = progress; computeCenter() ; setCenterText() ; break;
|
574 |
|
|
case R.id.vertex3dcenterY : centerY = progress; computeCenter() ; setCenterText() ; break;
|
575 |
d40cfeb2
|
Leszek Koltunski
|
case R.id.vertex3ddeformBar1 : deformX = progress; computeDeform() ; setDeformText() ; break;
|
576 |
|
|
case R.id.vertex3ddeformBar2 : deformY = progress; computeDeform() ; setDeformText() ; break;
|
577 |
|
|
case R.id.vertex3ddeformBar3 : deformZ = progress; computeDeform() ; setDeformText() ; break;
|
578 |
|
|
case R.id.vertex3ddistortBar1 : distortX= progress; computeDistort(); setDistortText() ; break;
|
579 |
|
|
case R.id.vertex3ddistortBar2 : distortY= progress; computeDistort(); setDistortText() ; break;
|
580 |
|
|
case R.id.vertex3ddistortBar3 : distortZ= progress; computeDistort(); setDistortText() ; break;
|
581 |
|
|
case R.id.vertex3dsinkBar1 : sinkA = progress; computeSink() ; setSinkText() ; break;
|
582 |
|
|
case R.id.vertex3dswirlBar1 : swirlA = progress; computeSwirl() ; setSwirlText() ; break;
|
583 |
08f92d82
|
Leszek Koltunski
|
}
|
584 |
d40cfeb2
|
Leszek Koltunski
|
}
|
585 |
08f92d82
|
Leszek Koltunski
|
|
586 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
587 |
|
|
|
588 |
d40cfeb2
|
Leszek Koltunski
|
public void onStartTrackingTouch(SeekBar bar) { }
|
589 |
08f92d82
|
Leszek Koltunski
|
|
590 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
591 |
|
|
|
592 |
d40cfeb2
|
Leszek Koltunski
|
public void onStopTrackingTouch(SeekBar bar) { }
|
593 |
|
|
}
|