Project

General

Profile

« Previous | Next » 

Revision 4d5b37fe

Added by Leszek Koltunski about 8 years ago

Unify Effects3D and Matrix3D (still incomplete!)

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
77 77
  private EffectNames[] mEffectNames;
78 78

  
79 79
  private static boolean mSupportsRegion;
80
  private static boolean mTypeVertex;
80
  private static boolean mSupportsCenter;
81 81

  
82 82
///////////////////////////////////////////////////////////////////////////////////////////////////
83 83

  
......
235 235

  
236 236
///////////////////////////////////////////////////////////////////////////////////////////////////
237 237

  
238
  public static void setTypeVertex(boolean type)
238
  public static void setSupportsCenter(boolean supports)
239 239
    {
240
    mTypeVertex = type;
240
    mSupportsCenter = supports;
241 241
    }
242 242

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

  
245
  public static boolean isTypeVertex()
245
  public static boolean supportsCenter()
246 246
    {
247
    return mTypeVertex;
247
    return mSupportsCenter;
248 248
    }
249 249

  
250 250
///////////////////////////////////////////////////////////////////////////////////////////////////
......
461 461
    mRegionR = getWidth()/2;
462 462

  
463 463
    mSupportsRegion = true;
464
    mTypeVertex     =false;
464
    mSupportsCenter =false;
465 465
    }
466 466

  
467 467
///////////////////////////////////////////////////////////////////////////////////////////////////
......
500 500
    View view = eff.createView();
501 501
    layout.addView(view);
502 502

  
503
    if( mTypeVertex )
503
    if( mSupportsCenter )
504 504
      {
505 505
      View center = eff.createCenter();
506 506
      layout.addView(center);
src/main/java/org/distorted/examples/effects3d/Effects3DEffect.java
408 408
      }
409 409

  
410 410
    Effects3DActivity.setSupportsRegion(mName.supportsRegion());
411
    Effects3DActivity.setTypeVertex(mName.getType() == EffectTypes.VERTEX);
411
    Effects3DActivity.setSupportsCenter(mName.supportsCenter());
412 412

  
413 413
    return mEffect;
414 414
    }
......
555 555
    if( fromUser )
556 556
      {
557 557
      Effects3DActivity.setSupportsRegion(mName.supportsRegion());
558
      Effects3DActivity.setTypeVertex(mName.getType() == EffectTypes.VERTEX);
558
      Effects3DActivity.setSupportsCenter(mName.supportsCenter());
559 559

  
560 560
      Effects3DActivity act = mAct.get();
561 561

  
src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
126 126
      mBackground.draw(time);
127 127
      mObject.draw(time);
128 128

  
129
      if( Effects3DActivity.isTypeVertex() )
129
      if( Effects3DActivity.supportsCenter() )
130 130
        {
131 131
        mCenter.draw(time);
132 132
        if( Effects3DActivity.supportsRegion() ) mRegion.draw(time);
src/main/java/org/distorted/examples/matrix3d/Matrix3DActivity.java
19 19

  
20 20
package org.distorted.examples.matrix3d;
21 21

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

  
26 22
import android.app.Activity;
27
import android.os.Bundle;
23
import android.graphics.Bitmap;
24
import android.graphics.BitmapFactory;
28 25
import android.opengl.GLSurfaceView;
26
import android.os.Bundle;
29 27
import android.view.View;
28
import android.widget.AdapterView;
29
import android.widget.ArrayAdapter;
30 30
import android.widget.LinearLayout;
31
import android.widget.SeekBar;
32
import android.widget.TextView;
33
import android.widget.SeekBar.OnSeekBarChangeListener;
31
import android.widget.Spinner;
34 32

  
35
///////////////////////////////////////////////////////////////////////////////////////////////////
33
import org.distorted.examples.R;
34
import org.distorted.library.Distorted;
35
import org.distorted.library.DistortedCubes;
36
import org.distorted.library.DistortedObject;
37
import org.distorted.library.EffectNames;
38
import org.distorted.library.EffectTypes;
39

  
40
import java.io.IOException;
41
import java.io.InputStream;
42
import java.util.ArrayList;
36 43

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

  
46
public class Matrix3DActivity extends Activity implements AdapterView.OnItemSelectedListener
47
  {
48
  private DistortedObject mObject;
49

  
50
  private ArrayList<Matrix3DEffect> mEffects;
51
  private int mEffectAdd;
52

  
53
  private EffectNames[] mEffectNames;
54

  
55
  private static boolean mSupportsCenter;
56
  private float mCenterX, mCenterY;
61 57

  
62 58
///////////////////////////////////////////////////////////////////////////////////////////////////
63 59

  
64
    public void Default(View view)
65
      {
66
      effects[0] = EffectNames.MOVE;
67
      effects[1] = EffectNames.SCALE;
68
      effects[2] = EffectNames.ROTATE;
69
      effects[3] = EffectNames.SHEAR;
70
    
71
      moveX = 50;
72
      moveY = 50;
73
      moveZ = 50;
74
      
75
      scaleX = 50;
76
      scaleY = 50;
77
      scaleZ = 50;
78
      
79
      rotateX = 100;
80
      rotateY =  50;
81
      rotateZ =  50;
82
      rotateA =  50;
83
      
84
      shearX = 50;
85
      shearY = 50;
86
      shearZ = 50;
87
      
88
      addViews();
89
      }
90
    
60
  @Override
61
  protected void onCreate(Bundle savedState)
62
    {
63
    super.onCreate(savedState);
64

  
65
    mEffects = new ArrayList<>();
66

  
67
    createEffectNames();
68

  
69
    mObject = new DistortedCubes( 1, "1", 100);
70

  
71
    setEffectView();
72
    }
73

  
91 74
///////////////////////////////////////////////////////////////////////////////////////////////////
92
    
93
    private void addViews()
94
      {
95
      LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
96
    
97
      layout.removeAllViews();
98
      
99
      View move   = getLayoutInflater().inflate(R.layout.matrix3dmove, null);
100
      View scale  = getLayoutInflater().inflate(R.layout.matrix3dscale, null);
101
      View rotate = getLayoutInflater().inflate(R.layout.matrix3drotate, null);
102
      View shear  = getLayoutInflater().inflate(R.layout.matrix3dshear, null);
103
     
104
      for( int i=effects.length-1 ; i>=0 ; i-- )
75

  
76
  private void createEffectNames()
77
    {
78
    EffectTypes type = EffectTypes.MATRIX;
79

  
80
    EffectNames[] names = EffectNames.values();
81

  
82
    int numEffects=0;
83

  
84
    for(int i=0; i<names.length; i++)
85
      if( names[i].getType() == type ) numEffects++;
86

  
87
    mEffectNames = new EffectNames[numEffects];
88

  
89
    numEffects=0;
90

  
91
    for(int i=0; i<names.length; i++)
92
      if( names[i].getType() == type )
105 93
        {
106
        switch(effects[i])
107
          {
108
          case MOVE  : layout.addView(move   , 0); break; 
109
          case SCALE : layout.addView(scale  , 0); break;
110
          case ROTATE: layout.addView(rotate , 0); break;
111
          case SHEAR : layout.addView(shear  , 0); break;
112
          }
94
        mEffectNames[numEffects++] = names[i];
113 95
        }
114
      
115
      textMove  = (TextView)findViewById(R.id.matrix3dmoveText);
116
      textScale = (TextView)findViewById(R.id.matrix3dscaleText);
117
      textRotate= (TextView)findViewById(R.id.matrix3drotateText);
118
      textShear = (TextView)findViewById(R.id.matrix3dshearText);
119
     
120
      setMoveText();
121
      setScaleText();
122
      setRotateText();
123
      setShearText();
124
      
125
      setBar(R.id.matrix3dmoveBar1, moveX);
126
      setBar(R.id.matrix3dmoveBar2, moveY);
127
      setBar(R.id.matrix3dmoveBar3, moveZ);
128
      
129
      setBar(R.id.matrix3dscaleBar1, scaleX);
130
      setBar(R.id.matrix3dscaleBar2, scaleY);
131
      setBar(R.id.matrix3dscaleBar3, scaleZ);
132
      
133
      setBar(R.id.matrix3drotateBar1, rotateX);
134
      setBar(R.id.matrix3drotateBar2, rotateY);
135
      setBar(R.id.matrix3drotateBar3, rotateZ);
136
      setBar(R.id.matrix3drotateBar4, rotateA);
137
      
138
      setBar(R.id.matrix3dshearBar1, shearX);
139
      setBar(R.id.matrix3dshearBar2, shearY);
140
      setBar(R.id.matrix3dshearBar3, shearZ);
141
      
142
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
143
      view.getRenderer().setOrder(effects);
144
      }
96
    }
145 97

  
146 98
///////////////////////////////////////////////////////////////////////////////////////////////////
147 99

  
148
    private void moveUp(EffectNames name)
149
      {
150
      int len = effects.length-1;	
151
      int index = -1;
152
      
153
      for(int i=0; i<=len; i++)	
154
        {
155
        if( effects[i]==name )
156
          {
157
          index=i;
158
          break;
159
          }
160
        }
161
      
162
      if( index==0 )
163
        {
164
        for(int i=0; i<len; i++)
165
          effects[i] = effects[i+1];
166
    	
167
        effects[len] = name;
168
        }
169
      else if( index>0 )
170
        {
171
        effects[index]   = effects[index-1];
172
        effects[index-1] = name;
173
        }
174
      
175
      addViews();
176
      }
177
 
100
  public DistortedObject getObject()
101
    {
102
    return mObject;
103
    }
104

  
178 105
///////////////////////////////////////////////////////////////////////////////////////////////////
179 106

  
180
    public void ButtonMove(View v)
181
      {
182
      moveUp(EffectNames.MOVE);
183
      }
107
  public void setRegion(float x, float y, float r)
108
    {
109

  
110
    }
184 111

  
185 112
///////////////////////////////////////////////////////////////////////////////////////////////////
186 113

  
187
    public void ButtonScale(View v)
188
      {
189
      moveUp(EffectNames.SCALE);
190
      }
191
    
114
  public void setCenter(float x, float y)
115
    {
116
    mCenterX = x;
117
    mCenterY = y;
118
    }
119

  
192 120
///////////////////////////////////////////////////////////////////////////////////////////////////
193 121

  
194
    public void ButtonRotate(View v)
195
      {
196
      moveUp(EffectNames.ROTATE);
197
      }
122
  public static void setSupportsRegion(boolean supports)
123
    {
124

  
125
    }
198 126

  
199 127
///////////////////////////////////////////////////////////////////////////////////////////////////
200 128

  
201
    public void ButtonShear(View v)
202
      {
203
      moveUp(EffectNames.SHEAR);
204
      }
205
 
129
  public static boolean supportsRegion()
130
    {
131
    return false;
132
    }
133

  
206 134
///////////////////////////////////////////////////////////////////////////////////////////////////
207
    
208
    private void setBar(int id, int value)
209
      {
210
      SeekBar bar = (SeekBar)findViewById(id);
211
      bar.setOnSeekBarChangeListener(this); 
212
      bar.setProgress(value);
213
      }
135

  
136
  public static void setSupportsCenter(boolean supports)
137
    {
138
    mSupportsCenter = supports;
139
    }
214 140

  
215 141
///////////////////////////////////////////////////////////////////////////////////////////////////
216 142

  
217
    private void computeMove()
218
      {
219
      fmoveX = (moveX-50)*maxX/50.0f;
220
      fmoveY = (moveY-50)*maxY/50.0f;
221
      fmoveZ = (moveZ-50)*maxZ/50.0f;
143
  public static boolean supportsCenter()
144
    {
145
    return mSupportsCenter;
146
    }
222 147

  
223
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
224
      view.getRenderer().setMove( fmoveX, fmoveY, fmoveZ);
225
      }
226
    
227 148
///////////////////////////////////////////////////////////////////////////////////////////////////
228 149

  
229
    private void setMoveText()
150
  public Bitmap getBitmap()
151
    {
152
    Bitmap bmp;
153

  
154
    InputStream is = getResources().openRawResource(R.raw.grid);
155

  
156
    try
157
      {
158
      bmp = BitmapFactory.decodeStream(is);
159
      }
160
    finally
230 161
      {
231
      fmoveX = ((int)(100*fmoveX))/100.0f;
232
      fmoveY = ((int)(100*fmoveY))/100.0f;
233
      fmoveZ = ((int)(100*fmoveZ))/100.0f;
234
      
235
      textMove.setText("move("+fmoveX+" , "+fmoveY+" , "+fmoveZ+")");
162
      try
163
        {
164
        is.close();
165
        }
166
      catch(IOException e) { }
236 167
      }
237 168

  
169
    return bmp;
170
    }
171

  
238 172
///////////////////////////////////////////////////////////////////////////////////////////////////
239 173

  
240
    private void computeScale()
241
      {
242
      fscaleX = (scaleX>50 ? 0.18f : 0.018f)*(scaleX-50)+1;
243
      fscaleY = (scaleY>50 ? 0.18f : 0.018f)*(scaleY-50)+1;
244
      fscaleZ = (scaleZ>50 ? 0.18f : 0.018f)*(scaleZ-50)+1;
174
  public int getWidth()
175
    {
176
    return mObject==null ? 0: mObject.getWidth();
177
    }
245 178

  
246
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
247
      view.getRenderer().setScale(fscaleX, fscaleY, fscaleZ);
248
      }
249
    
250 179
///////////////////////////////////////////////////////////////////////////////////////////////////
251 180

  
252
    private void setScaleText()
253
      {
254
      fscaleX = ((int)(100*fscaleX))/100.0f;
255
      fscaleY = ((int)(100*fscaleY))/100.0f;
256
      fscaleZ = ((int)(100*fscaleZ))/100.0f;
257
      
258
      textScale.setText("scale("+fscaleX+" , "+fscaleY+" , "+fscaleZ+")");
259
      }
181
  public int getHeight()
182
    {
183
    return mObject==null ? 0: mObject.getHeight();
184
    }
260 185

  
261 186
///////////////////////////////////////////////////////////////////////////////////////////////////
262 187

  
263
    private void computeRotate()
188
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
189
    {
190
    switch(parent.getId())
264 191
      {
265
      frotateX = (rotateX-50)/50.0f;
266
      frotateY = (rotateY-50)/50.0f;
267
      frotateZ = (rotateZ-50)/50.0f;
268
    
269
      Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
270
      view.getRenderer().setRotate( frotateA, frotateX, frotateY, frotateZ );
192
      case R.id.matrix3dspinner          : mEffectAdd = pos;
193
                                           break;
271 194
      }
272
    
195
    }
196

  
273 197
///////////////////////////////////////////////////////////////////////////////////////////////////
274 198

  
275
    private void setRotateText()
276
      {
277
      frotateX = ((int)(100*frotateX))/100.0f;
278
      frotateY = ((int)(100*frotateY))/100.0f;
279
      frotateZ = ((int)(100*frotateZ))/100.0f;
280
      
281
      frotateA = ((rotateA-50)*180)/50;
282
      
283
      textRotate.setText("rotate( "+frotateA+" ("+frotateX+","+frotateY+","+frotateZ+") )");
284
      }
199
  public void onNothingSelected(AdapterView<?> parent)
200
    {
201
    }
285 202

  
286 203
///////////////////////////////////////////////////////////////////////////////////////////////////
287 204

  
288
    private void computeShear()
289
      {
290
      fshearX = (shearX-50)/25.0f;
291
      fshearY = (shearY-50)/25.0f;
292
      fshearZ = (shearZ-50)/25.0f;
205
  private void resetData()
206
    {
207
    mCenterX = 0.5f*getWidth();
208
    mCenterY = 0.5f*getHeight();
293 209

  
294
    	Matrix3DSurfaceView view = (Matrix3DSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
295
      view.getRenderer().setShear( fshearX, fshearY, fshearZ );
296
      }
297
    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
210
    mSupportsCenter=false;
211
    }
299 212

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

  
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320
    
321
    @Override
322
    protected void onResume() 
323
      {
324
      super.onResume();
325
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
326
      view.onResume();
327
      }
215
  private void setEffectView()
216
    {
217
    resetData();
218

  
219
    final View view = getLayoutInflater().inflate(R.layout.matrix3dlayout, null);
220

  
221
    setContentView(view);
222

  
223
    String[] effects = new String[mEffectNames.length];
224

  
225
    for(int i=0; i<mEffectNames.length; i++) effects[i] = mEffectNames[i].name();
226

  
227
    Spinner effectSpinner = (Spinner)findViewById(R.id.matrix3dspinner );
228
    effectSpinner.setOnItemSelectedListener(this);
229

  
230
    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects);
231
    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
232
    effectSpinner.setAdapter(adapterEffect);
233

  
234
    mEffectAdd = 0;
235
    }
328 236

  
329 237
///////////////////////////////////////////////////////////////////////////////////////////////////
330
    
331
    @Override
332
    public void onWindowFocusChanged(boolean hasFocus) 
238

  
239
  public void newEffect(View v)
240
    {
241
    Matrix3DEffect eff = new Matrix3DEffect(mEffectNames[mEffectAdd], this);
242
    mEffects.add(eff);
243

  
244
    LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
245
    View view = eff.createView();
246
    layout.addView(view);
247

  
248
    if( mSupportsCenter )
333 249
      {
334
      super.onWindowFocusChanged(hasFocus);
335
  
336
      GLSurfaceView view = (GLSurfaceView) this.findViewById(R.id.matrix3dSurfaceView);
337
      
338
      maxX = view.getWidth();
339
      maxY = view.getHeight();
340
      maxZ = (maxX+maxY)/2;
250
      View center = eff.createCenter();
251
      layout.addView(center);
341 252
      }
342 253

  
254
    eff.apply(mObject);
255
    }
256

  
343 257
///////////////////////////////////////////////////////////////////////////////////////////////////
344
    
345
    @Override
346
    protected void onDestroy() 
347
      {
348
      Distorted.onDestroy();  
349
      super.onDestroy();
350
      }
351
    
258

  
259
  public void removeAll(View v)
260
    {
261
    mEffects.clear();
262
    LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
263
    layout.removeAllViews();
264
    mObject.abortEffects(EffectTypes.MATRIX);
265

  
266
    resetData();
267
    }
268

  
352 269
///////////////////////////////////////////////////////////////////////////////////////////////////
353
    
354
    public void onProgressChanged(SeekBar bar, int progress, boolean fromUser) 
270

  
271
  public void remove(View v)
272
    {
273
    for(Matrix3DEffect effect: mEffects)
355 274
      {
356
      switch (bar.getId()) 
275
      if( effect.thisView(v) )
357 276
        {
358
        case R.id.matrix3dmoveBar1  : moveX = progress; computeMove()  ; setMoveText()  ; break;
359
        case R.id.matrix3dmoveBar2  : moveY = progress; computeMove()  ; setMoveText()  ; break;
360
        case R.id.matrix3dmoveBar3  : moveZ = progress; computeMove()  ; setMoveText()  ; break;
361
        
362
        case R.id.matrix3dscaleBar1 : scaleX= progress; computeScale() ; setScaleText() ; break;
363
        case R.id.matrix3dscaleBar2 : scaleY= progress; computeScale() ; setScaleText() ; break;
364
        case R.id.matrix3dscaleBar3 : scaleZ= progress; computeScale() ; setScaleText() ; break;
365
        
366
        case R.id.matrix3drotateBar1: rotateX=progress; computeRotate(); setRotateText(); break;
367
        case R.id.matrix3drotateBar2: rotateY=progress; computeRotate(); setRotateText(); break;
368
        case R.id.matrix3drotateBar3: rotateZ=progress; computeRotate(); setRotateText(); break;
369
        case R.id.matrix3drotateBar4: rotateA=progress; computeRotate(); setRotateText(); break;
370
        
371
        case R.id.matrix3dshearBar1 : shearX= progress; computeShear() ; setShearText() ; break;
372
        case R.id.matrix3dshearBar2 : shearY= progress; computeShear() ; setShearText() ; break;
373
        case R.id.matrix3dshearBar3 : shearZ= progress; computeShear() ; setShearText() ; break;
277
        LinearLayout layout = (LinearLayout)findViewById(R.id.matrix3dlayout);
278
        View view;
279

  
280
        view = effect.getEffect();
281
        if( view!=null ) layout.removeView(view);
282
        view = effect.getCenter();
283
        if( view!=null ) layout.removeView(view);
284
        view = effect.getRegion();
285
        if( view!=null ) layout.removeView(view);
286

  
287
        long id = effect.getId();
288
        mObject.abortEffect(id);
289
        mEffects.remove(effect);
290

  
291
        resetData();
292

  
293
        break;
374 294
        }
375 295
      }
296
    }
376 297

  
377 298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
// Overrides
300

  
301
  @Override
302
  protected void onPause()
303
    {
304
    GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.matrix3dSurfaceView);
305
    if( mView!=null ) mView.onPause();
306
    super.onPause();
307
    }
378 308

  
379
    public void onStartTrackingTouch(SeekBar bar) { }
380
    
381 309
///////////////////////////////////////////////////////////////////////////////////////////////////
310
    
311
  @Override
312
  protected void onResume()
313
    {
314
    super.onResume();
315
    GLSurfaceView mView = (GLSurfaceView)findViewById(R.id.matrix3dSurfaceView);
316
    if( mView!=null ) mView.onResume();
317
    }
382 318

  
383
    public void onStopTrackingTouch(SeekBar bar)  { }
319
///////////////////////////////////////////////////////////////////////////////////////////////////
384 320
    
385
}
321
  @Override
322
  protected void onDestroy()
323
    {
324
    Distorted.onDestroy();
325
    super.onDestroy();
326
    }
327

  
328
  }
src/main/java/org/distorted/examples/matrix3d/Matrix3DEffect.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.view.View;
23
import android.widget.SeekBar;
24
import android.widget.TextView;
25

  
26
import org.distorted.examples.R;
27
import org.distorted.library.DistortedObject;
28
import org.distorted.library.EffectNames;
29
import org.distorted.library.EffectTypes;
30
import org.distorted.library.type.Dynamic1D;
31
import org.distorted.library.type.Dynamic2D;
32
import org.distorted.library.type.Dynamic3D;
33
import org.distorted.library.type.Dynamic4D;
34
import org.distorted.library.type.Dynamic5D;
35
import org.distorted.library.type.Static1D;
36
import org.distorted.library.type.Static2D;
37
import org.distorted.library.type.Static3D;
38
import org.distorted.library.type.Static4D;
39
import org.distorted.library.type.Static5D;
40

  
41
import java.lang.ref.WeakReference;
42

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

  
45
class Matrix3DEffect implements SeekBar.OnSeekBarChangeListener
46
  {
47
  private WeakReference<Matrix3DActivity> mAct;
48

  
49
  private EffectNames mName;
50
  private int[] mInter;
51
  private int[] mInterRegion;
52
  private int[] mInterCenter;
53
  private int[] mSeekID;
54
  private int[] mSeekRegionID;
55
  private int[] mSeekCenterID;
56
  private int mDimension;
57
  private TextView mText,mTextRegion,mTextCenter;
58

  
59
  private Dynamic1D mDyn1;
60
  private Dynamic2D mDyn2;
61
  private Dynamic3D mDyn3;
62
  private Dynamic5D mDyn5;
63
  private Static1D  mSta1;
64
  private Static2D  mSta2;
65
  private Static3D  mSta3;
66
  private Static5D  mSta5;
67
  private Dynamic4D mRegionDyn;
68
  private Static4D  mRegionSta;
69
  private Dynamic2D mCenterDyn;
70
  private Static2D  mCenterSta;
71

  
72
  private View mButton, mEffect, mCenter, mRegion;
73
  private long mId;
74

  
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// requires knowledge about effect nature
77

  
78
  void apply(DistortedObject object)
79
    {
80
    switch(mName)
81
      {
82
      case ROTATE           : break;//object.rotate    (mDyn4, mCenterDyn); break;
83
      case QUATERNION       : break;//object.quaternion(mDyn4, mCenterDyn); break;
84
      case MOVE             : object.move      (mDyn3)            ; break;
85
      case SCALE            : object.scale     (mDyn3)            ; break;
86
      case SHEAR            : break;//object.shear     (mDyn3, mCenterDyn); break;
87

  
88
      case DISTORT: mId = object.distort(mDyn3, mCenterDyn, mRegionDyn); break;
89
      case DEFORM : mId = object.deform (mDyn3, mCenterDyn            ); break;
90
      case SINK   : mId = object.sink   (mDyn1, mCenterDyn, mRegionDyn); break;
91
      case SWIRL  : mId = object.swirl  (mDyn1, mCenterDyn, mRegionDyn); break;
92
      case WAVE   : mId = object.wave   (mDyn5, mCenterDyn, mRegionDyn); break;
93

  
94
      case ALPHA            : mId = object.alpha     (mDyn1,        mRegionDyn, false); break;
95
      case SMOOTH_ALPHA     : mId = object.alpha     (mDyn1,        mRegionDyn, true ); break;
96
      case CHROMA           : mId = object.chroma    (mDyn1, mDyn3, mRegionDyn, false); break;
97
      case SMOOTH_CHROMA    : mId = object.chroma    (mDyn1, mDyn3, mRegionDyn, true ); break;
98
      case BRIGHTNESS       : mId = object.brightness(mDyn1,        mRegionDyn, false); break;
99
      case SMOOTH_BRIGHTNESS: mId = object.brightness(mDyn1,        mRegionDyn, true ); break;
100
      case SATURATION       : mId = object.saturation(mDyn1,        mRegionDyn, false); break;
101
      case SMOOTH_SATURATION: mId = object.saturation(mDyn1,        mRegionDyn, true ); break;
102
      case CONTRAST         : mId = object.contrast  (mDyn1,        mRegionDyn, false); break;
103
      case SMOOTH_CONTRAST  : mId = object.contrast  (mDyn1,        mRegionDyn, true ); break;
104

  
105
      default: mId = -1;
106
      }
107
    }
108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
// requires knowledge about effect nature
111

  
112
  private void fillStatics()
113
    {
114
    switch(mName)
115
      {
116
      case ROTATE           :
117
                              break;
118
      case QUATERNION       :
119
                              break;
120
      case MOVE             : float lm = mAct.get().getWidth()/50.0f;
121
                              float xm = (mInter[0]-50)*lm;
122
                              float ym = (mInter[1]-50)*lm;
123
                              float zm = (mInter[2]-50)*lm;
124
                              mSta3.set(xm,ym,zm);
125
                              break;
126
      case SCALE            : float xs = (mInter[0])/50.0f;
127
                              float ys = (mInter[1])/50.0f;
128
                              float zs = (mInter[2])/50.0f;
129
                              mSta3.set(xs,ys,zs);
130
                              break;
131
      case SHEAR            :
132
                              break;
133
      case DISTORT          :
134
      case DEFORM           : float ld = mAct.get().getWidth()/50.0f;
135
                              float xd = (mInter[0]-50)*ld;
136
                              float yd = (mInter[1]-50)*ld;
137
                              float zd = (mInter[2]-50)*ld;
138
                              mSta3.set(xd,yd,zd);
139
                              break;
140
      case WAVE             : float l2 = mAct.get().getWidth()/50.0f;
141
                              float x2 = (mInter[0]-50)*l2;
142
                              float y2 = (mInter[1]-50)*l2;
143
                              float z2 = (mInter[2]-50)*180 / 50;
144
                              float w2 = (mInter[3]-50)*180 / 50;
145
                              float v2 = (mInter[4]-50)*180 / 50;
146
                              mSta5.set(x2,y2,z2,w2,v2);
147
                              break;
148
      case SWIRL            : mSta1.set( 3.6f*(mInter[0]-50) );
149
                              break;
150
      case ALPHA            :
151
      case SMOOTH_ALPHA     : mSta1.set(mInter[0]/100.0f);
152
                              break;
153
      case SINK             :
154
      case SATURATION       :
155
      case SMOOTH_SATURATION:
156
      case CONTRAST         :
157
      case SMOOTH_CONTRAST  :
158
      case BRIGHTNESS       :
159
      case SMOOTH_BRIGHTNESS: mSta1.set(mInter[0] > 50 ? 50.0f/(100.01f-mInter[0]) : mInter[0] / 50.0f);
160
                              break;
161
      case CHROMA           :
162
      case SMOOTH_CHROMA    : mSta1.set(mInter[0]/100.0f);
163
                              mSta3.set(mInter[1]/100.0f,
164
                                        mInter[2]/100.0f,
165
                                        mInter[3]/100.0f);
166
                              break;
167
      }
168
    }
169

  
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

  
172
  private void setDefaultInter()
173
    {
174
    switch(mDimension)
175
      {
176
      case 5: mInter[4] = 50;
177
      case 4: mInter[3] = 50;
178
      case 3: mInter[2] = 50;
179
      case 2: mInter[1] = 50;
180
      case 1: mInter[0] = 50;
181
      }
182
    }
183

  
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185

  
186
  private void setText()
187
    {
188
    String text = mName.name();
189

  
190
    if( mSta1 !=null )
191
      {
192
      float f1 = ((int)(mSta1.getX()*100))/100.0f;
193
      text += " "+f1;
194
      }
195

  
196
    if( mSta2 !=null )
197
      {
198
      float f1 = ((int)(mSta2.getX()*100))/100.0f;
199
      float f2 = ((int)(mSta2.getY()*100))/100.0f;
200
      text += " ("+f1+","+f2+")";
201
      }
202

  
203
    if( mSta3 !=null )
204
      {
205
      float f1 = ((int)(mSta3.getX()*100))/100.0f;
206
      float f2 = ((int)(mSta3.getY()*100))/100.0f;
207
      float f3 = ((int)(mSta3.getZ()*100))/100.0f;
208
      text += " ("+f1+","+f2+","+f3+")";
209
      }
210

  
211
    if( mSta5 !=null )
212
      {
213
      float f1 = ((int)(mSta5.getX()*100))/100.0f;
214
      float f2 = ((int)(mSta5.getY()*100))/100.0f;
215
      float f3 = ((int)(mSta5.getZ()*100))/100.0f;
216
      float f4 = ((int)(mSta5.getW()*100))/100.0f;
217
      float f5 = ((int)(mSta5.getV()*100))/100.0f;
218
      text += " ("+f1+","+f2+","+f3+","+f4+","+f5+")";
219
      }
220

  
221
    mText.setText(text);
222
    }
223

  
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

  
226
  private void fillCenterStatics()
227
    {
228
    Matrix3DActivity act = mAct.get();
229

  
230
    float x = (mInterCenter[0]*0.012f - 0.1f)*act.getWidth();
231
    float y = (mInterCenter[1]*0.012f - 0.1f)*act.getHeight();
232
    mCenterSta.set(x,y);
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
  private void setDefaultCenterInter()
238
    {
239
    mInterCenter[0] = 50;
240
    mInterCenter[1] = 50;
241
    }
242

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

  
245
  private void setCenterText()
246
    {
247
    int f0 = (int)mCenterSta.getX();
248
    int f1 = (int)mCenterSta.getY();
249

  
250
    mTextCenter.setText("center ("+f0+","+f1+")");
251
    }
252

  
253
///////////////////////////////////////////////////////////////////////////////////////////////////
254

  
255
  private void fillRegionStatics()
256
    {
257
    Matrix3DActivity act = mAct.get();
258

  
259
    float factorX = act.getWidth() / 100.0f;
260
    float factorY = act.getHeight()/ 100.0f;
261

  
262
    int deduct = (mName.getType() == EffectTypes.VERTEX ? 50:0);
263

  
264
    float  x = (mInterRegion[0]-deduct)*factorX;
265
    float  y = (mInterRegion[1]-deduct)*factorY;
266
    float rx =  mInterRegion[2]        *factorX;
267
    float ry =  mInterRegion[3]        *factorY;
268

  
269
    mRegionSta.set(x,y,rx,ry);
270
    }
271

  
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

  
274
  private void setDefaultRegionInter()
275
    {
276
    mInterRegion[0] = 50;
277
    mInterRegion[1] = 50;
278
    mInterRegion[2] = 50;
279
    mInterRegion[3] = 50;
280
    }
281

  
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283

  
284
  private void setRegionText()
285
    {
286
    int f0 = (int)mRegionSta.getX();
287
    int f1 = (int)mRegionSta.getY();
288
    int f2 = (int)mRegionSta.getZ();
289
    int f3 = (int)mRegionSta.getW();
290

  
291
    mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")");
292
    }
293

  
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

  
296
  Matrix3DEffect(EffectNames name, Matrix3DActivity act)
297
    {
298
    mAct = new WeakReference<>(act);
299
    mName = name;
300

  
301
    mDyn1 = null;
302
    mDyn2 = null;
303
    mDyn3 = null;
304
    mDyn5 = null;
305
    mSta1 = null;
306
    mSta2 = null;
307
    mSta3 = null;
308
    mSta5 = null;
309

  
310
    mDimension = mName.getDimension();
311

  
312
    switch(mDimension)
313
      {
314
      case 1 : mDyn1 = new Dynamic1D();
315
               mSta1 = new Static1D(0);
316
               mDyn1.add(mSta1);
317
               break;
318
      case 2 : mDyn2 = new Dynamic2D();
319
               mSta2 = new Static2D(0,0);
320
               mDyn2.add(mSta2);
321
               break;
322
      case 3 : mDyn3 = new Dynamic3D();
323
               mSta3 = new Static3D(0,0,0);
324
               mDyn3.add(mSta3);
325
               break;
326
      case 4 : mDyn3 = new Dynamic3D();
327
               mSta3 = new Static3D(0,0,0);
328
               mDyn3.add(mSta3);
329
               mDyn1 = new Dynamic1D();
330
               mSta1 = new Static1D(0);
331
               mDyn1.add(mSta1);
332
               break;
333
      case 5 : mDyn5 = new Dynamic5D();
334
               mSta5 = new Static5D(0,0,0,0,0);
335
               mDyn5.add(mSta5);
336
               break;
337
      default: throw new RuntimeException("unsupported effect");
338
      }
339

  
340
    mInter = new int[mDimension];
341
    mSeekID= new int[mDimension];
342

  
343
    mInterRegion = new int[4];
344
    mSeekRegionID= new int[4];
345
    mRegionDyn   = new Dynamic4D();
346
    mRegionSta   = new Static4D(0,0,0,0);
347
    mRegionDyn.add(mRegionSta);
348

  
349
    mInterCenter = new int[2];
350
    mSeekCenterID= new int[2];
351
    mCenterDyn   = new Dynamic2D();
352
    mCenterSta   = new Static2D(0,0);
353
    mCenterDyn.add(mCenterSta);
354

  
355
    mButton = null;
356
    mEffect = null;
357
    mCenter = null;
358
    mRegion = null;
359
    }
360

  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

  
363
  View createView()
364
    {
365
    SeekBar[] seek = new SeekBar[mDimension];
366

  
367
    Matrix3DActivity act = mAct.get();
368

  
369
    switch(mDimension)
370
      {
371
      case 1 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect1d, null);
372
               mText      = (TextView)mEffect.findViewById(R.id.effect1dText);
373
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect1dbar1);
374
               mSeekID[0] = seek[0].getId();
375
               mButton    = mEffect.findViewById(R.id.button1dRemove);
376
               break;
377
      case 2 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect2d, null);
378
               mText      = (TextView)mEffect.findViewById(R.id.effect2dText);
379
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect2dbar1);
380
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect2dbar2);
381
               mSeekID[0] = seek[0].getId();
382
               mSeekID[1] = seek[1].getId();
383
               mButton    = mEffect.findViewById(R.id.button2dRemove);
384
               break;
385
      case 3 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect3d, null);
386
               mText      = (TextView)mEffect.findViewById(R.id.effect3dText);
387
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar1);
388
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar2);
389
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect3dbar3);
390
               mSeekID[0] = seek[0].getId();
391
               mSeekID[1] = seek[1].getId();
392
               mSeekID[2] = seek[2].getId();
393
               mButton    = mEffect.findViewById(R.id.button3dRemove);
394
               break;
395
      case 4 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect4d, null);
396
               mText      = (TextView)mEffect.findViewById(R.id.effect4dText);
397
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar1);
398
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar2);
399
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar3);
400
               seek[3]    = (SeekBar)mEffect.findViewById(R.id.effect4dbar4);
401
               mSeekID[0] = seek[0].getId();
402
               mSeekID[1] = seek[1].getId();
403
               mSeekID[2] = seek[2].getId();
404
               mSeekID[3] = seek[3].getId();
405
               mButton    = mEffect.findViewById(R.id.button4dRemove);
406
               break;
407
      case 5 : mEffect    = act.getLayoutInflater().inflate(R.layout.effect5d, null);
408
               mText      = (TextView)mEffect.findViewById(R.id.effect5dText);
409
               seek[0]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar1);
410
               seek[1]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar2);
411
               seek[2]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar3);
412
               seek[3]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar4);
413
               seek[4]    = (SeekBar)mEffect.findViewById(R.id.effect5dbar5);
414
               mSeekID[0] = seek[0].getId();
415
               mSeekID[1] = seek[1].getId();
416
               mSeekID[2] = seek[2].getId();
417
               mSeekID[3] = seek[3].getId();
418
               mSeekID[4] = seek[4].getId();
419
               mButton    = mEffect.findViewById(R.id.button5dRemove);
420
               break;
421
      default: android.util.Log.e("Matrix3DEffect", "dimension "+mDimension+" not supported!");
422
               return null;
423
      }
424

  
425
    setDefaultInter();
426

  
427
    for(int i=0; i<mDimension; i++)
428
      {
429
      seek[i].setOnSeekBarChangeListener(this);
430
      seek[i].setProgress( mInter[i] );
431
      }
432

  
433
    Matrix3DActivity.setSupportsRegion(mName.supportsRegion());
434
    Matrix3DActivity.setSupportsCenter(mName.supportsCenter());
435

  
436
    return mEffect;
437
    }
438

  
439
///////////////////////////////////////////////////////////////////////////////////////////////////
440

  
441
  View createRegion()
442
    {
443
    Matrix3DActivity act = mAct.get();
444

  
445
    mRegion = act.getLayoutInflater().inflate(R.layout.effectregion, null);
446

  
447
    SeekBar[] seek = new SeekBar[4];
448

  
449
    seek[0] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarX );
450
    seek[1] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarY );
451
    seek[2] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarRX);
452
    seek[3] = (SeekBar)mRegion.findViewById(R.id.effectRegionBarRY);
453

  
454
    mSeekRegionID[0] = seek[0].getId();
455
    mSeekRegionID[1] = seek[1].getId();
456
    mSeekRegionID[2] = seek[2].getId();
457
    mSeekRegionID[3] = seek[3].getId();
458

  
459
    mTextRegion = (TextView)mRegion.findViewById(R.id.effectRegionText);
460

  
461
    setDefaultRegionInter();
462

  
463
    for(int i=0; i<4; i++)
464
      {
465
      seek[i].setOnSeekBarChangeListener(this);
466
      seek[i].setProgress( mInterRegion[i] );
467
      }
468

  
469
    act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
470

  
471
    return mRegion;
472
    }
473

  
474
///////////////////////////////////////////////////////////////////////////////////////////////////
475

  
476
  View createCenter()
477
    {
478
    Matrix3DActivity act = mAct.get();
479

  
480
    mCenter = act.getLayoutInflater().inflate(R.layout.effectcenter, null);
481

  
482
    SeekBar[] seek = new SeekBar[2];
483

  
484
    seek[0] = (SeekBar)mCenter.findViewById(R.id.effectCenterBarX );
485
    seek[1] = (SeekBar)mCenter.findViewById(R.id.effectCenterBarY );
486

  
487
    mSeekCenterID[0] = seek[0].getId();
488
    mSeekCenterID[1] = seek[1].getId();
489

  
490
    mTextCenter = (TextView)mCenter.findViewById(R.id.effectCenterText);
491

  
492
    setDefaultCenterInter();
493

  
494
    for(int i=0; i<2; i++)
495
      {
496
      seek[i].setOnSeekBarChangeListener(this);
497
      seek[i].setProgress( mInterCenter[i] );
498
      }
499

  
500
    act.setCenter(mCenterSta.getX(),mCenterSta.getY());
501

  
502
    return mCenter;
503
    }
504

  
505
///////////////////////////////////////////////////////////////////////////////////////////////////
506

  
507
  public void onProgressChanged(SeekBar bar, int progress, boolean fromUser)
508
    {
509
    if ( mDimension>=1 && bar.getId()==mSeekID[0] )
510
      {
511
      mInter[0] = progress;
512
      fillStatics();
513
      setText();
514
      }
515
    if ( mDimension>=2 && bar.getId()==mSeekID[1] )
516
      {
517
      mInter[1] = progress;
518
      fillStatics();
519
      setText();
520
      }
521
    if ( mDimension>=3 && bar.getId()==mSeekID[2] )
522
      {
523
      mInter[2] = progress;
524
      fillStatics();
525
      setText();
526
      }
527
    if ( mDimension>=4 && bar.getId()==mSeekID[3] )
528
      {
529
      mInter[3] = progress;
530
      fillStatics();
531
      setText();
532
      }
533
    if ( mDimension>=5 && bar.getId()==mSeekID[4] )
534
      {
535
      mInter[4] = progress;
536
      fillStatics();
537
      setText();
538
      }
539

  
540
    if( bar.getId() == mSeekRegionID[0] )
541
      {
542
      mInterRegion[0] = progress;
543
      fillRegionStatics();
544
      setRegionText();
545
      }
546
    if( bar.getId() == mSeekRegionID[1] )
547
      {
548
      mInterRegion[1] = progress;
549
      fillRegionStatics();
550
      setRegionText();
551
      }
552
    if( bar.getId() == mSeekRegionID[2] )
553
      {
554
      mInterRegion[2] = progress;
555
      fillRegionStatics();
556
      setRegionText();
557
      }
558
    if( bar.getId() == mSeekRegionID[3] )
559
      {
560
      mInterRegion[3] = progress;
561
      fillRegionStatics();
562
      setRegionText();
563
      }
564

  
565
    if( bar.getId() == mSeekCenterID[0] )
566
      {
567
      mInterCenter[0] = progress;
568
      fillCenterStatics();
569
      setCenterText();
570
      }
571
    if( bar.getId() == mSeekCenterID[1] )
572
      {
573
      mInterCenter[1] = progress;
574
      fillCenterStatics();
575
      setCenterText();
576
      }
577

  
578
    if( fromUser )
579
      {
580
      Matrix3DActivity.setSupportsRegion(mName.supportsRegion());
581
      Matrix3DActivity.setSupportsCenter(mName.supportsCenter());
582

  
583
      Matrix3DActivity act = mAct.get();
584

  
585
      act.setCenter(mCenterSta.getX(),mCenterSta.getY());
586
      act.setRegion(mRegionSta.getX(),mRegionSta.getY(),mRegionSta.getZ());
587
      }
588
    }
589

  
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

  
592
  public boolean thisView(View v)
593
    {
594
    return v==mButton;
595
    }
596

  
597
///////////////////////////////////////////////////////////////////////////////////////////////////
598

  
599
  public long getId()
600
    {
601
    return mId;
602
    }
603

  
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605

  
606
  public View getEffect()
607
    {
608
    return mEffect;
609
    }
610

  
611
///////////////////////////////////////////////////////////////////////////////////////////////////
612

  
613
  public View getRegion()
614
    {
615
    return mRegion;
616
    }
617

  
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

  
620
  public View getCenter()
621
    {
622
    return mCenter;
623
    }
624

  
625
///////////////////////////////////////////////////////////////////////////////////////////////////
626

  
627
  public void onStartTrackingTouch(SeekBar bar) { }
628

  
629
///////////////////////////////////////////////////////////////////////////////////////////////////
630

  
631
  public void onStopTrackingTouch(SeekBar bar)  { }
632
  }
src/main/java/org/distorted/examples/matrix3d/Matrix3DRenderer.java
19 19

  
20 20
package org.distorted.examples.matrix3d;
21 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;
22
import android.opengl.GLES20;
23
import android.opengl.GLSurfaceView;
29 24

  
30
import org.distorted.library.DistortedCubes;
31
import org.distorted.library.EffectNames;
32
import org.distorted.library.EffectTypes;
33
import org.distorted.library.type.Dynamic3D;
34
import org.distorted.library.type.Static3D;
35
import org.distorted.library.type.Static4D;
36
import org.distorted.library.type.Dynamic4D;
37 25
import org.distorted.library.Distorted;
26
import org.distorted.library.DistortedObject;
27
import org.distorted.library.EffectTypes;
38 28

  
39
import android.graphics.Bitmap;
40
import android.graphics.BitmapFactory;
41
import android.opengl.GLES20;
42
import android.opengl.GLSurfaceView;
29
import javax.microedition.khronos.egl.EGLConfig;
30
import javax.microedition.khronos.opengles.GL10;
43 31

  
44 32
///////////////////////////////////////////////////////////////////////////////////////////////////
45 33

  
46 34
class Matrix3DRenderer implements GLSurfaceView.Renderer
47 35
{
48
    private static final int SIZE = 100;
49
	
50 36
    private GLSurfaceView mView;
51
    private DistortedCubes mCube;
52
    private EffectNames[] order;
53
    
54
    private Dynamic3D mMoveInter, mScaleInter, mShearInter;
55
    private Dynamic4D mDynamicRotate;
56
    private Static3D mZeroPoint, mMovePoint, mScalePoint, mShearPoint;
57
    private Static4D mRotatePoint;
37
    private DistortedObject mObject;
58 38

  
59 39
///////////////////////////////////////////////////////////////////////////////////////////////////
60 40

  
61
    void setMove(float x, float y, float z)
41
    Matrix3DRenderer(GLSurfaceView v)
62 42
      {
63
      mMovePoint.set(x, y, z);
64
      }
65
    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
43
      mView = v;
67 44

  
68
    void setScale(float x, float y, float z)
69
      {
70
      mScalePoint.set(x, y, z);
45
      mObject= ((Matrix3DActivity)v.getContext()).getObject();
71 46
      }
72
     
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74 47

  
75
    void setRotate(float a, float x, float y, float z)
76
      {
77
      mRotatePoint.set(a,x,y,z);
78
      }
79
    
80 48
///////////////////////////////////////////////////////////////////////////////////////////////////
81 49

  
82
    void setShear(float x, float y, float z)
50
    public void onDrawFrame(GL10 glUnused)
83 51
      {
84
      mShearPoint.set(x, y, z);
85
      }
52
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
86 53

  
87
///////////////////////////////////////////////////////////////////////////////////////////////////
54
      long time = System.currentTimeMillis();
88 55

  
89
    void setOrder(EffectNames[] effects)
90
      {
91
      order = effects;
92
      setMatrixEffects();
56
      mObject.draw(time);
93 57
      }
94
      
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96 58

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

  
115
    Matrix3DRenderer(GLSurfaceView v)
61
    public void onSurfaceChanged(GL10 glUnused, int width, int height)
116 62
      {
117
      mView = v;
118
      mCube = new DistortedCubes( 1, "1", SIZE);
119
      
120
      mZeroPoint   = new Static3D(0,0,0);
121
      mMovePoint   = new Static3D(0,0,0);
122
      mScalePoint  = new Static3D(1,1,1);
123
      mShearPoint  = new Static3D(0,0,0);
124
      mRotatePoint = new Static4D(0,1,0,0);
125

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

  
131
      mMoveInter.add(mMovePoint);
132
      mScaleInter.add(mScalePoint);
133
      mShearInter.add(mShearPoint);
134
      mDynamicRotate.add(mRotatePoint);
135
      }
63
      mObject.abortEffects(EffectTypes.MATRIX);
136 64

  
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
   
139
    public void onDrawFrame(GL10 glUnused) 
140
      {
141
      GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
142
      mCube.draw(System.currentTimeMillis());
65
      Distorted.onSurfaceChanged(width, height);
143 66
      }
144 67

  
145 68
///////////////////////////////////////////////////////////////////////////////////////////////////
146
    
147
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
148
      {
149
      setMatrixEffects();
150

  
151
      Distorted.onSurfaceChanged(width, height); 
152
      }
153 69

  
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155
    
156
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
70
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
157 71
      {
158 72
      GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff