Project

General

Profile

« Previous | Next » 

Revision b5636dbf

Added by Leszek Koltunski over 7 years ago

Improve Dynamic and FBO apps.

View differences:

src/main/java/org/distorted/examples/dynamic/DynamicActivity.java
31 31
import android.widget.TextView;
32 32
import android.widget.SeekBar.OnSeekBarChangeListener;
33 33

  
34
///////////////////////////////////////////////////////////////////
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35 35

  
36 36
public class DynamicActivity extends Activity implements OnSeekBarChangeListener
37 37
    {
38 38
    private TextView textD, textN;
39
    private int progress0, progress1, progress2;
39
    private int p0,p1,p2;
40
    private int mDim, mMode;
40 41

  
41
///////////////////////////////////////////////////////////////////
42
///////////////////////////////////////////////////////////////////////////////////////////////////
42 43
    @Override
43
    protected void onCreate(Bundle savedInstanceState) 
44
    protected void onCreate(Bundle savedState)
44 45
      {
45
      super.onCreate(savedInstanceState);
46
      super.onCreate(savedState);
46 47
      setContentView(R.layout.dynamicslayout);
47 48

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

  
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
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
60
      bar.setProgress(0);
61
      bar.setOnSeekBarChangeListener(this);
62
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
63
      bar.setProgress(0);
64
      bar.setOnSeekBarChangeListener(this);
65
      bar = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
66
      bar.setProgress(0);
67
      bar.setOnSeekBarChangeListener(this);
52
      p0=p1=p2=0;
53
      mDim = DynamicSurfaceView.DIM_2D;
54
      mMode= Dynamic1D.MODE_LOOP;
55

  
56
      SeekBar barD = (SeekBar)findViewById(R.id.dynamicSeekDuration);
57
      barD.setOnSeekBarChangeListener(this);
58
      SeekBar bar0 = (SeekBar)findViewById(R.id.dynamicSeekNoise0);
59
      bar0.setOnSeekBarChangeListener(this);
60
      SeekBar bar1 = (SeekBar)findViewById(R.id.dynamicSeekNoise1);
61
      bar1.setOnSeekBarChangeListener(this);
62
      SeekBar bar2 = (SeekBar)findViewById(R.id.dynamicSeekNoise2);
63
      bar2.setOnSeekBarChangeListener(this);
64

  
65
      if( savedState==null )
66
        {
67
        barD.setProgress(50);
68
        bar0.setProgress(0);
69
        bar1.setProgress(0);
70
        bar2.setProgress(0);
71
        }
68 72
      }
69 73

  
70
///////////////////////////////////////////////////////////////////
74
///////////////////////////////////////////////////////////////////////////////////////////////////
71 75
    @Override
72 76
    protected void onResume() 
73 77
      {
......
77 81
      view.onResume();
78 82
      }
79 83

  
80
///////////////////////////////////////////////////////////////////
84
///////////////////////////////////////////////////////////////////////////////////////////////////
81 85
    @Override
82 86
    protected void onPause() 
83 87
      {
......
87 91
      super.onPause();
88 92
      }
89 93
    
90
///////////////////////////////////////////////////////////////////
94
///////////////////////////////////////////////////////////////////////////////////////////////////
91 95
    @Override
92 96
    public void onStop()
93 97
      {
94 98
      super.onStop();
95 99
      }
96 100

  
97
///////////////////////////////////////////////////////////////////
101
///////////////////////////////////////////////////////////////////////////////////////////////////
98 102
    @Override
99 103
    public void onDestroy()
100 104
      {  
......
102 106
      super.onDestroy();
103 107
      }     
104 108
 
105
///////////////////////////////////////////////////////////////////
109
///////////////////////////////////////////////////////////////////////////////////////////////////
106 110
    
107 111
    public void Loop(View v)
108 112
      {
109 113
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
110 114
      view.setMode(Dynamic1D.MODE_LOOP);
115
      mMode = Dynamic1D.MODE_LOOP;
111 116
      }     
112 117
    
113
///////////////////////////////////////////////////////////////////
118
///////////////////////////////////////////////////////////////////////////////////////////////////
114 119

  
115 120
    public void Path(View v)
116 121
      {
117 122
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
118 123
      view.setMode(Dynamic1D.MODE_PATH);
124
      mMode = Dynamic1D.MODE_PATH;
119 125
      }  
120 126

  
121
///////////////////////////////////////////////////////////////////
127
///////////////////////////////////////////////////////////////////////////////////////////////////
122 128

  
123 129
    public void Jump(View v)
124 130
      {
125 131
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
126 132
      view.setMode(Dynamic1D.MODE_JUMP);
133
      mMode = Dynamic1D.MODE_JUMP;
127 134
      }  
128 135
    
129
///////////////////////////////////////////////////////////////////
136
///////////////////////////////////////////////////////////////////////////////////////////////////
130 137

  
131 138
    public void Dim1D(View v)
132 139
      {
133 140
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
134 141
      view.setDimension(DynamicSurfaceView.DIM_1D);
142
      mDim = DynamicSurfaceView.DIM_1D;
135 143
      }  
136 144

  
137
///////////////////////////////////////////////////////////////////
145
///////////////////////////////////////////////////////////////////////////////////////////////////
138 146

  
139 147
    public void Dim2D(View v)
140 148
      {
141 149
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
142 150
      view.setDimension(DynamicSurfaceView.DIM_2D);
151
      mDim = DynamicSurfaceView.DIM_2D;
143 152
      }  
144 153
    
145
///////////////////////////////////////////////////////////////////
154
///////////////////////////////////////////////////////////////////////////////////////////////////
146 155

  
147 156
    public void Dim3DXY(View v)
148 157
      {
149 158
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
150 159
      view.setDimension(DynamicSurfaceView.DIM_3DXY);
160
      mDim = DynamicSurfaceView.DIM_3DXY;
151 161
      }  
152 162

  
153
///////////////////////////////////////////////////////////////////
163
///////////////////////////////////////////////////////////////////////////////////////////////////
154 164

  
155 165
    public void Dim3DXZ(View v)
156 166
      {
157 167
      DynamicSurfaceView view = (DynamicSurfaceView) this.findViewById(R.id.dynamicSurfaceView);
158 168
      view.setDimension(DynamicSurfaceView.DIM_3DXZ);
169
      mDim = DynamicSurfaceView.DIM_3DXZ;
159 170
      }  
160
    
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

  
174
    @Override
175
    public void onSaveInstanceState(Bundle savedInstanceState)
176
      {
177
      super.onSaveInstanceState(savedInstanceState);
178

  
179
      savedInstanceState.putInt("dim" , mDim );
180
      savedInstanceState.putInt("mode", mMode);
181
      }
182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
    @Override
186
    public void onRestoreInstanceState(Bundle savedInstanceState)
187
      {
188
      super.onRestoreInstanceState(savedInstanceState);
189

  
190
      mDim = savedInstanceState.getInt("dim");
191
      mMode= savedInstanceState.getInt("mode");
192

  
193
      switch(mDim)
194
        {
195
        case DynamicSurfaceView.DIM_1D  : Dim1D(null)  ; break;
196
        case DynamicSurfaceView.DIM_2D  : Dim2D(null)  ; break;
197
        case DynamicSurfaceView.DIM_3DXY: Dim3DXY(null); break;
198
        case DynamicSurfaceView.DIM_3DXZ: Dim3DXZ(null); break;
199
        }
200

  
201
      switch(mMode)
202
        {
203
        case Dynamic1D.MODE_JUMP: Jump(null); break;
204
        case Dynamic1D.MODE_PATH: Path(null); break;
205
        case Dynamic1D.MODE_LOOP: Loop(null); break;
206
        }
207
      }
208

  
161 209
///////////////////////////////////////////////////////////////////
162 210
    
163 211
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
......
177 225
        {
178 226
        switch(id)
179 227
          {
180
          case R.id.dynamicSeekNoise0  : progress0 = progress; break;
181
          case R.id.dynamicSeekNoise1  : progress1 = progress; break;
182
          case R.id.dynamicSeekNoise2  : progress2 = progress; break;
228
          case R.id.dynamicSeekNoise0  : p0 = progress; break;
229
          case R.id.dynamicSeekNoise1  : p1 = progress; break;
230
          case R.id.dynamicSeekNoise2  : p2 = progress; break;
183 231
          }
184 232

  
185
        view.setNoise(progress0/100.0f,progress1/100.0f,progress2/100.0f);
186
        textN.setText("Noise: "+(progress0/100.f)+" "+(progress1/100.f)+" "+(progress2/100.f));
233
        view.setNoise(p0/100.0f,p1/100.0f,p2/100.0f);
234
        textN.setText("Noise: "+(p0/100.f)+" "+(p1/100.f)+" "+(p2/100.f));
187 235
        }
188 236
      }
189 237

  
src/main/java/org/distorted/examples/fbo/FBOActivity.java
30 30

  
31 31
public class FBOActivity extends Activity 
32 32
{
33
    private boolean mDepth;
34

  
33 35
///////////////////////////////////////////////////////////////////////////////////////////////////
34 36
    
35 37
    @Override
36
    protected void onCreate(Bundle icicle) 
38
    protected void onCreate(Bundle savedState)
37 39
      {
38
      super.onCreate(icicle);
40
      super.onCreate(savedState);
39 41
      setContentView(R.layout.fbolayout);
42

  
43
      if( savedState==null )
44
        {
45
        mDepth = true;
46
        }
40 47
      }
41 48

  
42 49
///////////////////////////////////////////////////////////////////////////////////////////////////
......
78 85
      FBORenderer renderer = view.getRenderer();
79 86

  
80 87
      renderer.setDepth(true);
88
      mDepth = true;
81 89
      }
82 90

  
83 91
///////////////////////////////////////////////////////////////////////////////////////////////////
......
88 96
      FBORenderer renderer = view.getRenderer();
89 97

  
90 98
      renderer.setDepth(false);
99
      mDepth = false;
91 100
      }
101

  
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

  
104
    @Override
105
    public void onSaveInstanceState(Bundle savedInstanceState)
106
      {
107
      super.onSaveInstanceState(savedInstanceState);
108
      savedInstanceState.putBoolean("depth", mDepth);
109
      }
110

  
111
///////////////////////////////////////////////////////////////////////////////////////////////////
112

  
113
    @Override
114
    public void onRestoreInstanceState(Bundle savedInstanceState)
115
      {
116
      super.onRestoreInstanceState(savedInstanceState);
117

  
118
      mDepth = savedInstanceState.getBoolean("depth");
119

  
120
      if(mDepth) DepthYes(null);
121
      else       DepthNo(null);
122
      }
123

  
92 124
}
src/main/java/org/distorted/examples/fbo/FBORenderer.java
56 56
   private DistortedScreen mScreen;
57 57
   private DistortedNode mRoot;
58 58
   private int lisaHeight, lisaWidth;
59
   private boolean mDepth;
59 60

  
60 61
///////////////////////////////////////////////////////////////////////////////////////////////////
61 62

  
62 63
   FBORenderer(GLSurfaceView v)
63 64
      {
64 65
      mView   = v;
66
      mDepth  = true;
65 67
      mEffects= new DistortedEffects();
66 68
      mScreen = new DistortedScreen();
67 69
      }
68 70

  
69 71
///////////////////////////////////////////////////////////////////////////////////////////////////
70 72

  
71
   void setDepth(boolean depth)
72
      {
73
      if( mRoot!=null )
74
        {
75
        if( depth ) mRoot.glEnable (GLES30.GL_DEPTH_TEST);
76
        else        mRoot.glDisable(GLES30.GL_DEPTH_TEST);
73
   private void setDepthPriv()
74
     {
75
     if( mDepth ) mRoot.glEnable (GLES30.GL_DEPTH_TEST);
76
     else         mRoot.glDisable(GLES30.GL_DEPTH_TEST);
77 77

  
78
        mRoot.glDepthMask(depth);
78
     mRoot.glDepthMask(mDepth);
79 79

  
80
        // we can also, to save memory, delete/recreate
81
        // the depth buffer each time. This is optional.
82
        DistortedFramebuffer fbo = mRoot.getFramebuffer();
83
        fbo.enableDepth(depth);
84
        }
80
     // we can also, to save memory, delete/recreate
81
     // the depth buffer each time. This is optional.
82
     DistortedFramebuffer fbo = mRoot.getFramebuffer();
83
     if( fbo!=null ) fbo.enableDepth(mDepth);
84
     }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
   void setDepth(boolean depth)
89
      {
90
      mDepth = depth;
91
      if( mRoot!=null ) setDepthPriv();
85 92
      }
86 93

  
87 94
///////////////////////////////////////////////////////////////////////////////////////////////////
......
161 168
      mRoot = new DistortedNode(lisa, mEffects,new MeshFlat(1,1));
162 169
      mRoot.attach(grid,gridEffects,new MeshCubes(10,10,false));
163 170

  
171
      setDepthPriv();
172

  
164 173
      mScreen.detachAll();
165 174
      mScreen.attach(mRoot);
166 175

  

Also available in: Unified diff