Project

General

Profile

« Previous | Next » 

Revision e2b9e87e

Added by Leszek Koltunski over 3 years ago

Introduce Square-2 (unfinished)

View differences:

src/main/java/org/distorted/objects/ObjectList.java
222 222
         6,
223 223
         60
224 224
       ),
225

  
226
  SQU2 (
227
         new int[][] {
228
                       {3 , 18, 0, R.drawable.ui_small_diam2, R.drawable.ui_medium_diam2, R.drawable.ui_big_diam2, R.drawable.ui_huge_diam2} ,
229
                     },
230
         TwistySquare2.class,
231
         new MovementSquare(),
232
         6,
233
         60
234
       ),
225 235
  ;
226 236

  
227 237
  public static final int NUM_OBJECTS = values().length;
......
621 631
      case 15: return new TwistyBandagedEvil  (size, quat, texture, mesh, effects, moves, res, scrWidth);
622 632
      case 16: return new TwistyDiamond       (size, quat, texture, mesh, effects, moves, res, scrWidth);
623 633
      case 17: return new TwistySquare1       (size, quat, texture, mesh, effects, moves, res, scrWidth);
634
      case 18: return new TwistySquare2       (size, quat, texture, mesh, effects, moves, res, scrWidth);
624 635
      }
625 636

  
626 637
    return null;
src/main/java/org/distorted/objects/TwistySquare.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.mesh.MeshSquare;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.R;
36

  
37
import java.util.Random;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
abstract class TwistySquare extends TwistyObject
42
{
43
  static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
44
  static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
45
  static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
46
  static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
47

  
48
  static final float COS15 = (SQ6+SQ2)/4;
49
  static final float SIN15 = (SQ6-SQ2)/4;
50
  static final float     X = 3*(2-SQ3)/2;
51

  
52
  static final Static3D[] ROT_AXIS = new Static3D[]
53
    {
54
      new Static3D(0,1,0),
55
      new Static3D(COS15,0,SIN15)
56
    };
57

  
58
  static final int[] BASIC_ANGLE = new int[] { 12,2 };
59

  
60
  static final int[] FACE_COLORS = new int[]
61
    {
62
      COLOR_YELLOW, COLOR_WHITE,
63
      COLOR_BLUE  , COLOR_GREEN,
64
      COLOR_RED   , COLOR_ORANGE
65
    };
66

  
67
  static final Static4D[] QUATS = new Static4D[]
68
    {
69
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
70
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
71
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
72
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
73
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
74
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
75
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
76
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
77
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
78
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
79
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
80
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
81

  
82
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
83
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
84
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
85
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
86
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
87
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
88
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
89
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
90
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
91
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
92
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
93
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
94
    };
95

  
96
  static final double[][] VERTICES_MIDDLE = new double[][]
97
    {
98
      { -1.5-X, 0.5, 1.5 },
99
      {    0.0, 0.5, 1.5 },
100
      {    0.0, 0.5,-1.5 },
101
      { -1.5+X, 0.5,-1.5 },
102
      { -1.5-X,-0.5, 1.5 },
103
      {    0.0,-0.5, 1.5 },
104
      {    0.0,-0.5,-1.5 },
105
      { -1.5+X,-0.5,-1.5 }
106
    };
107

  
108
  static final int[][] VERT_INDEXES_MIDDLE = new int[][]
109
    {
110
      {0,1,2,3},   // counterclockwise!
111
      {4,5,6,7},
112
      {4,5,1,0},
113
      {5,6,2,1},
114
      {6,7,3,2},
115
      {7,4,0,3}
116
    };
117

  
118
  static final double[][] VERTICES_EDGE = new double[][]
119
    {
120
      { -X, 0.5, 0.0 },
121
      { +X, 0.5, 0.0 },
122
      {0.0, 0.5,-1.5 },
123
      { -X,-0.5, 0.0 },
124
      { +X,-0.5, 0.0 },
125
      {0.0,-0.5,-1.5 },
126
    };
127

  
128
  static final int[][] VERT_INDEXES_EDGE = new int[][]
129
    {
130
      {0,1,2},   // counterclockwise!
131
      {3,4,5},
132
      {3,4,1,0},
133
      {4,5,2,1},
134
      {5,3,0,2}
135
    };
136

  
137
  // QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
138
  static final int[][] QUAT_MULT = new int[][]
139
    {
140
      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
141
      {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
142
      {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
143
      {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
144
      {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
145
      {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
146
      {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
147
      {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
148
      {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
149
      {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
150
      { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
151
      { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
152
      { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
153
      { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
154
      { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
155
      { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
156
      { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
157
      { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
158
      { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
159
      { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
160
      { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
161
      { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
162
      { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
163
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
164
    };
165

  
166
  static MeshBase[] mMeshes;
167
  int mLastRot;
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
172
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
173
    {
174
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
175
    }
176

  
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

  
179
  MeshBase createMiddleCubitMesh()
180
    {
181
    if( mMeshes[0]==null )
182
      {
183
      float[][] bands= new float[][]
184
        {
185
           {0.040f,35,0.8f,1.0f,5,2,1},
186
           {0.020f,35,0.8f,1.0f,5,2,1},
187
           {0.001f,35,0.8f,1.0f,5,2,1}
188
        };
189
      int[] bandIndexes   = new int[] { 2,2,1,1,0,2 };
190
      float[][] corners   = new float[][] { {0.03f,0.05f} };
191
      int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
192
      float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
193
      int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
194

  
195
      FactoryCubit factory = FactoryCubit.getInstance();
196
      factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
197
      mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
198
                                              bands, bandIndexes,
199
                                              corners, cornerIndexes,
200
                                              centers, centerIndexes,
201
                                              getNumCubitFaces() );
202
      }
203

  
204
    return mMeshes[0].copy(true);
205
    }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209
  MeshBase createEdgeCubitMesh()
210
    {
211
    if( mMeshes[1]==null )
212
       {
213
       float[][] bands= new float[][]
214
         {
215
           {0.038f,35,0.5f,0.9f, 5,2,1},
216
           {0.001f,35,0.5f,0.9f, 5,2,1}
217
         };
218
       int[] bandIndexes   = new int[] { 0,1,0,1,1 };
219
       float[][] corners   = new float[][] { {0.04f,0.15f} };
220
       int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
221
       float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
222
       int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
223

  
224
       FactoryCubit factory = FactoryCubit.getInstance();
225
       factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
226
       mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
227
                                               bands, bandIndexes,
228
                                               corners, cornerIndexes,
229
                                               centers, centerIndexes,
230
                                               getNumCubitFaces() );
231
       }
232
    return mMeshes[1].copy(true);
233
    }
234

  
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

  
237
  Static4D[] getQuats()
238
    {
239
    return QUATS;
240
    }
241

  
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

  
244
  boolean shouldResetTextureMaps()
245
    {
246
    return false;
247
    }
248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
  int getNumFaces()
252
    {
253
    return FACE_COLORS.length;
254
    }
255

  
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

  
258
  int getNumCubitFaces()
259
    {
260
    return 6;
261
    }
262

  
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

  
265
  float getScreenRatio()
266
    {
267
    return 0.5f;
268
    }
269

  
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

  
272
  float returnMultiplier()
273
    {
274
    return 1.0f;
275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  float[][] getCuts(int numLayers)
280
    {
281
    return new float[][] { {-0.5f,+0.5f}, {0.0f} };
282
    }
283

  
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285
// PUBLIC API
286

  
287
  public Static3D[] getRotationAxis()
288
    {
289
    return ROT_AXIS;
290
    }
291

  
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

  
294
  public int[] getBasicAngle()
295
    {
296
    return BASIC_ANGLE;
297
    }
298

  
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

  
301
  public boolean isSolved()
302
    {
303
    int index = CUBITS[0].mQuatIndex;
304

  
305
    for(int i=1; i<NUM_CUBITS; i++)
306
      {
307
      if( CUBITS[i].mQuatIndex != index ) return false;
308
      }
309

  
310
    return true;
311
    }
312

  
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314
// only needed for solvers - there are no Square solvers ATM)
315

  
316
  public String retObjectString()
317
    {
318
    return "";
319
    }
320

  
321
}
src/main/java/org/distorted/objects/TwistySquare1.java
38 38

  
39 39
///////////////////////////////////////////////////////////////////////////////////////////////////
40 40

  
41
class TwistySquare1 extends TwistyObject
41
class TwistySquare1 extends TwistySquare
42 42
{
43
  private static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
44
  private static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
45
  private static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
46
  private static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
47

  
48
  private static final float COS15 = (SQ6+SQ2)/4;
49
  private static final float SIN15 = (SQ6-SQ2)/4;
50
  private static final float     X = 3*(2-SQ3)/2;
51

  
52
  static final Static3D[] ROT_AXIS = new Static3D[]
53
    {
54
      new Static3D(0,1,0),
55
      new Static3D(COS15,0,SIN15)
56
    };
57

  
58
  private static final int[] BASIC_ANGLE = new int[] { 12,2 };
59

  
60
  private static final int[] FACE_COLORS = new int[]
61
    {
62
      COLOR_YELLOW, COLOR_WHITE,
63
      COLOR_BLUE  , COLOR_GREEN,
64
      COLOR_RED   , COLOR_ORANGE
65
    };
66

  
67
  private static final Static4D[] QUATS = new Static4D[]
68
    {
69
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
70
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
71
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
72
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
73
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
74
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
75
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
76
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
77
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
78
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
79
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
80
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
81

  
82
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
83
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
84
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
85
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
86
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
87
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
88
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
89
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
90
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
91
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
92
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
93
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
94
    };
95

  
96 43
  private static final int[] QUAT_NUMBER = new int[]
97 44
    {
98 45
      0, 6,
......
125 72
      {-1.0f,-1.0f, 2.0f,-2.0f,-1.0f, 1.0f }
126 73
    };
127 74

  
128
  private static final double[][] VERTICES_MIDDLE = new double[][]
129
    {
130
      { -1.5-X, 0.5, 1.5 },
131
      {    0.0, 0.5, 1.5 },
132
      {    0.0, 0.5,-1.5 },
133
      { -1.5+X, 0.5,-1.5 },
134
      { -1.5-X,-0.5, 1.5 },
135
      {    0.0,-0.5, 1.5 },
136
      {    0.0,-0.5,-1.5 },
137
      { -1.5+X,-0.5,-1.5 }
138
    };
139

  
140
  private static final int[][] VERT_INDEXES_MIDDLE = new int[][]
141
    {
142
      {0,1,2,3},   // counterclockwise!
143
      {4,5,6,7},
144
      {4,5,1,0},
145
      {5,6,2,1},
146
      {6,7,3,2},
147
      {7,4,0,3}
148
    };
149

  
150
  private static final double[][] VERTICES_EDGE = new double[][]
151
    {
152
      { -X, 0.5, 0.0 },
153
      { +X, 0.5, 0.0 },
154
      {0.0, 0.5,-1.5 },
155
      { -X,-0.5, 0.0 },
156
      { +X,-0.5, 0.0 },
157
      {0.0,-0.5,-1.5 },
158
    };
159

  
160
  private static final int[][] VERT_INDEXES_EDGE = new int[][]
161
    {
162
      {0,1,2},   // counterclockwise!
163
      {3,4,5},
164
      {3,4,1,0},
165
      {4,5,2,1},
166
      {5,3,0,2}
167
    };
168

  
169 75
  private static final double[][] VERTICES_CORNER = new double[][]
170 76
    {
171 77
      { X-1.5, 0.5,  0.0 },
......
239 145
      { 5,11,14,20},
240 146
    };
241 147

  
242
  // QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
243
  private static final int[][] QUAT_MULT = new int[][]
244
    {
245
      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
246
      {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
247
      {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
248
      {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
249
      {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
250
      {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
251
      {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
252
      {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
253
      {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
254
      {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
255
      { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
256
      { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
257
      { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
258
      { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
259
      { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
260
      { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
261
      { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
262
      { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
263
      { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
264
      { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
265
      { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
266
      { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
267
      { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
268
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
269
    };
270

  
271
  private static MeshBase[] mMeshes;
272

  
273 148
  private final int[][] mPermittedAngles;
274 149
  private final int[] mCornerQuat;
275
  private int mLastRot, mPermittedUp, mPermittedDo;
150
  private int mPermittedUp, mPermittedDo;
276 151

  
277 152
///////////////////////////////////////////////////////////////////////////////////////////////////
278 153

  
279 154
  TwistySquare1(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
280 155
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
281 156
    {
282
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
157
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU1, res, scrWidth);
283 158

  
284 159
    mLastRot = LAST_SL;
285 160
    mPermittedAngles = new int[2][BASIC_ANGLE[0]];
......
293 168
    return QUATS[QUAT_NUMBER[cubit]];
294 169
    }
295 170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
  MeshBase createCornerCubitMesh()
174
    {
175
    if( mMeshes[2]==null )
176
      {
177
      float[][] bands= new float[][]
178
        {
179
          {0.038f,35,0.9f,1.0f, 5,2,1},
180
          {0.001f,35,0.9f,1.0f, 5,2,1}
181
        };
182
      int[] bandIndexes   = new int[] { 0,1,0,0,1,1 };
183
      float[][] corners   = new float[][] { {0.05f,0.13f} };
184
      int[] cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
185
      float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
186
      int[] centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
187

  
188
      FactoryCubit factory = FactoryCubit.getInstance();
189
      factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
190
      mMeshes[2] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
191
                                              bands, bandIndexes,
192
                                              corners, cornerIndexes,
193
                                              centers, centerIndexes,
194
                                              getNumCubitFaces() );
195
      }
196
    return mMeshes[2].copy(true);
197
    }
198

  
296 199
///////////////////////////////////////////////////////////////////////////////////////////////////
297 200

  
298 201
  MeshBase createCubitMesh(int cubit, int numLayers)
......
301 204
      {
302 205
      FactoryCubit factory = FactoryCubit.getInstance();
303 206
      factory.clear();
304
      mMeshes = new MeshBase[3];
207
      mMeshes = new MeshBase[4];
305 208
      }
306 209

  
307 210
    MeshBase mesh;
308 211

  
309
    if( cubit<2 )
310
      {
311
      if( mMeshes[0]==null )
312
        {
313
        float[][] bands= new float[][]
314
          {
315
             {0.040f,35,0.8f,1.0f,5,2,1},
316
             {0.020f,35,0.8f,1.0f,5,2,1},
317
             {0.001f,35,0.8f,1.0f,5,2,1}
318
          };
319
        int[] bandIndexes   = new int[] { 2,2,1,1,0,2 };
320
        float[][] corners   = new float[][] { {0.04f,0.05f} };
321
        int[] cornerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
322
        float[][] centers   = new float[][] { { -0.75f, 0.0f, 0.0f} };
323
        int[] centerIndexes = new int[] { 0,0,0,0,0,0,0,0 };
324

  
325
        FactoryCubit factory = FactoryCubit.getInstance();
326
        factory.createNewFaceTransform(VERTICES_MIDDLE,VERT_INDEXES_MIDDLE);
327
        mMeshes[0] = factory.createRoundedSolid(VERTICES_MIDDLE, VERT_INDEXES_MIDDLE,
328
                                                bands, bandIndexes,
329
                                                corners, cornerIndexes,
330
                                                centers, centerIndexes,
331
                                                getNumCubitFaces() );
332
        }
333
      mesh = mMeshes[0].copy(true);
334
      }
335
    else if( cubit<10 )
336
      {
337
      if( mMeshes[1]==null )
338
        {
339
        float[][] bands= new float[][]
340
          {
341
            {0.038f,35,0.5f,0.9f, 5,2,1},
342
            {0.001f,35,0.5f,0.9f, 5,2,1}
343
          };
344
        int[] bandIndexes   = new int[] { 0,1,0,1,1 };
345
        float[][] corners   = new float[][] { {0.05f,0.20f} };
346
        int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
347
        float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
348
        int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
349

  
350
        FactoryCubit factory = FactoryCubit.getInstance();
351
        factory.createNewFaceTransform(VERTICES_EDGE,VERT_INDEXES_EDGE);
352
        mMeshes[1] = factory.createRoundedSolid(VERTICES_EDGE, VERT_INDEXES_EDGE,
353
                                                bands, bandIndexes,
354
                                                corners, cornerIndexes,
355
                                                centers, centerIndexes,
356
                                                getNumCubitFaces() );
357
        }
358
      mesh = mMeshes[1].copy(true);
359
      }
360
    else
361
      {
362
      if( mMeshes[2]==null )
363
        {
364
        float[][] bands= new float[][]
365
          {
366
            {0.038f,35,0.9f,1.0f, 5,2,1},
367
            {0.001f,35,0.9f,1.0f, 5,2,1}
368
          };
369
        int[] bandIndexes   = new int[] { 0,1,0,0,1,1 };
370
        float[][] corners   = new float[][] { {0.07f,0.20f} };
371
        int[] cornerIndexes = new int[] { 0,0,0,-1,0,0,0,-1 };
372
        float[][] centers   = new float[][] { { -0.5f, 0.0f,-0.5f} };
373
        int[] centerIndexes = new int[] { -1,0,-1,-1,-1,0,-1,-1 };
374

  
375
        FactoryCubit factory = FactoryCubit.getInstance();
376
        factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
377
        mMeshes[2] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
378
                                                bands, bandIndexes,
379
                                                corners, cornerIndexes,
380
                                                centers, centerIndexes,
381
                                                getNumCubitFaces() );
382
        }
383
      mesh = mMeshes[2].copy(true);
384
      }
212
         if( cubit< 2 ) mesh = createMiddleCubitMesh();
213
    else if( cubit<10 ) mesh = createEdgeCubitMesh();
214
    else                mesh = createCornerCubitMesh();
385 215

  
386 216
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
387 217
    mesh.apply(quat,0xffffffff,0);
......
419 249
    return CENTERS;
420 250
    }
421 251

  
422
///////////////////////////////////////////////////////////////////////////////////////////////////
423

  
424
  Static4D[] getQuats()
425
    {
426
    return QUATS;
427
    }
428

  
429
///////////////////////////////////////////////////////////////////////////////////////////////////
430

  
431
  boolean shouldResetTextureMaps()
432
    {
433
    return false;
434
    }
435

  
436
///////////////////////////////////////////////////////////////////////////////////////////////////
437

  
438
  int getNumFaces()
439
    {
440
    return FACE_COLORS.length;
441
    }
442

  
443 252
///////////////////////////////////////////////////////////////////////////////////////////////////
444 253

  
445 254
  int getNumStickerTypes(int numLayers)
......
447 256
    return STICKERS.length;
448 257
    }
449 258

  
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451

  
452
  int getNumCubitFaces()
453
    {
454
    return 6;
455
    }
456

  
457
///////////////////////////////////////////////////////////////////////////////////////////////////
458

  
459
  float getScreenRatio()
460
    {
461
    return 0.5f;
462
    }
463

  
464 259
///////////////////////////////////////////////////////////////////////////////////////////////////
465 260

  
466 261
  int getFaceColor(int cubit, int cubitface, int numLayers)
......
474 269
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
475 270
    }
476 271

  
477
///////////////////////////////////////////////////////////////////////////////////////////////////
478

  
479
  float returnMultiplier()
480
    {
481
    return 1.0f;
482
    }
483

  
484
///////////////////////////////////////////////////////////////////////////////////////////////////
485

  
486
  float[][] getCuts(int numLayers)
487
    {
488
    return new float[][] { {-0.5f,+0.5f}, {0.0f} };
489
    }
490

  
491 272
///////////////////////////////////////////////////////////////////////////////////////////////////
492 273
// this implements the fact that corner cubits have multiple 'centers' and this means the cubit
493 274
// might span more than one layer along a given axis - i.e. that this is a bandaged puzzle.
......
709 490
///////////////////////////////////////////////////////////////////////////////////////////////////
710 491
// PUBLIC API
711 492

  
712
  public Static3D[] getRotationAxis()
713
    {
714
    return ROT_AXIS;
715
    }
716

  
717
///////////////////////////////////////////////////////////////////////////////////////////////////
718

  
719
  public int[] getBasicAngle()
720
    {
721
    return BASIC_ANGLE;
722
    }
723

  
724
///////////////////////////////////////////////////////////////////////////////////////////////////
725

  
726 493
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
727 494
    {
728 495
    int layer, nextAngle;
......
791 558
      }
792 559
    }
793 560

  
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795

  
796
  public boolean isSolved()
797
    {
798
    int index = CUBITS[0].mQuatIndex;
799

  
800
    for(int i=1; i<NUM_CUBITS; i++)
801
      {
802
      if( CUBITS[i].mQuatIndex != index ) return false;
803
      }
804

  
805
    return true;
806
    }
807

  
808
///////////////////////////////////////////////////////////////////////////////////////////////////
809
// only needed for solvers - there are no Square solvers ATM)
810

  
811
  public String retObjectString()
812
    {
813
    return "";
814
    }
815

  
816 561
///////////////////////////////////////////////////////////////////////////////////////////////////
817 562

  
818 563
  public int getObjectName(int numLayers)
src/main/java/org/distorted/objects/TwistySquare2.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.mesh.MeshSquare;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.R;
36

  
37
import java.util.Random;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
class TwistySquare2 extends TwistySquare
42
{
43
  private static final float Y = 0.75f + X/2;
44
  private static final float Z = 0.75f - X/2;
45

  
46
  private static final int[] QUAT_NUMBER = new int[]
47
    {
48
      0, 6,
49
      0, 9, 6, 3, 18, 15, 12, 21,
50
      0, 9, 6, 3, 15, 12, 21, 18,
51
      0, 9, 6, 3, 15, 12, 21, 18
52
    };
53

  
54
  // centers of the 2 middles + 8 edges + 8 left corners + 8 right corners
55
  private static final float[][] CENTERS = new float[][]
56
    {
57
      { 1.5f, 0.0f, 0.0f },
58
      {-1.5f, 0.0f, 0.0f },
59

  
60
      { 0.0f, 1.0f, 1.5f },
61
      { 1.5f, 1.0f, 0.0f },
62
      { 0.0f, 1.0f,-1.5f },
63
      {-1.5f, 1.0f, 0.0f },
64
      { 0.0f,-1.0f, 1.5f },
65
      { 1.5f,-1.0f, 0.0f },
66
      { 0.0f,-1.0f,-1.5f },
67
      {-1.5f,-1.0f, 0.0f },
68

  
69
      {    Y, 1.0f, 1.5f },
70
      { 1.5f, 1.0f,   -Y },
71
      {   -Y, 1.0f,-1.5f },
72
      {-1.5f, 1.0f,    Y },
73
      {    Y,-1.0f, 1.5f },
74
      { 1.5f,-1.0f,   -Y },
75
      {   -Y,-1.0f,-1.5f },
76
      {-1.5f,-1.0f,    Y },
77

  
78
      { 1.5f, 1.0f,    Y },
79
      {    Y, 1.0f,-1.5f },
80
      {-1.5f, 1.0f,   -Y },
81
      {   -Y, 1.0f, 1.5f },
82
      { 1.5f,-1.0f,    Y },
83
      {    Y,-1.0f,-1.5f },
84
      {-1.5f,-1.0f,   -Y },
85
      {   -Y,-1.0f, 1.5f },
86
    };
87

  
88
  private static final double[][] VERTICES_CORNER = new double[][]
89
    {
90
      { X-1.5+Z, 0.5,  0.0 },
91
      {       Z, 0.5,  0.0 },
92
      {  -1.5+Z, 0.5, -1.5 },
93
      { X-1.5+Z,-0.5,  0.0 },
94
      {       Z,-0.5,  0.0 },
95
      {  -1.5+Z,-0.5, -1.5 }
96
    };
97

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

  
107
  private static final float[][] STICKERS = new float[][]
108
    {
109
      { -0.5f, -0.26289170f, 0.5f, -0.26289170f, 0.5f, 0.26289170f, -0.5f, 0.26289170f }, // middle front
110
      { -0.5f, -0.16666667f, 0.5f, -0.16666667f, 0.5f, 0.16666667f, -0.5f, 0.16666667f }, // middle right
111
      { -0.5f, -0.45534182f, 0.5f, -0.45534182f, 0.5f, 0.45534182f, -0.5f, 0.45534182f }, // middle back
112
      { -0.20096192f, -0.25f, 0.20096192f, -0.25f, 0.0f, 0.5f },                          // edge top
113
      { -0.40192384f, -0.5f, 0.40192384f, -0.5f, 0.40192384f, 0.5f, -0.40192384f, 0.5f }, // edge face
114
      { -0.11602539f, -0.25f, 0.4330127f, -0.25f, -0.3169873f, 0.5f }                     // corner top
115
    };
116

  
117
  private static final int NUM_ST = STICKERS.length;
118

  
119
  private static final int[][] mStickerType = new int[][]
120
    {
121
      {  NUM_ST,NUM_ST,0,     1,     2,NUM_ST },
122
      {       3,NUM_ST,4,NUM_ST,NUM_ST,NUM_ST },
123
      {       5,NUM_ST,2,NUM_ST,NUM_ST,NUM_ST },
124
      {  NUM_ST,     5,2,NUM_ST,NUM_ST,NUM_ST }
125
    };
126

  
127
  // YELLOW 0 WHITE 1 BLUE 2 GREEN 3 RED 4 ORANGE 5
128
  private static final int[][] mStickerColor = new int[][]
129
    {
130
      { 0, 0, 4, 0, 5, 0 }, // 0
131
      { 0, 0, 5, 1, 4, 0 },
132

  
133
      { 2, 0, 4, 0, 0, 0 }, // 2
134
      { 2, 0, 0, 0, 0, 0 },
135
      { 2, 0, 5, 0, 0, 0 },
136
      { 2, 0, 1, 0, 0, 0 },
137
      { 3, 0, 4, 0, 0, 0 },
138
      { 3, 0, 0, 0, 0, 0 },
139
      { 3, 0, 5, 0, 0, 0 },
140
      { 3, 0, 1, 0, 0, 0 },
141

  
142
      { 2, 0, 4, 0, 0, 0 }, // 10
143
      { 2, 0, 0, 0, 0, 0 },
144
      { 2, 0, 5, 0, 0, 0 },
145
      { 2, 0, 1, 0, 0, 0 },
146
      { 0, 3, 4, 0, 0, 0 },
147
      { 0, 3, 0, 0, 0, 0 },
148
      { 0, 3, 5, 0, 0, 0 },
149
      { 0, 3, 1, 0, 0, 0 },
150

  
151
      { 0, 2, 4, 0, 0, 0 }, // 18
152
      { 0, 2, 0, 0, 0, 0 },
153
      { 0, 2, 5, 0, 0, 0 },
154
      { 0, 2, 1, 0, 0, 0 },
155
      { 3, 0, 0, 0, 0, 0 },
156
      { 3, 0, 5, 0, 0, 0 },
157
      { 3, 0, 1, 0, 0, 0 },
158
      { 3, 0, 4, 0, 0, 0 },
159
    };
160

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

  
163
  TwistySquare2(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
164
                DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
165
    {
166
    super(size, quat, texture, mesh, effects, moves, ObjectList.SQU2, res, scrWidth);
167

  
168
    FactoryCubit factory = FactoryCubit.getInstance();
169
    factory.printStickerCoords();
170
    }
171

  
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

  
174
  private Static4D getQuat(int cubit)
175
    {
176
    if( (cubit>=0 && cubit<=13) || (cubit>=22))
177
      {
178
      return QUATS[QUAT_NUMBER[cubit]];
179
      }
180
    else
181
      {
182
      return QUATS[0];
183
      }
184
    }
185

  
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

  
188
  MeshBase createCornerCubitMesh()
189
    {
190
    if( mMeshes[3]==null )
191
      {
192
      float[][] bands= new float[][]
193
        {
194
          {0.038f,35,0.9f,1.0f, 5,2,1},
195
          {0.001f,35,0.9f,1.0f, 5,2,1}
196
        };
197
      int[] bandIndexes   = new int[] { 0,1,0,1,1 };
198
      float[][] corners   = new float[][] { {0.05f,0.13f} };
199
      int[] cornerIndexes = new int[] { 0,0,-1,0,0,-1 };
200
      float[][] centers   = new float[][] { { 0.0f, 0.0f,-0.5f} };
201
      int[] centerIndexes = new int[] { 0,0,-1,0,0,-1 };
202

  
203
      FactoryCubit factory = FactoryCubit.getInstance();
204
      factory.createNewFaceTransform(VERTICES_CORNER,VERT_INDEXES_CORNER);
205
      mMeshes[3] = factory.createRoundedSolid(VERTICES_CORNER, VERT_INDEXES_CORNER,
206
                                              bands, bandIndexes,
207
                                              corners, cornerIndexes,
208
                                              centers, centerIndexes,
209
                                              getNumCubitFaces() );
210
      }
211
    return mMeshes[3].copy(true);
212
    }
213

  
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

  
216
  MeshBase createCubitMesh(int cubit, int numLayers)
217
    {
218
    if( mMeshes==null )
219
      {
220
      FactoryCubit factory = FactoryCubit.getInstance();
221
      factory.clear();
222
      mMeshes = new MeshBase[4];
223
      }
224

  
225
    MeshBase mesh;
226

  
227
         if( cubit< 2 ) mesh = createMiddleCubitMesh();
228
    else if( cubit<10 ) mesh = createEdgeCubitMesh();
229
    else                mesh = createCornerCubitMesh();
230

  
231
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
232
    mesh.apply(quat,0xffffffff,0);
233

  
234
    return mesh;
235
    }
236

  
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

  
239
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
240
    {
241
    int COLORS = FACE_COLORS.length;
242
    int stickerType = face/COLORS;
243
    float R,S;
244

  
245
    switch(stickerType)
246
      {
247
      case 0:  R = 0.060f; S = 0.05f; break;
248
      case 1:  R = 0.040f; S = 0.04f; break;
249
      case 2:  R = 0.110f; S = 0.09f; break;
250
      case 3:  R = 0.030f; S = 0.05f; break;
251
      case 4:  R = 0.110f; S = 0.08f; break;
252
      case 5:  R = 0.025f; S = 0.06f; break;
253
      default: R = 0.000f; S = 0.00f; break;
254
      }
255

  
256
    FactorySticker factory = FactorySticker.getInstance();
257
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[stickerType], S, FACE_COLORS[face%COLORS], R);
258
    }
259

  
260
///////////////////////////////////////////////////////////////////////////////////////////////////
261

  
262
  float[][] getCubitPositions(int numLayers)
263
    {
264
    return CENTERS;
265
    }
266

  
267
///////////////////////////////////////////////////////////////////////////////////////////////////
268

  
269
  int getNumStickerTypes(int numLayers)
270
    {
271
    return STICKERS.length;
272
    }
273

  
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

  
276
  int getFaceColor(int cubit, int cubitface, int numLayers)
277
    {
278
    int type;
279

  
280
         if( cubit< 2             ) type = 0;
281
    else if( cubit<10             ) type = 1;
282
    else if( cubit>13 && cubit<22 ) type = 3;
283
    else                            type = 2;
284

  
285
    return mStickerType[type][cubitface]*FACE_COLORS.length + mStickerColor[cubit][cubitface];
286
    }
287

  
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289
// PUBLIC API
290

  
291
  public void randomizeNewScramble(int[][] scramble, Random rnd, int num)
292
    {
293
    int layer, nextAngle;
294

  
295
    if( num==0 ) mLastRot = rnd.nextInt(4);
296

  
297
    switch(mLastRot)
298
      {
299
      case LAST_SL: layer = rnd.nextInt(2);
300
                    nextAngle = rnd.nextInt(12)-6;
301

  
302
                    if( nextAngle==0 )
303
                      {
304
                      layer = 1-layer;
305
                      nextAngle = (2*rnd.nextInt(2)-1)*(rnd.nextInt(5)+1);
306
                      }
307

  
308
                    scramble[num][0] = 0;
309
                    scramble[num][1] = 2*layer;
310
                    scramble[num][2] = nextAngle;
311
                    mLastRot = layer==0 ? LAST_LO : LAST_UP;
312
                    break;
313
      case LAST_LO:
314
      case LAST_UP: layer = mLastRot==LAST_LO ? 1:0;
315
                    nextAngle = rnd.nextInt(12)-6;
316

  
317
                    if( nextAngle!=0 )
318
                      {
319
                      scramble[num][0] = 0;
320
                      scramble[num][1] = 2*layer;
321
                      scramble[num][2] = nextAngle;
322
                      mLastRot = LAST_UL;
323
                      }
324
                    else
325
                      {
326
                      scramble[num][0] = 1;
327
                      scramble[num][1] = rnd.nextInt(2);
328
                      scramble[num][2] = 1;
329
                      mLastRot = LAST_SL;
330
                      }
331
                    break;
332
      case LAST_UL: scramble[num][0] = 1;
333
                    scramble[num][1] = rnd.nextInt(2);
334
                    scramble[num][2] = 1;
335
                    mLastRot = LAST_SL;
336
                    break;
337
      }
338
    }
339

  
340
///////////////////////////////////////////////////////////////////////////////////////////////////
341

  
342
  public int getObjectName(int numLayers)
343
    {
344
    return R.string.squa2;
345
    }
346

  
347
///////////////////////////////////////////////////////////////////////////////////////////////////
348

  
349
  public int getInventor(int numLayers)
350
    {
351
    return R.string.squa2_inventor;
352
    }
353

  
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

  
356
  public int getComplexity(int numLayers)
357
    {
358
    return 7;
359
    }
360
}

Also available in: Unified diff