Project

General

Profile

« Previous | Next » 

Revision 680469e6

Added by Leszek Koltunski over 3 years ago

Convert the Redi Cube to the new engine.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
43 43
  private static final float SQ2 = (float)Math.sqrt(2);
44 44
  private static final float SQ3 = (float)Math.sqrt(3);
45 45
  private static final float SQ5 = (float)Math.sqrt(5);
46
  private static final float SQ6 = (float)Math.sqrt(6);
47 46

  
48 47
  private static final Static1D RADIUS = new Static1D(1);
49 48
  private static FactoryCubit mThis;
......
238 237
      }
239 238
    }
240 239

  
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

  
243
  MeshBase createFacesHelicopterFace()
244
    {
245
    MeshBase[] meshes = new MeshBase[4];
246

  
247
    float E = 0.5f;
248
    float F = SQ2/4;
249
    float G = 1.0f/12;
250
    float[] vertices0 = { -E+E/4,E/4, E/4,-E+E/4, E/4,E/4};
251
    float[] bands0 = computeBands(0.028f,35,E/4,0.7f,7);
252

  
253
    meshes[0] = new MeshPolygon(vertices0, bands0, 3, 3);
254
    meshes[0].setEffectAssociation(0,1,0);
255

  
256
    float[] vertices1 = { -F,-G, +F,-G, 0,2*G};
257
    float[] bands1 = computeBands(0.01f,45,F,0.0f,3);
258

  
259
    meshes[1] = new MeshPolygon(vertices1, bands1, 1, 3);
260
    meshes[1].setEffectAssociation(0,2,0);
261

  
262
    float[] vertices2 = { -E/2,-F/3, +E/2,-F/3, 0,2*F/3};
263

  
264
    meshes[2] = new MeshPolygon(vertices2, bands1, 1, 3);
265
    meshes[2].setEffectAssociation(0,4,0);
266
    meshes[3] = meshes[2].copy(true);
267
    meshes[3].setEffectAssociation(0,8,0);
268

  
269
    return new MeshJoined(meshes);
270
    }
271

  
272
///////////////////////////////////////////////////////////////////////////////////////////////////
273

  
274
  MeshBase createFacesRediEdge()
275
    {
276
    MeshBase[] meshes = new MeshPolygon[6];
277

  
278
    float F = 0.25f;
279
    float[] vertices0 = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
280
    float[] bands0 = computeBands(0.038f,35,F,0.7f,7);
281

  
282
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 2);
283
    meshes[0].setEffectAssociation(0,1,0);
284
    meshes[1] = meshes[0].copy(true);
285
    meshes[1].setEffectAssociation(0,2,0);
286

  
287
    float[] bands1 = computeBands(0.02f,35,F/2,0.2f,3);
288
    float[] vertices1 = { -F/2, +F/2, -F/2, -1.5f*F, 1.5f*F, +F/2 };
289

  
290
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
291
    meshes[2].setEffectAssociation(0,4,0);
292
    meshes[3] = meshes[2].copy(true);
293
    meshes[3].setEffectAssociation(0,8,0);
294

  
295
    float X = 0.25f*SQ2;
296
    float Y = SQ6/16;
297
    float[] vertices2 = { -X, Y, -1.5f*X, -Y, +1.5f*X, -Y, +X, Y };
298

  
299
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 1);
300
    meshes[4].setEffectAssociation(0,16,0);
301
    meshes[5] = meshes[4].copy(true);
302
    meshes[5].setEffectAssociation(0,32,0);
303

  
304
    return new MeshJoined(meshes);
305
    }
306

  
307
///////////////////////////////////////////////////////////////////////////////////////////////////
308

  
309
  MeshBase createFacesRediCorner()
310
    {
311
    MeshBase[] meshes = new MeshBase[6];
312

  
313
    float E = 0.5f;
314
    float[] vertices0 = { -E,-E, +E,-E, +E,+E, -E,+E };
315
    float[] bands0 = computeBands(0.06f,35,E,0.7f,6);
316

  
317
    meshes[0] = new MeshPolygon(vertices0,bands0,2,2);
318
    meshes[0].setEffectAssociation(0,1,0);
319
    meshes[1] = meshes[0].copy(true);
320
    meshes[1].setEffectAssociation(0,2,0);
321
    meshes[2] = meshes[0].copy(true);
322
    meshes[2].setEffectAssociation(0,4,0);
323

  
324
    float F = 0.5f;
325
    float X = 0.5f;
326
    float G = 0.72f;
327
    float[] vertices1 = { -E,+F, -E+X,0, -E,-F, -E*G,-F, +E*G,-F, +E,-F, +E-X,0, +E,+F, +E*G,+F, -E*G,+F };
328
    float[] bands1 = computeBands(0.0f,0,1.0f,0.0f,2);
329

  
330
    meshes[3] = new MeshPolygon(vertices1,bands1,0,0);
331
    meshes[3].setEffectAssociation(0,8,0);
332
    meshes[4] = meshes[3].copy(true);
333
    meshes[4].setEffectAssociation(0,16,0);
334
    meshes[5] = meshes[3].copy(true);
335
    meshes[5].setEffectAssociation(0,32,0);
336

  
337
    return new MeshJoined(meshes);
338
    }
339

  
340 240
///////////////////////////////////////////////////////////////////////////////////////////////////
341 241

  
342 242
  MeshBase createFacesIvyCorner()
......
722 622

  
723 623
///////////////////////////////////////////////////////////////////////////////////////////////////
724 624
// EFFECTS
725
///////////////////////////////////////////////////////////////////////////////////////////////////
726

  
727
  VertexEffect[] createVertexEffectsRediEdge()
728
    {
729
    Static3D move0 = new Static3D(0.0f, -0.5f, 0.0f);
730
    Static3D move1 = new Static3D(0.25f, -0.25f, 0.0f);
731
    Static3D move2 = new Static3D(0.5f, 0.0f, 0.0f);
732
    Static3D move3 = new Static3D(0.0f, (SQ3-6)/8, (SQ3-6)/8);
733
    Static3D flipZ = new Static3D(1,1,-1);
734
    Static3D flipX = new Static3D(-1,1,1);
735
    Static3D scale = new Static3D(2,2,2);
736
    Static3D cent0 = new Static3D(0,0, 0);
737
    Static3D cent1 = new Static3D(0,0, -1.5f);
738
    Static3D axisX = new Static3D(1,0, 0);
739
    Static3D axisY = new Static3D(0,1, 0);
740
    Static3D axis  = new Static3D(0,SQ2/2,-SQ2/2);
741
    Static1D angle1= new Static1D(90);
742
    Static1D angle2= new Static1D(45);
743
    Static1D angle3= new Static1D( (float)(180/Math.PI*Math.acos(SQ3/3)) );
744

  
745
    VertexEffect[] effect = new VertexEffect[12];
746

  
747
    effect[0] = new VertexEffectScale(scale);
748
    effect[1] = new VertexEffectMove(move0);
749
    effect[2] = new VertexEffectScale(flipZ);
750
    effect[3] = new VertexEffectRotate(angle1,axisX,cent0);
751
    effect[4] = new VertexEffectMove(move1);
752
    effect[5] = new VertexEffectRotate(angle1,axisY,cent0);
753
    effect[6] = new VertexEffectMove(move2);
754
    effect[7] = new VertexEffectScale(flipX);
755
    effect[8] = new VertexEffectRotate(angle2,axisX,cent0);
756
    effect[9] = new VertexEffectMove(move3);
757
    effect[10]= new VertexEffectRotate(angle3,axis ,cent1);
758
    effect[11]= new VertexEffectScale(flipX);
759

  
760
    effect[0].setMeshAssociation(63,-1);  // meshes 0,1,2,3,4,5
761
    effect[1].setMeshAssociation( 3,-1);  // meshes 0,1
762
    effect[2].setMeshAssociation( 2,-1);  // mesh 1
763
    effect[3].setMeshAssociation( 2,-1);  // mesh 1
764
    effect[4].setMeshAssociation(12,-1);  // meshes 2,3
765
    effect[5].setMeshAssociation(60,-1);  // meshes 2,3,4,5
766
    effect[6].setMeshAssociation(12,-1);  // meshes 2,3
767
    effect[7].setMeshAssociation( 8,-1);  // mesh 3
768
    effect[8].setMeshAssociation(48,-1);  // meshes 4,5
769
    effect[9].setMeshAssociation(48,-1);  // meshes 4,5
770
    effect[10].setMeshAssociation(48,-1); // meshes 4,5
771
    effect[11].setMeshAssociation(32,-1); // mesh 5
772

  
773
    return effect;
774
    }
775

  
776
///////////////////////////////////////////////////////////////////////////////////////////////////
777

  
778
  VertexEffect[] createVertexEffectsRediCorner()
779
    {
780
    Static3D axisY   = new Static3D(0,1,0);
781
    Static3D axisX   = new Static3D(1,0,0);
782
    Static3D axisZ   = new Static3D(0,0,1);
783
    Static3D center  = new Static3D(0,0,0);
784
    Static1D angle90 = new Static1D(90);
785
    Static1D angle270= new Static1D(270);
786
    Static1D angle45 = new Static1D(-45);
787
    Static3D scale   = new Static3D(1.0f, SQ2, 1.0f);
788

  
789
    VertexEffect[] effect = new VertexEffect[7];
790

  
791
    effect[0] = new VertexEffectMove(new Static3D(0,0,+0.5f));
792
    effect[1] = new VertexEffectRotate( angle270, axisX, center );
793
    effect[2] = new VertexEffectRotate( angle90 , axisY, center );
794
    effect[3] = new VertexEffectScale(scale);
795
    effect[4] = new VertexEffectRotate( angle45 , axisX, center );
796
    effect[5] = new VertexEffectRotate( angle90 , axisY, center );
797
    effect[6] = new VertexEffectRotate( angle270, axisZ, center );
798

  
799
    effect[0].setMeshAssociation( 7,-1);  // 0,1,2
800
    effect[1].setMeshAssociation( 2,-1);  // 1
801
    effect[2].setMeshAssociation( 4,-1);  // 2
802
    effect[3].setMeshAssociation(56,-1);  // 3,4,5
803
    effect[4].setMeshAssociation(56,-1);  // 3,4,5
804
    effect[5].setMeshAssociation(16,-1);  // 4
805
    effect[6].setMeshAssociation(32,-1);  // 5
806

  
807
    return effect;
808
    }
809

  
810 625
///////////////////////////////////////////////////////////////////////////////////////////////////
811 626

  
812 627
  VertexEffect[] createVertexEffectsIvyCorner()
......
1198 1013

  
1199 1014
///////////////////////////////////////////////////////////////////////////////////////////////////
1200 1015
// OBJECTS
1201
///////////////////////////////////////////////////////////////////////////////////////////////////
1202

  
1203
  public MeshBase createRediEdgeMesh()
1204
    {
1205
    MeshBase mesh = createFacesRediEdge();
1206
    VertexEffect[] effects = createVertexEffectsRediEdge();
1207
    for( VertexEffect effect : effects ) mesh.apply(effect);
1208

  
1209
    Static3D center = new Static3D(0.0f,-0.75f,-0.75f);
1210
    Static3D[] vertices = new Static3D[2];
1211
    vertices[0] = new Static3D( 0.5f, 0.0f, 0.0f);
1212
    vertices[1] = new Static3D(-0.5f, 0.0f, 0.0f);
1213
    roundCorners(mesh,center,vertices,0.06f,0.20f);
1214

  
1215
    mesh.mergeEffComponents();
1216

  
1217
    return mesh;
1218
    }
1219

  
1220
///////////////////////////////////////////////////////////////////////////////////////////////////
1221

  
1222
  public MeshBase createRediCornerMesh()
1223
    {
1224
    MeshBase mesh = createFacesRediCorner();
1225
    VertexEffect[] effects = createVertexEffectsRediCorner();
1226
    for( VertexEffect effect : effects ) mesh.apply(effect);
1227

  
1228
    Static3D center = new Static3D(0,0,0);
1229
    Static3D[] vertices = new Static3D[8];
1230
    vertices[0] = new Static3D(+0.5f,+0.5f,+0.5f);
1231
    vertices[1] = new Static3D(+0.5f,+0.5f,-0.5f);
1232
    vertices[2] = new Static3D(+0.5f,-0.5f,+0.5f);
1233
    vertices[3] = new Static3D(+0.5f,-0.5f,-0.5f);
1234
    vertices[4] = new Static3D(-0.5f,+0.5f,+0.5f);
1235
    vertices[5] = new Static3D(-0.5f,+0.5f,-0.5f);
1236
    vertices[6] = new Static3D(-0.5f,-0.5f,+0.5f);
1237
    vertices[7] = new Static3D(-0.5f,-0.5f,-0.5f);
1238

  
1239
    roundCorners(mesh,center,vertices,0.06f,0.12f);
1240

  
1241
    mesh.mergeEffComponents();
1242

  
1243
    return mesh;
1244
    }
1245

  
1246 1016
///////////////////////////////////////////////////////////////////////////////////////////////////
1247 1017

  
1248 1018
  public MeshBase createIvyCornerMesh()
src/main/java/org/distorted/objects/TwistyHelicopter.java
295 295

  
296 296
  int getNumStickerTypes(int numLayers)
297 297
    {
298
    return 1;
298
    return STICKERS.length;
299 299
    }
300 300

  
301 301
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyRedi.java
133 133
           {  7,11,12,12,12,12 },
134 134
         };
135 135

  
136
  private static MeshBase mCornerMesh, mEdgeMesh;
136
  private static final float G = 0.72f;
137

  
138
  private static final double[][] VERTICES_CORNER = new double[][]
139
          {
140
             { 0.0f, 0.0f, 0.0f },
141
             {-0.5f, 0.5f, 0.5f },
142
             {-0.5f,-0.5f, 0.5f },
143
             { 0.5f, 0.5f, 0.5f },
144
             { 0.5f,-0.5f, 0.5f },
145
             { 0.5f, 0.5f,-0.5f },
146
             { 0.5f,-0.5f,-0.5f },
147
             {-0.5f, 0.5f,-0.5f },
148

  
149
             {-0.5f, 0.5f*G, 0.5f },
150
             {-0.5f,-0.5f*G, 0.5f },
151
             {-0.5f*G,-0.5f, 0.5f },
152
             { 0.5f*G,-0.5f, 0.5f },
153
             { 0.5f,-0.5f, 0.5f*G },
154
             { 0.5f,-0.5f,-0.5f*G },
155
             { 0.5f,-0.5f*G,-0.5f },
156
             { 0.5f, 0.5f*G,-0.5f },
157
             { 0.5f*G, 0.5f,-0.5f },
158
             {-0.5f*G, 0.5f,-0.5f },
159
             {-0.5f, 0.5f,-0.5f*G },
160
             {-0.5f, 0.5f, 0.5f*G },
161
          };
162

  
163
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
164
          {
165
             { 2,4,3,1 },
166
             { 1,3,5,7 },
167
             { 4,6,5,3 },
168

  
169
             { 2,10,11,4,0,5,16,17,7,0},
170
             { 4,12,13,6,0,7,18,19,1,0},
171
             { 1, 8, 9,2,0,6,14,15,5,0}
172
          };
173

  
174
  private static final double[][] VERTICES_EDGE = new double[][]
175
          {
176
             {-0.5f, 0.0f, 0.0f},
177
             { 0.5f, 0.0f, 0.0f},
178
             {-0.5f,-1.0f, 0.0f},
179
             { 0.5f,-1.0f, 0.0f},
180
             { 0.0f,-1.5f, 0.0f},
181
             {-0.5f, 0.0f,-1.0f},
182
             { 0.5f, 0.0f,-1.0f},
183
             { 0.0f, 0.0f,-1.5f},
184
          };
185

  
186
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
187
          {
188
             { 0,2,4,3,1 },
189
             { 0,1,6,7,5 },
190
             { 1,3,6 },
191
             { 0,2,5 },
192
             { 4,7,6,3 },
193
             { 4,7,5,2 }
194
          };
195

  
196
  private static final float[][] STICKERS = new float[][]
197
          {
198
             { -0.5f, -0.5f, 0.5f, -0.5f, 0.5f, 0.5f, -0.5f, 0.5f },
199
             { -0.3125f, 0.4375f, -0.3125f, -0.1875f, 0.0f, -0.5f, 0.3125f, -0.1875f, 0.3125f, 0.4375f }
200
          };
201

  
202
  private static MeshBase[] mMeshes;
137 203

  
138 204
///////////////////////////////////////////////////////////////////////////////////////////////////
139 205

  
......
144 210
    }
145 211

  
146 212
///////////////////////////////////////////////////////////////////////////////////////////////////
147
// TODO
148 213

  
149 214
  double[][] getVertices(int cubitType)
150 215
    {
216
    if( cubitType==0 ) return VERTICES_CORNER;
217
    if( cubitType==1 ) return VERTICES_EDGE;
151 218
    return null;
152 219
    }
153 220

  
154 221
///////////////////////////////////////////////////////////////////////////////////////////////////
155
// TODO
156 222

  
157 223
  int[][] getVertIndexes(int cubitType)
158 224
    {
225
    if( cubitType==0 ) return VERT_INDEXES_CORNER;
226
    if( cubitType==1 ) return VERT_INDEXES_EDGE;
159 227
    return null;
160 228
    }
161 229

  
......
263 331

  
264 332
  MeshBase createCubitMesh(int cubit, int numLayers)
265 333
    {
334
    if( mMeshes==null )
335
      {
336
      FactoryCubit factory = FactoryCubit.getInstance();
337
      factory.clear();
338
      mMeshes = new MeshBase[2];
339
      }
340

  
266 341
    MeshBase mesh;
267 342

  
268 343
    if( cubit<8 )
269 344
      {
270
      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createRediCornerMesh();
271
      mesh = mCornerMesh.copy(true);
345
      if( mMeshes[0]==null )
346
        {
347
        float[][] bands= new float[][]
348
          {
349
             {0.06f,35,0.5f,0.7f,6,2,2},
350
             {0.00f, 0,1.0f,0.0f,2,0,0}
351
          };
352
        int[] bandIndexes   = new int[] { 0,0,0,1,1,1 };
353
        float[][] corners   = new float[][] { {0.06f,0.12f} };
354
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
355
        float[][] centers   = new float[][] { { 0.0f, 0.0f, 0.0f} };
356
        int[] centerIndexes = new int[] { -1,0,-1,0,0,0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 };
357

  
358
        FactoryCubit factory = FactoryCubit.getInstance();
359
        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
360
        mMeshes[0] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
361
                                                bands, bandIndexes,
362
                                                corners, cornerIndexes,
363
                                                centers, centerIndexes,
364
                                                getNumCubitFaces() );
365
        }
366
      mesh = mMeshes[0].copy(true);
272 367
      }
273 368
    else
274 369
      {
275
      if( mEdgeMesh==null ) mEdgeMesh = FactoryCubit.getInstance().createRediEdgeMesh();
276
      mesh = mEdgeMesh.copy(true);
370
      if( mMeshes[1]==null )
371
        {
372
        float[][] bands= new float[][]
373
          {
374
            {0.038f,35,0.250f,0.7f, 7,2,2},
375
            {0.020f,35,0.125f,0.2f, 3,1,2},
376
            {0.020f,35,0.125f,0.2f, 3,1,1}
377
          };
378
        int[] bandIndexes   = new int[] { 0,0,1,1,2,2 };
379
        float[][] corners   = new float[][] { {0.06f,0.20f} };
380
        int[] cornerIndexes = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
381
        float[][] centers   = new float[][] { { 0.0f,-0.75f,-0.75f} };
382
        int[] centerIndexes = new int[] { 0,0,-1,-1,-1,-1,-1,-1 };
383

  
384
        FactoryCubit factory = FactoryCubit.getInstance();
385
        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
386
        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
387
                                                bands, bandIndexes,
388
                                                corners, cornerIndexes,
389
                                                centers, centerIndexes,
390
                                                getNumCubitFaces() );
391
        }
392
      mesh = mMeshes[1].copy(true);
277 393
      }
278 394

  
279 395
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
......
294 410
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
295 411
    {
296 412
    int COLORS = FACE_COLORS.length;
297
    FactorySticker factory = FactorySticker.getInstance();
413
    int stickerType = face/COLORS;
414
    float R,S;
298 415

  
299
    if( face<COLORS )
416
    switch(stickerType)
300 417
      {
301
      float F =  0.5f;
302
      float R = 0.10f;
303
      float S = 0.10f;
304
      float[] vertices = { -F,-F, +F,-F, +F,+F, -F,+F};
305

  
306
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
418
      case 0:  R = 0.09f; S = 0.09f; break;
419
      case 1:  R = 0.06f; S = 0.06f; break;
420
      default: R = 0.00f; S = 0.00f; break;
307 421
      }
308
    else
309
      {
310
      float F = 0.25f;
311
      float R = 0.05f;
312
      float S = 0.05f;
313
      float[] vertices = { -F,+F, -F,-F, 0, -2*F, +F,-F, +F,+F };
314 422

  
315
      factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face-COLORS], R);
316
      }
423
    FactorySticker factory = FactorySticker.getInstance();
424
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[stickerType], S, FACE_COLORS[face%COLORS], R);
317 425
    }
318 426

  
319 427
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff