Project

General

Profile

« Previous | Next » 

Revision 24624a1a

Added by Leszek Koltunski almost 6 years ago

Add support for MeshSphere (add ability to display it in the 'Effects3D' and 'Inflate' apps).
Still a bit buggy!

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity.java
41 41
  {
42 42
  private static final int COLOR_OFF = 0xffffe81f;
43 43
  private static final int COLOR_ON  = 0xff0000ff;
44
  private static final int COLOR_INAC= 0xff00ff00;
44
  private static final int COLOR_INAC= 0xff999999;
45 45

  
46 46
  private int mNumCols = 1;
47 47
  private int mNumRows = 1;
......
108 108
    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
109 109
    typeSpinner.setOnItemSelectedListener(this);
110 110

  
111
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
111
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat", "Mesh: Sphere", "Mesh: Quad"};
112 112

  
113 113
    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
114 114
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
......
178 178

  
179 179
  public void onClick(View view)
180 180
    {
181
    if( mObjectType!=1 )
181
    if( mObjectType==0 )  // cubes
182 182
      {
183 183
      Button tmp = (Button)view;
184 184
      int id = tmp.getId();
......
201 201
      for(int col=0; col<mNumCols; col++)
202 202
        {
203 203
        butt = (Button)tr.getVirtualChildAt(col);
204
        butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
204
        butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC);
205 205
        mShape[row*mNumCols+col] = true;
206 206
        }
207 207
      }
......
214 214
    Intent mainInt = new Intent( getApplicationContext(), Effects3DActivity2.class);
215 215
    Bundle b = new Bundle();
216 216

  
217
    int rows=0, cols=0;
218

  
219
    switch(mObjectType)
220
      {
221
      case 0:
222
      case 1: rows = mNumRows;
223
              cols = mNumCols;
224
              break;
225
      case 2: rows = mNumRows;   // always make the sphere equal in X and Y
226
              cols = mNumRows;   //
227
              break;
228
      case 3: rows = 1;          // a quad is always 1x1
229
              cols = 1;
230
              break;
231
      }
232

  
217 233
    b.putInt("type", mObjectType);
218
    b.putInt("cols", mNumCols);
219
    b.putInt("rows", mNumRows);
234
    b.putInt("cols", cols);
235
    b.putInt("rows", rows);
220 236
    b.putInt("slices", mNumSlic);
221 237
    b.putInt("bitmap", mBitmapID);
222 238

  
223
    if( mObjectType==1 )
224
      {
225
      b.putString("string", "");
226
      }
227
    else
239
    if( mObjectType==0 )   // cubes
228 240
      {
229 241
      String str = "";
230 242

  
......
233 245

  
234 246
      b.putString("string", str);
235 247
      }
248
    else
249
      {
250
      b.putString("string", "");
251
      }
236 252

  
237 253
    mainInt.putExtras(b);
238 254
    startActivity(mainInt);
......
248 264
                                              {
249 265
                                              mObjectType = pos;
250 266
                                              uncheckAll();
267

  
268
                                              switch(mObjectType)
269
                                                {
270
                                                case 0: mColsPicker.setEnabled(true);
271
                                                        mRowsPicker.setEnabled(true);
272
                                                        mSlicPicker.setEnabled(true);
273
                                                        break;
274
                                                case 1: mColsPicker.setEnabled(true);
275
                                                        mRowsPicker.setEnabled(true);
276
                                                        mSlicPicker.setEnabled(false);
277
                                                        break;
278
                                                case 2: mColsPicker.setEnabled(false);
279
                                                        mRowsPicker.setEnabled(true);
280
                                                        mSlicPicker.setEnabled(false);
281
                                                        break;
282
                                                case 3: mColsPicker.setEnabled(false);
283
                                                        mRowsPicker.setEnabled(false);
284
                                                        mSlicPicker.setEnabled(false);
285
                                                        break;
286
                                                }
251 287
                                              }
252 288
                                            break;
253 289
      case R.id.objectpicker_spinnerBitmap: switch(pos)
src/main/java/org/distorted/examples/effects3d/Effects3DActivity2.java
39 39
import org.distorted.library.mesh.MeshCubes;
40 40
import org.distorted.library.mesh.MeshFlat;
41 41
import org.distorted.library.mesh.MeshBase;
42
import org.distorted.library.mesh.MeshQuad;
43
import org.distorted.library.mesh.MeshSphere;
42 44

  
43 45
import java.io.IOException;
44 46
import java.io.InputStream;
......
101 103
    DistortedEffects.setMax(EffectType.VERTEX  ,10);    // those have to be called before
102 104
    DistortedEffects.setMax(EffectType.FRAGMENT,10);    // any DistortedEffect get created!
103 105

  
104
    if( mObjectType==1 ) mMesh = new MeshFlat(mNumCols,mNumRows);
105
    else                 mMesh = new MeshCubes(mNumCols, mString, mNumSlic);
106
    switch(mObjectType)
107
      {
108
      case 0: mMesh = new MeshCubes(mNumCols, mString, mNumSlic);
109
              break;
110
      case 1: mMesh = new MeshFlat(mNumCols,mNumRows);
111
              break;
112
      case 2: mMesh = new MeshSphere(mNumRows);
113
              break;
114
      case 3: mMesh = new MeshQuad();
115
              break;
116
      }
106 117

  
107 118
    mMesh.setShowNormals(mShowNormal);
108 119
    mTexture= new DistortedTexture(mNumCols,mNumRows);
src/main/java/org/distorted/examples/effects3d/Effects3DRenderer.java
93 93
      DistortedEffects regionEffects     = new DistortedEffects();
94 94

  
95 95
      MeshBase mesh    = act.getMesh();
96
      MeshFlat quad      = new MeshFlat(1,1);
96
      MeshFlat quad    = new MeshFlat(1,1);
97 97

  
98 98
      mObjWidth = mObjectTexture.getWidth();
99 99
      mObjHeight= mObjectTexture.getHeight();
src/main/java/org/distorted/examples/inflate/InflateActivity.java
41 41
  {
42 42
  private static final int COLOR_OFF = 0xffffe81f;
43 43
  private static final int COLOR_ON  = 0xff0000ff;
44
  private static final int COLOR_INAC= 0xff00ff00;
44
  private static final int COLOR_INAC= 0xff999999;
45 45

  
46 46
  private int mNumCols = 1;
47 47
  private int mNumRows = 1;
......
108 108
    Spinner typeSpinner  = findViewById(R.id.objectpicker_spinnerType);
109 109
    typeSpinner.setOnItemSelectedListener(this);
110 110

  
111
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat"};
111
    String[] objectType = new String[] {"Mesh: Cubes", "Mesh: Flat", "Mesh: Sphere", "Mesh: Quad"};
112 112

  
113 113
    ArrayAdapter<String> adapterType = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, objectType);
114 114
    adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
......
178 178

  
179 179
  public void onClick(View view)
180 180
    {
181
    if( mObjectType!=1 )
181
    if( mObjectType==0 )  // cubes
182 182
      {
183 183
      Button tmp = (Button)view;
184 184
      int id = tmp.getId();
......
201 201
      for(int col=0; col<mNumCols; col++)
202 202
        {
203 203
        butt = (Button)tr.getVirtualChildAt(col);
204
        butt.setBackgroundColor(mObjectType==1 ? COLOR_INAC : COLOR_ON);
204
        butt.setBackgroundColor(mObjectType==0 ? COLOR_ON : COLOR_INAC);
205 205
        mShape[row*mNumCols+col] = true;
206 206
        }
207 207
      }
......
214 214
    Intent mainInt = new Intent( getApplicationContext(), InflateActivity2.class);
215 215
    Bundle b = new Bundle();
216 216

  
217
    int rows=0, cols=0;
218

  
219
    switch(mObjectType)
220
      {
221
      case 0:
222
      case 1: rows = mNumRows;
223
              cols = mNumCols;
224
              break;
225
      case 2: rows = mNumRows;   // always make the sphere equal in X and Y
226
              cols = mNumRows;   //
227
              break;
228
      case 3: rows = 1;          // a quad is always 1x1
229
              cols = 1;
230
              break;
231
      }
232

  
217 233
    b.putInt("type", mObjectType);
218
    b.putInt("cols", mNumCols);
219
    b.putInt("rows", mNumRows);
234
    b.putInt("cols", cols);
235
    b.putInt("rows", rows);
220 236
    b.putInt("slices", mNumSlic);
221 237
    b.putInt("bitmap", mBitmapID);
222 238

  
223
    if( mObjectType==1 )
224
      {
225
      b.putString("string", "");
226
      }
227
    else
239
    if( mObjectType==0 )   // cubes
228 240
      {
229 241
      String str = "";
230 242

  
......
233 245

  
234 246
      b.putString("string", str);
235 247
      }
248
    else
249
      {
250
      b.putString("string", "");
251
      }
236 252

  
237 253
    mainInt.putExtras(b);
238 254
    startActivity(mainInt);
......
248 264
                                              {
249 265
                                              mObjectType = pos;
250 266
                                              uncheckAll();
267

  
268
                                              switch(mObjectType)
269
                                                {
270
                                                case 0: mColsPicker.setEnabled(true);
271
                                                        mRowsPicker.setEnabled(true);
272
                                                        mSlicPicker.setEnabled(true);
273
                                                        break;
274
                                                case 1: mColsPicker.setEnabled(true);
275
                                                        mRowsPicker.setEnabled(true);
276
                                                        mSlicPicker.setEnabled(false);
277
                                                        break;
278
                                                case 2: mColsPicker.setEnabled(false);
279
                                                        mRowsPicker.setEnabled(true);
280
                                                        mSlicPicker.setEnabled(false);
281
                                                        break;
282
                                                case 3: mColsPicker.setEnabled(false);
283
                                                        mRowsPicker.setEnabled(false);
284
                                                        mSlicPicker.setEnabled(false);
285
                                                        break;
286
                                                }
251 287
                                              }
252 288
                                            break;
253 289
      case R.id.objectpicker_spinnerBitmap: switch(pos)
src/main/java/org/distorted/examples/inflate/InflateActivity2.java
35 35
import org.distorted.library.mesh.MeshBase;
36 36
import org.distorted.library.mesh.MeshCubes;
37 37
import org.distorted.library.mesh.MeshFlat;
38
import org.distorted.library.mesh.MeshQuad;
39
import org.distorted.library.mesh.MeshSphere;
38 40

  
39 41
import java.io.IOException;
40 42
import java.io.InputStream;
......
100 102
      mNumSlic       = b.getInt("slices");
101 103
      mBitmapID      = b.getInt("bitmap");
102 104

  
103
      if( objectType==1 ) mMesh = new MeshFlat(mNumCols,mNumRows);
104
      else                mMesh = new MeshCubes(mNumCols, str, mNumSlic);
105
      switch(objectType)
106
        {
107
        case 0: mMesh = new MeshCubes(mNumCols, str, mNumSlic);
108
                break;
109
        case 1: mMesh = new MeshFlat(mNumCols,mNumRows);
110
                break;
111
        case 2: mMesh = new MeshSphere(mNumRows);
112
                break;
113
        case 3: mMesh = new MeshQuad();
114
                break;
115
        }
105 116

  
106 117
      mTexture= new DistortedTexture(mNumCols,mNumRows);
107 118

  
108 119
      setContentView(R.layout.inflatelayout);
109 120

  
110
      mTextLevel = (TextView)findViewById(R.id.inflateText);
121
      mTextLevel = findViewById(R.id.inflateText);
111 122
      SeekBar levelBar = findViewById(R.id.inflateLevel);
112 123
      levelBar.setOnSeekBarChangeListener(this);
113 124

  
src/main/java/org/distorted/examples/inflate/InflateRenderer.java
100 100
    
101 101
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
102 102
      {
103
      final float SCALE = 0.75f;
104

  
103 105
      mScreenMin = width<height ? width:height;
104
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (0.75f*height)/mObjHeight :  (0.75f*width)/mObjWidth;
106
      float factor = ( width*mObjHeight > height*mObjWidth ) ? (SCALE*height)/mObjHeight :  (SCALE*width)/mObjWidth;
105 107
      mMove.set( (width-factor*mObjWidth)/2 , (height-factor*mObjHeight)/2 , 0);
106 108
      mScale.set(factor,factor,factor);
107 109
      mCenter.set( (float)mObjWidth/2, (float)mObjHeight/2, -(float)mObjDepth/2 );

Also available in: Unified diff