Project

General

Profile

« Previous | Next » 

Revision 596d62a4

Added by Leszek Koltunski about 3 years ago

Convert the Dino and one of the Skewb's cubits to the new engine.

View differences:

src/main/java/org/distorted/helpers/FactoryCubit.java
298 298
    return new MeshJoined(meshes);
299 299
    }
300 300

  
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

  
303
  MeshBase createFacesDino()
304
    {
305
    MeshBase[] meshes = new MeshPolygon[4];
306

  
307
    float E = 0.5f*SQ2;
308
    float F = 0.5f;
309
    float[] vertices0 = { -F,F/3, 0,-2*F/3, +F,F/3 };
310
    float[] bands0 = computeBands(0.028f,30,F/3,0.8f,7);
311

  
312
    meshes[0] = new MeshPolygon(vertices0, bands0, 2, 5);
313
    meshes[0].setEffectAssociation(0,1,0);
314
    meshes[1] = meshes[0].copy(true);
315
    meshes[1].setEffectAssociation(0,2,0);
316

  
317
    float[] vertices1 = { -E/2,-E*(SQ3/6), E/2,-E*(SQ3/6), 0,E*(SQ3/3) };
318
    float[] bands1 = computeBands(0.02f,45,F/3,0.2f,3);
319

  
320
    meshes[2] = new MeshPolygon(vertices1, bands1, 1, 2);
321
    meshes[2].setEffectAssociation(0,4,0);
322
    meshes[3] = meshes[2].copy(true);
323
    meshes[3].setEffectAssociation(0,8,0);
324

  
325
    return new MeshJoined(meshes);
326
    }
327

  
328 301
///////////////////////////////////////////////////////////////////////////////////////////////////
329 302

  
330 303
  MeshBase createFacesHelicopterCorner()
......
918 891
    return effect;
919 892
    }
920 893

  
921
///////////////////////////////////////////////////////////////////////////////////////////////////
922

  
923
  VertexEffect[] createVertexEffectsDino()
924
    {
925
    float E = 0.5f*SQ2;
926
    float F = 0.5f;
927
    final float ANGLE = (float)((180/Math.PI)*(Math.atan(SQ2)));
928

  
929
    Static1D angle1 = new Static1D(-ANGLE);
930
    Static1D angle2 = new Static1D(+ANGLE);
931
    Static3D axisX  = new Static3D(1,0,0);
932
    Static3D axisY  = new Static3D(0,1,0);
933
    Static3D axisZ  = new Static3D(0,-1,1);
934
    Static3D center0= new Static3D(0,0,0);
935
    Static3D center1= new Static3D(0,-3*F,0);
936

  
937
    VertexEffect[] effect = new VertexEffect[10];
938

  
939
    effect[0] = new VertexEffectScale ( new Static3D(3,3,3) );
940
    effect[1] = new VertexEffectMove  ( new Static3D(0,-F,0) );
941
    effect[2] = new VertexEffectRotate( new Static1D(90), axisX, center0 );
942
    effect[3] = new VertexEffectScale ( new Static3D(1,-1,1) );
943
    effect[4] = new VertexEffectMove  ( new Static3D(3*E/2,E*(SQ3/2)-3*F,0) );
944
    effect[5] = new VertexEffectRotate( new Static1D(+90), axisY, center1 );
945
    effect[6] = new VertexEffectScale ( new Static3D(-1,1,1) );
946
    effect[7] = new VertexEffectRotate( new Static1D( 45), axisX, center1 );
947
    effect[8] = new VertexEffectRotate( angle1           , axisZ, center1 );
948
    effect[9] = new VertexEffectRotate( angle2           , axisZ, center1 );
949

  
950
    effect[0].setMeshAssociation(15,-1);  // apply to meshes 0,1,2,3
951
    effect[1].setMeshAssociation( 3,-1);  // apply to meshes 0,1
952
    effect[2].setMeshAssociation( 2,-1);  // apply to mesh 1
953
    effect[3].setMeshAssociation( 2,-1);  // apply to mesh 1
954
    effect[4].setMeshAssociation(12,-1);  // apply to meshes 2,3
955
    effect[5].setMeshAssociation(12,-1);  // apply to meshes 2,3
956
    effect[6].setMeshAssociation( 8,-1);  // apply to mesh 3
957
    effect[7].setMeshAssociation(12,-1);  // apply to meshes 2,3
958
    effect[8].setMeshAssociation( 4,-1);  // apply to mesh 2
959
    effect[9].setMeshAssociation( 8,-1);  // apply to mesh 3
960

  
961
    return effect;
962
    }
963

  
964 894
///////////////////////////////////////////////////////////////////////////////////////////////////
965 895

  
966 896
  VertexEffect[] createVertexEffectsHelicopterCorner()
......
1588 1518
    return mesh;
1589 1519
    }
1590 1520

  
1591
///////////////////////////////////////////////////////////////////////////////////////////////////
1592
// DINO
1593

  
1594
  public MeshBase createDinoMesh()
1595
    {
1596
    MeshBase mesh = createFacesDino();
1597
    VertexEffect[] effects = createVertexEffectsDino();
1598
    for( VertexEffect effect : effects ) mesh.apply(effect);
1599

  
1600
    float F = 0.5f;
1601
    Static3D roundingCenter = new Static3D(0.0f, -1.5f*F, -1.5f*F);
1602
    Static3D[] verticesRound = new Static3D[4];
1603
    verticesRound[0] = new Static3D(     0,-3*F,    0 );
1604
    verticesRound[1] = new Static3D(     0,   0, -3*F );
1605
    verticesRound[2] = new Static3D(  -3*F,   0,    0 );
1606
    verticesRound[3] = new Static3D(  +3*F,   0,    0 );
1607
    roundCorners(mesh,roundingCenter,verticesRound,0.10f,0.40f);
1608

  
1609
    mesh.mergeEffComponents();
1610

  
1611
    return mesh;
1612
    }
1613

  
1614 1521
///////////////////////////////////////////////////////////////////////////////////////////////////
1615 1522
// Helicopter
1616 1523

  
src/main/java/org/distorted/objects/TwistyDino.java
88 88
             {-1.5f, 0.0f,-1.5f }
89 89
         };
90 90

  
91
  private final double[][] VERTICES = new double[][]
91
  private static final double[][] VERTICES = new double[][]
92 92
          {
93
             {-0.5, 0.0, 0.0},
94
             { 0.5, 0.0, 0.0},
95
             { 0.0,-0.5, 0.0},
96
             { 0.0, 0.0,-0.5}
93
             {-1.5, 0.0, 0.0},
94
             { 1.5, 0.0, 0.0},
95
             { 0.0,-1.5, 0.0},
96
             { 0.0, 0.0,-1.5}
97 97
          };
98 98

  
99
  private final int[][] VERT_INDEXES = new int[][]
99
  private static final int[][] VERT_INDEXES = new int[][]
100 100
          {
101 101
             {2,1,0},   // counterclockwise!
102
             {3,0,1},
102 103
             {2,3,1},
103 104
             {3,2,0},
104
             {3,0,1}
105 105
          };
106 106

  
107
  private static MeshBase mMesh;
107
  private static final float[][] STICKERS = new float[][]
108
          {
109
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
110
          };
111

  
112
  private static MeshBase[] mMeshes;
108 113

  
109 114
///////////////////////////////////////////////////////////////////////////////////////////////////
110 115

  
......
207 212

  
208 213
  int getNumStickerTypes(int numLayers)
209 214
    {
210
    return 1;
215
    return STICKERS.length;
211 216
    }
212 217

  
213 218
///////////////////////////////////////////////////////////////////////////////////////////////////
......
228 233

  
229 234
  MeshBase createCubitMesh(int cubit, int numLayers)
230 235
    {
231
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createDinoMesh();
236
    if( mMeshes==null )
237
      {
238
      FactoryCubit factory = FactoryCubit.getInstance();
239
      factory.clear();
240
      mMeshes = new MeshBase[1];
241
      }
242

  
243
    if( mMeshes[0]==null )
244
      {
245
      float[][] bands= new float[][]
246
          {
247
             {0.035f,30,0.16f,0.8f,7,2,5},
248
             {0.020f,45,0.16f,0.2f,3,1,2}
249
          };
250
      int[] bandIndexes   = new int[] { 0,0,1,1 };
251
      float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
252
      int[] cornerIndexes = new int[] { 0,0,1,1 };
253

  
254
      FactoryCubit factory = FactoryCubit.getInstance();
255

  
256
      factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
257
      mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
258
                                              bands, bandIndexes,
259
                                              corners, cornerIndexes,
260
                                              getNumCubitFaces() );
261
      }
232 262

  
233
    MeshBase mesh = mMesh.copy(true);
263
    MeshBase mesh = mMeshes[0].copy(true);
234 264
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
235 265
    mesh.apply(quat,0xffffffff,0);
236 266

  
......
241 271

  
242 272
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
243 273
    {
244
    float F = 0.5f;
245 274
    float R = 0.025f;
246 275
    float S = 0.05f;
247
    float[] vertices = { -F,F/3, 0,-2*F/3, +F,F/3 };
248 276

  
249 277
    FactorySticker factory = FactorySticker.getInstance();
250
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
278
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
251 279
    }
252 280

  
253 281
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistySkewb.java
25 25

  
26 26
import org.distorted.helpers.FactoryCubit;
27 27
import org.distorted.helpers.FactorySticker;
28
import org.distorted.library.effect.MatrixEffect;
29 28
import org.distorted.library.effect.MatrixEffectQuaternion;
30
import org.distorted.library.effect.MatrixEffectScale;
31 29
import org.distorted.library.main.DistortedEffects;
32 30
import org.distorted.library.main.DistortedTexture;
33 31
import org.distorted.library.mesh.MeshBase;
......
117 115
           { 17, 18,18,18,18,18 },
118 116
         };
119 117

  
120
  private static MeshBase mCornerMesh, mFaceMesh, mEdgeMesh;
118
  private static final double[][] VERTICES_CORNER = new double[][]
119
          {
120
             // TODO
121
          };
122

  
123
  private static final int[][] VERT_INDEXES_CORNER = new int[][]
124
          {
125
             // TODO
126
          };
127

  
128
  private static final double[][] VERTICES_EDGE = new double[][]
129
          {
130
             {-0.5, 0.0, 0.0},
131
             { 0.5, 0.0, 0.0},
132
             { 0.0,-0.5, 0.0},
133
             { 0.0, 0.0,-0.5}
134
          };
135

  
136
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
137
          {
138
             {2,1,0},   // counterclockwise!
139
             {3,0,1},
140
             {2,3,1},
141
             {3,2,0},
142
          };
143

  
144
  private static final double[][] VERTICES_FACE = new double[][]
145
          {
146
             // TODO
147
          };
148

  
149
  private static final int[][] VERT_INDEXES_FACE = new int[][]
150
          {
151
             // TODO
152
          };
153

  
154
  private static MeshBase[] mMeshes;
121 155

  
122 156
///////////////////////////////////////////////////////////////////////////////////////////////////
123 157

  
......
128 162
    }
129 163

  
130 164
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// TODO
132 165

  
133 166
  double[][] getVertices(int cubitType)
134 167
    {
168
    if( cubitType==0 ) return VERTICES_CORNER;
169
    if( cubitType==1 ) return VERTICES_EDGE;
170
    if( cubitType==2 ) return VERTICES_FACE;
135 171
    return null;
136 172
    }
137 173

  
138 174
///////////////////////////////////////////////////////////////////////////////////////////////////
139
// TODO
140 175

  
141 176
  int[][] getVertIndexes(int cubitType)
142 177
    {
178
    if( cubitType==0 ) return VERT_INDEXES_CORNER;
179
    if( cubitType==1 ) return VERT_INDEXES_EDGE;
180
    if( cubitType==2 ) return VERT_INDEXES_FACE;
143 181
    return null;
144 182
    }
145 183

  
......
425 463

  
426 464
  MeshBase createCubitMesh(int cubit, int numLayers)
427 465
    {
466
    if( mMeshes==null )
467
      {
468
      FactoryCubit factory = FactoryCubit.getInstance();
469
      factory.clear();
470
      mMeshes = new MeshBase[3];
471
      }
472

  
428 473
    MeshBase mesh;
429 474

  
430 475
    int numCorners = getNumCorners();
......
432 477

  
433 478
    if( cubit<numCorners )
434 479
      {
435
      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createSkewbCornerMesh();
436
      mesh = mCornerMesh.copy(true);
480
      if( mMeshes[0]==null )
481
        {
482
        mMeshes[0] = FactoryCubit.getInstance().createSkewbCornerMesh();
483
        }
484
      mesh = mMeshes[0].copy(true);
437 485
      }
438 486
    else if( cubit<numCorners+numEdges )
439 487
      {
440
      if( mEdgeMesh==null )
488
      if( mMeshes[1]==null )
441 489
        {
442
        mEdgeMesh = FactoryCubit.getInstance().createDinoMesh();
443
        MatrixEffect effect = new MatrixEffectScale(1.0f/3);
444
        mEdgeMesh.apply(effect,-1,0);
445
        mEdgeMesh.addEmptyTexComponent();
446
        mEdgeMesh.addEmptyTexComponent();
490
        float[][] bands= new float[][]
491
          {
492
             {0.035f,30,0.16f,0.8f,7,2,5},
493
             {0.020f,45,0.16f,0.2f,3,1,2}
494
          };
495
        int[] bandIndexes   = new int[] { 0,0,1,1 };
496
        float[][] corners   = new float[][] { {0.07f,0.20f}, {0.02f,0.30f} };
497
        int[] cornerIndexes = new int[] { 0,0,1,1 };
498

  
499
        FactoryCubit factory = FactoryCubit.getInstance();
500

  
501
        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
502
        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
503
                                                bands, bandIndexes,
504
                                                corners, cornerIndexes,
505
                                                getNumCubitFaces() );
447 506
        }
448
      mesh = mEdgeMesh.copy(true);
507
      mesh = mMeshes[1].copy(true);
449 508
      }
450 509
    else
451 510
      {
452
      if( mFaceMesh==null ) mFaceMesh = FactoryCubit.getInstance().createSkewbFaceMesh();
453
      mesh = mFaceMesh.copy(true);
511
      if( mMeshes[2]==null )
512
        {
513
        mMeshes[2] = FactoryCubit.getInstance().createSkewbFaceMesh();
514
        }
515
      mesh = mMeshes[2].copy(true);
454 516
      }
455 517

  
456 518
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );

Also available in: Unified diff