Project

General

Profile

« Previous | Next » 

Revision 65270124

Added by Leszek Koltunski over 8 years ago

Fragment3D should be pretty much finished.

View differences:

src/main/java/org/distorted/examples/fragment3d/Fragment3DActivity.java
29 29
import android.widget.Button;
30 30
import android.widget.LinearLayout;
31 31
import android.widget.NumberPicker;
32
import android.widget.SeekBar;
33
import android.widget.SeekBar.OnSeekBarChangeListener;
34 32
import android.widget.Spinner;
35 33
import android.widget.TableRow;
36
import android.widget.TextView;
37 34

  
38 35
import org.distorted.examples.R;
39 36
import org.distorted.library.Distorted;
......
64 61
  private int mNumCols = 3;
65 62
  private int mNumRows = 3;
66 63
  private NumberPicker mColsPicker, mRowsPicker;
67
  private LinearLayout mLay;
68 64
  private boolean[] mShape;
69 65
  private DistortedObject mObject;
70 66
  private int mObjectType;
71 67
  private int mBitmap;
72 68

  
73 69
  private ArrayList<Fragment3DEffect> mEffects;
70
  private int mEffectAdd;
74 71

  
75 72
///////////////////////////////////////////////////////////////////////////////////////////////////
76 73
    
......
136 133

  
137 134
  private void setGrid()
138 135
    {
139
    mLay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
136
    LinearLayout lay = (LinearLayout)findViewById(R.id.objectpicker_buttongrid);
140 137

  
141
    int width = mLay.getWidth();
142
    int height= mLay.getHeight();
138
    int width = lay.getWidth();
139
    int height= lay.getHeight();
143 140
    int w = mNumCols>0 ? (width / mNumCols) -10 : 0;
144 141
    int h = mNumRows>0 ? (height/ mNumRows) -10 : 0;
145 142
    int size= w<h ? w:h;
146 143
    int pad = size/20;
147 144

  
148
    mLay.removeAllViews();
145
    lay.removeAllViews();
149 146

  
150 147
    mShape = new boolean[mNumRows*mNumCols];
151 148

  
......
174 171
        mShape[rows*mNumCols+cols] = true;
175 172
        }
176 173

  
177
      mLay.addView(tr);
174
      lay.addView(tr);
178 175
      }
179 176
    }
180 177

  
......
251 248
    {
252 249
    switch(parent.getId())
253 250
      {
254
      case R.id.objectpicker_spinnerType  : mObjectType = pos; break;
251
      case R.id.objectpicker_spinnerType  : mObjectType = pos;
252
                                            break;
255 253
      case R.id.objectpicker_spinnerBitmap: switch(pos)
256 254
                                              {
257 255
                                              case 0: mBitmap = R.raw.face; break;
......
260 258
                                              case 3: mBitmap = R.raw.grid; break;
261 259
                                              }
262 260
                                            break;
261
      case R.id.fragment3dspinner         : mEffectAdd = pos;
262
                                            break;
263 263
      }
264 264
    }
265 265

  
......
270 270
    }
271 271

  
272 272
///////////////////////////////////////////////////////////////////////////////////////////////////
273
// 'second screen' methods
274 273

  
275
  private void setFragmentView()
274
  public int getWidth()
276 275
    {
277
    final View view = getLayoutInflater().inflate(R.layout.fragment3dlayout, null);
278

  
279
    setContentView(view);
276
    return mObject==null ? 0: mObject.getWidth();
280 277
    }
281 278

  
282 279
///////////////////////////////////////////////////////////////////////////////////////////////////
283 280

  
284
  public void newChroma(View v)
281
  public int getHeight()
285 282
    {
286
    Fragment3DEffect chroma = new Fragment3DEffect(EffectNames.CHROMA);
287
    mEffects.add(chroma);
288

  
289
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
290
    View view = chroma.createView(this);
291
    layout.addView(view);
292
    View region = chroma.createRegion(this);
293
    layout.addView(region);
294

  
295
    Dynamic1D dyn1 = chroma.getDyn1();
296
    Dynamic3D dyn3 = chroma.getDyn3();
297
    Dynamic4D regi = chroma.getRegion();
298

  
299
    mObject.chroma(dyn1, dyn3, regi, false);
283
    return mObject==null ? 0: mObject.getHeight();
300 284
    }
301 285

  
302 286
///////////////////////////////////////////////////////////////////////////////////////////////////
287
// 'second screen' methods
303 288

  
304
  public void newAlpha(View v)
289
  private void setFragmentView()
305 290
    {
306
    Fragment3DEffect alpha = new Fragment3DEffect(EffectNames.ALPHA);
307
    mEffects.add(alpha);
308

  
309
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
310
    View view = alpha.createView(this);
311
    layout.addView(view);
312
    View region = alpha.createRegion(this);
313
    layout.addView(region);
291
    final View view = getLayoutInflater().inflate(R.layout.fragment3dlayout, null);
314 292

  
315
    Dynamic1D dyn1 = alpha.getDyn1();
316
    Dynamic4D regi = alpha.getRegion();
293
    setContentView(view);
317 294

  
318
    mObject.alpha(dyn1, regi, false);
319
    }
295
    String[] effects = new String[] {"CHROMA", "ALPHA", "BRIGHTNESS", "SATURATION"};
320 296

  
321
///////////////////////////////////////////////////////////////////////////////////////////////////
297
    Spinner effectSpinner = (Spinner)findViewById(R.id.fragment3dspinner );
298
    effectSpinner.setOnItemSelectedListener(this);
322 299

  
323
  public void newBrightness(View v)
324
    {
325
    Fragment3DEffect brightness = new Fragment3DEffect(EffectNames.BRIGHTNESS);
326
    mEffects.add(brightness);
300
    ArrayAdapter<String> adapterEffect = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, effects);
301
    adapterEffect.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
302
    effectSpinner.setAdapter(adapterEffect);
327 303

  
328
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
329
    View view = brightness.createView(this);
330
    layout.addView(view);
331
    View region = brightness.createRegion(this);
332
    layout.addView(region);
333

  
334
    Dynamic1D dyn1 = brightness.getDyn1();
335
    Dynamic4D regi = brightness.getRegion();
336

  
337
    mObject.brightness(dyn1, regi, false);
304
    mEffectAdd = 0;
338 305
    }
339 306

  
340 307
///////////////////////////////////////////////////////////////////////////////////////////////////
341 308

  
342
  public void newSaturation(View v)
309
  public void newEffect(View v)
343 310
    {
344
    Fragment3DEffect saturation = new Fragment3DEffect(EffectNames.SATURATION);
345
    mEffects.add(saturation);
311
    EffectNames name;
312

  
313
    switch(mEffectAdd)
314
      {
315
      case 0 : name = EffectNames.CHROMA    ; break;
316
      case 1 : name = EffectNames.ALPHA     ; break;
317
      case 2 : name = EffectNames.BRIGHTNESS; break;
318
      case 3 : name = EffectNames.SATURATION; break;
319
      default: return;
320
      }
321

  
322
    Fragment3DEffect eff = new Fragment3DEffect(name, this);
323
    mEffects.add(eff);
346 324

  
347 325
    LinearLayout layout = (LinearLayout)findViewById(R.id.fragment3dlayout);
348
    View view = saturation.createView(this);
326
    View view = eff.createView();
349 327
    layout.addView(view);
350
    View region = saturation.createRegion(this);
328
    View region = eff.createRegion();
351 329
    layout.addView(region);
352 330

  
353
    Dynamic1D dyn1 = saturation.getDyn1();
354
    Dynamic4D regi = saturation.getRegion();
331
    Dynamic1D dyn1 = eff.getDyn1();
332
    Dynamic3D dyn3 = eff.getDyn3();
333
    Dynamic4D regi = eff.getRegion();
355 334

  
356
    mObject.saturation(dyn1, regi, false);
335
    switch(mEffectAdd)
336
      {
337
      case 0: mObject.chroma    (dyn1, dyn3, regi, false); break;
338
      case 1: mObject.alpha     (dyn1,       regi, false); break;
339
      case 2: mObject.brightness(dyn1,       regi, false); break;
340
      case 3: mObject.saturation(dyn1,       regi, false); break;
341
      }
357 342
    }
358 343

  
359 344
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/examples/fragment3d/Fragment3DEffect.java
19 19

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

  
22
import android.app.Activity;
23 22
import android.view.View;
24
import android.widget.LinearLayout;
25 23
import android.widget.SeekBar;
26 24
import android.widget.TextView;
27 25

  
......
34 32
import org.distorted.library.type.Static3D;
35 33
import org.distorted.library.type.Static4D;
36 34

  
35
import java.lang.ref.WeakReference;
36

  
37 37
///////////////////////////////////////////////////////////////////////////////////////////////////
38 38

  
39 39
public class Fragment3DEffect implements SeekBar.OnSeekBarChangeListener
40 40
  {
41
  private WeakReference<Fragment3DActivity> mAct;
42

  
41 43
  private EffectNames mName;
42 44
  private int[] mInter;
43 45
  private int[] mInterRegion;
......
58 60

  
59 61
  private void fillRegionStatics()
60 62
    {
61
    float factorX = 2.0f;
62
    float factorY = 2.0f;
63
    Fragment3DActivity act = mAct.get();
64

  
65
    float factorX = act.getWidth() / 100.0f;
66
    float factorY = act.getHeight()/ 100.0f;
63 67

  
64
    float  x = (mInterRegion[0]-50)*factorX;
65
    float  y = (mInterRegion[1]-50)*factorY;
66
    float rx = (mInterRegion[2]   )*factorX;
67
    float ry = (mInterRegion[3]   )*factorY;
68
    float  x = mInterRegion[0]*factorX;
69
    float  y = mInterRegion[1]*factorY;
70
    float rx = mInterRegion[2]*factorX;
71
    float ry = mInterRegion[3]*factorY;
68 72

  
69 73
    mRegionSta.set(x,y,rx,ry);
70 74
    }
......
83 87

  
84 88
  private void setRegionText()
85 89
    {
86
    mTextRegion.setText("region ("+mRegionSta.getX()+","+mRegionSta.getY()+","+mRegionSta.getZ()+","+mRegionSta.getW()+")");
90
    float f0 = ((int)(mRegionSta.getX()*100))/100.0f;
91
    float f1 = ((int)(mRegionSta.getY()*100))/100.0f;
92
    float f2 = ((int)(mRegionSta.getZ()*100))/100.0f;
93
    float f3 = ((int)(mRegionSta.getW()*100))/100.0f;
94

  
95
    mTextRegion.setText("region ("+f0+","+f1+","+f2+","+f3+")");
87 96
    }
88 97

  
89 98
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 108
                       break;
100 109
      case ALPHA     : mSta1.set(mInter[0]/100.0f);
101 110
                       break;
102
      case SATURATION: mSta1.set(mInter[0]/100.0f);
103
                       break;
104
      case CONTRAST  : mSta1.set(mInter[0]/100.0f);
105
                       break;
106 111
      case BRIGHTNESS: mSta1.set(mInter[0]/100.0f);
107 112
                       break;
113
      case SATURATION: mSta1.set(mInter[0]/100.0f);
114
                       break;
108 115
      }
109 116
    }
110 117

  
......
121 128
                       break;
122 129
      case ALPHA     : mInter[0] = 100;
123 130
                       break;
124
      case SATURATION: mInter[0] = 100;
125
                       break;
126
      case CONTRAST  : mInter[0] = 100;
127
                       break;
128 131
      case BRIGHTNESS: mInter[0] = 100;
129 132
                       break;
133
      case SATURATION: mInter[0] = 100;
134
                       break;
130 135
      }
131 136
    }
132 137

  
......
134 139

  
135 140
  private void setText()
136 141
    {
142
    float f1 = ((int)mSta1.getX()*100)/100.0f;
143

  
137 144
    switch(mName)
138 145
      {
139
      case CHROMA    : mText.setText("chroma "+mSta1.getX()+"("+mSta3.getX()+","+mSta3.getY()+","+mSta3.getZ()+")");
140
                       break;
141
      case ALPHA     : mText.setText("alpha ("+mSta1.getX()+")");
146
      case CHROMA    : float f2 = ((int)mSta3.getX()*100)/100.0f;
147
                       float f3 = ((int)mSta3.getY()*100)/100.0f;
148
                       float f4 = ((int)mSta3.getZ()*100)/100.0f;
149
                       mText.setText("chroma "+f1+"("+f2+","+f3+","+f4+")");
142 150
                       break;
143
      case SATURATION: mText.setText("saturation ("+mSta1.getX()+")");
151
      case ALPHA     : mText.setText("alpha ("+f1+")");
144 152
                       break;
145
      case CONTRAST  : mText.setText("contrast ("+mSta1.getX()+")");
153
      case BRIGHTNESS: mText.setText("brightness ("+f1+")");
146 154
                       break;
147
      case BRIGHTNESS: mText.setText("brightness ("+mSta1.getX()+")");
155
      case SATURATION: mText.setText("saturation ("+f1+")");
148 156
                       break;
149 157
      }
150 158
    }
151 159

  
152 160
///////////////////////////////////////////////////////////////////////////////////////////////////
153 161

  
154
  public Fragment3DEffect(EffectNames name)
162
  public Fragment3DEffect(EffectNames name, Fragment3DActivity act)
155 163
    {
164
    mAct = new WeakReference<>(act);
156 165
    mName = name;
157 166

  
158 167
    if( mName==EffectNames.CHROMA )
......
206 215

  
207 216
///////////////////////////////////////////////////////////////////////////////////////////////////
208 217

  
209
  public View createView(Activity act)
218
  public View createView()
210 219
    {
211 220
    View effect;
212 221
    SeekBar[] seek = new SeekBar[mDimension];
213 222

  
223
    Fragment3DActivity act = mAct.get();
224

  
214 225
    switch(mDimension)
215 226
      {
216 227
      case 1 : effect     = act.getLayoutInflater().inflate(R.layout.effect1d, null);
......
264 275

  
265 276
///////////////////////////////////////////////////////////////////////////////////////////////////
266 277

  
267
  public View createRegion(Activity act)
278
  public View createRegion()
268 279
    {
280
    Fragment3DActivity act = mAct.get();
281

  
269 282
    View region = act.getLayoutInflater().inflate(R.layout.effectregion, null);
270 283

  
271 284
    SeekBar[] seek = new SeekBar[4];
src/main/java/org/distorted/examples/fragment3d/Fragment3DRenderer.java
27 27
import org.distorted.examples.R;
28 28
import org.distorted.library.Distorted;
29 29
import org.distorted.library.DistortedBitmap;
30
import org.distorted.library.DistortedCubes;
31 30
import org.distorted.library.DistortedObject;
32
import org.distorted.library.EffectNames;
33 31
import org.distorted.library.EffectTypes;
34
import org.distorted.library.type.Dynamic1D;
35
import org.distorted.library.type.Dynamic2D;
36
import org.distorted.library.type.Dynamic3D;
37 32
import org.distorted.library.type.DynamicQuat;
38
import org.distorted.library.type.Static1D;
39
import org.distorted.library.type.Static2D;
40 33
import org.distorted.library.type.Static3D;
41 34
import org.distorted.library.type.Static4D;
42 35

  
......
50 43

  
51 44
class Fragment3DRenderer implements GLSurfaceView.Renderer
52 45
{
53
    private static final int SIZE = 100;
54

  
55 46
    private GLSurfaceView mView;
56 47
    private DistortedObject mObject;
57 48
    private DistortedBitmap mBackground;
58
    private float mFactorObj;
59

  
60 49
    private int mObjWidth, mObjHeight;
61

  
62 50
    private DynamicQuat mQuatInt1, mQuatInt2;
63

  
64 51
    Static4D mQuat1, mQuat2;
65 52
    int mScreenMin;
66 53

  
......
71 58
      mView = v;
72 59

  
73 60
      mObject     = ((Fragment3DActivity)v.getContext()).getObject();
74
      mBackground = new DistortedBitmap(SIZE, SIZE, 1);
61
      mBackground = new DistortedBitmap(100, 100, 1);
75 62

  
76 63
      mObjWidth = mObject.getWidth();
77 64
      mObjHeight= mObject.getHeight();
......
107 94

  
108 95
      mObject.abortEffects(EffectTypes.MATRIX);
109 96
      mBackground.abortEffects(EffectTypes.MATRIX);
97
      float factorObj;
110 98

  
111 99
      if( width*mObjHeight > height*mObjWidth ) // screen is more 'horizontal' than the Object
112 100
        {
113
        mFactorObj = (0.70f*height)/mObjHeight;
101
        factorObj = (0.80f*height)/mObjHeight;
114 102
        }
115 103
      else
116 104
        {
117
        mFactorObj = (0.70f*width)/mObjWidth;
105
        factorObj = (0.80f*width)/mObjWidth;
118 106
        }
119 107

  
120 108
      Static3D rotateObj = new Static3D(mObjWidth/2,mObjHeight/2, 0);
121 109

  
122
      mObject.move( new Static3D( (width-mFactorObj*mObjWidth)/2 , (height-mFactorObj*mObjHeight)/2 , 0) );
123
      mObject.scale(mFactorObj);
110
      mObject.move( new Static3D( (width-factorObj*mObjWidth)/2 , (height-factorObj*mObjHeight)/2 , 0) );
111
      mObject.scale(factorObj);
124 112
      mObject.quaternion(mQuatInt1, rotateObj);
125 113
      mObject.quaternion(mQuatInt2, rotateObj);
126 114

  
......
128 116
      float factorBackX = ((float)width)/backgroundSize;
129 117
      float factorBackY = ((float)height)/backgroundSize;
130 118

  
131
      mBackground.move(new Static3D( -width/2, -height/2,-mFactorObj*(mObjWidth+mObjHeight)/2) );
119
      mBackground.move(new Static3D( -width/2, -height/2,-factorObj*(mObjWidth+mObjHeight)/2) );
132 120
      mBackground.scale(new Static3D(2*factorBackX, 2*factorBackY, 1.0f) );
133 121

  
134 122
      Distorted.onSurfaceChanged(width, height); 
src/main/res/layout/effect1d.xml
22 22
            android:layout_marginLeft="5dp"
23 23
            android:layout_marginRight="5dp" />
24 24

  
25

  
26
        <View
27
            android:layout_height="1dip"
28
            android:background="#777777"
29
            android:layout_width="match_parent"
30
            />
31

  
32 25
</LinearLayout>
src/main/res/layout/effect2d.xml
30 30
            android:layout_marginLeft="5dp"
31 31
            android:layout_marginRight="5dp" />
32 32

  
33
        <View
34
            android:layout_height="1dip"
35
            android:background="#777777"
36
            android:layout_width="match_parent"
37
            />
38

  
39 33
</LinearLayout>
src/main/res/layout/effect3d.xml
37 37
            android:layout_marginLeft="5dp"
38 38
            android:layout_marginRight="5dp" />
39 39

  
40
        <View
41
            android:layout_height="1dip"
42
            android:background="#777777"
43
            android:layout_width="match_parent"
44
            />
45

  
46 40
</LinearLayout>
src/main/res/layout/effect4d.xml
45 45
            android:layout_marginLeft="5dp"
46 46
            android:layout_marginRight="5dp" />
47 47

  
48
        <View
49
            android:layout_height="1dip"
50
            android:background="#777777"
51
            android:layout_width="match_parent"
52
            />
53

  
54 48
</LinearLayout>
src/main/res/layout/fragment3dlayout.xml
19 19
        <Button
20 20
            android:layout_width="wrap_content"
21 21
            android:layout_height="wrap_content"
22
            android:text="@string/reset"
23
            android:id="@+id/buttonRemove"
24
            android:onClick="removeAll"
22
            android:text="@string/Add"
23
            android:id="@+id/buttonAdd"
24
            android:onClick="newEffect"
25 25
            />
26 26

  
27
        <Button
27
        <TextView
28 28
            android:layout_width="wrap_content"
29 29
            android:layout_height="wrap_content"
30
            android:text="@string/chroma"
31
            android:id="@+id/buttonChroma"
32
            android:onClick="newChroma"/>
30
            android:textAppearance="?android:attr/textAppearanceMedium"
31
            android:text="@string/New"
32
            android:id="@+id/textView10"/>
33 33

  
34
        <Button
34
        <Spinner
35 35
            android:layout_width="wrap_content"
36 36
            android:layout_height="wrap_content"
37
            android:text="@string/alpha"
38
            android:id="@+id/buttonAlpha"
39
            android:onClick="newAlpha"/>
37
            android:id="@+id/fragment3dspinner"
38
            android:layout_weight="0.5"/>
40 39

  
41 40
        <Button
42 41
            android:layout_width="wrap_content"
43 42
            android:layout_height="wrap_content"
44
            android:text="@string/brightness"
45
            android:id="@+id/buttonBrightness"
46
            android:onClick="newBrightness"/>
43
            android:text="@string/RemoveAll"
44
            android:id="@+id/buttonRemove"
45
            android:onClick="removeAll"
46
            />
47 47

  
48
        <Button
49
            android:layout_width="wrap_content"
50
            android:layout_height="wrap_content"
51
            android:text="@string/saturation"
52
            android:id="@+id/buttonSaturation"
53
            android:onClick="newSaturation"/>
54 48
    </LinearLayout>
55 49

  
56 50
    <View
src/main/res/values/strings.xml
13 13
    <string name="brightness">Brightness</string>
14 14
    <string name="saturation">Saturation</string>
15 15
    <string name="contrast">Contrast</string>
16
    <string name="swirl">Swirl</string>
16 17

  
17 18
    <string name="continu">Continue</string>
18 19
    <string name="rows">Rows</string>
......
30 31
    <string name="type">effects by type</string>
31 32
    <string name="id">effects by ID</string>
32 33
    <string name="list">List of all existing effects</string>
33
    <string name="swirl">Swirl</string>
34 34
    <string name="print">Print</string>
35 35
    <string name="abort">Abort</string>
36 36
    <string name="count">Count</string>
......
49 49
    <string name="Up">Up</string>
50 50
    <string name="Default">Default</string>
51 51
    <string name="save">Save</string>
52
    <string name="New">new</string>
52 53
    <string name="Create">Create</string>
53 54
    <string name="Bitmap">Bitmap</string>
55
    <string name="Add">Add</string>
56
    <string name="RemoveAll">Remove All</string>
54 57

  
55 58
    <string name="example_monalisa">Mona Lisa</string>  
56 59
    <string name="example_monalisa_subtitle">The basics of Distortions.</string>

Also available in: Unified diff