Project

General

Profile

« Previous | Next » 

Revision 4db4e39b

Added by Leszek Koltunski almost 6 years ago

Improvements for texturing MeshCubes objects in two apps (in light of the recent change in default texture mapping)

View differences:

src/main/java/org/distorted/examples/effects3d/Effects3DActivity2.java
32 32
import android.widget.CheckBox;
33 33

  
34 34
import org.distorted.examples.R;
35
import org.distorted.library.effect.EffectType;
36 35
import org.distorted.library.main.Distorted;
37 36
import org.distorted.library.main.DistortedEffects;
38 37
import org.distorted.library.main.DistortedTexture;
......
41 40
import org.distorted.library.mesh.MeshBase;
42 41
import org.distorted.library.mesh.MeshQuad;
43 42
import org.distorted.library.mesh.MeshSphere;
43
import org.distorted.library.type.Static4D;
44 44

  
45 45
import java.io.IOException;
46 46
import java.io.InputStream;
......
51 51
  {
52 52
  public static final int NUM_TABS = 4;
53 53

  
54
  private int mNumCols;
55
  private int mNumRows;
56
  private int mNumSlic;
57
  private int mObjectType;
58
  private int mBitmapID;
59
  private String mString;
60

  
61 54
  private DistortedTexture mTexture;
62 55
  private MeshBase mMesh;
63 56
  private Bitmap mBitmap;
......
66 59
  private float mRegionX, mRegionY, mRegionZ, mRegionR;
67 60
  private DistortedEffects mEffects;
68 61
  private ViewPager mViewPager;
69
  private Effects3DTabViewPager mPager;
70 62

  
71 63
  private boolean mShowCenter;
72 64
  private boolean mShowRegion;
......
88 80

  
89 81
    Bundle b = getIntent().getExtras();
90 82

  
91
    mObjectType = b.getInt("type");
92
    mNumCols    = b.getInt("cols");
93
    mNumRows    = b.getInt("rows");
94
    mNumSlic    = b.getInt("slices");
95
    mBitmapID   = b.getInt("bitmap");
96
    mString     = b.getString("string");
83
    int objectType = b.getInt("type");
84
    int numCols    = b.getInt("cols");
85
    int numRows    = b.getInt("rows");
86
    int numSlic    = b.getInt("slices");
87
    int bitmapID   = b.getInt("bitmap");
88
    String str     = b.getString("string");
97 89

  
98 90
    mShowCenter = false;
99 91
    mShowRegion = false;
100 92
    mShowNormal = false;
101 93
    mUseOIT     = false;
102 94

  
103
    switch(mObjectType)
95
    int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic) ;
96

  
97
    createBitmap(maxsize, bitmapID);
98

  
99
    switch(objectType)
104 100
      {
105
      case 0: mMesh = new MeshCubes(mNumCols, mString, mNumSlic);
101
      case 0: if( bitmapID!=-1 )
102
                {
103
                mMesh = new MeshCubes(numCols, str, numSlic);
104
                }
105
              else
106
                {
107
                Static4D mapFB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numRows/maxsize);
108
                Static4D mapLR = new Static4D(0.0f,0.0f, (float)numSlic/maxsize, (float)numRows/maxsize);
109
                Static4D mapTB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numSlic/maxsize);
110

  
111
                mMesh = new MeshCubes(numCols, str, numSlic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
112
                }
106 113
              break;
107
      case 1: mMesh = new MeshFlat(mNumCols,mNumRows);
114
      case 1: mMesh = new MeshFlat(numCols,numRows);
108 115
              break;
109
      case 2: mMesh = new MeshSphere(mNumRows);
116
      case 2: mMesh = new MeshSphere(numRows);
110 117
              break;
111 118
      case 3: mMesh = new MeshQuad();
112 119
              break;
113 120
      }
114 121

  
115 122
    mMesh.setShowNormals(mShowNormal);
116
    mTexture= new DistortedTexture(mNumCols,mNumRows);
123
    mTexture= new DistortedTexture(numCols,numRows);
117 124
    mEffects= new DistortedEffects();
118 125

  
119 126
    final View view = getLayoutInflater().inflate(R.layout.effects3dlayout, null);
......
122 129

  
123 130
    mViewPager = findViewById(R.id.effects3d_viewpager);
124 131
    mViewPager.setOffscreenPageLimit( NUM_TABS-1 );
125
    mPager = new Effects3DTabViewPager(this, getSupportFragmentManager() );
126
    mViewPager.setAdapter(mPager);
132
    Effects3DTabViewPager pager = new Effects3DTabViewPager(this, getSupportFragmentManager() );
133
    mViewPager.setAdapter(pager);
127 134
    TabLayout tabLayout = findViewById(R.id.effects3d_sliding_tabs);
128 135
    tabLayout.setupWithViewPager(mViewPager);
129 136

  
130 137
    resetData();
131 138
    }
132 139

  
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

  
142
  private void createBitmap(int size, int bitmapID)
143
    {
144
    if( bitmapID!=-1)
145
      {
146
      InputStream is = getResources().openRawResource(bitmapID);
147

  
148
      try
149
        {
150
        mBitmap = BitmapFactory.decodeStream(is);
151
        }
152
      finally
153
        {
154
        try
155
          {
156
          is.close();
157
          }
158
        catch(IOException e) { }
159
        }
160
      }
161
    else
162
      {
163
      final int T = 64;
164
      final int S = T*size;
165

  
166
      Paint paint = new Paint();
167
      mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
168
      Canvas canvas = new Canvas(mBitmap);
169

  
170
      paint.setAntiAlias(true);
171
      paint.setTextAlign(Paint.Align.CENTER);
172
      paint.setColor(0xff008800);
173
      paint.setStyle(Paint.Style.FILL);
174
      canvas.drawRect(0, 0, S, S, paint);
175
      paint.setColor(0xffffffff);
176

  
177
      for(int i=0; i<=size ; i++ )
178
        {
179
        canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
180
        canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
181
        }
182
      }
183
    }
184

  
133 185
///////////////////////////////////////////////////////////////////////////////////////////////////
134 186

  
135 187
  public DistortedTexture getTexture()
......
148 200

  
149 201
  public Bitmap getBitmap()
150 202
    {
151
    if( mBitmap==null )
152
      {
153
      if( mBitmapID!=-1)
154
        {
155
        InputStream is = getResources().openRawResource(mBitmapID);
156

  
157
        try
158
          {
159
          mBitmap = BitmapFactory.decodeStream(is);
160
          }
161
        finally
162
          {
163
          try
164
            {
165
            is.close();
166
            }
167
          catch(IOException e) { }
168
          }
169
        }
170
      else
171
        {
172
        final int W = 64*mNumCols;
173
        final int H = 64*mNumRows;
174

  
175
        Paint paint = new Paint();
176
        mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
177
        Canvas canvas = new Canvas(mBitmap);
178

  
179
        paint.setAntiAlias(true);
180
        paint.setTextAlign(Paint.Align.CENTER);
181
        paint.setColor(0xff008800);
182
        paint.setStyle(Paint.Style.FILL);
183
        canvas.drawRect(0, 0, W, H, paint);
184
        paint.setColor(0xffffffff);
185

  
186
        for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
187
        for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W,  H*i/mNumRows+1, paint);
188
        }
189
      }
190

  
191 203
    return mBitmap;
192 204
    }
193 205

  
src/main/java/org/distorted/examples/inflate/InflateActivity2.java
27 27
import org.distorted.library.mesh.MeshFlat;
28 28
import org.distorted.library.mesh.MeshQuad;
29 29
import org.distorted.library.mesh.MeshSphere;
30
import org.distorted.library.type.Static4D;
30 31

  
31 32
import android.app.Activity;
32 33
import android.graphics.Bitmap;
......
49 50

  
50 51
public class InflateActivity2 extends Activity implements SeekBar.OnSeekBarChangeListener, AdapterView.OnItemSelectedListener
51 52
{
52
    private int mNumCols = 3;
53
    private int mNumRows = 3;
54
    private int mNumSlic = 1;
55
    private int mBitmapID;
56 53
    private Bitmap mBitmap;
57 54
    private TextView mTextLevel;
58 55
    private DistortedTexture mTexture;
......
101 98

  
102 99
      String str     = b.getString("string");
103 100
      int objectType = b.getInt("type");
104
      mNumCols       = b.getInt("cols");
105
      mNumRows       = b.getInt("rows");
106
      mNumSlic       = b.getInt("slices");
107
      mBitmapID      = b.getInt("bitmap");
101
      int numCols    = b.getInt("cols");
102
      int numRows    = b.getInt("rows");
103
      int numSlic    = b.getInt("slices");
104
      int bitmapID   = b.getInt("bitmap");
105

  
106
      int maxsize = numCols > numRows ? (numCols>numSlic ? numCols:numSlic) : (numRows>numSlic ? numRows:numSlic) ;
107

  
108
      createBitmap(maxsize,bitmapID);
108 109

  
109 110
      switch(objectType)
110 111
        {
111
        case 0: mMesh = new MeshCubes(mNumCols, str, mNumSlic); break;
112
        case 1: mMesh = new MeshFlat(mNumCols,mNumRows)       ; break;
113
        case 2: mMesh = new MeshSphere(mNumRows)              ; break;
114
        case 3: mMesh = new MeshQuad()                        ; break;
112
        case 0: if( bitmapID!=-1 )
113
                  {
114
                  mMesh = new MeshCubes(numCols, str, numSlic);
115
                  }
116
                else
117
                  {
118
                  Static4D mapFB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numRows/maxsize);
119
                  Static4D mapLR = new Static4D(0.0f,0.0f, (float)numSlic/maxsize, (float)numRows/maxsize);
120
                  Static4D mapTB = new Static4D(0.0f,0.0f, (float)numCols/maxsize, (float)numSlic/maxsize);
121

  
122
                  mMesh = new MeshCubes(numCols, str, numSlic, mapFB, mapFB, mapLR, mapLR, mapTB, mapTB);
123
                  }
124
                break;
125
        case 1: mMesh = new MeshFlat(numCols,numRows);
126
                break;
127
        case 2: mMesh = new MeshSphere(numRows);
128
                break;
129
        case 3: mMesh = new MeshQuad();
130
                break;
115 131
        }
116 132

  
117
      mTexture = new DistortedTexture(mNumCols,mNumRows);
133
      mTexture = new DistortedTexture(numCols,numRows);
118 134

  
119 135
      setContentView(R.layout.inflatelayout);
120 136

  
......
140 156

  
141 157
///////////////////////////////////////////////////////////////////////////////////////////////////
142 158

  
143
    public Bitmap getBitmap()
159
    private void createBitmap(int size, int bitmapID)
144 160
      {
145
      if( mBitmap==null )
161
      if( bitmapID!=-1)
146 162
        {
147
        if( mBitmapID!=-1)
148
          {
149
          InputStream is = getResources().openRawResource(mBitmapID);
163
        InputStream is = getResources().openRawResource(bitmapID);
150 164

  
165
        try
166
          {
167
          mBitmap = BitmapFactory.decodeStream(is);
168
          }
169
        finally
170
          {
151 171
          try
152 172
            {
153
            mBitmap = BitmapFactory.decodeStream(is);
154
            }
155
          finally
156
            {
157
            try
158
              {
159
              is.close();
160
              }
161
            catch(IOException e) { }
173
            is.close();
162 174
            }
175
          catch(IOException e) { }
163 176
          }
164
        else
177
        }
178
      else
179
        {
180
        final int T = 64;
181
        final int S = T*size;
182

  
183
        Paint paint = new Paint();
184
        mBitmap = Bitmap.createBitmap(S,S, Bitmap.Config.ARGB_8888);
185
        Canvas canvas = new Canvas(mBitmap);
186

  
187
        paint.setAntiAlias(true);
188
        paint.setTextAlign(Paint.Align.CENTER);
189
        paint.setColor(0xff008800);
190
        paint.setStyle(Paint.Style.FILL);
191
        canvas.drawRect(0, 0, S, S, paint);
192
        paint.setColor(0xffffffff);
193

  
194
        for(int i=0; i<=size ; i++ )
165 195
          {
166
          final int W = 64*mNumCols;
167
          final int H = 64*mNumRows;
168

  
169
          Paint paint = new Paint();
170
          mBitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
171
          Canvas canvas = new Canvas(mBitmap);
172

  
173
          paint.setAntiAlias(true);
174
          paint.setTextAlign(Paint.Align.CENTER);
175
          paint.setColor(0xff008800);
176
          paint.setStyle(Paint.Style.FILL);
177
          canvas.drawRect(0, 0, W, H, paint);
178
          paint.setColor(0xffffffff);
179

  
180
          for(int i=0; i<=mNumCols ; i++ ) canvas.drawRect(W*i/mNumCols-1, 0, W*i/mNumCols + 1, H, paint);
181
          for(int i=0; i<=mNumRows ; i++ ) canvas.drawRect( 0, H*i/mNumRows-1, W,  H*i/mNumRows+1, paint);
196
          canvas.drawRect( T*i-1, 0, T*i+1, S, paint);
197
          canvas.drawRect( 0, T*i-1, S, T*i+1, paint);
182 198
          }
183 199
        }
200
      }
184 201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
    public Bitmap getBitmap()
205
      {
185 206
      return mBitmap;
186 207
      }
187 208

  

Also available in: Unified diff