Project

General

Profile

« Previous | Next » 

Revision eaee1ddc

Added by Leszek Koltunski about 4 years ago

Add the 4-color Dino.

Still one thing needs to be done about it: randomization of Moves (now sometimes in Level 1 the randomized move leads to an already solved position)

View differences:

src/main/java/org/distorted/objects/RubikCube.java
158 158
    return QUATS;
159 159
    }
160 160

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
  boolean shouldResetTextureMaps()
164
    {
165
    return false;
166
    }
167

  
161 168
///////////////////////////////////////////////////////////////////////////////////////////////////
162 169

  
163 170
  int getNumFaces()
src/main/java/org/distorted/objects/RubikDino.java
37 37
import org.distorted.library.type.Static1D;
38 38
import org.distorted.library.type.Static3D;
39 39
import org.distorted.library.type.Static4D;
40
import org.distorted.main.RubikSurfaceView;
41 40

  
42 41
import java.util.Random;
43 42

  
......
45 44

  
46 45
///////////////////////////////////////////////////////////////////////////////////////////////////
47 46

  
48
public class RubikDino extends RubikObject
47
public abstract class RubikDino extends RubikObject
49 48
{
50 49
  private static final float SQ2 = (float)Math.sqrt(2);
51 50
  private static final float SQ3 = (float)Math.sqrt(3);
......
75 74
         };
76 75

  
77 76
  // All legal rotation quats of a RubikDino
78
  private static final Static4D[] QUATS = new Static4D[]
77
  static final Static4D[] QUATS = new Static4D[]
79 78
         {
80 79
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
81 80
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
......
108 107
           new Static3D(-1.5f, 0.0f,-1.5f )
109 108
         };
110 109

  
111
  private static final int[] mFaceMap = {4,2, 0,4, 4,3, 1,4,
112
                                         2,0, 3,0, 3,1, 2,1,
113
                                         5,2, 0,5, 5,3, 1,5 };
114

  
115 110
  private static MeshBase mMesh;
116 111

  
117 112
///////////////////////////////////////////////////////////////////////////////////////////////////
118 113

  
119
  RubikDino(int size, Static4D quat, DistortedTexture texture,
120
            MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
114
  RubikDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
115
            DistortedEffects effects, int[][] moves, RubikObjectList obj, Resources res, int scrWidth)
121 116
    {
122
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
117
    super(size, 60, quat, texture, mesh, effects, moves, obj, res, scrWidth);
123 118
    }
124 119

  
125 120
///////////////////////////////////////////////////////////////////////////////////////////////////
......
312 307
    return mesh;
313 308
    }
314 309

  
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

  
317
  int getFaceColor(int cubit, int cubitface, int size)
318
    {
319
    switch(cubitface)
320
      {
321
      case 0 : return mFaceMap[2*cubit];
322
      case 1 : return mFaceMap[2*cubit+1];
323
      default: return NUM_FACES;
324
      }
325
    }
326

  
327 310
///////////////////////////////////////////////////////////////////////////////////////////////////
328 311

  
329 312
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
......
468 451
      }
469 452
    }
470 453

  
471
///////////////////////////////////////////////////////////////////////////////////////////////////
472
// remember about the double cover or unit quaternions!
473

  
474
  private int mulQuat(int q1, int q2)
475
    {
476
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
477

  
478
    float rX = result.get0();
479
    float rY = result.get1();
480
    float rZ = result.get2();
481
    float rW = result.get3();
482

  
483
    final float MAX_ERROR = 0.1f;
484
    float dX,dY,dZ,dW;
485

  
486
    for(int i=0; i<QUATS.length; i++)
487
      {
488
      dX = QUATS[i].get0() - rX;
489
      dY = QUATS[i].get1() - rY;
490
      dZ = QUATS[i].get2() - rZ;
491
      dW = QUATS[i].get3() - rW;
492

  
493
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
494
          dY<MAX_ERROR && dY>-MAX_ERROR &&
495
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
496
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
497

  
498
      dX = QUATS[i].get0() + rX;
499
      dY = QUATS[i].get1() + rY;
500
      dZ = QUATS[i].get2() + rZ;
501
      dW = QUATS[i].get3() + rW;
502

  
503
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
504
          dY<MAX_ERROR && dY>-MAX_ERROR &&
505
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
506
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
507
      }
508

  
509
    return -1;
510
    }
511

  
512
///////////////////////////////////////////////////////////////////////////////////////////////////
513
// Dino is solved if and only if:
514
//
515
// All four 'X' cubits (i.e. those whose longest edge goes along the X axis) are rotated
516
// by the same quaternion qX, similarly all four 'Y' cubits by the same qY and all four 'Z'
517
// by the same qZ, and then either:
518
//
519
// a) qX = qY = qZ
520
// b) qY = qX*Q2 and qZ = qX*Q8  (i.e. swap of WHITE and YELLOW faces)
521
// c) qX = qY*Q2 and qZ = qY*Q10 (i.e. swap of BLUE and GREEN faces)
522
// d) qX = qZ*Q8 and qY = qZ*Q10 (i.e. swap of RED and BROWN faces)
523
//
524
// BUT: cases b), c) and d) are really the same - it's all just a mirror image of the original.
525
//
526
// X cubits: 0, 2, 8, 10
527
// Y cubits: 1, 3, 9, 11
528
// Z cubits: 4, 5, 6, 7
529

  
530
  public boolean isSolved()
531
    {
532
    int qX = CUBITS[0].mQuatIndex;
533
    int qY = CUBITS[1].mQuatIndex;
534
    int qZ = CUBITS[4].mQuatIndex;
535

  
536
    if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX ||
537
        CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY ||
538
        CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ  )
539
      {
540
      return false;
541
      }
542

  
543
    return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
544
    }
545

  
546 454
///////////////////////////////////////////////////////////////////////////////////////////////////
547 455
// only needed for solvers - there are no Dino solvers ATM)
548 456

  
src/main/java/org/distorted/objects/RubikDino4.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube 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
// Magic Cube 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 Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
import android.content.res.Resources;
23

  
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static4D;
28
import org.distorted.main.RubikSurfaceView;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public class RubikDino4 extends RubikDino
33
{
34
  private static final int[] mFaceMap = {4,4, 2,2, 2,2, 4,4,
35
                                         0,0, 2,2, 1,1, 4,4,
36
                                         0,0, 0,0, 1,1, 1,1 };
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  RubikDino4(int size, Static4D quat, DistortedTexture texture,
41
             MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
42
    {
43
    super(size, quat, texture, mesh, effects, moves, RubikObjectList.DIN4, res, scrWidth);
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  int getFaceColor(int cubit, int cubitface, int size)
49
    {
50
    switch(cubitface)
51
      {
52
      case 0 : return mFaceMap[2*cubit];
53
      case 1 : return mFaceMap[2*cubit+1];
54
      default: return NUM_FACES;
55
      }
56
    }
57

  
58
///////////////////////////////////////////////////////////////////////////////////////////////////
59

  
60
  boolean shouldResetTextureMaps()
61
    {
62
    return true;
63
    }
64

  
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66
// Dino4 is solved if and only if the four groups of three same-colored cubits each are rotate with
67
// the same quaternion (actually we need to check only 3 first groups - if those are correct, the
68
// fourth one also needs to be correct).
69
//
70
// White group : 6,10,11
71
// Red group   : 0,3,7
72
// Blue group  : 1,2,5
73
// Yellow group: 4,8,9
74

  
75
  public boolean isSolved()
76
    {
77
    int qR = CUBITS[0].mQuatIndex;
78
    int qB = CUBITS[1].mQuatIndex;
79
    int qY = CUBITS[4].mQuatIndex;
80

  
81
    return (CUBITS[3].mQuatIndex == qR && CUBITS[7].mQuatIndex == qR &&
82
            CUBITS[2].mQuatIndex == qB && CUBITS[5].mQuatIndex == qB &&
83
            CUBITS[8].mQuatIndex == qY && CUBITS[9].mQuatIndex == qY  );
84
    }
85
}
src/main/java/org/distorted/objects/RubikDino6.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube 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
// Magic Cube 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 Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objects;
21

  
22
import android.content.res.Resources;
23

  
24
import org.distorted.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static4D;
28
import org.distorted.main.RubikSurfaceView;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
public class RubikDino6 extends RubikDino
33
{
34
  private static final int[] mFaceMap = {4,2, 0,4, 4,3, 1,4,
35
                                         2,0, 3,0, 3,1, 2,1,
36
                                         5,2, 0,5, 5,3, 1,5 };
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  RubikDino6(int size, Static4D quat, DistortedTexture texture,
41
             MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
42
    {
43
    super(size, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
44
    }
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
  private int mulQuat(int q1, int q2)
49
    {
50
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
51

  
52
    float rX = result.get0();
53
    float rY = result.get1();
54
    float rZ = result.get2();
55
    float rW = result.get3();
56

  
57
    final float MAX_ERROR = 0.1f;
58
    float dX,dY,dZ,dW;
59

  
60
    for(int i=0; i<QUATS.length; i++)
61
      {
62
      dX = QUATS[i].get0() - rX;
63
      dY = QUATS[i].get1() - rY;
64
      dZ = QUATS[i].get2() - rZ;
65
      dW = QUATS[i].get3() - rW;
66

  
67
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
68
          dY<MAX_ERROR && dY>-MAX_ERROR &&
69
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
70
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
71

  
72
      dX = QUATS[i].get0() + rX;
73
      dY = QUATS[i].get1() + rY;
74
      dZ = QUATS[i].get2() + rZ;
75
      dW = QUATS[i].get3() + rW;
76

  
77
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
78
          dY<MAX_ERROR && dY>-MAX_ERROR &&
79
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
80
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
81
      }
82

  
83
    return -1;
84
    }
85

  
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87

  
88
  int getFaceColor(int cubit, int cubitface, int size)
89
    {
90
    switch(cubitface)
91
      {
92
      case 0 : return mFaceMap[2*cubit];
93
      case 1 : return mFaceMap[2*cubit+1];
94
      default: return NUM_FACES;
95
      }
96
    }
97

  
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

  
100
  boolean shouldResetTextureMaps()
101
    {
102
    return false;
103
    }
104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106
// Dino6 is solved if and only if:
107
//
108
// All four 'X' cubits (i.e. those whose longest edge goes along the X axis) are rotated
109
// by the same quaternion qX, similarly all four 'Y' cubits by the same qY and all four 'Z'
110
// by the same qZ, and then either:
111
//
112
// a) qX = qY = qZ
113
// b) qY = qX*Q2 and qZ = qX*Q8  (i.e. swap of WHITE and YELLOW faces)
114
// c) qX = qY*Q2 and qZ = qY*Q10 (i.e. swap of BLUE and GREEN faces)
115
// d) qX = qZ*Q8 and qY = qZ*Q10 (i.e. swap of RED and BROWN faces)
116
//
117
// BUT: cases b), c) and d) are really the same - it's all just a mirror image of the original.
118
//
119
// X cubits: 0, 2, 8, 10
120
// Y cubits: 1, 3, 9, 11
121
// Z cubits: 4, 5, 6, 7
122

  
123
  public boolean isSolved()
124
    {
125
    int qX = CUBITS[0].mQuatIndex;
126
    int qY = CUBITS[1].mQuatIndex;
127
    int qZ = CUBITS[4].mQuatIndex;
128

  
129
    if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX ||
130
        CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY ||
131
        CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ  )
132
      {
133
      return false;
134
      }
135

  
136
    return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
137
    }
138
}
src/main/java/org/distorted/objects/RubikHelicopter.java
484 484
    return QUATS;
485 485
    }
486 486

  
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

  
489
  boolean shouldResetTextureMaps()
490
    {
491
    return false;
492
    }
493

  
487 494
///////////////////////////////////////////////////////////////////////////////////////////////////
488 495

  
489 496
  int getNumFaces()
src/main/java/org/distorted/objects/RubikObject.java
209 209
        CUBITS[i] = new Cubit(this,mOrigPos[i]);
210 210
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
211 211
        }
212

  
213
      if( shouldResetTextureMaps() ) resetAllTextureMaps();
212 214
      }
213 215
    else
214 216
      {
......
694 696
  abstract float returnMultiplier();
695 697
  abstract float[] getRowChances();
696 698
  abstract float getBasicStep();
699
  abstract boolean shouldResetTextureMaps();
697 700

  
698 701
  public abstract boolean isSolved();
699 702
  public abstract Static3D[] getRotationAxis();
src/main/java/org/distorted/objects/RubikObjectList.java
61 61
         new int[][] {
62 62
                       {3 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
63 63
                     },
64
         RubikDino.class,
64
         RubikDino6.class,
65
         new RubikMovementDino(),
66
         2
67
       ),
68

  
69
  DIN4 (
70
         new int[][] {
71
                       {3 ,  7, R.raw.dino, R.drawable.ui_small_din4, R.drawable.ui_medium_din4, R.drawable.ui_big_din4, R.drawable.ui_huge_din4} ,
72
                     },
73
         RubikDino4.class,
65 74
         new RubikMovementDino(),
66 75
         2
67 76
       ),
......
457 466
      {
458 467
      case 0: return new RubikCube      (size, quat, texture, mesh, effects, moves, res, scrWidth);
459 468
      case 1: return new RubikPyraminx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
460
      case 2: return new RubikDino      (size, quat, texture, mesh, effects, moves, res, scrWidth);
461
      case 3: return new RubikSkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
462
      case 4: return new RubikHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
469
      case 2: return new RubikDino6     (size, quat, texture, mesh, effects, moves, res, scrWidth);
470
      case 3: return new RubikDino4     (size, quat, texture, mesh, effects, moves, res, scrWidth);
471
      case 4: return new RubikSkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
472
      case 5: return new RubikHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
463 473
      }
464 474

  
465 475
    return null;
src/main/java/org/distorted/objects/RubikPyraminx.java
249 249
    return 0.82f;
250 250
    }
251 251

  
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253

  
254
  boolean shouldResetTextureMaps()
255
    {
256
    return false;
257
    }
258

  
252 259
///////////////////////////////////////////////////////////////////////////////////////////////////
253 260

  
254 261
  int getFaceColor(int cubit, int cubitface, int size)
src/main/java/org/distorted/objects/RubikSkewb.java
397 397
    return FACE_COLORS.length;
398 398
    }
399 399

  
400
///////////////////////////////////////////////////////////////////////////////////////////////////
401

  
402
  boolean shouldResetTextureMaps()
403
    {
404
    return false;
405
    }
406

  
400 407
///////////////////////////////////////////////////////////////////////////////////////////////////
401 408
// Each face has two types of a texture: the central square and the triangle in the corner.
402 409

  
src/main/java/org/distorted/states/RubikStatePlay.java
219 219
        View popupView = mPlayPopup.getContentView();
220 220
        popupView.setSystemUiVisibility(RubikActivity.FLAGS);
221 221

  
222
        final int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize);
223
        final int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex);
224
        final int levelsShown = Math.min(maxLevel,LEVELS_SHOWN);
225

  
222 226
        mPlayPopup.showAsDropDown(view, margin, margin, Gravity.RIGHT);
223
        mPlayPopup.update(view, mPlayLayoutWidth, (int)(LEVELS_SHOWN*(mMenuItemSize+margin)+margin));
227
        mPlayPopup.update(view, mPlayLayoutWidth, (int)(levelsShown*(mMenuItemSize+margin)+2*margin));
224 228

  
225 229
        mPlayPopup.setFocusable(true);
226 230
        mPlayPopup.update();

Also available in: Unified diff