Revision 100e2da7
Added by Leszek Koltunski about 8 years ago
src/main/java/org/distorted/examples/flag/FlagActivity.java | ||
---|---|---|
20 | 20 |
package org.distorted.examples.flag; |
21 | 21 |
|
22 | 22 |
import android.app.Activity; |
23 |
import android.opengl.GLSurfaceView; |
|
23 | 24 |
import android.os.Bundle; |
25 |
import android.widget.SeekBar; |
|
26 |
import android.widget.TextView; |
|
24 | 27 |
|
28 |
import org.distorted.examples.R; |
|
25 | 29 |
import org.distorted.library.Distorted; |
30 |
import org.distorted.library.type.Static5D; |
|
26 | 31 |
|
27 | 32 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
28 | 33 |
|
29 |
public class FlagActivity extends Activity |
|
34 |
public class FlagActivity extends Activity implements SeekBar.OnSeekBarChangeListener
|
|
30 | 35 |
{ |
31 |
private FlagSurfaceView mView; |
|
36 |
private SeekBar barAmplitude, barLength, barAngleA, barAngleB; |
|
37 |
private TextView textAmplitude, textLength, textAngleA, textAngleB; |
|
38 |
private SeekBar barNoiseAmplitude, barNoiseLength, barNoiseAngleA, barNoiseAngleB; |
|
39 |
private TextView textNoiseAmplitude, textNoiseLength, textNoiseAngleA, textNoiseAngleB; |
|
32 | 40 |
|
41 |
private Static5D noise; |
|
42 |
private String mStr; |
|
33 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
34 | 44 |
|
35 | 45 |
@Override |
36 | 46 |
protected void onCreate(Bundle savedState) |
37 | 47 |
{ |
38 | 48 |
super.onCreate(savedState); |
39 |
mView = new FlagSurfaceView(this); |
|
40 |
setContentView(mView); |
|
49 |
setContentView(R.layout.flaglayout); |
|
50 |
|
|
51 |
noise = new Static5D(0,0,0,0,0); |
|
52 |
mStr = new String(); |
|
53 |
|
|
54 |
textAmplitude = (TextView)findViewById(R.id.flagAmplitude); |
|
55 |
textLength = (TextView)findViewById(R.id.flagLength); |
|
56 |
textAngleA = (TextView)findViewById(R.id.flagAngleA); |
|
57 |
textAngleB = (TextView)findViewById(R.id.flagAngleB); |
|
58 |
|
|
59 |
barAmplitude = (SeekBar)findViewById(R.id.flagSeekAmplitude); |
|
60 |
barLength = (SeekBar)findViewById(R.id.flagSeekLength); |
|
61 |
barAngleA = (SeekBar)findViewById(R.id.flagSeekAngleA); |
|
62 |
barAngleB = (SeekBar)findViewById(R.id.flagSeekAngleB); |
|
63 |
|
|
64 |
barAmplitude.setOnSeekBarChangeListener(this); |
|
65 |
barLength.setOnSeekBarChangeListener(this); |
|
66 |
barAngleA.setOnSeekBarChangeListener(this); |
|
67 |
barAngleB.setOnSeekBarChangeListener(this); |
|
68 |
|
|
69 |
barAmplitude.setProgress(50); |
|
70 |
barLength.setProgress(50); |
|
71 |
barAngleA.setProgress(25); |
|
72 |
barAngleB.setProgress(1); |
|
73 |
|
|
74 |
textNoiseAmplitude = (TextView)findViewById(R.id.flagNoiseAmplitude); |
|
75 |
textNoiseLength = (TextView)findViewById(R.id.flagNoiseLength); |
|
76 |
textNoiseAngleA = (TextView)findViewById(R.id.flagNoiseAngleA); |
|
77 |
textNoiseAngleB = (TextView)findViewById(R.id.flagNoiseAngleB); |
|
78 |
|
|
79 |
barNoiseAmplitude = (SeekBar)findViewById(R.id.flagSeekNoiseAmplitude); |
|
80 |
barNoiseLength = (SeekBar)findViewById(R.id.flagSeekNoiseLength); |
|
81 |
barNoiseAngleA = (SeekBar)findViewById(R.id.flagSeekNoiseAngleA); |
|
82 |
barNoiseAngleB = (SeekBar)findViewById(R.id.flagSeekNoiseAngleB); |
|
83 |
|
|
84 |
barNoiseAmplitude.setOnSeekBarChangeListener(this); |
|
85 |
barNoiseLength.setOnSeekBarChangeListener(this); |
|
86 |
barNoiseAngleA.setOnSeekBarChangeListener(this); |
|
87 |
barNoiseAngleB.setOnSeekBarChangeListener(this); |
|
88 |
|
|
89 |
barNoiseAmplitude.setProgress( (int)noise.getX() ); |
|
90 |
barNoiseLength.setProgress ( (int)noise.getY() ); |
|
91 |
barNoiseAngleA.setProgress ( (int)noise.getW() ); |
|
92 |
barNoiseAngleB.setProgress ( (int)noise.getV() ); |
|
93 |
|
|
94 |
textNoiseAmplitude.setText("Noise 0.00"); |
|
95 |
textNoiseLength.setText("Noise 0.00"); |
|
96 |
textNoiseAngleA.setText("Noise 0.00"); |
|
97 |
textNoiseAngleB.setText("Noise 0.00"); |
|
41 | 98 |
} |
42 | 99 |
|
43 | 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
45 | 102 |
@Override |
46 | 103 |
protected void onPause() |
47 | 104 |
{ |
105 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView); |
|
48 | 106 |
mView.onPause(); |
107 |
|
|
49 | 108 |
super.onPause(); |
50 | 109 |
} |
51 | 110 |
|
... | ... | |
55 | 114 |
protected void onResume() |
56 | 115 |
{ |
57 | 116 |
super.onResume(); |
117 |
|
|
118 |
GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.flagSurfaceView); |
|
58 | 119 |
mView.onResume(); |
59 | 120 |
} |
60 | 121 |
|
... | ... | |
66 | 127 |
Distorted.onDestroy(); |
67 | 128 |
super.onDestroy(); |
68 | 129 |
} |
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
|
|
133 |
private void convert(int progress) |
|
134 |
{ |
|
135 |
if( progress== 0 ) mStr="0.00"; |
|
136 |
else if( progress==100 ) mStr="1.00"; |
|
137 |
else if( progress< 10 ) mStr="0.0"+progress; |
|
138 |
else mStr="0."+progress; |
|
139 |
} |
|
140 |
|
|
141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
142 |
|
|
143 |
public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) |
|
144 |
{ |
|
145 |
switch (bar.getId()) |
|
146 |
{ |
|
147 |
case R.id.flagSeekAmplitude : FlagRenderer.setAmplitude(progress); |
|
148 |
textAmplitude.setText("Amplitude "+progress); |
|
149 |
break; |
|
150 |
case R.id.flagSeekNoiseAmplitude: noise.set( (float)progress, noise.getY(), noise.getZ(), noise.getW(), noise.getV() ); |
|
151 |
FlagRenderer.setNoise(noise); |
|
152 |
convert(progress); |
|
153 |
textNoiseAmplitude.setText("Noise "+mStr ); |
|
154 |
break; |
|
155 |
case R.id.flagSeekLength : FlagRenderer.setLength(progress); |
|
156 |
textLength.setText("Length "+(progress*2)); |
|
157 |
break; |
|
158 |
case R.id.flagSeekNoiseLength : noise.set( noise.getX(), (float)progress, noise.getZ(), noise.getW(), noise.getV() ); |
|
159 |
FlagRenderer.setNoise(noise); |
|
160 |
convert(progress); |
|
161 |
textNoiseLength.setText("Noise "+mStr ); |
|
162 |
break; |
|
163 |
case R.id.flagSeekAngleA : FlagRenderer.setAngleA(progress); |
|
164 |
textAngleA.setText("Alpha "+((360*progress)/100)); |
|
165 |
break; |
|
166 |
case R.id.flagSeekNoiseAngleA : noise.set( noise.getX(), noise.getY(), noise.getZ() ,(float)progress, noise.getV() ); |
|
167 |
FlagRenderer.setNoise(noise); |
|
168 |
convert(progress); |
|
169 |
textNoiseAngleA.setText("Noise "+mStr ); |
|
170 |
break; |
|
171 |
case R.id.flagSeekAngleB : FlagRenderer.setAngleB(progress); |
|
172 |
textAngleB.setText("Beta "+((360*progress)/100)); |
|
173 |
break; |
|
174 |
case R.id.flagSeekNoiseAngleB : noise.set( noise.getX(), noise.getY(), noise.getZ(), noise.getW(), (float)progress ); |
|
175 |
FlagRenderer.setNoise(noise); |
|
176 |
convert(progress); |
|
177 |
textNoiseAngleB.setText("Noise "+mStr ); |
|
178 |
break; |
|
179 |
} |
|
180 |
} |
|
181 |
|
|
182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
183 |
|
|
184 |
public void onStartTrackingTouch(SeekBar bar) { } |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
public void onStopTrackingTouch(SeekBar bar) { } |
|
189 |
|
|
69 | 190 |
} |
src/main/java/org/distorted/examples/flag/FlagRenderer.java | ||
---|---|---|
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
96 |
|
|
96 |
|
|
97 |
public static void setAmplitude(int a) |
|
98 |
{ |
|
99 |
|
|
100 |
} |
|
101 |
|
|
102 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
103 |
|
|
104 |
public static void setLength(int l) |
|
105 |
{ |
|
106 |
|
|
107 |
} |
|
108 |
|
|
109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
110 |
|
|
111 |
public static void setAngleA(int a) |
|
112 |
{ |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
public static void setAngleB(int b) |
|
119 |
{ |
|
120 |
|
|
121 |
} |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
public static void setNoise(Static5D noise) |
|
126 |
{ |
|
127 |
|
|
128 |
} |
|
129 |
|
|
130 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
131 |
|
|
97 | 132 |
public void onDrawFrame(GL10 glUnused) |
98 | 133 |
{ |
99 | 134 |
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
src/main/java/org/distorted/examples/flag/FlagSurfaceView.java | ||
---|---|---|
22 | 22 |
import android.content.Context; |
23 | 23 |
import android.opengl.GLSurfaceView; |
24 | 24 |
import android.os.Build; |
25 |
import android.util.AttributeSet; |
|
25 | 26 |
import android.view.MotionEvent; |
26 |
import android.widget.Toast; |
|
27 |
|
|
28 |
import org.distorted.examples.R; |
|
29 | 27 |
|
30 | 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
31 | 29 |
|
... | ... | |
36 | 34 |
|
37 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 36 |
|
39 |
public FlagSurfaceView(Context c) |
|
37 |
public FlagSurfaceView(Context c, AttributeSet attrs)
|
|
40 | 38 |
{ |
41 |
super(c); |
|
39 |
super(c,attrs);
|
|
42 | 40 |
|
43 | 41 |
mX = -1; |
44 | 42 |
mY = -1; |
... | ... | |
55 | 53 |
mRenderer = new FlagRenderer(this); |
56 | 54 |
|
57 | 55 |
setRenderer(mRenderer); |
58 |
|
|
59 |
Toast.makeText(c, R.string.example_rotate_toast , Toast.LENGTH_SHORT).show(); |
|
60 | 56 |
} |
61 | 57 |
} |
62 | 58 |
|
src/main/java/org/distorted/examples/girl/GirlActivity.java | ||
---|---|---|
60 | 60 |
barSwing.setProgress(0); |
61 | 61 |
barSize.setProgress(50); |
62 | 62 |
barHips.setProgress(0); |
63 |
|
|
63 |
|
|
64 | 64 |
textSwing.setText("Swing: 0"); |
65 | 65 |
textSize.setText("Size: 1.0"); |
66 | 66 |
textHips.setText("Hips: 0"); |
... | ... | |
107 | 107 |
switch (bar.getId()) |
108 | 108 |
{ |
109 | 109 |
case R.id.girlSeekSwing: v = progress/5; |
110 |
GirlRenderer.setSwing(v); |
|
111 |
textSwing.setText("Swing: "+v); |
|
112 |
break; |
|
110 |
GirlRenderer.setSwing(v);
|
|
111 |
textSwing.setText("Swing: "+v);
|
|
112 |
break;
|
|
113 | 113 |
case R.id.girlSeekSize : if( progress> 50) |
114 |
{ |
|
115 |
s = (progress-50)/16.0f + 1.0f; |
|
116 |
} |
|
117 |
else |
|
118 |
{ |
|
119 |
s = 0.015f*progress + 0.25f; |
|
120 |
} |
|
121 |
GirlRenderer.setSize(s); |
|
122 |
textSize.setText("Size: "+(((int)(s*10))/10.0f)); |
|
123 |
break;
|
|
114 |
{
|
|
115 |
s = (progress-50)/16.0f + 1.0f;
|
|
116 |
}
|
|
117 |
else
|
|
118 |
{
|
|
119 |
s = 0.015f*progress + 0.25f;
|
|
120 |
}
|
|
121 |
GirlRenderer.setSize(s);
|
|
122 |
textSize.setText("Size: "+(((int)(s*10))/10.0f));
|
|
123 |
break;
|
|
124 | 124 |
case R.id.girlSeekHips : v = progress/5; |
125 |
GirlRenderer.setHips(v); |
|
126 |
textHips.setText("Hips: "+v); |
|
127 |
break; |
|
128 |
|
|
125 |
GirlRenderer.setHips(v); |
|
126 |
textHips.setText("Hips: "+v); |
|
127 |
break; |
|
129 | 128 |
} |
130 | 129 |
} |
131 | 130 |
|
src/main/res/layout/flaglayout.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8"?> |
|
2 |
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
|
3 |
android:layout_width="fill_parent" |
|
4 |
android:layout_height="fill_parent" |
|
5 |
android:orientation="vertical" > |
|
6 |
|
|
7 |
<org.distorted.examples.flag.FlagSurfaceView |
|
8 |
android:id="@+id/flagSurfaceView" |
|
9 |
android:layout_width="fill_parent" |
|
10 |
android:layout_height="0dp" |
|
11 |
android:layout_weight="0.85" /> |
|
12 |
|
|
13 |
<TableLayout |
|
14 |
android:layout_width="match_parent" |
|
15 |
android:layout_height="wrap_content" |
|
16 |
android:paddingLeft="10dp" |
|
17 |
android:paddingRight="10dp" > |
|
18 |
|
|
19 |
<TableRow |
|
20 |
android:id="@+id/tableRow1" |
|
21 |
android:layout_width="wrap_content" |
|
22 |
android:layout_height="wrap_content" |
|
23 |
android:paddingBottom="5dp" |
|
24 |
android:paddingTop="5dp" > |
|
25 |
|
|
26 |
<TextView |
|
27 |
android:id="@+id/flagAmplitude" |
|
28 |
android:layout_width="wrap_content" |
|
29 |
android:layout_height="wrap_content" |
|
30 |
android:gravity="center_vertical|center" |
|
31 |
android:text="@string/amplitude" |
|
32 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
33 |
|
|
34 |
<SeekBar |
|
35 |
android:id="@+id/flagSeekAmplitude" |
|
36 |
android:layout_width="105dp" |
|
37 |
android:layout_height="wrap_content" |
|
38 |
android:layout_weight="1" |
|
39 |
android:paddingLeft="15dp" |
|
40 |
android:paddingRight="10dp" /> |
|
41 |
|
|
42 |
<TextView |
|
43 |
android:id="@+id/flagNoiseAmplitude" |
|
44 |
android:layout_width="wrap_content" |
|
45 |
android:layout_height="wrap_content" |
|
46 |
android:gravity="center_vertical|center" |
|
47 |
android:text="@string/noise" |
|
48 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
49 |
|
|
50 |
<SeekBar |
|
51 |
android:id="@+id/flagSeekNoiseAmplitude" |
|
52 |
android:layout_width="105dp" |
|
53 |
android:layout_height="wrap_content" |
|
54 |
android:layout_weight="1" |
|
55 |
android:paddingLeft="15dp" |
|
56 |
android:paddingRight="10dp" /> |
|
57 |
|
|
58 |
</TableRow> |
|
59 |
|
|
60 |
<TableRow |
|
61 |
android:id="@+id/tableRow2" |
|
62 |
android:layout_width="wrap_content" |
|
63 |
android:layout_height="wrap_content" |
|
64 |
android:paddingBottom="5dp" |
|
65 |
android:paddingTop="5dp" > |
|
66 |
|
|
67 |
<TextView |
|
68 |
android:id="@+id/flagLength" |
|
69 |
android:layout_width="wrap_content" |
|
70 |
android:layout_height="wrap_content" |
|
71 |
android:gravity="center_vertical|center" |
|
72 |
android:text="@string/length" |
|
73 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
74 |
|
|
75 |
<SeekBar |
|
76 |
android:id="@+id/flagSeekLength" |
|
77 |
android:layout_width="106dp" |
|
78 |
android:layout_height="wrap_content" |
|
79 |
android:layout_weight="1" |
|
80 |
android:paddingLeft="15dp" |
|
81 |
android:paddingRight="10dp" /> |
|
82 |
|
|
83 |
<TextView |
|
84 |
android:id="@+id/flagNoiseLength" |
|
85 |
android:layout_width="wrap_content" |
|
86 |
android:layout_height="wrap_content" |
|
87 |
android:gravity="center_vertical|center" |
|
88 |
android:text="@string/noise" |
|
89 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
90 |
|
|
91 |
<SeekBar |
|
92 |
android:id="@+id/flagSeekNoiseLength" |
|
93 |
android:layout_width="106dp" |
|
94 |
android:layout_height="wrap_content" |
|
95 |
android:layout_weight="1" |
|
96 |
android:paddingLeft="15dp" |
|
97 |
android:paddingRight="10dp" /> |
|
98 |
|
|
99 |
</TableRow> |
|
100 |
|
|
101 |
<TableRow |
|
102 |
android:id="@+id/tableRow3" |
|
103 |
android:layout_width="wrap_content" |
|
104 |
android:layout_height="wrap_content" |
|
105 |
android:paddingBottom="5dp" |
|
106 |
android:paddingTop="5dp" > |
|
107 |
|
|
108 |
<TextView |
|
109 |
android:id="@+id/flagAngleA" |
|
110 |
android:layout_width="wrap_content" |
|
111 |
android:layout_height="wrap_content" |
|
112 |
android:gravity="center_vertical|center" |
|
113 |
android:text="@string/angleA" |
|
114 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
115 |
|
|
116 |
<SeekBar |
|
117 |
android:id="@+id/flagSeekAngleA" |
|
118 |
android:layout_width="105dp" |
|
119 |
android:layout_height="wrap_content" |
|
120 |
android:layout_weight="1" |
|
121 |
android:paddingLeft="15dp" |
|
122 |
android:paddingRight="10dp" /> |
|
123 |
|
|
124 |
<TextView |
|
125 |
android:id="@+id/flagNoiseAngleA" |
|
126 |
android:layout_width="wrap_content" |
|
127 |
android:layout_height="wrap_content" |
|
128 |
android:gravity="center_vertical|center" |
|
129 |
android:text="@string/noise" |
|
130 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
131 |
|
|
132 |
<SeekBar |
|
133 |
android:id="@+id/flagSeekNoiseAngleA" |
|
134 |
android:layout_width="105dp" |
|
135 |
android:layout_height="wrap_content" |
|
136 |
android:layout_weight="1" |
|
137 |
android:paddingLeft="15dp" |
|
138 |
android:paddingRight="10dp" /> |
|
139 |
|
|
140 |
</TableRow> |
|
141 |
|
|
142 |
<TableRow |
|
143 |
android:id="@+id/tableRow4" |
|
144 |
android:layout_width="wrap_content" |
|
145 |
android:layout_height="wrap_content" |
|
146 |
android:paddingBottom="5dp" |
|
147 |
android:paddingTop="5dp" > |
|
148 |
|
|
149 |
<TextView |
|
150 |
android:id="@+id/flagAngleB" |
|
151 |
android:layout_width="wrap_content" |
|
152 |
android:layout_height="wrap_content" |
|
153 |
android:gravity="center_vertical|center" |
|
154 |
android:text="@string/angleB" |
|
155 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
156 |
|
|
157 |
<SeekBar |
|
158 |
android:id="@+id/flagSeekAngleB" |
|
159 |
android:layout_width="105dp" |
|
160 |
android:layout_height="wrap_content" |
|
161 |
android:layout_weight="1" |
|
162 |
android:paddingLeft="15dp" |
|
163 |
android:paddingRight="10dp" /> |
|
164 |
|
|
165 |
<TextView |
|
166 |
android:id="@+id/flagNoiseAngleB" |
|
167 |
android:layout_width="wrap_content" |
|
168 |
android:layout_height="wrap_content" |
|
169 |
android:gravity="center_vertical|center" |
|
170 |
android:text="@string/noise" |
|
171 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
172 |
|
|
173 |
<SeekBar |
|
174 |
android:id="@+id/flagSeekNoiseAngleB" |
|
175 |
android:layout_width="105dp" |
|
176 |
android:layout_height="wrap_content" |
|
177 |
android:layout_weight="1" |
|
178 |
android:paddingLeft="15dp" |
|
179 |
android:paddingRight="10dp" /> |
|
180 |
|
|
181 |
</TableRow> |
|
182 |
|
|
183 |
</TableLayout> |
|
184 |
|
|
185 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
53 | 53 |
<string name="Bitmap">Bitmap</string> |
54 | 54 |
<string name="Add">Add</string> |
55 | 55 |
<string name="RemoveAll">Remove All</string> |
56 |
<string name="amplitude">Amplitude</string> |
|
57 |
<string name="length">Length</string> |
|
58 |
<string name="angleA">Alpha</string> |
|
59 |
<string name="angleB">Beta</string> |
|
56 | 60 |
|
57 | 61 |
<string name="example_monalisa">Mona Lisa</string> |
58 | 62 |
<string name="example_monalisa_subtitle">The basics of Distortions.</string> |
Also available in: Unified diff
Progress with the 'Flag' test app.