Project

General

Profile

« Previous | Next » 

Revision db5d943e

Added by Leszek Koltunski over 8 years ago

Rename Effects3D to Matrix3D

View differences:

src/main/AndroidManifest.xml
34 34
        <activity android:name=".olimpic.OlimpicActivity" />  
35 35
        <activity android:name=".cubes.CubesActivity" />       
36 36
        <activity android:name=".quaternion.QuaternionActivity" />          
37
        <activity android:name=".effects3d.Effects3DActivity" />  
37
        <activity android:name=".matrix3d.Matrix3DActivity" />
38 38
        <activity android:name=".plainmonalisa.PlainMonaLisaActivity" />
39 39
        <activity android:name=".save.SaveActivity"/>
40 40
    </application>
src/main/java/org/distorted/examples/TableOfContents.java
53 53
import org.distorted.examples.starwars.StarWarsActivity;
54 54
import org.distorted.examples.cubes.CubesActivity;
55 55
import org.distorted.examples.quaternion.QuaternionActivity;
56
import org.distorted.examples.effects3d.Effects3DActivity;
56
import org.distorted.examples.matrix3d.Matrix3DActivity;
57 57
import org.distorted.examples.plainmonalisa.PlainMonaLisaActivity;
58 58
import org.distorted.examples.save.SaveActivity;
59 59

  
......
251 251
   
252 252
   {
253 253
      final Map<String, Object> item = new HashMap<>();
254
      item.put(ITEM_IMAGE, R.drawable.icon_example_effects3d);
255
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_effects3d));
256
      item.put(ITEM_SUBTITLE, getText(R.string.example_effects3d_subtitle));
254
      item.put(ITEM_IMAGE, R.drawable.icon_example_matrix3d);
255
      item.put(ITEM_TITLE, (i+1)+". "+getText(R.string.example_matrix3d));
256
      item.put(ITEM_SUBTITLE, getText(R.string.example_matrix3d_subtitle));
257 257
      data.add(item);
258
      activityMapping.put(i++, Effects3DActivity.class);
258
      activityMapping.put(i++, Matrix3DActivity.class);
259 259
   }
260 260

  
261 261
   {
src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.effects3d;
21

  
22
import org.distorted.library.Distorted;
23
import org.distorted.examples.R;
24

  
25
import android.app.Activity;
26
import android.os.Bundle;
27
import android.opengl.GLSurfaceView;
28
import android.view.View;
29
import android.widget.LinearLayout;
30
import android.widget.SeekBar;
31
import android.widget.TextView;
32
import android.widget.SeekBar.OnSeekBarChangeListener;
33

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

  
36
public class Effects3DActivity extends Activity implements OnSeekBarChangeListener
37
{
38
    public static final int MOVE   =0;
39
    public static final int SCALE  =1;
40
    public static final int ROTATE =2;
41
    public static final int SHEAR  =3;
42
	
43
    private SeekBar bar;
44
    private TextView textMove, textScale, textRotate, textShear;
45
    private int moveX, moveY, moveZ;
46
    private int scaleX, scaleY, scaleZ;
47
    private int rotateX, rotateY, rotateZ, rotateA;
48
    private int shearX, shearY, shearZ;
49
    
50
    private int maxX, maxY, maxZ;
51
    
52
    private float fmoveX, fmoveY, fmoveZ;
53
    private float fscaleX, fscaleY, fscaleZ;
54
    private float frotateX, frotateY, frotateZ, frotateA;
55
    private float fshearX, fshearY, fshearZ;
56
    
57
    private int[] effects = new int[4];
58
    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
    
61
    @Override
62
    protected void onCreate(Bundle icicle) 
63
      {
64
      super.onCreate(icicle);
65
      setContentView(R.layout.effects3dlayout);
66
      Default(null);
67
      }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
    public void Default(View view)
72
      {
73
      effects[0] = MOVE;
74
      effects[1] = SCALE;
75
      effects[2] = ROTATE;
76
      effects[3] = SHEAR;
77
    
78
      moveX = 50;
79
      moveY = 50;
80
      moveZ = 50;
81
      
82
      scaleX = 50;
83
      scaleY = 50;
84
      scaleZ = 50;
85
      
86
      rotateX = 100;
87
      rotateY =  50;
88
      rotateZ =  50;
89
      rotateA =  50;
90
      
91
      shearX = 50;
92
      shearY = 50;
93
      shearZ = 50;
94
      
95
      addViews();
96
      }
97
    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
    
100
    private void addViews()
101
      {
102
      LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
103
    
104
      layout.removeAllViews();
105
      
106
      View move   = getLayoutInflater().inflate(R.layout.effects3dmove   , null);
107
      View scale  = getLayoutInflater().inflate(R.layout.effects3dscale  , null);
108
      View rotate = getLayoutInflater().inflate(R.layout.effects3drotate , null);
109
      View shear  = getLayoutInflater().inflate(R.layout.effects3dshear  , null);
110
     
111
      for( int i=effects.length-1 ; i>=0 ; i-- )
112
        {
113
        switch(effects[i])
114
          {
115
          case MOVE  : layout.addView(move   , 0); break; 
116
          case SCALE : layout.addView(scale  , 0); break;
117
          case ROTATE: layout.addView(rotate , 0); break;
118
          case SHEAR : layout.addView(shear  , 0); break;
119
          }
120
        }
121
      
122
      textMove  = (TextView)findViewById(R.id.matrix3dmoveText);
123
      textScale = (TextView)findViewById(R.id.matrix3dscaleText);
124
      textRotate= (TextView)findViewById(R.id.matrix3drotateText);
125
      textShear = (TextView)findViewById(R.id.matrix3dshearText);
126
     
127
      setMoveText();
128
      setScaleText();
129
      setRotateText();
130
      setShearText();
131
      
132
      setBar(R.id.matrix3dmoveBar1, moveX);
133
      setBar(R.id.matrix3dmoveBar2, moveY);
134
      setBar(R.id.matrix3dmoveBar3, moveZ);
135
      
136
      setBar(R.id.matrix3dscaleBar1, scaleX);
137
      setBar(R.id.matrix3dscaleBar2, scaleY);
138
      setBar(R.id.matrix3dscaleBar3, scaleZ);
139
      
140
      setBar(R.id.matrix3drotateBar1, rotateX);
141
      setBar(R.id.matrix3drotateBar2, rotateY);
142
      setBar(R.id.matrix3drotateBar3, rotateZ);
143
      setBar(R.id.matrix3drotateBar4, rotateA);
144
      
145
      setBar(R.id.matrix3dshearBar1, shearX);
146
      setBar(R.id.matrix3dshearBar2, shearY);
147
      setBar(R.id.matrix3dshearBar3, shearZ);
148
      
149
      Effects3DRenderer.setOrder(effects);
150
      }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
    private void moveUp(int effect)
155
      {
156
      int len = effects.length-1;	
157
      int index = -1;
158
      
159
      for(int i=0; i<=len; i++)	
160
        {
161
        if( effects[i]==effect ) 
162
          {
163
          index=i;
164
          break;
165
          }
166
        }
167
      
168
      if( index==0 )
169
        {
170
        for(int i=0; i<len; i++)
171
          effects[i] = effects[i+1];
172
    	
173
        effects[len] = effect;
174
        }
175
      else if( index>0 )
176
        {
177
        effects[index]   = effects[index-1];
178
        effects[index-1] = effect;
179
        }
180
      
181
      addViews();
182
      }
183
 
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
    public void ButtonMove(View v)
187
      {
188
      moveUp(MOVE); 	
189
      }
190

  
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193
    public void ButtonScale(View v)
194
      {
195
      moveUp(SCALE); 	
196
      }
197
    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

  
200
    public void ButtonRotate(View v)
201
      {
202
      moveUp(ROTATE); 	
203
      }
204

  
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

  
207
    public void ButtonShear(View v)
208
      {
209
      moveUp(SHEAR); 	
210
      }
211
 
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
    
214
    private void setBar(int id, int value)
215
      {
216
      bar = (SeekBar)findViewById(id);
217
      bar.setOnSeekBarChangeListener(this); 
218
      bar.setProgress(value);
219
      }
220

  
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

  
223
    private void computeMove()
224
      {
225
      fmoveX = (moveX-50)*maxX/50.0f;
226
      fmoveY = (moveY-50)*maxY/50.0f;
227
      fmoveZ = (moveZ-50)*maxZ/50.0f;
228

  
229
      Effects3DRenderer.setMove( fmoveX, fmoveY, fmoveZ);
230
      }
231
    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

  
234
    private void setMoveText()
235
      {
236
      fmoveX = ((int)(100*fmoveX))/100.0f;
237
      fmoveY = ((int)(100*fmoveY))/100.0f;
238
      fmoveZ = ((int)(100*fmoveZ))/100.0f;
239
      
240
      textMove.setText("move("+fmoveX+" , "+fmoveY+" , "+fmoveZ+")");
241
      }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
    private void computeScale()
246
      {
247
      fscaleX = (scaleX>50 ? 0.18f : 0.018f)*(scaleX-50)+1;
248
      fscaleY = (scaleY>50 ? 0.18f : 0.018f)*(scaleY-50)+1;
249
      fscaleZ = (scaleZ>50 ? 0.18f : 0.018f)*(scaleZ-50)+1;
250

  
251
      Effects3DRenderer.setScale(fscaleX, fscaleY, fscaleZ);
252
      }
253
    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

  
256
    private void setScaleText()
257
      {
258
      fscaleX = ((int)(100*fscaleX))/100.0f;
259
      fscaleY = ((int)(100*fscaleY))/100.0f;
260
      fscaleZ = ((int)(100*fscaleZ))/100.0f;
261
      
262
      textScale.setText("scale("+fscaleX+" , "+fscaleY+" , "+fscaleZ+")");
263
      }
264

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
    private void computeRotate()
268
      {
269
      frotateX = (rotateX-50)/50.0f;
270
      frotateY = (rotateY-50)/50.0f;
271
      frotateZ = (rotateZ-50)/50.0f;
272
    
273
      Effects3DRenderer.setRotate( frotateA, frotateX, frotateY, frotateZ );
274
      }
275
    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
    private void setRotateText()
279
      {
280
      frotateX = ((int)(100*frotateX))/100.0f;
281
      frotateY = ((int)(100*frotateY))/100.0f;
282
      frotateZ = ((int)(100*frotateZ))/100.0f;
283
      
284
      frotateA = ((rotateA-50)*180)/50;
285
      
286
      textRotate.setText("rotate( "+frotateA+" ("+frotateX+","+frotateY+","+frotateZ+") )");
287
      }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
    private void computeShear()
292
      {
293
      fshearX = (shearX-50)/25.0f;
294
      fshearY = (shearY-50)/25.0f;
295
      fshearZ = (shearZ-50)/25.0f;
296
    		
297
      Effects3DRenderer.setShear( fshearX, fshearY, fshearZ );
298
      }
299
    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

  
302
    private void setShearText()
303
      {
304
      fshearX = ((int)(100*fshearX))/100.0f;
305
      fshearY = ((int)(100*fshearY))/100.0f;
306
      fshearZ = ((int)(100*fshearZ))/100.0f;
307
      
308
      textShear.setText("shear("+fshearX+" , "+fshearY+" , "+fshearZ+")");	
309
      }
310
   
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
    
313
    @Override
314
    protected void onPause() 
315
      {
316
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView);
317
      mView.onPause(); 
318
      super.onPause();
319
      }
320

  
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
    
323
    @Override
324
    protected void onResume() 
325
      {
326
      super.onResume();
327
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView); 
328
      mView.onResume();
329
      }
330

  
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
    
333
    @Override
334
    public void onWindowFocusChanged(boolean hasFocus) 
335
      {
336
      super.onWindowFocusChanged(hasFocus);
337
  
338
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.effects3dSurfaceView);
339
      
340
      maxX = mView.getWidth();
341
      maxY = mView.getHeight();
342
      maxZ = (maxX+maxY)/2;
343
      }
344

  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
    
347
    @Override
348
    protected void onDestroy() 
349
      {
350
      Distorted.onDestroy();  
351
      super.onDestroy();
352
      }
353
    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
    
356
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
357
      {
358
      switch (bar.getId()) 
359
        {
360
        case R.id.matrix3dmoveBar1  : moveX = progress; computeMove()  ; setMoveText()  ; break;
361
        case R.id.matrix3dmoveBar2  : moveY = progress; computeMove()  ; setMoveText()  ; break;
362
        case R.id.matrix3dmoveBar3  : moveZ = progress; computeMove()  ; setMoveText()  ; break;
363
        
364
        case R.id.matrix3dscaleBar1 : scaleX= progress; computeScale() ; setScaleText() ; break;
365
        case R.id.matrix3dscaleBar2 : scaleY= progress; computeScale() ; setScaleText() ; break;
366
        case R.id.matrix3dscaleBar3 : scaleZ= progress; computeScale() ; setScaleText() ; break;
367
        
368
        case R.id.matrix3drotateBar1: rotateX=progress; computeRotate(); setRotateText(); break;
369
        case R.id.matrix3drotateBar2: rotateY=progress; computeRotate(); setRotateText(); break;
370
        case R.id.matrix3drotateBar3: rotateZ=progress; computeRotate(); setRotateText(); break;
371
        case R.id.matrix3drotateBar4: rotateA=progress; computeRotate(); setRotateText(); break;
372
        
373
        case R.id.matrix3dshearBar1 : shearX= progress; computeShear() ; setShearText() ; break;
374
        case R.id.matrix3dshearBar2 : shearY= progress; computeShear() ; setShearText() ; break;
375
        case R.id.matrix3dshearBar3 : shearZ= progress; computeShear() ; setShearText() ; break;
376
        }
377
      }
378

  
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

  
381
    public void onStartTrackingTouch(SeekBar bar) { }
382
    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

  
385
    public void onStopTrackingTouch(SeekBar bar)  { }
386
    
387
}
src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.effects3d;
21

  
22
import java.io.IOException;
23
import java.io.InputStream;
24

  
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27

  
28
import org.distorted.examples.R;
29

  
30
import org.distorted.library.DistortedCubes;
31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.Dynamic1D;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static1D;
35
import org.distorted.library.type.Static3D;
36
import org.distorted.library.type.Static4D;
37
import org.distorted.library.type.Dynamic4D;
38
import org.distorted.library.Distorted;
39

  
40
import android.graphics.Bitmap;
41
import android.graphics.BitmapFactory;
42
import android.opengl.GLES20;
43
import android.opengl.GLSurfaceView;
44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
class Effects3DRenderer implements GLSurfaceView.Renderer 
48
{
49
    private static final int SIZE = 100;
50
	
51
    private GLSurfaceView mView;
52
    private static DistortedCubes mCube;
53

  
54
    private static int[] order;
55
    
56
    private static Dynamic3D mMoveInter, mScaleInter, mShearInter;
57
    private static Dynamic4D mDynamicRotate;
58

  
59
    private static Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
60
    private static Static4D mRotatePoint;
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
    public static void setMove(float x, float y, float z)
65
      {
66
      mMovePoint.set(x, y, z);
67
      }
68
    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
    public static void setScale(float x, float y, float z)
72
      {
73
      mScalePoint.set(x, y, z);
74
      }
75
     
76
///////////////////////////////////////////////////////////////////////////////////////////////////
77

  
78
    public static void setRotate(float a, float x, float y, float z)
79
      {
80
      mRotatePoint.set(a,x,y,z);
81
      }
82
    
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84

  
85
    public static void setShear(float x, float y, float z)
86
      {
87
      mShearPoint.set(x, y, z);
88
      }
89

  
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91

  
92
    public static void setOrder(int[] effects)
93
      {
94
      order = effects;
95
      setMatrixEffects();
96
      }
97
      
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100
    public static void setMatrixEffects()
101
      {
102
      mCube.abortEffects(EffectTypes.MATRIX);
103
	
104
      for( int i=0; i<=order.length-1 ; i++ )
105
        {
106
        switch(order[i])
107
          {
108
          case Effects3DActivity.MOVE  : mCube.move(mMoveInter)                 ; break;
109
          case Effects3DActivity.SCALE : mCube.scale(mScaleInter)               ; break;
110
          case Effects3DActivity.ROTATE: mCube.rotate(mDynamicRotate,mZeroPoint); break;
111
          case Effects3DActivity.SHEAR : mCube.shear(mShearInter, mZeroPoint)   ; break;
112
          }
113
        }
114
      }
115
    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
    public Effects3DRenderer(GLSurfaceView v) 
119
      {
120
      mView = v;
121
      mCube = new DistortedCubes( 1, "1", SIZE);
122
      
123
      mZeroPoint   = new Static3D(0,0,0);
124
      mMovePoint   = new Static3D(0,0,0);
125
      mScalePoint  = new Static3D(1,1,1);
126
      mShearPoint  = new Static3D(0,0,0);
127
      mRotatePoint = new Static4D(0,1,0,0);
128

  
129
      mMoveInter    = new Dynamic3D();
130
      mScaleInter   = new Dynamic3D();
131
      mShearInter   = new Dynamic3D();
132
      mDynamicRotate= new Dynamic4D();
133

  
134
      mMoveInter.add(mMovePoint);
135
      mScaleInter.add(mScalePoint);
136
      mShearInter.add(mShearPoint);
137
      mDynamicRotate.add(mRotatePoint);
138
      }
139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141
   
142
    public void onDrawFrame(GL10 glUnused) 
143
      {
144
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
145
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
146
      
147
      mCube.draw(System.currentTimeMillis());
148
      }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
    
152
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
153
      {
154
      setMatrixEffects();
155

  
156
      Distorted.onSurfaceChanged(width, height); 
157
      }
158

  
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160
    
161
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
162
      {
163
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
164
      Bitmap bitmap;
165
        
166
      try 
167
        {
168
        bitmap = BitmapFactory.decodeStream(is);
169
        } 
170
      finally 
171
        {
172
        try 
173
          {
174
          is.close();
175
          } 
176
        catch(IOException e) { }
177
        }  
178
      
179
      mCube.setBitmap(bitmap);
180
      
181
      try
182
        {
183
        Distorted.onSurfaceCreated(mView.getContext());
184
        }
185
      catch(Exception ex)
186
        {
187
        android.util.Log.e("Quaternion", ex.getMessage() );
188
        }
189
      }
190
}
src/main/java/org/distorted/examples/effects3d/Effects3DSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.effects3d;
21

  
22
import android.content.Context;
23
import android.opengl.GLSurfaceView;
24
import android.os.Build;
25
import android.util.AttributeSet;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class Effects3DSurfaceView extends GLSurfaceView 
30
{
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
   
33
    public Effects3DSurfaceView(Context c, AttributeSet attrs) 
34
      {
35
      super(c, attrs);
36
      
37
      if(!isInEditMode())
38
        {
39
        setEGLContextClientVersion(2);
40
        
41
        if( Build.FINGERPRINT.startsWith("generic") )
42
          { 
43
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
44
          }
45
        
46
        setRenderer(new Effects3DRenderer(this));
47
        }
48
      }
49
}
50

  
src/main/java/org/distorted/examples/matrix3d/Matrix3DActivity.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.matrix3d;
21

  
22
import org.distorted.library.Distorted;
23
import org.distorted.examples.R;
24

  
25
import android.app.Activity;
26
import android.os.Bundle;
27
import android.opengl.GLSurfaceView;
28
import android.view.View;
29
import android.widget.LinearLayout;
30
import android.widget.SeekBar;
31
import android.widget.TextView;
32
import android.widget.SeekBar.OnSeekBarChangeListener;
33

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

  
36
public class Matrix3DActivity extends Activity implements OnSeekBarChangeListener
37
{
38
    public static final int MOVE   =0;
39
    public static final int SCALE  =1;
40
    public static final int ROTATE =2;
41
    public static final int SHEAR  =3;
42
	
43
    private SeekBar bar;
44
    private TextView textMove, textScale, textRotate, textShear;
45
    private int moveX, moveY, moveZ;
46
    private int scaleX, scaleY, scaleZ;
47
    private int rotateX, rotateY, rotateZ, rotateA;
48
    private int shearX, shearY, shearZ;
49
    
50
    private int maxX, maxY, maxZ;
51
    
52
    private float fmoveX, fmoveY, fmoveZ;
53
    private float fscaleX, fscaleY, fscaleZ;
54
    private float frotateX, frotateY, frotateZ, frotateA;
55
    private float fshearX, fshearY, fshearZ;
56
    
57
    private int[] effects = new int[4];
58
    
59
///////////////////////////////////////////////////////////////////////////////////////////////////
60
    
61
    @Override
62
    protected void onCreate(Bundle icicle) 
63
      {
64
      super.onCreate(icicle);
65
      setContentView(R.layout.matrix3dlayout);
66
      Default(null);
67
      }
68

  
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

  
71
    public void Default(View view)
72
      {
73
      effects[0] = MOVE;
74
      effects[1] = SCALE;
75
      effects[2] = ROTATE;
76
      effects[3] = SHEAR;
77
    
78
      moveX = 50;
79
      moveY = 50;
80
      moveZ = 50;
81
      
82
      scaleX = 50;
83
      scaleY = 50;
84
      scaleZ = 50;
85
      
86
      rotateX = 100;
87
      rotateY =  50;
88
      rotateZ =  50;
89
      rotateA =  50;
90
      
91
      shearX = 50;
92
      shearY = 50;
93
      shearZ = 50;
94
      
95
      addViews();
96
      }
97
    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99
    
100
    private void addViews()
101
      {
102
      LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
103
    
104
      layout.removeAllViews();
105
      
106
      View move   = getLayoutInflater().inflate(R.layout.matrix3dmove, null);
107
      View scale  = getLayoutInflater().inflate(R.layout.matrix3dscale, null);
108
      View rotate = getLayoutInflater().inflate(R.layout.matrix3drotate, null);
109
      View shear  = getLayoutInflater().inflate(R.layout.matrix3dshear, null);
110
     
111
      for( int i=effects.length-1 ; i>=0 ; i-- )
112
        {
113
        switch(effects[i])
114
          {
115
          case MOVE  : layout.addView(move   , 0); break; 
116
          case SCALE : layout.addView(scale  , 0); break;
117
          case ROTATE: layout.addView(rotate , 0); break;
118
          case SHEAR : layout.addView(shear  , 0); break;
119
          }
120
        }
121
      
122
      textMove  = (TextView)findViewById(R.id.matrix3dmoveText);
123
      textScale = (TextView)findViewById(R.id.matrix3dscaleText);
124
      textRotate= (TextView)findViewById(R.id.matrix3drotateText);
125
      textShear = (TextView)findViewById(R.id.matrix3dshearText);
126
     
127
      setMoveText();
128
      setScaleText();
129
      setRotateText();
130
      setShearText();
131
      
132
      setBar(R.id.matrix3dmoveBar1, moveX);
133
      setBar(R.id.matrix3dmoveBar2, moveY);
134
      setBar(R.id.matrix3dmoveBar3, moveZ);
135
      
136
      setBar(R.id.matrix3dscaleBar1, scaleX);
137
      setBar(R.id.matrix3dscaleBar2, scaleY);
138
      setBar(R.id.matrix3dscaleBar3, scaleZ);
139
      
140
      setBar(R.id.matrix3drotateBar1, rotateX);
141
      setBar(R.id.matrix3drotateBar2, rotateY);
142
      setBar(R.id.matrix3drotateBar3, rotateZ);
143
      setBar(R.id.matrix3drotateBar4, rotateA);
144
      
145
      setBar(R.id.matrix3dshearBar1, shearX);
146
      setBar(R.id.matrix3dshearBar2, shearY);
147
      setBar(R.id.matrix3dshearBar3, shearZ);
148
      
149
      Matrix3DRenderer.setOrder(effects);
150
      }
151

  
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

  
154
    private void moveUp(int effect)
155
      {
156
      int len = effects.length-1;	
157
      int index = -1;
158
      
159
      for(int i=0; i<=len; i++)	
160
        {
161
        if( effects[i]==effect ) 
162
          {
163
          index=i;
164
          break;
165
          }
166
        }
167
      
168
      if( index==0 )
169
        {
170
        for(int i=0; i<len; i++)
171
          effects[i] = effects[i+1];
172
    	
173
        effects[len] = effect;
174
        }
175
      else if( index>0 )
176
        {
177
        effects[index]   = effects[index-1];
178
        effects[index-1] = effect;
179
        }
180
      
181
      addViews();
182
      }
183
 
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
    public void ButtonMove(View v)
187
      {
188
      moveUp(MOVE); 	
189
      }
190

  
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

  
193
    public void ButtonScale(View v)
194
      {
195
      moveUp(SCALE); 	
196
      }
197
    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

  
200
    public void ButtonRotate(View v)
201
      {
202
      moveUp(ROTATE); 	
203
      }
204

  
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

  
207
    public void ButtonShear(View v)
208
      {
209
      moveUp(SHEAR); 	
210
      }
211
 
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
    
214
    private void setBar(int id, int value)
215
      {
216
      bar = (SeekBar)findViewById(id);
217
      bar.setOnSeekBarChangeListener(this); 
218
      bar.setProgress(value);
219
      }
220

  
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

  
223
    private void computeMove()
224
      {
225
      fmoveX = (moveX-50)*maxX/50.0f;
226
      fmoveY = (moveY-50)*maxY/50.0f;
227
      fmoveZ = (moveZ-50)*maxZ/50.0f;
228

  
229
      Matrix3DRenderer.setMove( fmoveX, fmoveY, fmoveZ);
230
      }
231
    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

  
234
    private void setMoveText()
235
      {
236
      fmoveX = ((int)(100*fmoveX))/100.0f;
237
      fmoveY = ((int)(100*fmoveY))/100.0f;
238
      fmoveZ = ((int)(100*fmoveZ))/100.0f;
239
      
240
      textMove.setText("move("+fmoveX+" , "+fmoveY+" , "+fmoveZ+")");
241
      }
242

  
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

  
245
    private void computeScale()
246
      {
247
      fscaleX = (scaleX>50 ? 0.18f : 0.018f)*(scaleX-50)+1;
248
      fscaleY = (scaleY>50 ? 0.18f : 0.018f)*(scaleY-50)+1;
249
      fscaleZ = (scaleZ>50 ? 0.18f : 0.018f)*(scaleZ-50)+1;
250

  
251
      Matrix3DRenderer.setScale(fscaleX, fscaleY, fscaleZ);
252
      }
253
    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

  
256
    private void setScaleText()
257
      {
258
      fscaleX = ((int)(100*fscaleX))/100.0f;
259
      fscaleY = ((int)(100*fscaleY))/100.0f;
260
      fscaleZ = ((int)(100*fscaleZ))/100.0f;
261
      
262
      textScale.setText("scale("+fscaleX+" , "+fscaleY+" , "+fscaleZ+")");
263
      }
264

  
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

  
267
    private void computeRotate()
268
      {
269
      frotateX = (rotateX-50)/50.0f;
270
      frotateY = (rotateY-50)/50.0f;
271
      frotateZ = (rotateZ-50)/50.0f;
272
    
273
      Matrix3DRenderer.setRotate( frotateA, frotateX, frotateY, frotateZ );
274
      }
275
    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

  
278
    private void setRotateText()
279
      {
280
      frotateX = ((int)(100*frotateX))/100.0f;
281
      frotateY = ((int)(100*frotateY))/100.0f;
282
      frotateZ = ((int)(100*frotateZ))/100.0f;
283
      
284
      frotateA = ((rotateA-50)*180)/50;
285
      
286
      textRotate.setText("rotate( "+frotateA+" ("+frotateX+","+frotateY+","+frotateZ+") )");
287
      }
288

  
289
///////////////////////////////////////////////////////////////////////////////////////////////////
290

  
291
    private void computeShear()
292
      {
293
      fshearX = (shearX-50)/25.0f;
294
      fshearY = (shearY-50)/25.0f;
295
      fshearZ = (shearZ-50)/25.0f;
296
    		
297
      Matrix3DRenderer.setShear( fshearX, fshearY, fshearZ );
298
      }
299
    
300
///////////////////////////////////////////////////////////////////////////////////////////////////
301

  
302
    private void setShearText()
303
      {
304
      fshearX = ((int)(100*fshearX))/100.0f;
305
      fshearY = ((int)(100*fshearY))/100.0f;
306
      fshearZ = ((int)(100*fshearZ))/100.0f;
307
      
308
      textShear.setText("shear("+fshearX+" , "+fshearY+" , "+fshearZ+")");	
309
      }
310
   
311
///////////////////////////////////////////////////////////////////////////////////////////////////
312
    
313
    @Override
314
    protected void onPause() 
315
      {
316
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
317
      mView.onPause(); 
318
      super.onPause();
319
      }
320

  
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
    
323
    @Override
324
    protected void onResume() 
325
      {
326
      super.onResume();
327
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
328
      mView.onResume();
329
      }
330

  
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
    
333
    @Override
334
    public void onWindowFocusChanged(boolean hasFocus) 
335
      {
336
      super.onWindowFocusChanged(hasFocus);
337
  
338
      GLSurfaceView mView = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
339
      
340
      maxX = mView.getWidth();
341
      maxY = mView.getHeight();
342
      maxZ = (maxX+maxY)/2;
343
      }
344

  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346
    
347
    @Override
348
    protected void onDestroy() 
349
      {
350
      Distorted.onDestroy();  
351
      super.onDestroy();
352
      }
353
    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355
    
356
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
357
      {
358
      switch (bar.getId()) 
359
        {
360
        case R.id.matrix3dmoveBar1  : moveX = progress; computeMove()  ; setMoveText()  ; break;
361
        case R.id.matrix3dmoveBar2  : moveY = progress; computeMove()  ; setMoveText()  ; break;
362
        case R.id.matrix3dmoveBar3  : moveZ = progress; computeMove()  ; setMoveText()  ; break;
363
        
364
        case R.id.matrix3dscaleBar1 : scaleX= progress; computeScale() ; setScaleText() ; break;
365
        case R.id.matrix3dscaleBar2 : scaleY= progress; computeScale() ; setScaleText() ; break;
366
        case R.id.matrix3dscaleBar3 : scaleZ= progress; computeScale() ; setScaleText() ; break;
367
        
368
        case R.id.matrix3drotateBar1: rotateX=progress; computeRotate(); setRotateText(); break;
369
        case R.id.matrix3drotateBar2: rotateY=progress; computeRotate(); setRotateText(); break;
370
        case R.id.matrix3drotateBar3: rotateZ=progress; computeRotate(); setRotateText(); break;
371
        case R.id.matrix3drotateBar4: rotateA=progress; computeRotate(); setRotateText(); break;
372
        
373
        case R.id.matrix3dshearBar1 : shearX= progress; computeShear() ; setShearText() ; break;
374
        case R.id.matrix3dshearBar2 : shearY= progress; computeShear() ; setShearText() ; break;
375
        case R.id.matrix3dshearBar3 : shearZ= progress; computeShear() ; setShearText() ; break;
376
        }
377
      }
378

  
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

  
381
    public void onStartTrackingTouch(SeekBar bar) { }
382
    
383
///////////////////////////////////////////////////////////////////////////////////////////////////
384

  
385
    public void onStopTrackingTouch(SeekBar bar)  { }
386
    
387
}
src/main/java/org/distorted/examples/matrix3d/Matrix3DRenderer.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.matrix3d;
21

  
22
import java.io.IOException;
23
import java.io.InputStream;
24

  
25
import javax.microedition.khronos.egl.EGLConfig;
26
import javax.microedition.khronos.opengles.GL10;
27

  
28
import org.distorted.examples.R;
29

  
30
import org.distorted.library.DistortedCubes;
31
import org.distorted.library.EffectTypes;
32
import org.distorted.library.type.Dynamic3D;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.library.type.Dynamic4D;
36
import org.distorted.library.Distorted;
37

  
38
import android.graphics.Bitmap;
39
import android.graphics.BitmapFactory;
40
import android.opengl.GLES20;
41
import android.opengl.GLSurfaceView;
42

  
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

  
45
class Matrix3DRenderer implements GLSurfaceView.Renderer
46
{
47
    private static final int SIZE = 100;
48
	
49
    private GLSurfaceView mView;
50
    private static DistortedCubes mCube;
51

  
52
    private static int[] order;
53
    
54
    private static Dynamic3D mMoveInter, mScaleInter, mShearInter;
55
    private static Dynamic4D mDynamicRotate;
56

  
57
    private static Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
58
    private static Static4D mRotatePoint;
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
    public static void setMove(float x, float y, float z)
63
      {
64
      mMovePoint.set(x, y, z);
65
      }
66
    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
    public static void setScale(float x, float y, float z)
70
      {
71
      mScalePoint.set(x, y, z);
72
      }
73
     
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

  
76
    public static void setRotate(float a, float x, float y, float z)
77
      {
78
      mRotatePoint.set(a,x,y,z);
79
      }
80
    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

  
83
    public static void setShear(float x, float y, float z)
84
      {
85
      mShearPoint.set(x, y, z);
86
      }
87

  
88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
    public static void setOrder(int[] effects)
91
      {
92
      order = effects;
93
      setMatrixEffects();
94
      }
95
      
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

  
98
    public static void setMatrixEffects()
99
      {
100
      mCube.abortEffects(EffectTypes.MATRIX);
101
	
102
      for( int i=0; i<=order.length-1 ; i++ )
103
        {
104
        switch(order[i])
105
          {
106
          case Matrix3DActivity.MOVE  : mCube.move(mMoveInter)                 ; break;
107
          case Matrix3DActivity.SCALE : mCube.scale(mScaleInter)               ; break;
108
          case Matrix3DActivity.ROTATE: mCube.rotate(mDynamicRotate,mZeroPoint); break;
109
          case Matrix3DActivity.SHEAR : mCube.shear(mShearInter, mZeroPoint)   ; break;
110
          }
111
        }
112
      }
113
    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

  
116
    public Matrix3DRenderer(GLSurfaceView v)
117
      {
118
      mView = v;
119
      mCube = new DistortedCubes( 1, "1", SIZE);
120
      
121
      mZeroPoint   = new Static3D(0,0,0);
122
      mMovePoint   = new Static3D(0,0,0);
123
      mScalePoint  = new Static3D(1,1,1);
124
      mShearPoint  = new Static3D(0,0,0);
125
      mRotatePoint = new Static4D(0,1,0,0);
126

  
127
      mMoveInter    = new Dynamic3D();
128
      mScaleInter   = new Dynamic3D();
129
      mShearInter   = new Dynamic3D();
130
      mDynamicRotate= new Dynamic4D();
131

  
132
      mMoveInter.add(mMovePoint);
133
      mScaleInter.add(mScalePoint);
134
      mShearInter.add(mShearPoint);
135
      mDynamicRotate.add(mRotatePoint);
136
      }
137

  
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
   
140
    public void onDrawFrame(GL10 glUnused) 
141
      {
142
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
143
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
144
      
145
      mCube.draw(System.currentTimeMillis());
146
      }
147

  
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149
    
150
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
151
      {
152
      setMatrixEffects();
153

  
154
      Distorted.onSurfaceChanged(width, height); 
155
      }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
    
159
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
160
      {
161
      InputStream is = mView.getContext().getResources().openRawResource(R.raw.grid);
162
      Bitmap bitmap;
163
        
164
      try 
165
        {
166
        bitmap = BitmapFactory.decodeStream(is);
167
        } 
168
      finally 
169
        {
170
        try 
171
          {
172
          is.close();
173
          } 
174
        catch(IOException e) { }
175
        }  
176
      
177
      mCube.setBitmap(bitmap);
178
      
179
      try
180
        {
181
        Distorted.onSurfaceCreated(mView.getContext());
182
        }
183
      catch(Exception ex)
184
        {
185
        android.util.Log.e("Quaternion", ex.getMessage() );
186
        }
187
      }
188
}
src/main/java/org/distorted/examples/matrix3d/Matrix3DSurfaceView.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
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.matrix3d;
21

  
22
import android.content.Context;
23
import android.opengl.GLSurfaceView;
24
import android.os.Build;
25
import android.util.AttributeSet;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
29
class Matrix3DSurfaceView extends GLSurfaceView
30
{
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
   
33
    public Matrix3DSurfaceView(Context c, AttributeSet attrs)
34
      {
35
      super(c, attrs);
36
      
37
      if(!isInEditMode())
38
        {
39
        setEGLContextClientVersion(2);
40
        
41
        if( Build.FINGERPRINT.startsWith("generic") )
42
          { 
43
          setEGLConfigChooser(8, 8, 8, 8, 16, 0);   
44
          }
45
        
46
        setRenderer(new Matrix3DRenderer(this));
47
        }
48
      }
49
}
50

  
src/main/res/layout/effects3dlayout.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.effects3d.Effects3DSurfaceView
8
        android:id="@+id/effects3dSurfaceView"
9
        android:layout_width="fill_parent"
10
        android:layout_height="0dp"
11
        android:layout_weight="1" />
12

  
13
    <Button
14
        android:id="@+id/button1"
15
        android:layout_width="fill_parent"
16
        android:layout_height="wrap_content"
17
        android:onClick="Default"
18
        android:text="@string/Default" />
19

  
20
    <ScrollView
21
        android:id="@+id/matrix3dscrollView"
22
        android:layout_width="match_parent"
23
        android:layout_height="0dp"
24
        android:layout_weight="0.82" >
25

  
26
        <LinearLayout
27
            android:id="@+id/matrix3dlayout"
28
            android:layout_width="match_parent"
29
            android:layout_height="wrap_content"
30
            android:orientation="vertical" >
31
        </LinearLayout>
32

  
33
    </ScrollView>
34

  
35
</LinearLayout>
src/main/res/layout/effects3dmove.xml
1
<?xml version="1.0" encoding="utf-8"?>
2

  
3
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
4
                android:id="@id/matrix3dRowMove"
5
                android:layout_width="match_parent"
6
                android:layout_height="wrap_content"
7
                android:orientation="horizontal" >
8

  
9
                <LinearLayout
10
                    android:layout_width="0dp"
11
                    android:layout_height="wrap_content"
12
                    android:layout_weight="0.8"
13
                    android:orientation="vertical" >
14

  
15
                    <TextView
16
                        android:id="@+id/matrix3dmoveText"
17
                        android:layout_width="wrap_content"
18
                        android:layout_height="wrap_content"
19
                        android:layout_marginEnd="5dp"
20
                        android:layout_marginStart="5dp"
21
                        android:layout_marginTop="3dp"
22
                        android:textAppearance="?android:attr/textAppearanceLarge" />
23

  
24
                    <SeekBar
25
                        android:id="@+id/matrix3dmoveBar1"
26
                        android:layout_width="fill_parent"
27
                        android:layout_height="wrap_content"
28
                        android:layout_marginEnd="5dp"
29
                        android:layout_marginLeft="5dp"
30
                        android:layout_marginRight="5dp" />
31

  
32
                    <SeekBar
33
                        android:id="@+id/matrix3dmoveBar2"
34
                        android:layout_width="fill_parent"
35
                        android:layout_height="wrap_content"
36
                        android:layout_marginEnd="5dp"
37
                        android:layout_marginLeft="5dp"
38
                        android:layout_marginRight="5dp" />
39

  
40
                    <SeekBar
41
                        android:id="@+id/matrix3dmoveBar3"
42
                        android:layout_width="fill_parent"
43
                        android:layout_height="wrap_content"
44
                        android:layout_marginEnd="5dp"
45
                        android:layout_marginLeft="5dp"
46
                        android:layout_marginRight="5dp" />
47

  
48
                </LinearLayout>
49

  
50
                <Button
51
                    android:id="@+id/matrix3dUpMove"
52
                    android:layout_width="60dp"
53
                    android:layout_height="fill_parent"
54
                    android:onClick="ButtonMove"
55
                    android:text="@string/Up" />
56

  
57
            </LinearLayout>
src/main/res/layout/effects3drotate.xml
1
<?xml version="1.0" encoding="utf-8"?>
2
            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
                android:id="@+id/matrix3dRowRotate"
4
                android:orientation="horizontal"
5
                android:layout_width="match_parent"
6
                android:layout_height="wrap_content" >
7

  
8
                <LinearLayout
9
                    android:layout_width="0dp"
10
                    android:layout_height="match_parent"
11
                    android:layout_weight="0.70"
12
                    android:orientation="vertical" >
13

  
14
                    <TextView
15
                        android:id="@+id/matrix3drotateText"
16
                        android:layout_width="wrap_content"
17
                        android:layout_height="wrap_content"
18
                        android:layout_marginEnd="5dp"
19
                        android:layout_marginStart="5dp"
20
                        android:layout_marginTop="3dp"
21
                        android:textAppearance="?android:attr/textAppearanceLarge" />
22

  
23
                    <SeekBar
24
                        android:id="@+id/matrix3drotateBar4"
25
                        android:layout_width="fill_parent"
26
                        android:layout_height="wrap_content"
27
                        android:layout_marginEnd="5dp"
28
                        android:layout_marginLeft="5dp"
29
                        android:layout_marginRight="5dp" />
30

  
31
                    <SeekBar
32
                        android:id="@+id/matrix3drotateBar1"
33
                        android:layout_width="fill_parent"
34
                        android:layout_height="wrap_content"
35
                        android:layout_gravity="end"
36
                        android:layout_marginEnd="5dp"
37
                        android:layout_marginLeft="5dp"
38
                        android:layout_marginRight="5dp" />
39

  
40
                    <SeekBar
41
                        android:id="@+id/matrix3drotateBar2"
42
                        android:layout_width="fill_parent"
43
                        android:layout_height="wrap_content"
44
                        android:layout_gravity="end"
45
                        android:layout_marginEnd="5dp"
46
                        android:layout_marginLeft="5dp"
47
                        android:layout_marginRight="5dp" />
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff