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