Project

General

Profile

« Previous | Next » 

Revision 8ac4c0bc

Added by Leszek Koltunski over 4 years ago

Progress with the MeshFile app.

View differences:

src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
26 26
import android.graphics.Paint;
27 27
import android.opengl.GLSurfaceView;
28 28

  
29
import org.distorted.examples.R;
29 30
import org.distorted.library.effect.MatrixEffectQuaternion;
30 31
import org.distorted.library.effect.MatrixEffectScale;
31 32
import org.distorted.library.main.DistortedEffects;
......
108 109
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
109 110
      {
110 111
      if( mTexture==null ) mTexture = new DistortedTexture();
111
      mTexture.setTexture( createTexture(0) );
112 112

  
113 113
      try
114 114
        {
......
124 124

  
125 125
    void open(int resourceID)
126 126
      {
127
      mTexture.setTexture( createTexture(resourceID) );
128

  
127 129
      long t1 = System.currentTimeMillis();
128 130
      mMesh = createMesh(resourceID);
129 131
      long t2 = System.currentTimeMillis();
......
138 140

  
139 141
    private Bitmap createTexture(int resourceID)
140 142
      {
141
      final int[] FACE_COLORS = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
142
      final int FACES=FACE_COLORS.length;
143
      switch(resourceID)
144
          {
145
          case  R.raw.deferredjob:
146
          case  R.raw.meshjoin   : final int[] TET_COLORS4 = new int[] { 0xffffff00,
147
                                                                         0xff00ff00,
148
                                                                         0xff0000ff,
149
                                                                         0xffff0000 };
150
                                   return createTetrahedrenTexture(TET_COLORS4);
151
          case  R.raw.predeform  : return createGridTexture(3);
152
          case  R.raw.cube2      :
153
          case  R.raw.cube3      :
154
          case  R.raw.cube4      :
155
          case  R.raw.cube5      : final int[] CUBE_COLORS = new int[] { 0xffffff00,
156
                                                                         0xffffffff,
157
                                                                         0xff0000ff,
158
                                                                         0xff00ff00,
159
                                                                         0xffff0000,
160
                                                                         0xffb5651d };
161
                                   return createCubeTexture(CUBE_COLORS);
162
          case  R.raw.pyra3      :
163
          case  R.raw.pyra4      :
164
          case  R.raw.pyra5      : final int[] TET_COLORS5 = new int[] { 0xffffff00,
165
                                                                         0xff00ff00,
166
                                                                         0xff0000ff,
167
                                                                         0xffff0000,
168
                                                                         0xff000000 };
169
                                   return createTetrahedrenTexture(TET_COLORS5);
170
          }
171

  
172
      return null;
173
      }
174

  
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

  
177
    private Bitmap createCubeTexture(int[] faceColors)
178
      {
179
      final int FACES=faceColors.length;
180
      int SIZE = 200;
181
      final float R = SIZE*0.10f;
182
      final float M = SIZE*0.05f;
183

  
184
      Bitmap bitmap;
185
      Paint paint = new Paint();
186
      bitmap = Bitmap.createBitmap( (FACES+1)*SIZE, SIZE, Bitmap.Config.ARGB_8888);
187
      Canvas canvas = new Canvas(bitmap);
188

  
189
      paint.setStyle(Paint.Style.FILL);
190
      paint.setColor(0xff000000);
191
      canvas.drawRect(0, 0, (FACES+1)*SIZE, SIZE, paint);
192

  
193
      for(int face=0; face<FACES; face++)
194
        {
195
        paint.setColor(faceColors[face]);
196
        canvas.drawRoundRect( face*SIZE+M, M, (face+1)*SIZE-M, SIZE-M, R, R, paint);
197
        }
198

  
199
      return bitmap;
200
      }
201

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

  
204
    private Bitmap createGridTexture(int lines)
205
      {
206
      int SIZE = 200;
207
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
208
      Canvas canvas = new Canvas(bitmap);
209

  
210
      Paint paint = new Paint();
211
      paint.setColor(0xff008800);
212
      paint.setStyle(Paint.Style.FILL);
213
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
214
      paint.setColor(0xffffffff);
215

  
216
      for(int i=0; i<=lines ; i++ )
217
        {
218
        int x = (SIZE*i)/lines;
219
        canvas.drawRect(x-1,   0,  x+1, SIZE, paint);
220
        canvas.drawRect(  0, x-1, SIZE,  x+1, paint);
221
        }
222

  
223
      return bitmap;
224
      }
225

  
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

  
228
    private Bitmap createTetrahedrenTexture(int[] faceColors)
229
      {
230
      final int FACES=faceColors.length;
143 231
      int SIZE = 200;
144 232
      float STROKE = 0.05f*SIZE;
145 233
      float OFF = STROKE/2 -1;
......
160 248

  
161 249
      for(int i=0; i<FACES; i++)
162 250
        {
163
        paint.setColor(FACE_COLORS[i]);
251
        paint.setColor(faceColors[i]);
164 252
        paint.setStyle(Paint.Style.FILL);
165 253

  
166 254
        canvas.drawRect(i*SIZE,0,(i+1)*SIZE,SIZE,paint);

Also available in: Unified diff