Project

General

Profile

« Previous | Next » 

Revision 8b7c0ab3

Added by Leszek Koltunski over 7 years ago

Improve the Dynamics app (multi-dimensional noise)

View differences:

src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
35 35

  
36 36
public class DynamicActivity extends Activity implements OnSeekBarChangeListener
37 37
    {
38
    private SeekBar barD, barN;
39 38
    private TextView textD, textN;
40
   
39
    private int progress0, progress1, progress2;
40

  
41 41
///////////////////////////////////////////////////////////////////
42 42
    @Override
43 43
    protected void onCreate(Bundle savedInstanceState) 
44 44
      {
45 45
      super.onCreate(savedInstanceState);
46
      setContentView(R.layout.interpolatorlayout);
47
      
48
      barD = (SeekBar)findViewById(R.id.interpolatorSeekDuration);
49
      barD.setOnSeekBarChangeListener(this); 
50
      textD = (TextView)findViewById(R.id.interpolatorTextDuration);
51
      
52
      barN = (SeekBar)findViewById(R.id.interpolatorSeekNoise);
53
      barN.setOnSeekBarChangeListener(this); 
54
      textN = (TextView)findViewById(R.id.interpolatorTextNoise);
55
      
56
      barD.setProgress(50);
57
      textD.setText("Duration: 10 s");
58
      
59
      barN.setProgress(0);
60
      textN.setText("Noise: 0.0");
46
      setContentView(R.layout.dynamicslayout);
47

  
48
      textD = (TextView)findViewById(R.id.dynamicTextDuration);
49
      textN = (TextView)findViewById(R.id.dynamicTextNoise);
50

  
51
      SeekBar bar = (SeekBar)findViewById(R.id.dynamicSeekDuration);
52
      bar.setOnSeekBarChangeListener(this);
53
      bar.setProgress(50);
54

  
55
      progress0=0;
56
      progress1=0;
57
      progress2=0;
58

  
59

  
60
      //textD.setText("Duration: 10 s");
61
      //textN.setText("Noise: 0.0");
62

  
63
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
64
      bar.setProgress(0);
65
      bar.setOnSeekBarChangeListener(this);
66
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
67
      bar.setProgress(0);
68
      bar.setOnSeekBarChangeListener(this);
69
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
70
      bar.setProgress(0);
71
      bar.setOnSeekBarChangeListener(this);
61 72
      }
62 73

  
63 74
///////////////////////////////////////////////////////////////////
......
66 77
      {
67 78
      super.onResume();
68 79
      
69
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.interpolatorSurfaceView);
80
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
70 81
      mView.onResume();
71 82
      }
72 83

  
......
74 85
    @Override
75 86
    protected void onPause() 
76 87
      {
77
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.interpolatorSurfaceView);
88
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
78 89
      mView.onPause();
79 90
         
80 91
      super.onPause();
......
148 159
    
149 160
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
150 161
      {
151
      float v, t; 
152
      int i;
153
      
154
      switch (bar.getId()) 
162
      int id = bar.getId();
163

  
164
      if( id == R.id.dynamicSeekDuration )
165
        {
166
        float v = progress*200;
167
        int i = (int)(v/100);
168
        float t = i/10.0f;
169
        DynamicSurfaceView.setDuration((int)v);
170
        textD.setText("Duration: "+(int)t+" s");
171
        }
172
      else
155 173
        {
156
        case R.id.interpolatorSeekDuration: v = progress*200;
157
                                            i = (int)(v/100);
158
                                            t = i/10.0f;
159
                                            DynamicSurfaceView.setDuration((int)v);
160
                                            textD.setText("Duration: "+(int)t+" s");
161
                                            break;
162
        case R.id.interpolatorSeekNoise   : DynamicSurfaceView.setNoise(progress/100.0f);
163
                                            textN.setText("Noise: "+(progress/100.f));
164
                                            break;
174
        switch(id)
175
          {
176
          case R.id.dynamicSeekNoise0  : progress0 = progress; break;
177
          case R.id.dynamicSeekNoise1  : progress1 = progress; break;
178
          case R.id.dynamicSeekNoise2  : progress2 = progress; break;
179
          }
180

  
181
        DynamicSurfaceView.setNoise(progress0/100.0f,progress1/100.0f,progress2/100.0f);
182
        textN.setText("Noise: "+(progress0/100.f)+" "+(progress1/100.f)+" "+(progress2/100.f));
165 183
        }
166 184
      }
167 185

  
src/main/java/org/distorted/examples/dynamic/DynamicSurfaceView.java
43 43
    public static final int DIM_2D   = 1; 
44 44
    public static final int DIM_3DXY = 2; 
45 45
    public static final int DIM_3DXZ = 3; 
46
   
46

  
47 47
    private static final int NUM_INTERPOLATIONS= 100;
48 48
    private static final int MAX_VECTORS       =   6;
49
   
50
    private DynamicRenderer mRenderer;
49

  
50
    private static final Object lock = new Object();
51

  
51 52
    private static int xDown,yDown;
52 53
    private static int mScrW, mScrH;
53 54
   
......
57 58
    
58 59
    private static Paint mPaint;
59 60
    private static int moving;
60
    private static Object lock = new Object();
61 61
    private static long mTime = 0;
62 62
    private static int mDuration;
63 63
    private static float mPosition;
64
    private static float mNoise;
64
    private static float mNoise0, mNoise1, mNoise2;
65 65
    
66 66
    private static int currentDim = DIM_2D;
67 67
    
......
88 88
      moving    = -1;
89 89
      mDuration = 10000;
90 90
      mPosition = 0;
91
      mNoise    = 0.0f;
92
      
91
      mNoise0   = 0.0f;
92
      mNoise1   = 0.0f;
93
      mNoise2   = 0.0f;
94

  
93 95
      di1D = new Dynamic1D(mDuration,0.5f);
94
      p1N = new Static1D(mNoise);
96
      p1N = new Static1D(mNoise0);
95 97
      di1D.setNoise(p1N);
96 98
      
97 99
      di2D = new Dynamic2D(mDuration,0.5f);
98
      p2N = new Static2D(mNoise,mNoise);
100
      p2N = new Static2D(mNoise0,mNoise1);
99 101
      di2D.setNoise(p2N);
100 102
      
101 103
      di3D = new Dynamic3D(mDuration,0.5f);
102
      p3N = new Static3D(mNoise,mNoise,mNoise);
104
      p3N = new Static3D(mNoise0,mNoise1,mNoise2);
103 105
      di3D.setNoise(p3N);
104 106
        
105 107
      if(!isInEditMode())
......
114 116
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
115 117
          }
116 118
        
117
        mRenderer = new DynamicRenderer(this);
119
        DynamicRenderer mRenderer = new DynamicRenderer(this);
118 120
        setRenderer(mRenderer);
119 121
        }
120 122
      }
......
149 151

  
150 152
///////////////////////////////////////////////////////////////////
151 153

  
152
    public static void setNoise(float noise)
154
    public static void setNoise(float noise0, float noise1, float noise2)
153 155
      {
154
      mNoise = noise;
156
      mNoise0 = noise0;
157
      mNoise1 = noise1;
158
      mNoise2 = noise2;
155 159

  
156
      p1N.set(mNoise);
157
      p2N.set(mNoise,mNoise);
158
      p3N.set(mNoise,mNoise,mNoise);
160
      p1N.set(mNoise0);
161
      p2N.set(mNoise0,mNoise1);
162
      p3N.set(mNoise0,mNoise1,mNoise2);
159 163

  
160 164
      di1D.setNoise(p1N);
161 165
      di2D.setNoise(p2N);
src/main/res/layout/dynamicslayout.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:layout_gravity="fill_horizontal"
6
    android:gravity="fill_horizontal"
7
    android:orientation="vertical" >
8

  
9
    <org.distorted.examples.dynamic.DynamicSurfaceView
10
        android:id="@+id/dynamicSurfaceView"
11
        android:layout_width="fill_parent"
12
        android:layout_height="0dp"
13
        android:layout_weight="1" />
14

  
15
        <RadioGroup
16
            android:id="@+id/radioGroup2"
17
            android:layout_width="wrap_content"
18
            android:layout_height="wrap_content"
19
            android:gravity="fill_horizontal"
20
            android:orientation="horizontal"
21
            android:paddingBottom="5dp"
22
            android:paddingTop="5dp"
23
            android:weightSum="1.0" >
24

  
25
            <RadioButton
26
                android:id="@+id/dynamic1D"
27
                android:layout_width="fill_parent"
28
                android:layout_height="wrap_content"
29
                android:layout_weight="0.25"
30
                android:onClick="Dim1D"
31
                android:text="@string/dim1D" />
32

  
33
            <RadioButton
34
                android:id="@+id/dynamic2D"
35
                android:layout_width="fill_parent"
36
                android:layout_height="wrap_content"
37
                android:layout_weight="0.25"
38
                android:checked="true"
39
                android:onClick="Dim2D"
40
                android:text="@string/dim2D" />
41

  
42
            <RadioButton
43
                android:id="@+id/dynamic3DXY"
44
                android:layout_width="fill_parent"
45
                android:layout_height="wrap_content"
46
                android:layout_weight="0.25"
47
                android:onClick="Dim3DXY"
48
                android:text="@string/dim3DXY" />
49

  
50
            <RadioButton
51
                android:id="@+id/dynamic3DXZ"
52
                android:layout_width="fill_parent"
53
                android:layout_height="wrap_content"
54
                android:layout_weight="0.25"
55
                android:onClick="Dim3DXZ"
56
                android:text="@string/dim3DXZ" />
57

  
58
        </RadioGroup>
59

  
60
        <RadioGroup
61
            android:id="@+id/radioGroup1"
62
            android:layout_width="wrap_content"
63
            android:layout_height="wrap_content"
64
            android:orientation="horizontal"
65
            android:paddingRight="20dp" >
66

  
67
            <RadioButton
68
                android:id="@+id/dynamicLoopButton"
69
                android:layout_width="wrap_content"
70
                android:layout_height="wrap_content"
71
                android:checked="true"
72
                android:onClick="Loop"
73
                android:text="@string/loop" />
74

  
75
            <RadioButton
76
                android:id="@+id/dynamicPathButton"
77
                android:layout_width="wrap_content"
78
                android:layout_height="wrap_content"
79
                android:checked="false"
80
                android:onClick="Path"
81
                android:text="@string/path" />
82

  
83
            <RadioButton
84
                android:id="@+id/dynamicJumpButton"
85
                android:layout_width="wrap_content"
86
                android:layout_height="wrap_content"
87
                android:checked="false"
88
                android:onClick="Jump"
89
                android:text="@string/jump" />
90

  
91
        </RadioGroup>
92

  
93
    <LinearLayout
94
        android:id="@+id/linearLayout1"
95
        android:layout_width="fill_parent"
96
        android:layout_height="80dp"
97
        android:layout_gravity="center_vertical"
98
        android:gravity="center|fill_horizontal" >
99

  
100
        <TableLayout
101
            android:layout_width="wrap_content"
102
            android:layout_height="match_parent"
103
            android:layout_gravity="center_vertical"
104
            android:layout_weight="15"
105
            android:gravity="center_vertical" >
106

  
107
            <TableRow
108
                android:id="@+id/tableRow1"
109
                android:layout_width="wrap_content"
110
                android:layout_height="wrap_content"
111
                android:layout_gravity="center_vertical"
112
                android:paddingBottom="5dp"
113
                android:paddingTop="5dp" >
114

  
115
                <TextView
116
                    android:id="@+id/dynamicTextDuration"
117
                    android:layout_width="wrap_content"
118
                    android:layout_height="wrap_content"
119
                    android:layout_gravity="center_vertical"
120
                    android:layout_weight="5"
121
                    android:paddingLeft="10dp"
122
                    android:text="@string/duration"
123
                    android:textAppearance="?android:attr/textAppearanceMedium"
124
                    android:textSize="12sp" />
125

  
126
                <SeekBar
127
                    android:id="@+id/dynamicSeekDuration"
128
                    android:layout_width="match_parent"
129
                    android:layout_height="wrap_content"
130
                    android:layout_weight="12"
131
                    android:paddingLeft="5dp"
132
                    android:paddingRight="10dp" />
133
            </TableRow>
134

  
135
            <TableRow
136
                android:id="@+id/tableRow2"
137
                android:layout_width="wrap_content"
138
                android:layout_height="wrap_content"
139
                android:paddingBottom="5dp"
140
                android:paddingTop="5dp" >
141

  
142
                <TextView
143
                    android:id="@+id/dynamicTextNoise"
144
                    android:layout_width="wrap_content"
145
                    android:layout_height="wrap_content"
146
                    android:layout_gravity="center_vertical"
147
                    android:layout_weight="5"
148
                    android:paddingLeft="10dp"
149
                    android:text="@string/noise"
150
                    android:textAppearance="?android:attr/textAppearanceMedium"
151
                    android:textSize="12sp" />
152

  
153
                <SeekBar
154
                    android:id="@+id/dynamicSeekNoise0"
155
                    android:layout_width="match_parent"
156
                    android:layout_height="wrap_content"
157
                    android:layout_weight="12"
158
                    android:paddingLeft="5dp"
159
                    android:paddingRight="10dp" />
160
                <SeekBar
161
                    android:id="@+id/dynamicSeekNoise1"
162
                    android:layout_width="match_parent"
163
                    android:layout_height="wrap_content"
164
                    android:layout_weight="12"
165
                    android:paddingLeft="5dp"
166
                    android:paddingRight="10dp" />
167
                <SeekBar
168
                    android:id="@+id/dynamicSeekNoise2"
169
                    android:layout_width="match_parent"
170
                    android:layout_height="wrap_content"
171
                    android:layout_weight="12"
172
                    android:paddingLeft="5dp"
173
                    android:paddingRight="10dp" />
174
            </TableRow>
175
        </TableLayout>
176
    </LinearLayout>
177

  
178
</LinearLayout>
src/main/res/layout/interpolatorlayout.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:layout_gravity="fill_horizontal"
6
    android:gravity="fill_horizontal"
7
    android:orientation="vertical" >
8

  
9
    <org.distorted.examples.dynamic.DynamicSurfaceView
10
        android:id="@+id/interpolatorSurfaceView"
11
        android:layout_width="fill_parent"
12
        android:layout_height="0dp"
13
        android:layout_weight="1" />
14

  
15
        <RadioGroup
16
            android:id="@+id/radioGroup2"
17
            android:layout_width="wrap_content"
18
            android:layout_height="wrap_content"
19
            android:gravity="fill_horizontal"
20
            android:orientation="horizontal"
21
            android:paddingBottom="5dp"
22
            android:paddingTop="5dp"
23
            android:weightSum="1.0" >
24

  
25
            <RadioButton
26
                android:id="@+id/interpolator1D"
27
                android:layout_width="fill_parent"
28
                android:layout_height="wrap_content"
29
                android:layout_weight="0.25"
30
                android:onClick="Dim1D"
31
                android:text="@string/dim1D" />
32

  
33
            <RadioButton
34
                android:id="@+id/interpolator2D"
35
                android:layout_width="fill_parent"
36
                android:layout_height="wrap_content"
37
                android:layout_weight="0.25"
38
                android:checked="true"
39
                android:onClick="Dim2D"
40
                android:text="@string/dim2D" />
41

  
42
            <RadioButton
43
                android:id="@+id/interpolator3DXY"
44
                android:layout_width="fill_parent"
45
                android:layout_height="wrap_content"
46
                android:layout_weight="0.25"
47
                android:onClick="Dim3DXY"
48
                android:text="@string/dim3DXY" />
49

  
50
            <RadioButton
51
                android:id="@+id/interpolator3DXZ"
52
                android:layout_width="fill_parent"
53
                android:layout_height="wrap_content"
54
                android:layout_weight="0.25"
55
                android:onClick="Dim3DXZ"
56
                android:text="@string/dim3DXZ" />
57

  
58
        </RadioGroup>
59

  
60
        <RadioGroup
61
            android:id="@+id/radioGroup1"
62
            android:layout_width="wrap_content"
63
            android:layout_height="wrap_content"
64
            android:orientation="horizontal"
65
            android:paddingRight="20dp" >
66

  
67
            <RadioButton
68
                android:id="@+id/interpolatorLoopButton"
69
                android:layout_width="wrap_content"
70
                android:layout_height="wrap_content"
71
                android:checked="true"
72
                android:onClick="Loop"
73
                android:text="@string/loop" />
74

  
75
            <RadioButton
76
                android:id="@+id/interpolatorPathButton"
77
                android:layout_width="wrap_content"
78
                android:layout_height="wrap_content"
79
                android:checked="false"
80
                android:onClick="Path"
81
                android:text="@string/path" />
82

  
83
            <RadioButton
84
                android:id="@+id/interpolatorJumpButton"
85
                android:layout_width="wrap_content"
86
                android:layout_height="wrap_content"
87
                android:checked="false"
88
                android:onClick="Jump"
89
                android:text="@string/jump" />
90

  
91
        </RadioGroup>
92

  
93
    <LinearLayout
94
        android:id="@+id/linearLayout1"
95
        android:layout_width="fill_parent"
96
        android:layout_height="80dp"
97
        android:layout_gravity="center_vertical"
98
        android:gravity="center|fill_horizontal" >
99

  
100
        <TableLayout
101
            android:layout_width="wrap_content"
102
            android:layout_height="match_parent"
103
            android:layout_gravity="center_vertical"
104
            android:layout_weight="15"
105
            android:gravity="center_vertical" >
106

  
107
            <TableRow
108
                android:id="@+id/tableRow1"
109
                android:layout_width="wrap_content"
110
                android:layout_height="wrap_content"
111
                android:layout_gravity="center_vertical"
112
                android:paddingBottom="5dp"
113
                android:paddingTop="5dp" >
114

  
115
                <TextView
116
                    android:id="@+id/interpolatorTextDuration"
117
                    android:layout_width="wrap_content"
118
                    android:layout_height="wrap_content"
119
                    android:layout_gravity="center_vertical"
120
                    android:layout_weight="5"
121
                    android:paddingLeft="10dp"
122
                    android:text="@string/duration"
123
                    android:textAppearance="?android:attr/textAppearanceMedium"
124
                    android:textSize="12sp" />
125

  
126
                <SeekBar
127
                    android:id="@+id/interpolatorSeekDuration"
128
                    android:layout_width="match_parent"
129
                    android:layout_height="wrap_content"
130
                    android:layout_weight="12"
131
                    android:paddingLeft="5dp"
132
                    android:paddingRight="10dp" />
133
            </TableRow>
134

  
135
            <TableRow
136
                android:id="@+id/tableRow2"
137
                android:layout_width="wrap_content"
138
                android:layout_height="wrap_content"
139
                android:paddingBottom="5dp"
140
                android:paddingTop="5dp" >
141

  
142
                <TextView
143
                    android:id="@+id/interpolatorTextNoise"
144
                    android:layout_width="wrap_content"
145
                    android:layout_height="wrap_content"
146
                    android:layout_gravity="center_vertical"
147
                    android:layout_weight="5"
148
                    android:paddingLeft="10dp"
149
                    android:text="@string/noise"
150
                    android:textAppearance="?android:attr/textAppearanceMedium"
151
                    android:textSize="12sp" />
152

  
153
                <SeekBar
154
                    android:id="@+id/interpolatorSeekNoise"
155
                    android:layout_width="match_parent"
156
                    android:layout_height="wrap_content"
157
                    android:layout_weight="12"
158
                    android:paddingLeft="5dp"
159
                    android:paddingRight="10dp" />
160
            </TableRow>
161
        </TableLayout>
162
    </LinearLayout>
163

  
164
</LinearLayout>

Also available in: Unified diff