Project

General

Profile

« Previous | Next » 

Revision d38f1397

Added by Leszek Koltunski almost 4 years ago

Progress with Megaminx.

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
1760 1760

  
1761 1761
    return mesh;
1762 1762
    }
1763

  
1764
///////////////////////////////////////////////////////////////////////////////////////////////////
1765
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1766
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
1767

  
1768
  MeshBase createMegaminxEdgeMesh(int index, int type)
1769
    {
1770

  
1771
    return createTetraMesh();
1772
    }
1763 1773
  }
src/main/java/org/distorted/objects/TwistyKilominx.java
71 71

  
72 72
  private int getQuat(int cubit)
73 73
    {
74
    return ( cubit>=0 && cubit<20 ) ? QUAT_INDICES[cubit] : 0;
74
    return ( cubit>=0 && cubit<20 ) ? QUAT_CORNER_INDICES[cubit] : 0;
75 75
    }
76 76

  
77 77
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/TwistyMegaminx.java
43 43
  private static final int NUM_CENTERS = 12;
44 44
  private static final int NUM_EDGES   = 30;
45 45

  
46
  private static final int[][] mFaceVertexMap =
46
  // the five vertices that form a given face. Order: the same as colors
47
  // of the faces in TwistyMinx.
48
  private static final int[][] mCenterMap =
47 49
         {
48
           { 0, 12,  8, 10, 16},
49 50
           { 0, 12,  4, 14,  2},
50
           { 2, 14,  9, 11, 18},
51 51
           { 0,  2, 18,  6, 16},
52
           { 8, 13,  5,  4, 12},
53
           { 4,  5, 15,  9, 14},
54 52
           { 6, 18, 11, 19,  7},
55
           {10, 16,  6,  7, 17},
56
           { 1, 13,  8, 10, 17},
57
           { 1, 13,  5, 15,  3},
58 53
           { 3, 15,  9, 11, 19},
54
           { 4,  5, 15,  9, 14},
55
           { 1, 13,  5, 15,  3},
59 56
           { 1,  3, 19,  7, 17},
57
           {10, 16,  6,  7, 17},
58
           { 0, 12,  8, 10, 16},
59
           { 8, 13,  5,  4, 12},
60
           { 1, 13,  8, 10, 17},
61
           { 2, 14,  9, 11, 18},
60 62
         };
61 63

  
62
  private static MeshBase[] mCenterMeshes, mCornerMeshes, mEdgeMeshes;
64
  // the quadruple ( vertex1, vertex2, face1, face2 ) defining an edge.
65
  // In fact the 2 vertices already define it, the faces only provide easy
66
  // way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
67
  // the 'left' or right of vector vertex1 --> vertex2, according to Quat.
68
  private static final int[][] mEdgeMap =
69
         {
70
           {  0, 12,  0,  8},
71
           { 12,  4,  0,  9},
72
           {  4, 14,  0,  4},
73
           { 14,  2,  0, 11},
74
           {  2,  0,  0,  1},
75
           { 14,  9,  4, 11},
76
           {  9, 11,  3, 11},
77
           { 11, 18,  2, 11},
78
           { 18,  2,  1, 11},
79
           { 18,  6,  2,  1},
80
           {  6, 16,  7,  1},
81
           { 16,  0,  8,  1},
82
           { 16, 10,  8,  7},
83
           { 10,  8,  8, 10},
84
           {  8, 12,  8,  9},
85
           {  8, 13,  9, 10},
86
           { 13,  5,  9,  5},
87
           {  5,  4,  9,  4},
88
           {  5, 15,  4,  5},
89
           { 15,  9,  4,  3},
90
           { 11, 19,  2,  3},
91
           { 19,  7,  2,  6},
92
           {  7,  6,  2,  7},
93
           {  7, 17,  7,  6},
94
           { 17, 10,  7, 10},
95
           { 17,  1,  6, 10},
96
           {  1,  3,  6,  4},
97
           {  3, 19,  6,  3},
98
           {  1, 13, 10,  5},
99
           {  3, 15,  5,  3},
100
         };
63 101

  
64
  private static final Static4D[] mBasicV, mCurrV;
102
  private static final float[][] mCenterCoords = new float[NUM_CENTERS][3];
65 103

  
66 104
  static
67 105
    {
68
    mBasicV = new Static4D[3];
69
    mCurrV  = new Static4D[3];
106
    for(int center=0; center<NUM_CENTERS; center++)
107
      {
108
      int[] map = mCenterMap[center];
109

  
110
      float x = CORNERS[map[0]].get0() +
111
                CORNERS[map[1]].get0() +
112
                CORNERS[map[2]].get0() +
113
                CORNERS[map[3]].get0() +
114
                CORNERS[map[4]].get0() ;
115

  
116
      float y = CORNERS[map[0]].get1() +
117
                CORNERS[map[1]].get1() +
118
                CORNERS[map[2]].get1() +
119
                CORNERS[map[3]].get1() +
120
                CORNERS[map[4]].get1() ;
121

  
122
      float z = CORNERS[map[0]].get2() +
123
                CORNERS[map[1]].get2() +
124
                CORNERS[map[2]].get2() +
125
                CORNERS[map[3]].get2() +
126
                CORNERS[map[4]].get2() ;
127

  
128
      mCenterCoords[center][0] = x/5;
129
      mCenterCoords[center][1] = y/5;
130
      mCenterCoords[center][2] = z/5;
131
      }
132
    }
133

  
134
  private static MeshBase[] mCenterMeshes, mCornerMeshes;
135
  private static MeshBase[][] mEdgeMeshes;
136

  
137
  private static final Static4D[] mBasicCornerV, mCurrCornerV;
70 138

  
71
    mBasicV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
72
    mBasicV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
73
    mBasicV[2] = new Static4D(              0,        -0.500f,    0.0f, 0.0f );
139
  static
140
    {
141
    mBasicCornerV = new Static4D[3];
142
    mCurrCornerV  = new Static4D[3];
143

  
144
    mBasicCornerV[0] = new Static4D( (SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
145
    mBasicCornerV[1] = new Static4D(-(SQ5+1)*0.125f, (SQ5-1)*0.125f, -0.250f, 0.0f );
146
    mBasicCornerV[2] = new Static4D(              0,        -0.500f,    0.0f, 0.0f );
74 147
    };
75 148

  
76 149
///////////////////////////////////////////////////////////////////////////////////////////////////
......
99 172

  
100 173
  int getNumStickerTypes(int numLayers)
101 174
    {
102
    return 1; //numLayers;
175
    return numLayers-1; //numLayers;
103 176
    }
104 177

  
105 178
///////////////////////////////////////////////////////////////////////////////////////////////////
......
129 202

  
130 203
  private void computeCenter(Static3D[] array, int center)
131 204
    {
132
    int[] map = mFaceVertexMap[center];
133

  
134
    float x = CORNERS[map[0]].get0() +
135
              CORNERS[map[1]].get0() +
136
              CORNERS[map[2]].get0() +
137
              CORNERS[map[3]].get0() +
138
              CORNERS[map[4]].get0() ;
139

  
140
    float y = CORNERS[map[0]].get1() +
141
              CORNERS[map[1]].get1() +
142
              CORNERS[map[2]].get1() +
143
              CORNERS[map[3]].get1() +
144
              CORNERS[map[4]].get1() ;
145

  
146
    float z = CORNERS[map[0]].get2() +
147
              CORNERS[map[1]].get2() +
148
              CORNERS[map[2]].get2() +
149
              CORNERS[map[3]].get2() +
150
              CORNERS[map[4]].get2() ;
151

  
152
    array[center].set(x/5,y/5,z/5);
205
    float[] coords = mCenterCoords[center];
206
    array[center].set( coords[0], coords[1], coords[2]);
153 207
    }
154 208

  
155 209
///////////////////////////////////////////////////////////////////////////////////////////////////
156
// Fill out mCurr{X,Y,Z} by applying appropriate Quat to mBasic{X,Y,Z}
210
// Fill out mCurrCorner{X,Y,Z} by applying appropriate Quat to mBasicCorner{X,Y,Z}
157 211
// Appropriate one: QUATS[QUAT_INDICES[corner]].
158 212

  
159
  private void computeBasicVectors(int corner)
213
  private void computeBasicCornerVectors(int corner)
160 214
    {
161
    Static4D quat = QUATS[QUAT_INDICES[corner]];
215
    Static4D quat = QUATS[QUAT_CORNER_INDICES[corner]];
162 216

  
163
    mCurrV[0] = RubikSurfaceView.rotateVectorByQuat(mBasicV[0],quat);
164
    mCurrV[1] = RubikSurfaceView.rotateVectorByQuat(mBasicV[1],quat);
165
    mCurrV[2] = RubikSurfaceView.rotateVectorByQuat(mBasicV[2],quat);
217
    mCurrCornerV[0] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[0],quat);
218
    mCurrCornerV[1] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[1],quat);
219
    mCurrCornerV[2] = RubikSurfaceView.rotateVectorByQuat(mBasicCornerV[2],quat);
166 220
    }
167 221

  
168 222
///////////////////////////////////////////////////////////////////////////////////////////////////
......
182 236
      int N = (numCubitsPerCorner-1)/3;
183 237
      int block = (part-1) % N;
184 238
      int index = (part-1) / N;
185
      Static4D pri = mCurrV[index];
186
      Static4D sec = mCurrV[(index+2)%3];
239
      Static4D pri = mCurrCornerV[index];
240
      Static4D sec = mCurrCornerV[(index+2)%3];
187 241

  
188 242
      int multP = (block % ((numLayers-3)/2)) + 1;
189 243
      int multS = (block / ((numLayers-3)/2));
......
195 249
    }
196 250

  
197 251
///////////////////////////////////////////////////////////////////////////////////////////////////
198
// TODO
199 252

  
200
  private void computeEdge(Static3D pos, int edge, int part)
253
  private int computeEdgeType(int cubit, int numCubitsPerCorner, int numCubitsPerEdge)
201 254
    {
255
    int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
256
    return (part+1)/2;
257
    }
202 258

  
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

  
261
  private void computeEdge(Static3D pos, int numLayers, int edge, int part)
262
    {
263
    Static3D c1 = CORNERS[ mEdgeMap[edge][0] ];
264
    Static3D c2 = CORNERS[ mEdgeMap[edge][1] ];
265
    float x = (c1.get0() + c2.get0())/2;
266
    float y = (c1.get1() + c2.get1())/2;
267
    float z = (c1.get2() + c2.get2())/2;
268

  
269
    if( part==0 )
270
      {
271
      pos.set(x,y,z);
272
      }
273
    else
274
      {
275
      int mult = (part+1)/2;
276
      int dir  = (part+1)%2;
277
      float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
278

  
279
      float vX = center[0]-x;
280
      float vY = center[1]-y;
281
      float vZ = center[2]-z;
282

  
283
      float A = mult*(0.5f-MEGA_D)/((1+SQ5/5)*(numLayers-1));
284

  
285
      pos.set( x+A*vX, y+A*vY, z+A*vZ );
286
      }
203 287
    }
204 288

  
205 289
///////////////////////////////////////////////////////////////////////////////////////////////////
......
207 291
  Static3D[] getCubitPositions(int numLayers)
208 292
    {
209 293
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
210
  //  int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
211
    int numCubits = NUM_CORNERS*numCubitsPerCorner ;//+ NUM_EDGES*numCubitsPerEdge + NUM_CENTERS;
294
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
295
    int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge;// + NUM_CENTERS;
212 296
    int index=0;
213 297

  
214 298
    final Static3D[] CENTERS = new Static3D[numCubits];
215 299

  
216 300
    for(int corner=0; corner<NUM_CORNERS; corner++)
217 301
      {
218
      computeBasicVectors(corner);
302
      computeBasicCornerVectors(corner);
219 303

  
220 304
      for(int part=0; part<numCubitsPerCorner; part++, index++)
221 305
        {
......
223 307
        computeCorner(CENTERS[index],numCubitsPerCorner,numLayers,corner,part);
224 308
        }
225 309
      }
226
/*
310

  
227 311
    for(int edge=0; edge<NUM_EDGES; edge++)
228 312
      {
229 313
      for(int part=0; part<numCubitsPerEdge; part++, index++)
230 314
        {
231
        computeEdge(CENTERS,index, edge, part );
315
        CENTERS[index] = new Static3D(0,0,0);
316
        computeEdge(CENTERS[index], numLayers, edge, part );
232 317
        }
233 318
      }
234

  
319
/*
235 320
    for(int center=0; center<NUM_CENTERS; center++, index++)
236 321
      {
237 322
      computeCenter(CENTERS,index);
......
249 334
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
250 335
      {
251 336
      int corner = cubit/numCubitsPerCorner;
252
      return QUAT_INDICES[corner];
253
      }
254
/*
255
    if( cubit < NUM_CENTERS + NUM_CORNERS*numCubitsPerCorner )
256
      {
257
      switch(cubit-NUM_CORNERS*numCubitsPerCorner)
258
        {
259
        case  0: return  0;
260
        case  1: return 52;
261
        case  2: return  3;
262
        case  3: return 53;
263
        case  4: return 59;
264
        case  5: return 20;
265
        case  6: return 22;
266
        case  7: return 58;
267
        case  8: return 55;
268
        case  9: return 13;
269
        case 10: return  1;
270
        case 11: return 14;
271
        }
337
      return QUAT_CORNER_INDICES[corner];
272 338
      }
273 339

  
274 340
    int numCubitsPerEdge = numCubitsPerEdge(numLayers);
275 341

  
276
    // TODO: edges
342
    if( cubit < NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
343
      {
344
      int edge = (cubit-NUM_CORNERS*numCubitsPerCorner)/numCubitsPerEdge;
345
      return QUAT_EDGE_INDICES[edge];
346
      }
347

  
348
/*
349
    else
350
      {
351
      // TODO: centers
352
      }
277 353
*/
354

  
278 355
    return 0;
279 356
    }
280 357

  
......
285 362
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
286 363
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
287 364
    int index = (numLayers-3)/2;
365
    int variants = ObjectList.MEGA.getNumVariants();
288 366
    MeshBase mesh;
289 367

  
290
    if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[ObjectList.MEGA.getNumVariants()];
368
    if( mCornerMeshes==null ) mCornerMeshes = new MeshBase[variants];
369
    if( mEdgeMeshes  ==null ) mEdgeMeshes   = new MeshBase[variants][index+1];
291 370

  
292
//    if( cubit < NUM_CORNERS*numCubitsPerCorner )
371
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
293 372
      {
294
      if( mCornerMeshes[index]==null ) mCornerMeshes[index] = FactoryCubit.getInstance().createMegaminxCornerMesh(numLayers);
373
      if( mCornerMeshes[index]==null )
374
        {
375
        mCornerMeshes[index] = FactoryCubit.getInstance().createMegaminxCornerMesh(numLayers);
376
        }
295 377
      mesh = mCornerMeshes[index].copy(true);
296 378
      }
297
/*
298
    else if( cubit<NUM_CENTERS + NUM_CORNERS*numCubitsPerCorner )
379
    else //if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
299 380
      {
300
      if( mCornerMesh==null ) mCornerMesh = FactoryCubit.getInstance().createMegaminxCenterMesh();
301
      mesh = mCornerMesh.copy(true);
381
      int type = computeEdgeType(cubit,numCubitsPerCorner,numCubitsPerEdge);
382

  
383
      if( mEdgeMeshes[index][type]==null )
384
        {
385
        mEdgeMeshes[index][type] = FactoryCubit.getInstance().createMegaminxEdgeMesh(index,type);
386
        }
387

  
388
      mesh = mEdgeMeshes[index][type].copy(true);
302 389
      }
390
/*
303 391
    else
304 392
      {
305
      if( mEdgeMesh==null ) mEdgeMesh = new MeshBase[(numLayers-1)/2];
306

  
307
      // TODO
393
      // TODO: centers
308 394
      }
309 395
*/
310 396
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit,numLayers)], new Static3D(0,0,0) );
......
314 400
    }
315 401

  
316 402
///////////////////////////////////////////////////////////////////////////////////////////////////
317
// TODO
318 403

  
319
  int getFaceColor(int cubit, int cubitface, int numLayers)
404
  int getCornerColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner)
320 405
    {
321 406
    if( cubitface<0 || cubitface>2 ) return NUM_TEXTURES*NUM_FACES;
322 407

  
323
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
324 408
    int part  = cubit % numCubitsPerCorner;
325 409
    int corner= cubit / numCubitsPerCorner;
326 410

  
......
357 441
    return NUM_TEXTURES*NUM_FACES;
358 442
    }
359 443

  
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

  
446
  int getEdgeColor(int cubit, int cubitface, int numLayers, int numCubitsPerCorner, int numCubitsPerEdge)
447
    {
448
    if( cubitface<0 || cubitface>1 ) return NUM_TEXTURES*NUM_FACES;
449

  
450
    int part = (cubit - NUM_CORNERS*numCubitsPerCorner) % numCubitsPerEdge;
451
    int edge = (cubit - NUM_CORNERS*numCubitsPerCorner) / numCubitsPerEdge;
452

  
453
    if( part==0 )
454
      {
455
      return mEdgeMap[edge][cubitface+2];
456
      }
457

  
458
    return cubitface==((part+1)%2) ? mEdgeMap[edge][cubitface+2] : NUM_TEXTURES*NUM_FACES;
459
    }
460

  
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462
// TODO
463

  
464
  int getCenterColor(int cubit, int cubitface, int numLayers)
465
    {
466
    return 0;
467
    }
468

  
469
///////////////////////////////////////////////////////////////////////////////////////////////////
470

  
471
  int getFaceColor(int cubit, int cubitface, int numLayers)
472
    {
473
    int numCubitsPerCorner = numCubitsPerCorner(numLayers);
474
    int numCubitsPerEdge   = numCubitsPerEdge(numLayers);
475

  
476
    if( cubit < NUM_CORNERS*numCubitsPerCorner )
477
      {
478
      return getCornerColor(cubit,cubitface,numLayers,numCubitsPerCorner);
479
      }
480
    else if( cubit<NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge )
481
      {
482
      return getEdgeColor(cubit,cubitface,numLayers,numCubitsPerCorner,numCubitsPerEdge);
483
      }
484
    else
485
      {
486
      return getCenterColor(cubit,cubitface,numLayers);
487
      }
488
    }
489

  
360 490
///////////////////////////////////////////////////////////////////////////////////////////////////
361 491
// TODO
362 492

  
363 493
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
364 494
    {
365
    paint.setColor(FACE_COLORS[face]);
495
    paint.setColor(FACE_COLORS[face%NUM_FACES]);
366 496
    paint.setStyle(Paint.Style.FILL);
367 497
    canvas.drawRect(left,top,left+TEXTURE_HEIGHT,top+TEXTURE_HEIGHT,paint);
368 498
    }
src/main/java/org/distorted/objects/TwistyMinx.java
192 192
           {  6, 2, 3 },
193 193
         };
194 194

  
195
  static final int[] QUAT_INDICES = {0,2,3,1,40,31,41,30,39,35,36,34,56,32,43,21,48,28,42,23};
195
  static final int[] QUAT_CORNER_INDICES
196
    = {
197
         0,  2,  3,  1, 40, 31, 41, 30, 39, 35,
198
        36, 34, 56, 32, 43, 21, 48, 28, 42, 23
199
      };
200

  
201
  static final int[] QUAT_EDGE_INDICES
202
    = {
203
         0, 56, 40, 43, 59, 35, 34, 42,  3, 25,
204
        49, 27, 36, 39, 51, 53, 32, 20, 47, 10,
205
        17, 37, 30,  5, 28, 33, 45, 14, 44, 38
206
      };
196 207

  
197 208
///////////////////////////////////////////////////////////////////////////////////////////////////
198 209

  

Also available in: Unified diff