1 |
175f355d
|
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.flag;
|
21 |
|
|
|
22 |
|
|
import android.app.Activity;
|
23 |
100e2da7
|
Leszek Koltunski
|
import android.opengl.GLSurfaceView;
|
24 |
175f355d
|
Leszek Koltunski
|
import android.os.Bundle;
|
25 |
100e2da7
|
Leszek Koltunski
|
import android.widget.SeekBar;
|
26 |
|
|
import android.widget.TextView;
|
27 |
175f355d
|
Leszek Koltunski
|
|
28 |
100e2da7
|
Leszek Koltunski
|
import org.distorted.examples.R;
|
29 |
175f355d
|
Leszek Koltunski
|
import org.distorted.library.Distorted;
|
30 |
100e2da7
|
Leszek Koltunski
|
import org.distorted.library.type.Static5D;
|
31 |
175f355d
|
Leszek Koltunski
|
|
32 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33 |
|
|
|
34 |
100e2da7
|
Leszek Koltunski
|
public class FlagActivity extends Activity implements SeekBar.OnSeekBarChangeListener
|
35 |
175f355d
|
Leszek Koltunski
|
{
|
36 |
100e2da7
|
Leszek Koltunski
|
private TextView textAmplitude, textLength, textAngleA, textAngleB;
|
37 |
|
|
private TextView textNoiseAmplitude, textNoiseLength, textNoiseAngleA, textNoiseAngleB;
|
38 |
e2c784bd
|
Leszek Koltunski
|
private Static5D mNoise;
|
39 |
100e2da7
|
Leszek Koltunski
|
private String mStr;
|
40 |
e2c784bd
|
Leszek Koltunski
|
|
41 |
175f355d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
42 |
|
|
|
43 |
|
|
@Override
|
44 |
|
|
protected void onCreate(Bundle savedState)
|
45 |
|
|
{
|
46 |
|
|
super.onCreate(savedState);
|
47 |
100e2da7
|
Leszek Koltunski
|
setContentView(R.layout.flaglayout);
|
48 |
|
|
|
49 |
e2c784bd
|
Leszek Koltunski
|
mNoise = new Static5D(0,0,0,0,0);
|
50 |
100e2da7
|
Leszek Koltunski
|
|
51 |
|
|
textAmplitude = (TextView)findViewById(R.id.flagAmplitude);
|
52 |
|
|
textLength = (TextView)findViewById(R.id.flagLength);
|
53 |
|
|
textAngleA = (TextView)findViewById(R.id.flagAngleA);
|
54 |
|
|
textAngleB = (TextView)findViewById(R.id.flagAngleB);
|
55 |
|
|
|
56 |
e2c784bd
|
Leszek Koltunski
|
SeekBar barAmplitude = (SeekBar)findViewById(R.id.flagSeekAmplitude);
|
57 |
|
|
SeekBar barLength = (SeekBar)findViewById(R.id.flagSeekLength);
|
58 |
|
|
SeekBar barAngleA = (SeekBar)findViewById(R.id.flagSeekAngleA);
|
59 |
|
|
SeekBar barAngleB = (SeekBar)findViewById(R.id.flagSeekAngleB);
|
60 |
100e2da7
|
Leszek Koltunski
|
|
61 |
|
|
barAmplitude.setOnSeekBarChangeListener(this);
|
62 |
|
|
barLength.setOnSeekBarChangeListener(this);
|
63 |
|
|
barAngleA.setOnSeekBarChangeListener(this);
|
64 |
|
|
barAngleB.setOnSeekBarChangeListener(this);
|
65 |
|
|
|
66 |
|
|
barAmplitude.setProgress(50);
|
67 |
|
|
barLength.setProgress(50);
|
68 |
|
|
barAngleA.setProgress(25);
|
69 |
|
|
barAngleB.setProgress(1);
|
70 |
|
|
|
71 |
|
|
textNoiseAmplitude = (TextView)findViewById(R.id.flagNoiseAmplitude);
|
72 |
|
|
textNoiseLength = (TextView)findViewById(R.id.flagNoiseLength);
|
73 |
|
|
textNoiseAngleA = (TextView)findViewById(R.id.flagNoiseAngleA);
|
74 |
|
|
textNoiseAngleB = (TextView)findViewById(R.id.flagNoiseAngleB);
|
75 |
|
|
|
76 |
e2c784bd
|
Leszek Koltunski
|
SeekBar barNoiseAmplitude = (SeekBar)findViewById(R.id.flagSeekNoiseAmplitude);
|
77 |
|
|
SeekBar barNoiseLength = (SeekBar)findViewById(R.id.flagSeekNoiseLength);
|
78 |
|
|
SeekBar barNoiseAngleA = (SeekBar)findViewById(R.id.flagSeekNoiseAngleA);
|
79 |
|
|
SeekBar barNoiseAngleB = (SeekBar)findViewById(R.id.flagSeekNoiseAngleB);
|
80 |
100e2da7
|
Leszek Koltunski
|
|
81 |
|
|
barNoiseAmplitude.setOnSeekBarChangeListener(this);
|
82 |
|
|
barNoiseLength.setOnSeekBarChangeListener(this);
|
83 |
|
|
barNoiseAngleA.setOnSeekBarChangeListener(this);
|
84 |
|
|
barNoiseAngleB.setOnSeekBarChangeListener(this);
|
85 |
|
|
|
86 |
e2c784bd
|
Leszek Koltunski
|
barNoiseAmplitude.setProgress( (int)mNoise.getX() );
|
87 |
|
|
barNoiseLength.setProgress ( (int)mNoise.getY() );
|
88 |
|
|
barNoiseAngleA.setProgress ( (int)mNoise.getW() );
|
89 |
|
|
barNoiseAngleB.setProgress ( (int)mNoise.getV() );
|
90 |
100e2da7
|
Leszek Koltunski
|
|
91 |
6f3024ae
|
Leszek Koltunski
|
textNoiseAmplitude.setText(getString(R.string.noise_placeholder,"0.00"));
|
92 |
|
|
textNoiseLength.setText(getString(R.string.noise_placeholder,"0.00"));
|
93 |
|
|
textNoiseAngleA.setText(getString(R.string.noise_placeholder,"0.00"));
|
94 |
|
|
textNoiseAngleB.setText(getString(R.string.noise_placeholder,"0.00"));
|
95 |
175f355d
|
Leszek Koltunski
|
}
|
96 |
|
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
|
|
@Override
|
100 |
|
|
protected void onPause()
|
101 |
|
|
{
|
102 |
100e2da7
|
Leszek Koltunski
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
|
103 |
175f355d
|
Leszek Koltunski
|
mView.onPause();
|
104 |
100e2da7
|
Leszek Koltunski
|
|
105 |
175f355d
|
Leszek Koltunski
|
super.onPause();
|
106 |
|
|
}
|
107 |
|
|
|
108 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
@Override
|
111 |
|
|
protected void onResume()
|
112 |
|
|
{
|
113 |
|
|
super.onResume();
|
114 |
100e2da7
|
Leszek Koltunski
|
|
115 |
|
|
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView);
|
116 |
175f355d
|
Leszek Koltunski
|
mView.onResume();
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
@Override
|
122 |
|
|
protected void onDestroy()
|
123 |
|
|
{
|
124 |
|
|
Distorted.onDestroy();
|
125 |
|
|
super.onDestroy();
|
126 |
|
|
}
|
127 |
100e2da7
|
Leszek Koltunski
|
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
|
130 |
|
|
private void convert(int progress)
|
131 |
|
|
{
|
132 |
|
|
if( progress== 0 ) mStr="0.00";
|
133 |
|
|
else if( progress==100 ) mStr="1.00";
|
134 |
|
|
else if( progress< 10 ) mStr="0.0"+progress;
|
135 |
|
|
else mStr="0."+progress;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
|
|
|
140 |
|
|
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
|
141 |
|
|
{
|
142 |
41d39cea
|
Leszek Koltunski
|
FlagSurfaceView mView = (FlagSurfaceView) this.findViewById(R.id.flagSurfaceView);
|
143 |
|
|
FlagRenderer renderer = mView.getRenderer();
|
144 |
|
|
|
145 |
100e2da7
|
Leszek Koltunski
|
switch (bar.getId())
|
146 |
|
|
{
|
147 |
41d39cea
|
Leszek Koltunski
|
case R.id.flagSeekAmplitude : renderer.setAmplitude(progress);
|
148 |
6f3024ae
|
Leszek Koltunski
|
textAmplitude.setText(getString(R.string.amplitude_placeholder,progress));
|
149 |
100e2da7
|
Leszek Koltunski
|
break;
|
150 |
e2c784bd
|
Leszek Koltunski
|
case R.id.flagSeekNoiseAmplitude: mNoise.set1((float)progress/100);
|
151 |
|
|
renderer.setNoise(mNoise);
|
152 |
100e2da7
|
Leszek Koltunski
|
convert(progress);
|
153 |
6f3024ae
|
Leszek Koltunski
|
textNoiseAmplitude.setText(getString(R.string.noise_placeholder,mStr));
|
154 |
100e2da7
|
Leszek Koltunski
|
break;
|
155 |
41d39cea
|
Leszek Koltunski
|
case R.id.flagSeekLength : progress = progress*2;
|
156 |
|
|
renderer.setLength(progress);
|
157 |
6f3024ae
|
Leszek Koltunski
|
textLength.setText(getString(R.string.length_placeholder,progress));
|
158 |
100e2da7
|
Leszek Koltunski
|
break;
|
159 |
e2c784bd
|
Leszek Koltunski
|
case R.id.flagSeekNoiseLength : mNoise.set2((float)progress/100);
|
160 |
|
|
renderer.setNoise(mNoise);
|
161 |
100e2da7
|
Leszek Koltunski
|
convert(progress);
|
162 |
6f3024ae
|
Leszek Koltunski
|
textNoiseLength.setText(getString(R.string.noise_placeholder,mStr));
|
163 |
100e2da7
|
Leszek Koltunski
|
break;
|
164 |
41d39cea
|
Leszek Koltunski
|
case R.id.flagSeekAngleA : progress = (360*progress)/100;
|
165 |
|
|
renderer.setAngleA(progress);
|
166 |
6f3024ae
|
Leszek Koltunski
|
textAngleA.setText(getString(R.string.alpha_placeholder,progress));
|
167 |
100e2da7
|
Leszek Koltunski
|
break;
|
168 |
e2c784bd
|
Leszek Koltunski
|
case R.id.flagSeekNoiseAngleA : mNoise.set4((float)progress/100);
|
169 |
|
|
renderer.setNoise(mNoise);
|
170 |
100e2da7
|
Leszek Koltunski
|
convert(progress);
|
171 |
6f3024ae
|
Leszek Koltunski
|
textNoiseAngleA.setText(getString(R.string.noise_placeholder,mStr));
|
172 |
100e2da7
|
Leszek Koltunski
|
break;
|
173 |
41d39cea
|
Leszek Koltunski
|
case R.id.flagSeekAngleB : progress = ((360*progress)/100);
|
174 |
|
|
renderer.setAngleB(progress);
|
175 |
6f3024ae
|
Leszek Koltunski
|
textAngleB.setText(getString(R.string.beta_placeholder,progress));
|
176 |
100e2da7
|
Leszek Koltunski
|
break;
|
177 |
e2c784bd
|
Leszek Koltunski
|
case R.id.flagSeekNoiseAngleB : mNoise.set5((float)progress/100);
|
178 |
|
|
renderer.setNoise(mNoise);
|
179 |
100e2da7
|
Leszek Koltunski
|
convert(progress);
|
180 |
6f3024ae
|
Leszek Koltunski
|
textNoiseAngleB.setText(getString(R.string.noise_placeholder,mStr));
|
181 |
100e2da7
|
Leszek Koltunski
|
break;
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
|
|
|
187 |
|
|
public void onStartTrackingTouch(SeekBar bar) { }
|
188 |
|
|
|
189 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190 |
|
|
|
191 |
|
|
public void onStopTrackingTouch(SeekBar bar) { }
|
192 |
|
|
|
193 |
175f355d
|
Leszek Koltunski
|
}
|