Project

General

Profile

Download (42.4 KB) Statistics
| Branch: | Revision:

examples / src / main / java / org / distorted / examples / meshfile / MeshFileRenderer.java @ c6f4bd1e

1 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.meshfile;
21
22 1af8e143 Leszek Koltunski
import android.content.Context;
23
import android.content.res.Resources;
24 42aa970f Leszek Koltunski
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27
import android.opengl.GLSurfaceView;
28
29 8ac4c0bc Leszek Koltunski
import org.distorted.examples.R;
30 a65604a7 Leszek Koltunski
import org.distorted.library.effect.Effect;
31 6991ece5 Leszek Koltunski
import org.distorted.library.effect.EffectType;
32 42aa970f Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34 39b925d5 Leszek Koltunski
import org.distorted.library.effect.VertexEffectDisappear;
35 42aa970f Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedLibrary;
37
import org.distorted.library.main.DistortedScreen;
38
import org.distorted.library.main.DistortedTexture;
39 6991ece5 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
40 1af8e143 Leszek Koltunski
import org.distorted.library.mesh.MeshFile;
41 1bb5d3b7 Leszek Koltunski
import org.distorted.library.mesh.MeshPolygon;
42 42aa970f Leszek Koltunski
import org.distorted.library.type.DynamicQuat;
43
import org.distorted.library.type.Static3D;
44
import org.distorted.library.type.Static4D;
45
46 1bb5d3b7 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
47 e018a923 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
48 1bb5d3b7 Leszek Koltunski
49 1af8e143 Leszek Koltunski
import java.io.DataInputStream;
50
import java.io.IOException;
51
import java.io.InputStream;
52
53 42aa970f Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
54
import javax.microedition.khronos.opengles.GL10;
55
56 1bb5d3b7 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.POLYGON;
57 6991ece5 Leszek Koltunski
import static org.distorted.examples.meshfile.MeshFileActivity.PROCEDURAL;
58 baace8e9 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.MESH_NICE;
59 6991ece5 Leszek Koltunski
60 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62 061449ed Leszek Koltunski
class MeshFileRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
63 42aa970f Leszek Koltunski
{
64 7edab735 Leszek Koltunski
    private static final float SQ2 = (float)Math.sqrt(2);
65
    private static final float SQ3 = (float)Math.sqrt(3);
66 db9903e8 Leszek Koltunski
    private static final float SQ5 = (float)Math.sqrt(5);
67 9db7b0e5 Leszek Koltunski
    private static final float SQ6 = (float)Math.sqrt(6);
68 16b336db Leszek Koltunski
    private final float DEFAULT_SCALE = 0.3f;
69
70 140f2c4e Leszek Koltunski
    private final GLSurfaceView mView;
71 42aa970f Leszek Koltunski
    private DistortedTexture mTexture;
72 140f2c4e Leszek Koltunski
    private final DistortedScreen mScreen;
73
    private final DistortedEffects mEffects;
74
    private final Static3D mScale;
75 48c88f57 Leszek Koltunski
    private long mTime;
76 16b336db Leszek Koltunski
    private float mCurrentScale;
77 6991ece5 Leszek Koltunski
    private MeshBase mMesh;
78 42aa970f Leszek Koltunski
79
    Static4D mQuat1, mQuat2;
80
    int mScreenMin;
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83
84
    MeshFileRenderer(GLSurfaceView v)
85
      {
86
      mView = v;
87
      mScreen = new DistortedScreen();
88
      mScale= new Static3D(1,1,1);
89
      Static3D center=new Static3D(0,0,0);
90
91 16b336db Leszek Koltunski
      mCurrentScale = DEFAULT_SCALE;
92
93 42aa970f Leszek Koltunski
      mQuat1 = new Static4D(0,0,0,1);
94 fe032f52 Leszek Koltunski
      mQuat2 = new Static4D(0,0,0,1);
95 42aa970f Leszek Koltunski
96
      DynamicQuat quatInt1 = new DynamicQuat(0,0.5f);
97
      DynamicQuat quatInt2 = new DynamicQuat(0,0.5f);
98
99
      quatInt1.add(mQuat1);
100
      quatInt2.add(mQuat2);
101
102 39b925d5 Leszek Koltunski
      VertexEffectDisappear disappear = new VertexEffectDisappear();
103
      disappear.setMeshAssociation(1,-1);
104
105 42aa970f Leszek Koltunski
      mEffects = new DistortedEffects();
106
      mEffects.apply( new MatrixEffectQuaternion(quatInt2, center) );
107
      mEffects.apply( new MatrixEffectQuaternion(quatInt1, center) );
108
      mEffects.apply( new MatrixEffectScale(mScale));
109
110 39b925d5 Leszek Koltunski
      mEffects.apply( disappear );
111
112 42aa970f Leszek Koltunski
      mScreen.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
113 48c88f57 Leszek Koltunski
      mScreen.showFPS();
114 42aa970f Leszek Koltunski
      }
115
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117
   
118
    public void onDrawFrame(GL10 glUnused) 
119
      {
120
      mScreen.render( System.currentTimeMillis() );
121
      }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
    
125
    public void onSurfaceChanged(GL10 glUnused, int width, int height) 
126
      {
127
      mScreenMin = Math.min(width, height);
128 16b336db Leszek Koltunski
      float factor = mCurrentScale*mScreenMin;
129 42aa970f Leszek Koltunski
      mScale.set(factor,factor,factor);
130
      mScreen.resize(width, height);
131
      }
132
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134
    
135
    public void onSurfaceCreated(GL10 glUnused, EGLConfig config) 
136
      {
137
      if( mTexture==null ) mTexture = new DistortedTexture();
138
139 a65604a7 Leszek Koltunski
      Effect.enableEffects(EffectType.VERTEX);
140 04a21ed6 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX, 20);
141 ef02f5e0 Leszek Koltunski
      DistortedLibrary.needTransformFeedback();
142 7c72e798 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(), this);
143 061449ed Leszek Koltunski
      }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
    public void distortedException(Exception ex)
148
      {
149
      android.util.Log.e("MeshFile", ex.getMessage() );
150 42aa970f Leszek Koltunski
      }
151
152 16b336db Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
153
//   0 ---> 0
154
//  50 ---> DEFAULT_SCALE
155
// 100 ---> 4*DEFAULT_SCALE
156
157
    void setScale(int scale)
158
      {
159
      if( scale<= 50 )
160
        {
161
        mCurrentScale = DEFAULT_SCALE * scale / 50.0f;
162
        }
163
      else
164
        {
165
        mCurrentScale = DEFAULT_SCALE * ( 3*(scale/50.0f) - 2.0f);
166
        }
167
168
      float factor = mCurrentScale*mScreenMin;
169
      mScale.set(factor,factor,factor);
170
      }
171
172 42aa970f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174 1af8e143 Leszek Koltunski
    void open(int resourceID)
175 42aa970f Leszek Koltunski
      {
176 099d8f8b Leszek Koltunski
      if( mTexture==null ) mTexture = new DistortedTexture();
177 8ac4c0bc Leszek Koltunski
      mTexture.setTexture( createTexture(resourceID) );
178
179 acad428e Leszek Koltunski
      long t1 = System.currentTimeMillis();
180 6991ece5 Leszek Koltunski
181 1bb5d3b7 Leszek Koltunski
      if( resourceID==PROCEDURAL )
182 6991ece5 Leszek Koltunski
        {
183 1bb5d3b7 Leszek Koltunski
        createMesh();
184
        }
185
      else if( resourceID==POLYGON )
186
        {
187
        createPolygon();
188 6991ece5 Leszek Koltunski
        }
189
      else
190
        {
191 1bb5d3b7 Leszek Koltunski
        openMesh(resourceID);
192 6991ece5 Leszek Koltunski
        }
193
194 acad428e Leszek Koltunski
      long t2 = System.currentTimeMillis();
195
196 48c88f57 Leszek Koltunski
      mTime = t2-t1;
197 42aa970f Leszek Koltunski
198 71c7624f Leszek Koltunski
      mScreen.detachAll();
199 7198e5c9 Leszek Koltunski
      mScreen.attach(mTexture,mEffects,mMesh);
200 42aa970f Leszek Koltunski
      }
201
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203
204 1af8e143 Leszek Koltunski
    private Bitmap createTexture(int resourceID)
205 42aa970f Leszek Koltunski
      {
206 7edab735 Leszek Koltunski
      TextureFactory factory = TextureFactory.getInstance();
207
208
      float[] vertices;
209
      int[] colors;
210
      float F = 0.5f;
211
      float E = SQ3/2;
212
213 8ac4c0bc Leszek Koltunski
      switch(resourceID)
214
          {
215
          case  R.raw.deferredjob:
216 7edab735 Leszek Koltunski
          case  R.raw.meshjoin   :
217 1beffb69 Leszek Koltunski
          case  PROCEDURAL       :
218 1bb5d3b7 Leszek Koltunski
          case  POLYGON          :
219 7edab735 Leszek Koltunski
          case  R.raw.predeform  : return createWhiteTexture();
220
221 8ac4c0bc Leszek Koltunski
          case  R.raw.cube2      :
222
          case  R.raw.cube3      :
223
          case  R.raw.cube4      :
224 7edab735 Leszek Koltunski
          case  R.raw.cube5      : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
225
                                   vertices = new float[] { -F,-F, +F,-F, +F,+F, -F,+F};
226
                                   return factory.createTexture(vertices,colors,0.10f, 0.10f, true);
227 8ac4c0bc Leszek Koltunski
          case  R.raw.pyra3      :
228
          case  R.raw.pyra4      :
229 7edab735 Leszek Koltunski
          case  R.raw.pyra5      : colors = new int[] { 0xffffff00, 0xff00ff00, 0xff0000ff, 0xffff0000 };
230
                                   vertices = new float[] { -F,-E/3, +F,-E/3, 0.0f,2*E/3};
231
                                   return factory.createTexture(vertices,colors,0.05f, 0.05f, true);
232 8ac4c0bc Leszek Koltunski
233 7edab735 Leszek Koltunski
          case  R.raw.dino       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
234
                                   vertices = new float[] { -F,F/3, 0,-2*F/3, +F,F/3 };
235
                                   return factory.createTexture(vertices,colors,0.05f, 0.03f, true);
236 8ac4c0bc Leszek Koltunski
237 7edab735 Leszek Koltunski
          case R.raw.skewb       : colors = new int[] { 0xffffff00, 0xffffffff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffb5651d };
238
                                   //vertices = new float[] { -G,-G, +G,-G, +G,+G, -G,+G };
239 8ac4c0bc Leszek Koltunski
240 7edab735 Leszek Koltunski
                                   vertices = new float[] { -F+F/4,F/4, F/4,-F+F/4, F/4,F/4};
241
                                   return factory.createTexture(vertices,colors,0.05f, 0.08f, true);
242
          }
243 8ac4c0bc Leszek Koltunski
244 7edab735 Leszek Koltunski
      return null;
245 8ac4c0bc Leszek Koltunski
      }
246
247
///////////////////////////////////////////////////////////////////////////////////////////////////
248
249 7edab735 Leszek Koltunski
    private Bitmap createWhiteTexture()
250 8ac4c0bc Leszek Koltunski
      {
251 7edab735 Leszek Koltunski
      int SIZE = 1;
252 8ac4c0bc Leszek Koltunski
      Bitmap bitmap = Bitmap.createBitmap(SIZE,SIZE, Bitmap.Config.ARGB_8888);
253
      Canvas canvas = new Canvas(bitmap);
254
255
      Paint paint = new Paint();
256 36793c52 Leszek Koltunski
      paint.setColor(0xffffff55);
257 1beffb69 Leszek Koltunski
      paint.setStyle(Paint.Style.FILL);
258 7edab735 Leszek Koltunski
      canvas.drawRect(0, 0, SIZE, SIZE, paint);
259 6991ece5 Leszek Koltunski
260 72059460 Leszek Koltunski
      return bitmap;
261 6991ece5 Leszek Koltunski
      }
262
263 1bb5d3b7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
264
265
    private void createPolygon()
266
      {
267
      float A = 0.5f;
268
      float B = 0.1f;
269
270 65dd40aa Leszek Koltunski
      int extraIndex    = 2;
271 1bb5d3b7 Leszek Koltunski
      int extraVertices = 2;
272 65dd40aa Leszek Koltunski
      int numBands      = 2;
273 1bb5d3b7 Leszek Koltunski
274
      float[] vertices = new float[] { -A,-A, A,-A, A,A, -A,A };
275
      float[] bands = new float[2*numBands];
276
277
      for(int i=0; i<numBands; i++)
278
        {
279
        bands[2*i  ] = 1 + i/(1.0f-numBands);
280
        bands[2*i+1] = B/(numBands-1)*i;
281
        }
282
283
      mMesh = new MeshPolygon(vertices,bands,extraIndex,extraVertices);
284
      mMesh.setEffectAssociation(0,0,0);
285
      mMesh.setShowNormals(true);
286
      }
287
288 6991ece5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
289
290
    private void createMesh()
291
      {
292 c6f4bd1e Leszek Koltunski
      int mode            =20;
293 a40adec7 Leszek Koltunski
      int numComponents   = 0;
294 3f7a9aec Leszek Koltunski
      float[][] vertices  = null;
295 28f4aba0 Leszek Koltunski
      int[][] vertIndexes = null;
296
      float[][] bands     = null;
297
      int[] bandIndexes   = null;
298
      float[][] corners   = null;
299
      int[] cornerIndexes = null;
300 6983badf Leszek Koltunski
      float[][] centers   = null;
301
      int[] centerIndexes = null;
302 a40adec7 Leszek Koltunski
      float[] convexCenter= null;
303 28f4aba0 Leszek Koltunski
304 4d883a92 Leszek Koltunski
      ///// CUBE ////////////////////////////////////////////////////////////////////////////////
305
306
      if( mode==0 )
307 28f4aba0 Leszek Koltunski
        {
308 3f7a9aec Leszek Koltunski
        vertices = new float[][]
309 33647db9 Leszek Koltunski
          {
310 3f7a9aec Leszek Koltunski
              { 0.5f, 0.5f, 0.5f },
311
              { 0.5f, 0.5f,-0.5f },
312
              { 0.5f,-0.5f, 0.5f },
313
              { 0.5f,-0.5f,-0.5f },
314
              {-0.5f, 0.5f, 0.5f },
315
              {-0.5f, 0.5f,-0.5f },
316
              {-0.5f,-0.5f, 0.5f },
317
              {-0.5f,-0.5f,-0.5f },
318 33647db9 Leszek Koltunski
          };
319
320 28f4aba0 Leszek Koltunski
        vertIndexes = new int[][]
321 33647db9 Leszek Koltunski
          {
322 140f2c4e Leszek Koltunski
              {2,3,1,0},   // counterclockwise!
323
              {7,6,4,5},
324
              {4,0,1,5},
325
              {7,3,2,6},
326
              {6,2,0,4},
327
              {3,7,5,1}
328 33647db9 Leszek Koltunski
          };
329
330 28f4aba0 Leszek Koltunski
        bands = new float[][]
331 33647db9 Leszek Koltunski
          {
332 6a96e571 Leszek Koltunski
              {0.05f,40,0.5f,0.2f,5,  2,2}
333 33647db9 Leszek Koltunski
          };
334 a65604a7 Leszek Koltunski
335 28f4aba0 Leszek Koltunski
        bandIndexes = new int[] { 0,0,0,0,0,0 };
336 1c41c4c9 Leszek Koltunski
337 28f4aba0 Leszek Koltunski
        corners = new float[][]
338 1b85f172 Leszek Koltunski
          {
339
              { 0.01f, 0.10f }
340
          };
341
342 28f4aba0 Leszek Koltunski
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
343 6983badf Leszek Koltunski
344
        centers = new float[][]
345
          {
346
              { 0.0f, 0.0f, 0.0f }
347
          };
348
349
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
350
351
        numComponents = 8;
352 28f4aba0 Leszek Koltunski
        }
353 4d883a92 Leszek Koltunski
354
      ///// TETRAHEDRON //////////////////////////////////////////////////////////////////////////
355
356
      else if( mode==1 )
357 28f4aba0 Leszek Koltunski
        {
358 3f7a9aec Leszek Koltunski
        vertices = new float[][]
359 28f4aba0 Leszek Koltunski
          {
360 3f7a9aec Leszek Koltunski
              {-0.5f, SQ2/4, 0.0f},
361
              { 0.5f, SQ2/4, 0.0f},
362
              { 0.0f,-SQ2/4, 0.5f},
363
              { 0.0f,-SQ2/4,-0.5f}
364 28f4aba0 Leszek Koltunski
          };
365
366
        vertIndexes = new int[][]
367
          {
368
              {2,1,0},   // counterclockwise!
369
              {2,3,1},
370
              {3,2,0},
371
              {3,0,1}
372
          };
373
374
        bands = new float[][]
375
          {
376
              {0.05f,30,0.6f,0.5f,5,  2,2}
377
          };
378
379
        bandIndexes = new int[] { 0,0,0,0 };
380
381
        corners = new float[][]
382
          {
383
              { 0.02f, 0.10f }
384
          };
385
386
        cornerIndexes = new int[] { 0,0,0,0 };
387 6983badf Leszek Koltunski
388
        centers = new float[][]
389
          {
390
              { 0.0f, 0.0f, 0.0f }
391
          };
392
393
        centerIndexes = new int[] { 0,0,0,0 };
394
395
        numComponents = 4;
396 28f4aba0 Leszek Koltunski
        }
397 4d883a92 Leszek Koltunski
398
      ///// DINO ////////////////////////////////////////////////////////////////////////////////
399
400
      else if( mode==2 )
401 28f4aba0 Leszek Koltunski
        {
402 3f7a9aec Leszek Koltunski
        vertices = new float[][]
403 28f4aba0 Leszek Koltunski
          {
404 3f7a9aec Leszek Koltunski
             {-1.5f, 0.0f, 0.0f},
405
             { 1.5f, 0.0f, 0.0f},
406
             { 0.0f,-1.5f, 0.0f},
407
             { 0.0f, 0.0f,-1.5f}
408 28f4aba0 Leszek Koltunski
          };
409
410
        vertIndexes = new int[][]
411
          {
412 4b2cad6d Leszek Koltunski
             {2,1,0},   // counterclockwise!
413
             {3,0,1},
414
             {2,3,1},
415
             {3,2,0},
416 28f4aba0 Leszek Koltunski
          };
417
418
        bands = new float[][]
419
          {
420 4b2cad6d Leszek Koltunski
              {0.035f,30,0.16f,0.8f,6,2,2},
421
              {0.010f,45,0.16f,0.2f,6,2,2}
422 28f4aba0 Leszek Koltunski
          };
423
424 4b2cad6d Leszek Koltunski
        bandIndexes = new int[] { 0,0,1,1 };
425 28f4aba0 Leszek Koltunski
426
        corners = new float[][]
427
          {
428 4b2cad6d Leszek Koltunski
               {0.07f,0.40f},
429
               {0.05f,0.30f}
430 28f4aba0 Leszek Koltunski
          };
431
432 4b2cad6d Leszek Koltunski
        cornerIndexes = new int[] { 0,0,1,1 };
433 6983badf Leszek Koltunski
434
        centers = new float[][]
435
          {
436 4b2cad6d Leszek Koltunski
              { 0.0f,-0.75f,-0.75f }
437 6983badf Leszek Koltunski
          };
438
439
        centerIndexes = new int[] { 0,0,0,0 };
440
441
        numComponents = 4;
442 28f4aba0 Leszek Koltunski
        }
443 1b85f172 Leszek Koltunski
444 6a96e571 Leszek Koltunski
      ///// OCTAHEDRON ////////////////////////////////////////////////////////////////////////////
445
446
      else if( mode==3 )
447
        {
448 3f7a9aec Leszek Koltunski
        vertices = new float[][]
449 6a96e571 Leszek Koltunski
          {
450 3f7a9aec Leszek Koltunski
              { 0.5f,   0.0f, 0.5f},
451
              { 0.5f,   0.0f,-0.5f},
452
              {-0.5f,   0.0f,-0.5f},
453
              {-0.5f,   0.0f, 0.5f},
454
              { 0.0f,  SQ2/2, 0.0f},
455
              { 0.0f, -SQ2/2, 0.0f},
456 6a96e571 Leszek Koltunski
          };
457
458
        vertIndexes = new int[][]
459
          {
460
              {3,0,4},   // counterclockwise!
461
              {0,1,4},
462
              {1,2,4},
463
              {2,3,4},
464
              {5,0,3},
465
              {5,1,0},
466
              {5,2,1},
467
              {5,3,2}
468
          };
469
470
        bands = new float[][]
471
          {
472
             {0.05f,17,0.5f,0.2f,5,  2,2}
473
          };
474
475
        bandIndexes = new int[] { 0,0,0,0,0,0,0,0 };
476
477
        corners = new float[][]
478
          {
479
              { 0.03f, 0.12f }
480
          };
481
482
        cornerIndexes = new int[] { 0,0,0,0,0,0 };
483 6983badf Leszek Koltunski
484
        centers = new float[][]
485
          {
486
              { 0.0f, 0.0f, 0.0f }
487
          };
488
489
        centerIndexes = new int[] { 0,0,0,0,0,0 };
490
491
        numComponents = 8;
492 6a96e571 Leszek Koltunski
        }
493
494 3083fab8 Leszek Koltunski
      ///// KILOMINX EDGE ////////////////////////////////////////////////////////////////////////
495
496
      else if( mode==4 )
497
        {
498 3f7a9aec Leszek Koltunski
        float SQ5  = (float)Math.sqrt(5);
499
        float SIN18= (SQ5-1)/4;
500
        float COS18= 0.25f*(float)Math.sqrt(10.0+2.0*SQ5);
501
        float H = 1.0f;
502
        float L = 2.0f;
503
        float X = H*(float)Math.sqrt((5+SQ5)/10);
504
        float Y = H*(float)Math.sqrt((5-SQ5)/10);
505
        float D = H*SIN18/COS18;
506
507
        vertices = new float[][]
508
          {
509
              { 0.0f,    Y, L/2},
510
              {    X, 0.0f, L/2},
511
              { 0.0f,   -Y, L/2},
512
              {   -X, 0.0f, L/2},
513
              { 0.0f,    Y, -L/2 +D},
514
              {    X, 0.0f,-L/2   },
515
              { 0.0f,   -Y, -L/2-D },
516
              {   -X, 0.0f,-L/2   }
517 3083fab8 Leszek Koltunski
          };
518
519
        vertIndexes = new int[][]
520
          {
521
              {3,2,1,0},   // counterclockwise!
522
              {0,1,5,4},
523
              {3,0,4,7},
524
              {2,1,5,6},
525
              {3,2,6,7},
526
              {4,5,6,7}
527
          };
528
529
        bands = new float[][]
530
          {
531
             {0.04f,13,(float)(L/3),(float)L/8, 5,2,3},
532
             {0.00f, 0,(float)(L/2),(float)L/4, 5,2,3}
533
          };
534
535
        bandIndexes = new int[] { 1,0,0,1,1,1 };
536
537
        corners = new float[][]
538
          {
539 6983badf Leszek Koltunski
              { 0.04f, 0.12f }
540
          };
541
542
        cornerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
543
544
        centers = new float[][]
545
          {
546
              { 0.0f, 0.0f, 0.0f }
547
          };
548
549
        centerIndexes = new int[] { 0,-1,-1,-1,0,-1,-1,-1 };
550
551
        numComponents = 6;
552
        }
553
554
      ///// IVY_CORNER ////////////////////////////////////////////////////////////////////////
555
556
      else if( mode==5 )
557
        {
558 a40adec7 Leszek Koltunski
        int IVY_N = 8;
559 6983badf Leszek Koltunski
        final float IVY_D = 0.003f;
560 3f7a9aec Leszek Koltunski
        final float angle = (float)Math.PI/(2*IVY_N);
561
        final float CORR  = 1.0f - 2*IVY_D;
562 6983badf Leszek Koltunski
563 3f7a9aec Leszek Koltunski
        vertices = new float[3*IVY_N+7][3];
564 6983badf Leszek Koltunski
        vertIndexes = new int[6][IVY_N+4];
565
566 3f7a9aec Leszek Koltunski
        vertices[0][0] = 0.0f;
567
        vertices[0][1] = 0.0f;
568
        vertices[0][2] = 0.0f;
569
        vertices[1][0] =-1.0f;
570
        vertices[1][1] = 0.0f;
571
        vertices[1][2] = 0.0f;
572
        vertices[2][0] = 0.0f;
573
        vertices[2][1] =-1.0f;
574
        vertices[2][2] = 0.0f;
575
        vertices[3][0] = 0.0f;
576
        vertices[3][1] = 0.0f;
577
        vertices[3][2] =-1.0f;
578 6983badf Leszek Koltunski
579
        vertIndexes[0][0] = 2;
580
        vertIndexes[0][1] = 0;
581
        vertIndexes[0][2] = 1;
582
        vertIndexes[3][0] = 2;
583
        vertIndexes[3][1] = 0;
584
        vertIndexes[3][2] = 1;
585
586
        vertIndexes[1][0] = 3;
587
        vertIndexes[1][1] = 0;
588
        vertIndexes[1][2] = 2;
589
        vertIndexes[4][0] = 3;
590
        vertIndexes[4][1] = 0;
591
        vertIndexes[4][2] = 2;
592
593
        vertIndexes[2][0] = 1;
594
        vertIndexes[2][1] = 0;
595
        vertIndexes[2][2] = 3;
596
        vertIndexes[5][0] = 1;
597
        vertIndexes[5][1] = 0;
598
        vertIndexes[5][2] = 3;
599
600
        int N1 = 4;
601
        int N2 = N1 + IVY_N + 1;
602
        int N3 = N2 + IVY_N + 1;
603
604
        for(int i=0; i<=IVY_N; i++)
605
          {
606 3f7a9aec Leszek Koltunski
          float cos1 = (float)Math.cos((IVY_N-i)*angle);
607
          float sin1 = (float)Math.sin((IVY_N-i)*angle);
608
          float cos2 = (float)Math.cos((      i)*angle);
609
          float sin2 = (float)Math.sin((      i)*angle);
610 6983badf Leszek Koltunski
611 3f7a9aec Leszek Koltunski
          vertices[N1+i][0] = CORR*(cos1-0.5f) - 0.5f;
612
          vertices[N1+i][1] = CORR*(sin1-0.5f) - 0.5f;
613
          vertices[N1+i][2] = 0.0f;
614 6983badf Leszek Koltunski
615 3f7a9aec Leszek Koltunski
          vertices[N2+i][0] = 0.0f;
616
          vertices[N2+i][1] = CORR*(sin2-0.5f) - 0.5f;
617
          vertices[N2+i][2] = CORR*(cos2-0.5f) - 0.5f;
618 6983badf Leszek Koltunski
619 3f7a9aec Leszek Koltunski
          vertices[N3+i][0] = CORR*(cos2-0.5f) - 0.5f;
620
          vertices[N3+i][1] = 0.0f;
621
          vertices[N3+i][2] = CORR*(sin2-0.5f) - 0.5f;
622 6983badf Leszek Koltunski
623
          vertIndexes[0][i+3] = N1 + i;
624
          vertIndexes[1][i+3] = N2 + i;
625
          vertIndexes[2][i+3] = N3 + i;
626
          vertIndexes[3][i+3] = N1 + i;
627
          vertIndexes[4][i+3] = N2 + i;
628
          vertIndexes[5][i+3] = N3 + i;
629
          }
630
631
        bands = new float[][]
632
          {
633
             {+0.012f,20,0.2f,0.5f,7,1,2},
634
             {-0.100f,20,0.2f,0.0f,2,1,2}
635
          };
636
637
        bandIndexes = new int[] { 0,0,0,1,1,1 };
638
639
        corners = new float[][]
640
          {
641
              { 0.04f, 0.12f }
642
          };
643
644
        cornerIndexes = new int[3*IVY_N+7];
645
646
        centers = new float[][]
647
          {
648
              {-0.5f,-0.5f,-0.5f}
649 3083fab8 Leszek Koltunski
          };
650
651 6983badf Leszek Koltunski
        centerIndexes = new int[3*IVY_N+7];
652
653
        for(int i=0; i<4; i++)
654
          {
655
          cornerIndexes[i] = 0;
656
          centerIndexes[i] = 0;
657
          }
658
        for(int i=4; i<3*IVY_N+7; i++)
659
          {
660
          cornerIndexes[i] = -1;
661
          centerIndexes[i] = -1;
662
          }
663
664 a40adec7 Leszek Koltunski
        float C = 0.5f - SQ2/4;
665
        convexCenter = new float[] {-C,-C,-C};
666
667 6983badf Leszek Koltunski
        numComponents = 6;
668
        }
669
670
      ///// IVY_FACE ////////////////////////////////////////////////////////////////////////
671
672
      else if( mode==6 )
673
        {
674
        int IVY_N = 6;
675
        final float IVY_D = 0.003f;
676 3f7a9aec Leszek Koltunski
        final float angle = (float)Math.PI/(2*IVY_N);
677
        final float CORR  = 1.0f - 2*IVY_D;
678 6983badf Leszek Koltunski
679 3f7a9aec Leszek Koltunski
        vertices   = new float[2*IVY_N][3];
680 6983badf Leszek Koltunski
        vertIndexes= new int[2][2*IVY_N];
681
682
        for(int i=0; i<IVY_N; i++)
683
          {
684 3f7a9aec Leszek Koltunski
          float cos = (float)Math.cos(i*angle);
685
          float sin = (float)Math.sin(i*angle);
686 6983badf Leszek Koltunski
687 3f7a9aec Leszek Koltunski
          vertices[i      ][0] = CORR*(0.5f-cos);
688
          vertices[i      ][1] = CORR*(0.5f-sin);
689
          vertices[i      ][2] = 0.0f;
690
          vertices[i+IVY_N][0] = CORR*(cos-0.5f);
691
          vertices[i+IVY_N][1] = CORR*(sin-0.5f);
692
          vertices[i+IVY_N][2] = 0.0f;
693 6983badf Leszek Koltunski
694
          vertIndexes[0][i      ] = i;
695
          vertIndexes[0][i+IVY_N] = i+IVY_N;
696
          vertIndexes[1][i      ] = i;
697
          vertIndexes[1][i+IVY_N] = i+IVY_N;
698
          }
699
700
        bands = new float[][]
701
          {
702
             {+0.012f,20,0.2f,0.5f,7,1,2},
703
             {-0.100f,20,0.2f,0.0f,2,1,2},
704
          };
705
706
        bandIndexes = new int[] { 0,1 };
707
708
        corners = new float[][]
709
          {
710
             {0.03f,0.10f}
711
          };
712
713
        centers = new float[][]
714
          {
715
              {-0.0f,-0.0f,-0.5f}
716
          };
717
718
        cornerIndexes = new int[2*IVY_N];
719
        centerIndexes = new int[2*IVY_N];
720
721
        for(int i=0; i<2*IVY_N; i++)
722
          {
723
          cornerIndexes[i] = -1;
724
          centerIndexes[i] = -1;
725
          }
726
727
        cornerIndexes[0    ] = 0;
728
        cornerIndexes[IVY_N] = 0;
729
        centerIndexes[0    ] = 0;
730
        centerIndexes[IVY_N] = 0;
731
732
        numComponents = 2;
733 3083fab8 Leszek Koltunski
        }
734
735 db9903e8 Leszek Koltunski
      ///// SKEWB Ultimate SMALL  /////////////////////////////////////////////////////////////
736
737
      else if( mode==7 )
738
        {
739 3f7a9aec Leszek Koltunski
        float S = (SQ5+1)/4;
740 db9903e8 Leszek Koltunski
741 3f7a9aec Leszek Koltunski
        vertices = new float[][]
742 db9903e8 Leszek Koltunski
          {
743 3f7a9aec Leszek Koltunski
              { 0.0f        ,  0.0f       , 0.0f       },
744
              { -0.5f*S     , 0.5f*S+0.25f, -0.25f     },
745
              {-0.25f       , -S/2        , (-2*S-1)/4 },
746
              { 0.5f*S+0.25f, 0.25f       , -S/2       },
747
              { 0.0f        , 0.5f        , -S-0.5f    },
748
              { 0.0f        , 0.5f        , 0.0f       },
749
              { -0.5f*S     ,-0.5f*S+0.25f, -0.25f     },
750
              {  0.5f*S     ,-0.5f*S+0.25f, -0.25f     }
751 db9903e8 Leszek Koltunski
          };
752
753
        vertIndexes = new int[][]
754
          {
755
              {6,0,5,1},   // counterclockwise!
756
              {0,7,3,5},
757
              {0,6,2,7},
758
              {4,3,5,1},
759
              {4,2,7,3},
760
              {4,1,6,2},
761
          };
762
763
        bands = new float[][]
764
          {
765
             {0.04f,17,0.5f,0.2f,5,  2,2},
766
             {0.01f, 1,0.5f,0.2f,5,  2,2}
767
          };
768
769
        bandIndexes = new int[] { 0,0,0,1,1,1 };
770
771
        corners = new float[][]
772
          {
773
              { 0.013f, 0.08f }
774
          };
775
776
        cornerIndexes = new int[] { 0, 0, 0, 0,-1,0,0,0 };
777
778
        centers = new float[][]
779
          {
780
              { 0.0f,-0.5f, (float)(-S-0.5) }
781
          };
782
783
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
784
785
        numComponents = 8;
786
        }
787
788
      ///// SKEWB Ultimate BIG ///////////////////////////////////////////////////////////////
789
790
      else if( mode==8 )
791
        {
792 3f7a9aec Leszek Koltunski
        float S = (SQ5+1)/4;
793 db9903e8 Leszek Koltunski
794 3f7a9aec Leszek Koltunski
        vertices = new float[][]
795 db9903e8 Leszek Koltunski
          {
796 3f7a9aec Leszek Koltunski
              {-S/2      ,-S/2+0.25f,     0.25f},
797
              { S/2      , S/2-0.25f,    -0.25f},
798
              {-S        ,     0.00f,     0.00f},
799
              {     0.25f, S/2      ,-S/2-0.25f},
800
              {-S/2      ,-S/2-0.25f,     0.25f},
801
              { S/2+0.25f,    -0.25f,-S/2      },
802
              {-S        ,    -0.50f,     0.00f},
803
              {     0.50f,     0.00f,-S        },
804
              {-S  +0.25f, S/2      ,-S/2-0.25f},
805
              {     0.25f,-S/2-0.50f,-S/2+0.25f},
806
              {-S/2      ,-S/2-0.25f,-S  -0.25f}
807 db9903e8 Leszek Koltunski
          };
808
809
        vertIndexes = new int[][]
810
          {
811
              {0,1,3,8,2},   // counterclockwise!
812
              {0,4,9,5,1},
813
              { 0,2,6,4},
814
              { 1,5,7,3},
815
              {10,9,4,6},
816
              {10,9,5,7},
817
              {10,8,3,7},
818
              {10,8,2,6}
819
          };
820
821
        bands = new float[][]
822
          {
823
             {0.04f,17,0.5f,0.2f,5,  2,2},
824
             {0.04f,17,0.5f,0.2f,5,  2,2},
825
             {0.01f, 1,0.5f,0.2f,5,  2,2}
826
          };
827
828
        bandIndexes = new int[] { 0,0,1,1,2,2,2,2 };
829
830
        corners = new float[][]
831
          {
832
              { 0.013f, 0.08f }
833
          };
834
835
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,-1 };
836
837
        centers = new float[][]
838
          {
839
              { (float)(-S/2), 0.25f, (float)(-S/2-0.5) }
840
          };
841
842
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0 };
843
844
        numComponents = 8;
845
        }
846
847 96a6db6c Leszek Koltunski
      ///// SQUARE-1 MIDDLE ///////////////////////////////////////////////////////////////
848
849
      else if( mode==9 )
850
        {
851
        final float X = 3*(2-SQ3)/2;
852
853 3f7a9aec Leszek Koltunski
        vertices = new float[][]
854 96a6db6c Leszek Koltunski
          {
855 3f7a9aec Leszek Koltunski
              { -1.5f-X, 0.5f, 1.5f },
856
              {    0.0f, 0.5f, 1.5f },
857
              {    0.0f, 0.5f,-1.5f },
858
              { -1.5f+X, 0.5f,-1.5f },
859
              { -1.5f-X,-0.5f, 1.5f },
860
              {    0.0f,-0.5f, 1.5f },
861
              {    0.0f,-0.5f,-1.5f },
862
              { -1.5f+X,-0.5f,-1.5f }
863 96a6db6c Leszek Koltunski
          };
864
865
        vertIndexes = new int[][]
866
          {
867
              {0,1,2,3},   // counterclockwise!
868
              {4,5,6,7},
869
              {4,5,1,0},
870
              {5,6,2,1},
871
              {6,7,3,2},
872
              {7,4,0,3}
873
          };
874
875
        bands = new float[][]
876
          {
877
             {0.040f,35,0.8f,1.0f,5,2,1},
878
             {0.020f,35,0.8f,1.0f,5,2,1},
879
             {0.001f,35,0.8f,1.0f,5,2,1}
880
          };
881
882
        bandIndexes = new int[] { 2,2,1,1,0,2 };
883
884
        corners = new float[][]
885
          {
886
              {0.04f,0.05f}
887
          };
888
889
        cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
890
891
        centers = new float[][]
892
          {
893
              { -0.75f, 0.0f, 0.0f}
894
          };
895
896
        centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
897
898
        numComponents = 6;
899
        }
900
901
      ///// SQUARE-1 EDGE ///////////////////////////////////////////////////////////////
902
903
      else if( mode==10 )
904
        {
905
        final float X = 3*(2-SQ3)/2;
906
907 3f7a9aec Leszek Koltunski
        vertices = new float[][]
908 96a6db6c Leszek Koltunski
          {
909 3f7a9aec Leszek Koltunski
              {  -X, 0.5f, 0.0f },
910
              {  +X, 0.5f, 0.0f },
911
              {0.0f, 0.5f,-1.5f },
912
              {  -X,-0.5f, 0.0f },
913
              {  +X,-0.5f, 0.0f },
914
              {0.0f,-0.5f,-1.5f },
915 96a6db6c Leszek Koltunski
          };
916
917
        vertIndexes = new int[][]
918
          {
919
              {0,1,2},   // counterclockwise!
920
              {3,4,5},
921
              {3,4,1,0},
922
              {4,5,2,1},
923
              {5,3,0,2}
924
          };
925
926
        bands = new float[][]
927
          {
928
            {0.038f,35,0.5f,0.9f, 5,2,1},
929
            {0.001f,35,0.5f,0.9f, 5,2,1}
930
          };
931
932
        bandIndexes = new int[]  { 0,1,0,1,1 };
933
934
        corners = new float[][]
935
          {
936
             {0.06f,0.20f}
937
          };
938
939
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
940
941
        centers = new float[][]
942
          {
943
              { 0.0f, 0.0f,-0.5f}
944
          };
945
946
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
947
948
        numComponents = 6;
949
        }
950
951
      ///// SQUARE-1 CORNER ///////////////////////////////////////////////////////////////
952
953
      else if( mode==11 )
954
        {
955
        final float X = 3*(2-SQ3)/2;
956
957 3f7a9aec Leszek Koltunski
        vertices = new float[][]
958 96a6db6c Leszek Koltunski
          {
959 3f7a9aec Leszek Koltunski
              { X-1.5f, 0.5f,  0.0f },
960
              {   0.0f, 0.5f,  0.0f },
961
              {   0.0f, 0.5f,X-1.5f },
962
              {  -1.5f, 0.5f, -1.5f },
963
              { X-1.5f,-0.5f,  0.0f },
964
              {   0.0f,-0.5f,  0.0f },
965
              {   0.0f,-0.5f,X-1.5f },
966
              {  -1.5f,-0.5f, -1.5f }
967 96a6db6c Leszek Koltunski
          };
968
969
        vertIndexes = new int[][]
970
          {
971
              {0,1,2,3},   // counterclockwise!
972
              {4,5,6,7},
973
              {4,5,1,0},
974
              {5,6,2,1},
975
              {7,4,0,3},
976
              {6,7,3,2}
977
          };
978
979
        bands = new float[][]
980
          {
981
            {0.038f,35,0.9f,1.0f, 5,2,1},
982
            {0.001f,35,0.9f,1.0f, 5,2,1}
983
          };
984
985
        bandIndexes = new int[]  { 0,1,0,0,1,1 };
986
987
        corners = new float[][]
988
          {
989
            {0.08f,0.20f}
990
          };
991
992
        cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
993
994
        centers = new float[][]
995
          {
996
             { -0.5f, 0.0f,-0.5f}
997
          };
998
999
        centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
1000
1001
        numComponents = 6;
1002
        }
1003
1004 31d42722 Leszek Koltunski
      ///// SQUARE-2 CORNER ///////////////////////////////////////////////////////////////
1005
1006
      else if( mode==12 )
1007
        {
1008
        final float X = 3*(2-SQ3)/2;
1009
        final float Z = 0.75f - X/2;
1010
1011 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1012 31d42722 Leszek Koltunski
          {
1013 3f7a9aec Leszek Koltunski
              { X-1.5f+Z, 0.5f,  0.0f },
1014
              {        Z, 0.5f,  0.0f },
1015
              {  -1.5f+Z, 0.5f, -1.5f },
1016
              { X-1.5f+Z,-0.5f,  0.0f },
1017
              {        Z,-0.5f,  0.0f },
1018
              {  -1.5f+Z,-0.5f, -1.5f }
1019 31d42722 Leszek Koltunski
          };
1020
1021
        vertIndexes = new int[][]
1022
          {
1023
              {0,1,2},   // counterclockwise!
1024
              {5,4,3},
1025
              {3,4,1,0},
1026
              {4,5,2,1},
1027
              {5,3,0,2}
1028
          };
1029
1030
        bands = new float[][]
1031
          {
1032
            {0.040f,35,0.9f,1.0f, 5,2,1},
1033
            {0.001f,35,0.9f,1.0f, 5,2,1}
1034
          };
1035
1036
        bandIndexes = new int[] { 0,0,0,1,1 };
1037
1038
        corners = new float[][]
1039
          {
1040
            {0.05f,0.13f}
1041
          };
1042
1043
        cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
1044
1045
        centers = new float[][]
1046
          {
1047
             { 0.0f, 0.0f,-0.5f}
1048
          };
1049
1050
        centerIndexes = new int[] { 0,0,-1,0,0,-1 };
1051
1052
        numComponents = 5;
1053
        }
1054
1055 4b2cad6d Leszek Koltunski
      ///// REDI CORNER ///////////////////////////////////////////////////////////////
1056
1057
      else if( mode==13 )
1058
        {
1059 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1060 4b2cad6d Leszek Koltunski
          {
1061
             { 0.0f, 0.0f, 0.0f },
1062
             {-0.5f, 0.5f, 0.5f },
1063
             {-0.5f,-0.5f, 0.5f },
1064
             { 0.5f, 0.5f, 0.5f },
1065
             { 0.5f,-0.5f, 0.5f },
1066
             { 0.5f, 0.5f,-0.5f },
1067
             { 0.5f,-0.5f,-0.5f },
1068
             {-0.5f, 0.5f,-0.5f },
1069
          };
1070
1071
        vertIndexes = new int[][]
1072
          {
1073
             { 2,4,3,1 },
1074
             { 1,3,5,7 },
1075
             { 4,6,5,3 },
1076
1077
             { 2,4,0 },
1078
             { 5,7,0 },
1079
             { 4,6,0 },
1080
             { 7,1,0 },
1081
             { 1,2,0 },
1082
             { 6,5,0 }
1083
          };
1084
1085
        bands = new float[][]
1086
          {
1087
             {0.06f,35,0.5f,0.7f,5,2,2},
1088
             {0.01f,35,0.2f,0.4f,5,2,2}
1089
          };
1090
1091
        bandIndexes = new int[] { 0,0,0,1,1,1,1,1,1 };
1092
1093
        corners = new float[][]
1094
          {
1095
            {0.06f,0.12f}
1096
          };
1097
1098
        cornerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1099
1100
        centers = new float[][]
1101
          {
1102
             { 0.0f, 0.0f, 0.0f}
1103
          };
1104
1105
        centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1 };
1106
1107
        numComponents = 9;
1108
        }
1109
1110 9db7b0e5 Leszek Koltunski
      ///// JING CORNER ///////////////////////////////////////////////////////////////
1111
1112
      else if( mode==14 )
1113
        {
1114 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1115 99571baa Leszek Koltunski
        final float X = F/2;
1116
        final float Y = F*SQ2/2;
1117
        final float Z =-F/2;
1118 9db7b0e5 Leszek Koltunski
1119 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1120 9db7b0e5 Leszek Koltunski
          {
1121 3f7a9aec Leszek Koltunski
             { 0.0f, 0.0f,  0.0f },
1122
             {    X,    Y,     Z },
1123
             { 0.0f,  2*Y,   2*Z },
1124
             {   -X,    Y,     Z },
1125
             { 0.0f, 0.0f,    -F },
1126
             {    X,    Y,   Z-F },
1127
             { 0.0f,  2*Y, 2*Z-F },
1128
             {   -X,    Y,   Z-F },
1129 9db7b0e5 Leszek Koltunski
          };
1130
1131
        vertIndexes = new int[][]
1132
          {
1133 99571baa Leszek Koltunski
             {0,1,2,3},
1134 9db7b0e5 Leszek Koltunski
             {1,0,4,5},
1135 99571baa Leszek Koltunski
             {7,4,0,3},
1136
             {1,5,6,2},
1137
             {7,3,2,6},
1138
             {4,7,6,5}
1139 9db7b0e5 Leszek Koltunski
          };
1140
1141
        bands = new float[][]
1142
          {
1143
             {0.015f,35,0.5f*F,F,5,1,1},
1144
             {0.001f,35,0.5f*F,F,5,1,1}
1145
          };
1146
1147
        bandIndexes = new int[] { 0,0,0,1,1,1 };
1148
1149
        corners = new float[][]
1150
          {
1151 cf7ec8fa Leszek Koltunski
            {0.08f,0.20f*F},
1152 9db7b0e5 Leszek Koltunski
            {0.07f,0.20f*F}
1153
          };
1154
1155
        cornerIndexes = new int[] { 0,1,1,-1,1,-1,-1,-1 };
1156
1157
        centers = new float[][]
1158
          {
1159 99571baa Leszek Koltunski
             { 0.0f, Y, Z-F/2}
1160 9db7b0e5 Leszek Koltunski
          };
1161
1162
        centerIndexes = new int[] { 0,0,0,-1,0,-1,-1,-1 };
1163
1164
        numComponents = 6;
1165
        }
1166
1167
      ///// JING EDGE ///////////////////////////////////////////////////////////////
1168
1169
      else if( mode==15 )
1170
        {
1171 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1172 99571baa Leszek Koltunski
        final float X = F/2;
1173
        final float Y = F*SQ2/2;
1174
        final float Z =-F/2;
1175 9db7b0e5 Leszek Koltunski
1176 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1177 9db7b0e5 Leszek Koltunski
          {
1178 3f7a9aec Leszek Koltunski
             { 0.0f, 0.0f,     0.5f-F },
1179
             {    X,    Y,   Z+0.5f-F },
1180
             { 0.0f,  2*Y, 2*Z+0.5f-F },
1181
             {   -X,    Y,   Z+0.5f-F },
1182
             { 0.0f, 0.0f,    -0.5f+F },
1183
             {    X,    Y,  -Z-0.5f+F },
1184
             { 0.0f,  2*Y,-2*Z-0.5f+F },
1185
             {   -X,    Y,  -Z-0.5f+F },
1186 9db7b0e5 Leszek Koltunski
          };
1187
1188
        vertIndexes = new int[][]
1189
          {
1190 99571baa Leszek Koltunski
             {0,4,5,1},
1191
             {3,7,4,0},
1192
             {0,1,2,3},
1193
             {4,7,6,5},
1194
             {1,5,6,2},
1195
             {2,6,7,3}
1196 9db7b0e5 Leszek Koltunski
          };
1197
1198
        bands = new float[][]
1199
          {
1200
             {0.015f,35,0.5f*F,F,5,1,1},
1201
             {0.001f,35,0.5f*F,F,5,1,1}
1202
          };
1203
1204
        bandIndexes = new int[] { 0,0,1,1,1,1 };
1205
1206
        corners = new float[][]
1207
          {
1208
            {0.07f,0.20f*F}
1209
          };
1210
1211 99571baa Leszek Koltunski
        cornerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1212 9db7b0e5 Leszek Koltunski
1213
        centers = new float[][]
1214
          {
1215 99571baa Leszek Koltunski
             { 0, F*SQ2/2, 0 }
1216 9db7b0e5 Leszek Koltunski
          };
1217
1218 99571baa Leszek Koltunski
        centerIndexes = new int[] { 0,0,-1,0,0,0,-1,0 };
1219 9db7b0e5 Leszek Koltunski
1220
        numComponents = 6;
1221
        }
1222
1223
      ///// JING FACE ///////////////////////////////////////////////////////////////
1224
1225
      else if( mode==16 )
1226
        {
1227 cf7ec8fa Leszek Koltunski
        final float F = 0.24f;
1228 99571baa Leszek Koltunski
        final float L = (1-3*F);
1229
        final float X = L/2;
1230
        final float Y = L*SQ2/2;
1231
        final float Z =-L/2;
1232
        final float D = F/L;
1233 9db7b0e5 Leszek Koltunski
1234 3f7a9aec Leszek Koltunski
        vertices = new float[][]
1235 9db7b0e5 Leszek Koltunski
          {
1236 3f7a9aec Leszek Koltunski
              {    0.0f,     -2*Y/3,   -2*Z/3 },
1237
              {       X,        Y/3,      Z/3 },
1238
              {      -X,        Y/3,      Z/3 },
1239
              {    0.0f,     -2*Y/3,   -2*Z/3+2*D*Z },
1240
              {   X-D*X,    Y/3-D*Y,  Z/3+D*Z },
1241
              {  -X+D*X,    Y/3-D*Y,  Z/3+D*Z },
1242 9db7b0e5 Leszek Koltunski
          };
1243
1244
        vertIndexes = new int[][]
1245
          {
1246 99571baa Leszek Koltunski
             {0,1,2},
1247
             {3,5,4},
1248
             {0,3,4,1},
1249
             {5,3,0,2},
1250
             {4,5,2,1}
1251 9db7b0e5 Leszek Koltunski
          };
1252
1253
        bands = new float[][]
1254
          {
1255 99571baa Leszek Koltunski
             {0.025f,35,0.20f*(1-3*F),0.6f*(1-3*F),5,1,1},
1256
             {0.001f,35,0.05f*(1-3*F),0.1f*(1-3*F),5,1,1}
1257 9db7b0e5 Leszek Koltunski
          };
1258
1259
        bandIndexes = new int[] { 0,1,1,1,1,1 };
1260
1261
        corners = new float[][]
1262
          {
1263 99571baa Leszek Koltunski
            {0.04f,0.15f}
1264 9db7b0e5 Leszek Koltunski
          };
1265
1266
        cornerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1267
1268
        centers = new float[][]
1269
          {
1270 99571baa Leszek Koltunski
            { 0, -2*Y/3, 4*Z/3 }
1271 9db7b0e5 Leszek Koltunski
          };
1272
1273
        centerIndexes = new int[] { 0,0,0,-1,-1,-1 };
1274
1275
        numComponents = 6;
1276
        }
1277
1278 e018a923 Leszek Koltunski
      ///// REX PETAL ///////////////////////////////////////////////////////////////
1279
1280
      else if( mode==17 )
1281
        {
1282
        final float REX_D = 0.2f;
1283
        float G = (1-REX_D)*SQ2/2;
1284
        vertices = new float[][] {{-0.10f,0.70f,0},{-0.70f,0.10f,0},{+0.65f,-0.71f,0},{+0.71f,-0.65f,0},{0,0.05f,-0.2f} };
1285
        vertIndexes = new int[][] { {0,1,2,3},{0,3,4},{3,2,4},{2,1,4},{1,0,4} };
1286
        centers= new float[][] { {0.0f,0.0f,-G} };
1287
        corners= new float[][] { {0.03f,0.30f} };
1288
        cornerIndexes = new int[] {-1,-1,0,0,-1};
1289
        centerIndexes = new int[] {-1,-1,0,0,-1};
1290
        bandIndexes   = new int[] { 0,1,1,1,1 };
1291
        bands = new float[][] { {+0.016f,10,G/3,0.5f,5,1,1},{ +0.0f,45,0.1f,0.1f,2,0,0} };
1292
1293
        numComponents = 5;
1294
        }
1295
1296 c6f4bd1e Leszek Koltunski
      ///// TRAJBER'S FACE ///////////////////////////////////////////////////////////////
1297
1298
      else if( mode==18 )
1299
        {
1300
        final float CUT = 1.0f/6;
1301
        final float LEN = 3*SQ2/2;
1302
1303
        final float A = CUT*LEN;
1304
        final float B = A-LEN;
1305
1306
        vertices = new float[][]
1307
          {
1308
             {    0,    0,    0},
1309
             {    0,    A,   -A},
1310
             {    0,   -A,   -A},
1311
             {    A,    0,   -A},
1312
             {   -A,    0,   -A},
1313
             {    A,    A, -2*A},
1314
             {    A,   -A, -2*A},
1315
             {   -A,    A, -2*A},
1316
             {   -A,   -A, -2*A},
1317
             {    A,    A,    B},
1318
             {    A,   -A,    B},
1319
             {   -A,    A,    B},
1320
             {   -A,   -A,    B}
1321
          };
1322
1323
        vertIndexes = new int[][]
1324
          {
1325
             {0,3,5,1},
1326
             {0,2,6,3},
1327
             {0,4,8,2},
1328
             {0,1,7,4},
1329
             {3,6,10,9,5},
1330
             {2,8,12,10,6},
1331
             {4,7,11,12,8},
1332
             {1,5,9,11,7},
1333
             {9,10,12,11}
1334
          };
1335
1336
         bands         = new float[][] { {0.05f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,3,0,0} };
1337
         bandIndexes   = new int[] { 0,0,0,0,1,1,1,1,1 };
1338
         corners       = new float[][] { {0.03f,0.10f} };
1339
         cornerIndexes = new int[] { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
1340
         centers       = new float[][] { {0.0f, 0.0f, -LEN/2} };
1341
         centerIndexes = new int[] { 0,-1,-1,-1,-1,0,0,0,0,-1,-1,-1,-1 };
1342
1343
         numComponents = 9;
1344
         }
1345
1346
      ///// TRAJBER'S EDGE ///////////////////////////////////////////////////////////////
1347
1348
      else if( mode==19 )
1349
        {
1350
        final float CUT = 1.0f/6;
1351
        final float LEN = 3*SQ2/2;
1352
1353
        final float A = CUT*LEN;
1354
        final float B = A-LEN;
1355
1356
        vertices = new float[][]
1357
          {
1358
             {    A-LEN/2,    0,   -A+LEN/2},
1359
             {    A-LEN/2,    A, -2*A+LEN/2},
1360
             {    A-LEN/2,   -A, -2*A+LEN/2},
1361
             {   -B-LEN/2,    0,    B+LEN/2},
1362
             { -B-A-LEN/2,    A,    B+LEN/2},
1363
             { -B-A-LEN/2,   -A,    B+LEN/2},
1364
             {    A-LEN/2,    A,    B+LEN/2},
1365
             {    A-LEN/2,   -A,    B+LEN/2},
1366
          };
1367
1368
        vertIndexes = new int[][]
1369
          {
1370
             {0,3,4,1},
1371
             {0,2,5,3},
1372
             {1,4,6},
1373
             {2,7,5},
1374
             {0,1,6,7,2},
1375
             {3,5,7,6,4}
1376
          };
1377
1378
        bands        = new float[][] { {0.03f,35,0.15f,0.3f,3,1,1},{0.00f,35,0.15f,0.3f,3,0,0} };
1379
        bandIndexes  = new int[] { 0,0,1,1,1,1 };
1380
        corners      = new float[][] { {0.02f,0.10f} };
1381
        cornerIndexes= new int[] { 0,0,0,0,0,0,-1,-1 };
1382
        centers      = new float[][] { {-LEN/4, 0, -LEN/4} };
1383
        centerIndexes= new int[] { 0,0,0,0,0,0,-1,-1 };
1384
1385
        numComponents = 9;
1386
        }
1387
1388
      ///// TRAJBER'S CORNER ///////////////////////////////////////////////////////////////
1389
1390
      else if( mode==20 )
1391
        {
1392
        final float CUT = 1.0f/6;
1393
        final float LEN = 3*SQ2/2;
1394
1395
        final float A = CUT*LEN;
1396
        final float B = A-LEN;
1397
1398
        vertices = new float[][]
1399
          {
1400
             {   A-LEN/3,   A-LEN/3, -2*A+2*LEN/3},
1401
             {-B-A-LEN/3,   A-LEN/3,    B+2*LEN/3},
1402
             {   A-LEN/3,-B-A-LEN/3,    B+2*LEN/3},
1403
             {   A-LEN/3,   A-LEN/3,    B+2*LEN/3},
1404
          };
1405
1406
        vertIndexes = new int[][]
1407
          {
1408
             {0,1,2},
1409
             {0,1,3},
1410
             {0,2,3},
1411
             {1,3,2},
1412
          };
1413
1414
        bands        = new float[][] { {0.05f,35,0.15f,0.3f,4,1,1},{0.00f,35,0.15f,0.3f,4,0,0} };
1415
        bandIndexes  = new int[] { 0,1,1,1 };
1416
        corners      = new float[][] { {0.02f,0.10f} };
1417
        cornerIndexes= new int[] { 0,0,0,-1 };
1418
        centers      = new float[][] { {(A-LEN/3)/2 , (A-LEN/3)/2 , (B-LEN/3)/2} };
1419
        centerIndexes= new int[] { 0,0,0,-1 };
1420
1421
        numComponents = 9;
1422
        }
1423
1424 db9903e8 Leszek Koltunski
      ///// END DEFINITIONS /////////////////////////////////////////////////////////////////
1425
1426 33647db9 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
1427 6991ece5 Leszek Koltunski
1428 6983badf Leszek Koltunski
      factory.clear();
1429
      factory.createNewFaceTransform(vertices,vertIndexes);
1430
      mMesh = factory.createRoundedSolid(vertices, vertIndexes,
1431
                                         bands, bandIndexes,
1432
                                         corners, cornerIndexes,
1433
                                         centers, centerIndexes,
1434 baace8e9 Leszek Koltunski
                                         numComponents, convexCenter, MESH_NICE );
1435 6983badf Leszek Koltunski
1436
      int numEff = mMesh.getNumEffComponents();
1437 6991ece5 Leszek Koltunski
1438
      for(int i=0; i<numEff; i++)
1439
        {
1440
        mMesh.setEffectAssociation(i, 0, i);
1441
        }
1442
      }
1443 42aa970f Leszek Koltunski
1444
///////////////////////////////////////////////////////////////////////////////////////////////////
1445
1446 6991ece5 Leszek Koltunski
    private void openMesh(int resourceID)
1447 42aa970f Leszek Koltunski
      {
1448 1af8e143 Leszek Koltunski
      Context con = mView.getContext();
1449
      Resources res = con.getResources();
1450
      InputStream is = res.openRawResource(resourceID);
1451
      DataInputStream dos = new DataInputStream(is);
1452 7198e5c9 Leszek Koltunski
      mMesh = new MeshFile(dos);
1453 1af8e143 Leszek Koltunski
1454 6983badf Leszek Koltunski
      int numEff = mMesh.getNumEffComponents();
1455 39b925d5 Leszek Koltunski
1456
      for(int i=0; i<numEff; i++)
1457
        {
1458
        mMesh.setEffectAssociation(i, 0, i);
1459
        }
1460
1461 1af8e143 Leszek Koltunski
      try
1462
        {
1463
        is.close();
1464
        }
1465
      catch(IOException e)
1466
        {
1467 48c88f57 Leszek Koltunski
        android.util.Log.e("MeshFile", "Error closing InputStream: "+e.toString());
1468 1af8e143 Leszek Koltunski
        }
1469 42aa970f Leszek Koltunski
      }
1470 48c88f57 Leszek Koltunski
1471 39b925d5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1472
1473 6991ece5 Leszek Koltunski
    MeshBase getMesh()
1474 39b925d5 Leszek Koltunski
      {
1475
      return mMesh;
1476
      }
1477
1478 48c88f57 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1479
1480
    long getTime()
1481
      {
1482
      return mTime;
1483
      }
1484
1485
///////////////////////////////////////////////////////////////////////////////////////////////////
1486
1487
    int getBytes()
1488
      {
1489 6991ece5 Leszek Koltunski
      if( mMesh instanceof MeshFile )
1490
        {
1491
        return ((MeshFile)mMesh).getNumBytes();
1492
        }
1493
1494
      return 0;
1495 48c88f57 Leszek Koltunski
      }
1496
1497
///////////////////////////////////////////////////////////////////////////////////////////////////
1498
1499
    int getVertices()
1500
      {
1501 7198e5c9 Leszek Koltunski
      return mMesh.getNumVertices();
1502
      }
1503
1504
///////////////////////////////////////////////////////////////////////////////////////////////////
1505
1506
    int getEndEffIndex(int component)
1507
      {
1508
      return mMesh.getLastVertexEff(component);
1509
      }
1510
1511
///////////////////////////////////////////////////////////////////////////////////////////////////
1512
1513
    int getEndTexIndex(int component)
1514
      {
1515
      return mMesh.getLastVertexTex(component);
1516
      }
1517
1518
///////////////////////////////////////////////////////////////////////////////////////////////////
1519
1520
    int getEffComponentNum()
1521
      {
1522 6983badf Leszek Koltunski
      return mMesh.getNumEffComponents();
1523 7198e5c9 Leszek Koltunski
      }
1524
1525
///////////////////////////////////////////////////////////////////////////////////////////////////
1526
1527
    int getTexComponentNum()
1528
      {
1529 6983badf Leszek Koltunski
      return mMesh.getNumTexComponents();
1530 48c88f57 Leszek Koltunski
      }
1531 42aa970f Leszek Koltunski
}