Project

General

Profile

Download (41.4 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 81141862

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.objectlib.main;
21

    
22
import android.content.SharedPreferences;
23
import android.content.res.Resources;
24
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27

    
28
import com.google.firebase.crashlytics.FirebaseCrashlytics;
29

    
30
import org.distorted.library.effect.Effect;
31
import org.distorted.library.effect.MatrixEffectMove;
32
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectQuaternion;
35
import org.distorted.library.effect.VertexEffectRotate;
36
import org.distorted.library.main.DistortedEffects;
37
import org.distorted.library.main.DistortedLibrary;
38
import org.distorted.library.main.DistortedNode;
39
import org.distorted.library.main.DistortedTexture;
40
import org.distorted.library.main.QuatHelper;
41
import org.distorted.library.mesh.MeshBase;
42
import org.distorted.library.mesh.MeshFile;
43
import org.distorted.library.mesh.MeshJoined;
44
import org.distorted.library.mesh.MeshSquare;
45
import org.distorted.library.message.EffectListener;
46
import org.distorted.library.type.Dynamic1D;
47
import org.distorted.library.type.Static1D;
48
import org.distorted.library.type.Static3D;
49
import org.distorted.library.type.Static4D;
50
import org.distorted.objectlib.BuildConfig;
51
import org.distorted.objectlib.helpers.FactoryCubit;
52
import org.distorted.objectlib.helpers.FactorySticker;
53
import org.distorted.objectlib.helpers.ObjectShape;
54
import org.distorted.objectlib.helpers.ObjectSticker;
55
import org.distorted.objectlib.helpers.ScrambleState;
56

    
57
import java.io.DataInputStream;
58
import java.io.IOException;
59
import java.io.InputStream;
60
import java.util.Random;
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
public abstract class TwistyObject extends DistortedNode
65
  {
66
  public static final int COLOR_YELLOW = 0xffffff00;
67
  public static final int COLOR_WHITE  = 0xffffffff;
68
  public static final int COLOR_BLUE   = 0xff0000ff;
69
  public static final int COLOR_GREEN  = 0xff00bb00;
70
  public static final int COLOR_RED    = 0xff990000;
71
  public static final int COLOR_ORANGE = 0xffff6200;
72
  public static final int COLOR_GREY   = 0xff727c7b;
73
  public static final int COLOR_VIOLET = 0xff7700bb;
74
  public static final int COLOR_BLACK  = 0xff000000;
75

    
76
  public static final int TEXTURE_HEIGHT = 256;
77
  static final int NUM_STICKERS_IN_ROW = 4;
78

    
79
  public static final float SQ2 = (float)Math.sqrt(2);
80
  public static final float SQ3 = (float)Math.sqrt(3);
81
  public static final float SQ5 = (float)Math.sqrt(5);
82
  public static final float SQ6 = (float)Math.sqrt(6);
83

    
84
  private static final float NODE_RATIO = 1.60f;
85
  private static final float MAX_SIZE_CHANGE = 1.35f;
86
  private static final float MIN_SIZE_CHANGE = 0.75f;
87

    
88
  private static final Static3D CENTER = new Static3D(0,0,0);
89
  private static final int POST_ROTATION_MILLISEC = 500;
90

    
91
  protected final int NUM_FACE_COLORS;
92
  protected final int NUM_TEXTURES;
93
  protected final Cubit[] CUBITS;
94

    
95
  MeshBase[] mMeshes;
96
  final Static4D[] OBJECT_QUATS;
97
  final int NUM_CUBITS;
98
  final int NUM_AXIS;
99
  final int NUM_QUATS;
100

    
101
  private final int mNumCubitFaces;
102
  private final Static3D[] mAxis;
103
  private final float[][] mCuts;
104
  private final int[] mNumCuts;
105
  private final int mNodeSize;
106
  private final float[][] mOrigPos;
107
  private final Static3D mNodeScale;
108
  private final Static4D mQuat;
109
  private final int mNumLayers, mRealSize;
110
  private final DistortedEffects mEffects;
111
  private final VertexEffectRotate mRotateEffect;
112
  private final Dynamic1D mRotationAngle;
113
  private final Static3D mRotationAxis;
114
  private final Static3D mObjectScale;
115
  private final int[] mQuatDebug;
116
  private final float mCameraDist;
117
  private final Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
118
  private final DistortedTexture mTexture;
119
  private final float mInitScreenRatio;
120
  private final int mSolvedFunctionIndex;
121
  private final boolean mIsBandaged;
122
  private float mObjectScreenRatio;
123
  private int[][] mSolvedQuats;
124
  private int[][] mQuatMult;
125
  private int[] mTmpQuats;
126
  private int mNumTexRows, mNumTexCols;
127
  private int mRotRowBitmap;
128
  private int mRotAxis;
129
  private MeshBase mMesh;
130
  private final TwistyObjectScrambler mScrambler;
131

    
132
  //////////////////// SOLVED1 ////////////////////////
133

    
134
  private int[] mFaceMap;
135
  private int[][] mScramble;
136
  private int[] mColors;
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  TwistyObject(int numLayers, int realSize, Static4D quat, DistortedTexture nodeTexture,
141
               MeshSquare nodeMesh, DistortedEffects nodeEffects, Resources res, int screenWidth)
142
    {
143
    super(nodeTexture,nodeEffects,nodeMesh);
144

    
145
    mNodeSize = screenWidth;
146

    
147
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
148

    
149
    mNumLayers = numLayers;
150
    mRealSize = realSize;
151
    mOrigPos = getCubitPositions(mNumLayers);
152
    mAxis = getRotationAxis();
153
    mInitScreenRatio = getScreenRatio();
154
    mObjectScreenRatio = 1.0f;
155
    mNumCubitFaces = getNumCubitFaces();
156
    mSolvedFunctionIndex = getSolvedFunctionIndex();
157

    
158
    mCuts = getCuts(mNumLayers);
159
    mNumCuts = new int[mAxis.length];
160
    if( mCuts==null ) for(int i=0; i<mAxis.length; i++) mNumCuts[i] = 0;
161
    else              for(int i=0; i<mAxis.length; i++) mNumCuts[i] = mCuts[i].length;
162

    
163
    OBJECT_QUATS = getQuats();
164
    NUM_CUBITS  = mOrigPos.length;
165
    NUM_FACE_COLORS = getNumFaceColors();
166
    NUM_TEXTURES = getNumStickerTypes(mNumLayers)*NUM_FACE_COLORS;
167
    NUM_AXIS = mAxis.length;
168
    NUM_QUATS = OBJECT_QUATS.length;
169

    
170
    int scramblingType = getScrambleType();
171
    ScrambleState[] states = getScrambleStates();
172
    mScrambler = new TwistyObjectScrambler(scramblingType,NUM_AXIS,numLayers,states);
173

    
174
    boolean bandaged=false;
175

    
176
    for(int c=0; c<NUM_CUBITS; c++)
177
      {
178
      if( mOrigPos[c].length>3 )
179
        {
180
        bandaged=true;
181
        break;
182
        }
183
      }
184

    
185
    mIsBandaged = bandaged;
186

    
187
    mQuatDebug = new int[NUM_CUBITS];
188

    
189
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
190
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
191

    
192
    mNodeScale= new Static3D(screenWidth,NODE_RATIO*screenWidth,screenWidth);
193
    mQuat = quat;
194

    
195
    mRotationAngle= new Dynamic1D();
196
    mRotationAxis = new Static3D(1,0,0);
197
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
198

    
199
    mRotationAngleStatic = new Static1D(0);
200
    mRotationAngleMiddle = new Static1D(0);
201
    mRotationAngleFinal  = new Static1D(0);
202

    
203
    float scale  = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
204
    mObjectScale = new Static3D(scale,scale,scale);
205
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
206
    MatrixEffectQuaternion quatEffect  = new MatrixEffectQuaternion(quat, CENTER);
207

    
208
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
209
    nodeEffects.apply(nodeScaleEffect);
210

    
211
    mNumTexCols = NUM_STICKERS_IN_ROW;
212
    mNumTexRows = (NUM_TEXTURES+1)/NUM_STICKERS_IN_ROW;
213

    
214
    if( mNumTexCols*mNumTexRows < NUM_TEXTURES+1 ) mNumTexRows++;
215

    
216
    CUBITS = new Cubit[NUM_CUBITS];
217
    createMeshAndCubits(res);
218
    createDataStructuresForSolved(numLayers);
219

    
220
    mTexture = new DistortedTexture();
221
    mEffects = new DistortedEffects();
222

    
223
    createTexture();
224

    
225
    for(int q=0; q<NUM_QUATS; q++)
226
      {
227
      VertexEffectQuaternion vq = new VertexEffectQuaternion(OBJECT_QUATS[q],CENTER);
228
      vq.setMeshAssociation(0,q);
229
      mEffects.apply(vq);
230
      }
231

    
232
    mEffects.apply(mRotateEffect);
233
    mEffects.apply(quatEffect);
234
    mEffects.apply(scaleEffect);
235

    
236
    // Now postprocessed effects (the glow when you solve an object) require component centers. In
237
    // order for the effect to be in front of the object, we need to set the center to be behind it.
238
    getMesh().setComponentCenter(0,0,0,-0.1f);
239

    
240
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
241

    
242
    float fov = getFOV();
243
    double halfFOV = fov * (Math.PI/360);
244
    mCameraDist = 0.5f*NODE_RATIO / (float)Math.tan(halfFOV);
245

    
246
    setProjection( fov, 0.1f);
247
    }
248

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

    
251
  private Static3D getPos(float[] origPos)
252
    {
253
    int len = origPos.length/3;
254
    float sumX = 0.0f;
255
    float sumY = 0.0f;
256
    float sumZ = 0.0f;
257

    
258
    for(int i=0; i<len; i++)
259
      {
260
      sumX += origPos[3*i  ];
261
      sumY += origPos[3*i+1];
262
      sumZ += origPos[3*i+2];
263
      }
264

    
265
    sumX /= len;
266
    sumY /= len;
267
    sumZ /= len;
268

    
269
    return new Static3D(sumX,sumY,sumZ);
270
    }
271

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

    
274
  private void createMeshAndCubits(Resources res)
275
    {
276
    int resourceID= getResource(mNumLayers);
277

    
278
    if( resourceID!=0 )
279
      {
280
      InputStream is = res.openRawResource(resourceID);
281
      DataInputStream dos = new DataInputStream(is);
282
      mMesh = new MeshFile(dos);
283

    
284
      try
285
        {
286
        is.close();
287
        }
288
      catch(IOException e)
289
        {
290
        android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
291
        }
292

    
293
      for(int i=0; i<NUM_CUBITS; i++)
294
        {
295
        CUBITS[i] = new Cubit(this,mOrigPos[i], NUM_AXIS);
296
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
297
        }
298

    
299
      if( shouldResetTextureMaps() ) resetAllTextureMaps();
300
      }
301
    else
302
      {
303
      MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS];
304

    
305
      for(int i=0; i<NUM_CUBITS; i++)
306
        {
307
        CUBITS[i] = new Cubit(this,mOrigPos[i], NUM_AXIS);
308
        cubitMesh[i] = createCubitMesh(i,mNumLayers);
309
        Static3D pos = getPos(mOrigPos[i]);
310
        cubitMesh[i].apply(new MatrixEffectMove(pos),1,0);
311
        cubitMesh[i].setEffectAssociation(0, CUBITS[i].computeAssociation(), 0);
312
        }
313

    
314
      mMesh = new MeshJoined(cubitMesh);
315
      resetAllTextureMaps();
316
      }
317
    }
318

    
319
///////////////////////////////////////////////////////////////////////////////////////////////////
320

    
321
  private MeshBase createCubitMesh(int cubit, int numLayers)
322
    {
323
    int variant = getCubitVariant(cubit,numLayers);
324

    
325
    if( mMeshes==null )
326
      {
327
      FactoryCubit factory = FactoryCubit.getInstance();
328
      factory.clear();
329
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
330
      }
331

    
332
    if( mMeshes[variant]==null )
333
      {
334
      ObjectShape shape = getObjectShape(cubit,numLayers);
335
      FactoryCubit factory = FactoryCubit.getInstance();
336
      factory.createNewFaceTransform(shape);
337
      mMeshes[variant] = factory.createRoundedSolid(shape);
338
      }
339

    
340
    MeshBase mesh = mMeshes[variant].copy(true);
341
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
342
    mesh.apply(quat,0xffffffff,0);
343

    
344
    return mesh;
345
    }
346

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

    
349
  private void createDataStructuresForSolved(int numLayers)
350
    {
351
    mTmpQuats = new int[NUM_QUATS];
352
    mSolvedQuats = new int[NUM_CUBITS][];
353

    
354
    for(int c=0; c<NUM_CUBITS; c++)
355
      {
356
      mSolvedQuats[c] = getSolvedQuats(c,numLayers);
357
      }
358
    }
359

    
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

    
362
  private int getMultQuat(int index1, int index2)
363
    {
364
    if( mQuatMult==null )
365
      {
366
      mQuatMult = new int[NUM_QUATS][NUM_QUATS];
367

    
368
      for(int i=0; i<NUM_QUATS; i++)
369
        for(int j=0; j<NUM_QUATS; j++) mQuatMult[i][j] = -1;
370
      }
371

    
372
    if( mQuatMult[index1][index2]==-1 )
373
      {
374
      mQuatMult[index1][index2] = mulQuat(index1,index2);
375
      }
376

    
377
    return mQuatMult[index1][index2];
378
    }
379

    
380
///////////////////////////////////////////////////////////////////////////////////////////////////
381
// This is used to build internal data structures for the generic 'isSolved()'
382
//
383
// if this is an internal cubit (all faces black): return -1
384
// if this is a face cubit (one non-black face): return the color index of the only non-black face.
385
// Color index, i.e. the index into the 'FACE_COLORS' table.
386
// else (edge or corner cubit, more than one non-black face): return -2.
387

    
388
  protected int retCubitSolvedStatus(int cubit, int numLayers)
389
    {
390
    int numNonBlack=0, nonBlackIndex=-1, color;
391

    
392
    for(int face=0; face<mNumCubitFaces; face++)
393
      {
394
      color = getFaceColor(cubit,face,numLayers);
395

    
396
      if( color<NUM_TEXTURES )
397
        {
398
        numNonBlack++;
399
        nonBlackIndex = color%NUM_FACE_COLORS;
400
        }
401
      }
402

    
403
    if( numNonBlack==0 ) return -1;
404
    if( numNonBlack>=2 ) return -2;
405

    
406
    return nonBlackIndex;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

    
411
  protected boolean shouldResetTextureMaps()
412
    {
413
    return false;
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
  protected int[] buildSolvedQuats(Static3D faceAx, Static4D[] quats)
419
    {
420
    final float MAXD = 0.0001f;
421
    float x = faceAx.get0();
422
    float y = faceAx.get1();
423
    float z = faceAx.get2();
424
    float a,dx,dy,dz,qx,qy,qz;
425
    Static4D quat;
426

    
427
    int len = quats.length;
428
    int place = 0;
429

    
430
    for(int q=1; q<len; q++)
431
      {
432
      quat = quats[q];
433
      qx = quat.get0();
434
      qy = quat.get1();
435
      qz = quat.get2();
436

    
437
           if( x!=0.0f ) { a = qx/x; }
438
      else if( y!=0.0f ) { a = qy/y; }
439
      else               { a = qz/z; }
440

    
441
      dx = a*x-qx;
442
      dy = a*y-qy;
443
      dz = a*z-qz;
444

    
445
      if( dx>-MAXD && dx<MAXD && dy>-MAXD && dy<MAXD && dz>-MAXD && dz<MAXD )
446
        {
447
        mTmpQuats[place++] = q;
448
        }
449
      }
450

    
451
    if( place!=0 )
452
      {
453
      int[] ret = new int[place];
454
      System.arraycopy(mTmpQuats,0,ret,0,place);
455
      return ret;
456
      }
457

    
458
    return null;
459
    }
460

    
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462

    
463
  private boolean isSolved0()
464
    {
465
    int len, q1,q = CUBITS[0].mQuatIndex;
466
    int[] solved;
467
    boolean skip;
468

    
469
    for(int c=1; c<NUM_CUBITS; c++)
470
      {
471
      q1 = CUBITS[c].mQuatIndex;
472

    
473
      if( q1==q ) continue;
474

    
475
      skip = false;
476
      solved = mSolvedQuats[c];
477
      len = solved==null ? 0:solved.length;
478

    
479
      for(int i=0; i<len; i++)
480
        {
481
        if( q1==getMultQuat(q,solved[i]) )
482
          {
483
          skip = true;
484
          break;
485
          }
486
        }
487

    
488
      if( !skip ) return false;
489
      }
490

    
491
    return true;
492
    }
493

    
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

    
496
  private int computeScramble(int quatNum, int centerNum)
497
    {
498
    float MAXDIFF = 0.01f;
499
    float[] center= mOrigPos[centerNum];
500
    Static4D sc = new Static4D(center[0], center[1], center[2], 1.0f);
501
    Static4D result = QuatHelper.rotateVectorByQuat(sc,OBJECT_QUATS[quatNum]);
502

    
503
    float x = result.get0();
504
    float y = result.get1();
505
    float z = result.get2();
506

    
507
    for(int c=0; c<NUM_CUBITS; c++)
508
      {
509
      float[] cent = mOrigPos[c];
510

    
511
      float qx = cent[0] - x;
512
      float qy = cent[1] - y;
513
      float qz = cent[2] - z;
514

    
515
      if( qx>-MAXDIFF && qx<MAXDIFF &&
516
          qy>-MAXDIFF && qy<MAXDIFF &&
517
          qz>-MAXDIFF && qz<MAXDIFF  ) return c;
518
      }
519

    
520
    return -1;
521
    }
522

    
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
// Dino4 uses this. It is solved if and only if groups of cubits
525
// (0,3,7), (1,2,5), (4,8,9), (6,10,11)
526
// or
527
// (0,1,4), (2,3,6), (5,9,10), (7,8,11)
528
// are all the same color.
529

    
530
  private boolean isSolved1()
531
    {
532
    if( mScramble==null )
533
      {
534
      mScramble = new int[NUM_QUATS][NUM_CUBITS];
535
      mColors   = new int[NUM_CUBITS];
536

    
537
      for(int q=0; q<NUM_QUATS; q++)
538
        for(int c=0; c<NUM_CUBITS; c++) mScramble[q][c] = computeScramble(q,c);
539
      }
540

    
541
    if( mFaceMap==null )
542
      {
543
      mFaceMap = new int[] { 4, 2, 2, 4, 0, 2, 1, 4, 0, 0, 1, 1 };
544
      }
545

    
546
    for(int c=0; c<NUM_CUBITS; c++)
547
      {
548
      int index = mScramble[CUBITS[c].mQuatIndex][c];
549
      mColors[index] = mFaceMap[c];
550
      }
551

    
552
    if( mColors[0]==mColors[3] && mColors[0]==mColors[7] &&
553
        mColors[1]==mColors[2] && mColors[1]==mColors[5] &&
554
        mColors[4]==mColors[8] && mColors[4]==mColors[9]  ) return true;
555

    
556
    if( mColors[0]==mColors[1] && mColors[0]==mColors[4] &&
557
        mColors[2]==mColors[3] && mColors[2]==mColors[6] &&
558
        mColors[5]==mColors[9] && mColors[5]==mColors[10] ) return true;
559

    
560
    return false;
561
    }
562

    
563
///////////////////////////////////////////////////////////////////////////////////////////////////
564
// Dino6 uses this. It is solved if and only if:
565
//
566
// All four 'X' cubits (i.e. those whose longest edge goes along the X axis) are rotated
567
// by the same quaternion qX, similarly all four 'Y' cubits by the same qY and all four 'Z'
568
// by the same qZ, and then either:
569
//
570
// a) qX = qY = qZ
571
// b) qY = qX*Q2 and qZ = qX*Q8  (i.e. swap of WHITE and YELLOW faces)
572
// c) qX = qY*Q2 and qZ = qY*Q10 (i.e. swap of BLUE and GREEN faces)
573
// d) qX = qZ*Q8 and qY = qZ*Q10 (i.e. swap of RED and BROWN faces)
574
//
575
// BUT: cases b), c) and d) are really the same - it's all just a mirror image of the original.
576
//
577
// X cubits: 0, 2, 8, 10
578
// Y cubits: 1, 3, 9, 11
579
// Z cubits: 4, 5, 6, 7
580

    
581
  private boolean isSolved2()
582
    {
583
    int qX = CUBITS[0].mQuatIndex;
584
    int qY = CUBITS[1].mQuatIndex;
585
    int qZ = CUBITS[4].mQuatIndex;
586

    
587
    if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX ||
588
        CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY ||
589
        CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ  )
590
      {
591
      return false;
592
      }
593

    
594
    return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
595
    }
596

    
597
///////////////////////////////////////////////////////////////////////////////////////////////////
598
// Square-2 is solved iff
599
// a) all of its cubits are rotated with the same quat
600
// b) its two 'middle' cubits are rotated with the same quat, the 6 'front' and 6 'back'
601
// edges and corners with this quat multiplied by QUATS[18] (i.e. those are upside down)
602
// and all the 12 left and right edges and corners also with the same quat multiplied by
603
// QUATS[12] - i.e. also upside down.
604

    
605
  private boolean isSolved3()
606
    {
607
    int index = CUBITS[0].mQuatIndex;
608

    
609
    if( CUBITS[1].mQuatIndex!=index ) return false;
610

    
611
    boolean solved = true;
612

    
613
    for(int i=2; i<NUM_CUBITS; i++)
614
      {
615
      if( CUBITS[i].mQuatIndex!=index )
616
        {
617
        solved = false;
618
        break;
619
        }
620
      }
621

    
622
    if( solved ) return true;
623

    
624
    int indexX = mulQuat(index,12);  // QUATS[12] = 180deg (1,0,0)
625
    int indexZ = mulQuat(index,18);  // QUATS[18] = 180deg (0,0,1)
626

    
627
    for(int i= 2; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
628
    for(int i= 3; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
629
    for(int i=18; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
630
    for(int i=19; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
631

    
632
    return true;
633
    }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
  int computeRow(float[] pos, int axisIndex)
638
    {
639
    int ret=0;
640
    int len = pos.length / 3;
641
    Static3D axis = mAxis[axisIndex];
642
    float axisX = axis.get0();
643
    float axisY = axis.get1();
644
    float axisZ = axis.get2();
645
    float casted;
646

    
647
    for(int i=0; i<len; i++)
648
      {
649
      casted = pos[3*i]*axisX + pos[3*i+1]*axisY + pos[3*i+2]*axisZ;
650
      ret |= computeSingleRow(axisIndex,casted);
651
      }
652

    
653
    return ret;
654
    }
655

    
656
///////////////////////////////////////////////////////////////////////////////////////////////////
657

    
658
  private int computeSingleRow(int axisIndex,float casted)
659
    {
660
    int num = mNumCuts[axisIndex];
661

    
662
    for(int i=0; i<num; i++)
663
      {
664
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
665
      }
666

    
667
    return (1<<num);
668
    }
669

    
670
///////////////////////////////////////////////////////////////////////////////////////////////////
671

    
672
  private boolean wasRotateApplied()
673
    {
674
    return mEffects.exists(mRotateEffect.getID());
675
    }
676

    
677
///////////////////////////////////////////////////////////////////////////////////////////////////
678

    
679
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
680
    {
681
    return (CUBITS[cubit].getRotRow(axis) & rowBitmap) != 0;
682
    }
683

    
684
///////////////////////////////////////////////////////////////////////////////////////////////////
685
// note the minus in front of the sin() - we rotate counterclockwise
686
// when looking towards the direction where the axis increases in values.
687

    
688
  private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
689
    {
690
    Static3D axis = mAxis[axisIndex];
691

    
692
    while( angleInDegrees<0 ) angleInDegrees += 360;
693
    angleInDegrees %= 360;
694
    
695
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
696
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
697

    
698
    return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA);
699
    }
700

    
701
///////////////////////////////////////////////////////////////////////////////////////////////////
702

    
703
  private synchronized void setupPosition(int[][] moves)
704
    {
705
    if( moves!=null )
706
      {
707
      Static4D quat;
708
      int index, axis, rowBitmap, angle;
709
      int[] basic = getBasicAngle();
710

    
711
      for(int[] move: moves)
712
        {
713
        axis     = move[0];
714
        rowBitmap= move[1];
715
        angle    = move[2]*(360/basic[axis]);
716
        quat     = makeQuaternion(axis,angle);
717

    
718
        for(int j=0; j<NUM_CUBITS; j++)
719
          if( belongsToRotation(j,axis,rowBitmap) )
720
            {
721
            index = CUBITS[j].removeRotationNow(quat);
722
            mMesh.setEffectAssociation(j, CUBITS[j].computeAssociation(),index);
723
            }
724
        }
725
      }
726
    }
727

    
728
///////////////////////////////////////////////////////////////////////////////////////////////////
729

    
730
  protected int getScrambleType()
731
    {
732
    return 0;
733
    }
734

    
735
///////////////////////////////////////////////////////////////////////////////////////////////////
736

    
737
  int computeBitmapFromRow(int rowBitmap, int axis)
738
    {
739
    if( mIsBandaged )
740
      {
741
      int bitmap, initBitmap=0;
742

    
743
      while( initBitmap!=rowBitmap )
744
        {
745
        initBitmap = rowBitmap;
746

    
747
        for(int cubit=0; cubit<NUM_CUBITS; cubit++)
748
          {
749
          bitmap = CUBITS[cubit].getRotRow(axis);
750
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
751
          }
752
        }
753
      }
754

    
755
    return rowBitmap;
756
    }
757

    
758
///////////////////////////////////////////////////////////////////////////////////////////////////
759
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
760
// Do so only if minimal Error is appropriately low (shape-shifting puzzles - Square-1)
761

    
762
  void clampPos(float[] pos, int offset)
763
    {
764
    float currError, minError = Float.MAX_VALUE;
765
    int minErrorIndex1 = -1;
766
    int minErrorIndex2 = -1;
767

    
768
    float x = pos[offset  ];
769
    float y = pos[offset+1];
770
    float z = pos[offset+2];
771

    
772
    float xo,yo,zo;
773

    
774
    for(int i=0; i<NUM_CUBITS; i++)
775
      {
776
      int len = mOrigPos[i].length / 3;
777

    
778
      for(int j=0; j<len; j++)
779
        {
780
        xo = mOrigPos[i][3*j  ];
781
        yo = mOrigPos[i][3*j+1];
782
        zo = mOrigPos[i][3*j+2];
783

    
784
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
785

    
786
        if( currError<minError )
787
          {
788
          minError = currError;
789
          minErrorIndex1 = i;
790
          minErrorIndex2 = j;
791
          }
792
        }
793
      }
794

    
795
    if( minError< 0.1f ) // TODO: 0.1 ?
796
      {
797
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
798
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
799
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
800
      }
801
    }
802

    
803
///////////////////////////////////////////////////////////////////////////////////////////////////
804
// remember about the double cover or unit quaternions!
805

    
806
  int mulQuat(int q1, int q2)
807
    {
808
    Static4D result = QuatHelper.quatMultiply(OBJECT_QUATS[q1],OBJECT_QUATS[q2]);
809

    
810
    float rX = result.get0();
811
    float rY = result.get1();
812
    float rZ = result.get2();
813
    float rW = result.get3();
814

    
815
    final float MAX_ERROR = 0.1f;
816
    float dX,dY,dZ,dW;
817

    
818
    for(int i=0; i<NUM_QUATS; i++)
819
      {
820
      dX = OBJECT_QUATS[i].get0() - rX;
821
      dY = OBJECT_QUATS[i].get1() - rY;
822
      dZ = OBJECT_QUATS[i].get2() - rZ;
823
      dW = OBJECT_QUATS[i].get3() - rW;
824

    
825
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
826
          dY<MAX_ERROR && dY>-MAX_ERROR &&
827
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
828
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
829

    
830
      dX = OBJECT_QUATS[i].get0() + rX;
831
      dY = OBJECT_QUATS[i].get1() + rY;
832
      dZ = OBJECT_QUATS[i].get2() + rZ;
833
      dW = OBJECT_QUATS[i].get3() + rW;
834

    
835
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
836
          dY<MAX_ERROR && dY>-MAX_ERROR &&
837
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
838
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
839
      }
840

    
841
    return -1;
842
    }
843

    
844
///////////////////////////////////////////////////////////////////////////////////////////////////
845

    
846
  private float getAngle()
847
    {
848
    int pointNum = mRotationAngle.getNumPoints();
849

    
850
    if( pointNum>=1 )
851
      {
852
      return mRotationAngle.getPoint(pointNum-1).get0();
853
      }
854
    else
855
      {
856
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
857
      crashlytics.log("points in RotationAngle: "+pointNum);
858
      return 0;
859
      }
860
    }
861

    
862
///////////////////////////////////////////////////////////////////////////////////////////////////
863

    
864
  private void recordQuatsState(String message)
865
    {
866
    StringBuilder quats = new StringBuilder();
867

    
868
    for(int j=0; j<NUM_CUBITS; j++)
869
      {
870
      quats.append(mQuatDebug[j]);
871
      quats.append(" ");
872
      }
873

    
874
    String name = intGetObjectType(mNumLayers).name();
875

    
876
    if( BuildConfig.DEBUG )
877
      {
878
      android.util.Log.e("quats" , quats.toString());
879
      android.util.Log.e("object", name);
880
      }
881
    else
882
      {
883
      Exception ex = new Exception(message);
884
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
885
      crashlytics.setCustomKey("quats" , quats.toString());
886
      crashlytics.setCustomKey("object", name);
887
      crashlytics.recordException(ex);
888
      }
889
    }
890

    
891
///////////////////////////////////////////////////////////////////////////////////////////////////
892

    
893
  void initializeObject(int[][] moves)
894
    {
895
    solve();
896
    setupPosition(moves);
897
    }
898

    
899
///////////////////////////////////////////////////////////////////////////////////////////////////
900

    
901
  synchronized void removeRotationNow()
902
    {
903
    float angle = getAngle();
904
    double nearestAngleInRadians = angle*Math.PI/180;
905
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
906
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
907
    float axisX = mAxis[mRotAxis].get0();
908
    float axisY = mAxis[mRotAxis].get1();
909
    float axisZ = mAxis[mRotAxis].get2();
910
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
911

    
912
    mRotationAngle.removeAll();
913
    mRotationAngleStatic.set0(0);
914

    
915
    for(int i=0; i<NUM_CUBITS; i++)
916
      if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
917
        {
918
        int index = CUBITS[i].removeRotationNow(quat);
919
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index);
920
        }
921
    }
922

    
923
///////////////////////////////////////////////////////////////////////////////////////////////////
924

    
925
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
926
    {
927
    if( wasRotateApplied() )
928
      {
929
      float angle = getAngle();
930
      mRotationAngleStatic.set0(angle);
931
      mRotationAngleFinal.set0(nearestAngleInDegrees);
932
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
933

    
934
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
935
      mRotationAngle.resetToBeginning();
936
      mRotationAngle.removeAll();
937
      mRotationAngle.add(mRotationAngleStatic);
938
      mRotationAngle.add(mRotationAngleMiddle);
939
      mRotationAngle.add(mRotationAngleFinal);
940
      mRotateEffect.notifyWhenFinished(listener);
941

    
942
      return mRotateEffect.getID();
943
      }
944

    
945
    return 0;
946
    }
947

    
948
///////////////////////////////////////////////////////////////////////////////////////////////////
949

    
950
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
951
    {
952
    if( wasRotateApplied() )
953
      {
954
      mRotAxis     = axis;
955
      mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis );
956

    
957
      mRotationAngleStatic.set0(0.0f);
958
      mRotationAxis.set( mAxis[axis] );
959
      mRotationAngle.setDuration(durationMillis);
960
      mRotationAngle.resetToBeginning();
961
      mRotationAngle.add(new Static1D(0));
962
      mRotationAngle.add(new Static1D(angle));
963
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1);
964
      mRotateEffect.notifyWhenFinished(listener);
965

    
966
      return mRotateEffect.getID();
967
      }
968

    
969
    return 0;
970
    }
971

    
972
///////////////////////////////////////////////////////////////////////////////////////////////////
973

    
974
  void continueRotation(float angleInDegrees)
975
    {
976
    mRotationAngleStatic.set0(angleInDegrees);
977
    }
978

    
979
///////////////////////////////////////////////////////////////////////////////////////////////////
980

    
981
  synchronized void beginNewRotation(int axis, int row )
982
    {
983
    if( axis<0 || axis>=NUM_AXIS )
984
      {
985
      android.util.Log.e("object", "invalid rotation axis: "+axis);
986
      return;
987
      }
988
    if( row<0 || row>=mNumLayers )
989
      {
990
      android.util.Log.e("object", "invalid rotation row: "+row);
991
      return;
992
      }
993

    
994
    mRotAxis     = axis;
995
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
996
    mRotationAngleStatic.set0(0.0f);
997
    mRotationAxis.set( mAxis[axis] );
998
    mRotationAngle.add(mRotationAngleStatic);
999
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*ObjectType.MAX_OBJECT_SIZE) , -1);
1000
    }
1001

    
1002
///////////////////////////////////////////////////////////////////////////////////////////////////
1003

    
1004
  void setTextureMap(int cubit, int face, int newColor)
1005
    {
1006
    final float ratioW = 1.0f/mNumTexCols;
1007
    final float ratioH = 1.0f/mNumTexRows;
1008
    final Static4D[] maps = new Static4D[mNumCubitFaces];
1009
    int row = (mNumTexRows-1) - newColor/mNumTexCols;
1010
    int col = newColor%mNumTexCols;
1011

    
1012
    maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1013
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1014
    }
1015

    
1016
///////////////////////////////////////////////////////////////////////////////////////////////////
1017

    
1018
  void resetAllTextureMaps()
1019
    {
1020
    final float ratioW = 1.0f/mNumTexCols;
1021
    final float ratioH = 1.0f/mNumTexRows;
1022
    int color, row, col;
1023

    
1024
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
1025
      {
1026
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1027

    
1028
      for(int cubitface=0; cubitface<mNumCubitFaces; cubitface++)
1029
        {
1030
        color = getFaceColor(cubit,cubitface,mNumLayers);
1031
        row = (mNumTexRows-1) - color/mNumTexCols;
1032
        col = color%mNumTexCols;
1033
        maps[cubitface] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1034
        }
1035

    
1036
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1037
      }
1038
    }
1039

    
1040
///////////////////////////////////////////////////////////////////////////////////////////////////
1041

    
1042
  void releaseResources()
1043
    {
1044
    mTexture.markForDeletion();
1045
    mMesh.markForDeletion();
1046
    mEffects.markForDeletion();
1047

    
1048
    for(int j=0; j<NUM_CUBITS; j++)
1049
      {
1050
      CUBITS[j].releaseResources();
1051
      }
1052
    }
1053

    
1054
///////////////////////////////////////////////////////////////////////////////////////////////////
1055

    
1056
  synchronized void restorePreferences(SharedPreferences preferences)
1057
    {
1058
    boolean error = false;
1059

    
1060
    for(int i=0; i<NUM_CUBITS; i++)
1061
      {
1062
      mQuatDebug[i] = CUBITS[i].restorePreferences(preferences);
1063

    
1064
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<NUM_QUATS)
1065
        {
1066
        CUBITS[i].modifyCurrentPosition(OBJECT_QUATS[mQuatDebug[i]]);
1067
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),mQuatDebug[i]);
1068
        }
1069
      else
1070
        {
1071
        error = true;
1072
        }
1073
      }
1074

    
1075
    if( error )
1076
      {
1077
      for(int i=0; i<NUM_CUBITS; i++)
1078
        {
1079
        CUBITS[i].solve();
1080
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),0);
1081
        }
1082
      recordQuatsState("Failed to restorePreferences");
1083
      }
1084
    }
1085

    
1086
///////////////////////////////////////////////////////////////////////////////////////////////////
1087

    
1088
  void savePreferences(SharedPreferences.Editor editor)
1089
    {
1090
    for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
1091
    }
1092

    
1093
///////////////////////////////////////////////////////////////////////////////////////////////////
1094

    
1095
  void recomputeScaleFactor(int scrWidth)
1096
    {
1097
    mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth);
1098
    }
1099

    
1100
///////////////////////////////////////////////////////////////////////////////////////////////////
1101
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
1102

    
1103
  void createTexture()
1104
    {
1105
    Bitmap bitmap;
1106

    
1107
    Paint paint = new Paint();
1108
    bitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
1109
    Canvas canvas = new Canvas(bitmap);
1110

    
1111
    paint.setAntiAlias(true);
1112
    paint.setTextAlign(Paint.Align.CENTER);
1113
    paint.setStyle(Paint.Style.FILL);
1114

    
1115
    paint.setColor(COLOR_BLACK);
1116
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1117

    
1118
    int face = 0;
1119
    FactorySticker factory = FactorySticker.getInstance();
1120

    
1121
    for(int row=0; row<mNumTexRows; row++)
1122
      for(int col=0; col<mNumTexCols; col++)
1123
        {
1124
        if( face>=NUM_TEXTURES ) break;
1125
        ObjectSticker sticker = retSticker(face);
1126
        factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, row*TEXTURE_HEIGHT, getColor(face%NUM_FACE_COLORS), sticker);
1127
        face++;
1128
        }
1129

    
1130
    if( !mTexture.setTexture(bitmap) )
1131
      {
1132
      int max = DistortedLibrary.getMaxTextureSize();
1133
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
1134
      crashlytics.log("failed to set texture of size "+bitmap.getWidth()+"x"+bitmap.getHeight()+" max is "+max);
1135
      }
1136
    }
1137

    
1138
///////////////////////////////////////////////////////////////////////////////////////////////////
1139

    
1140
  void setObjectRatio(float sizeChange)
1141
    {
1142
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1143

    
1144
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1145
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1146

    
1147
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
1148
    mObjectScale.set(scale,scale,scale);
1149
    }
1150

    
1151
///////////////////////////////////////////////////////////////////////////////////////////////////
1152

    
1153
  float getObjectRatio()
1154
    {
1155
    return mObjectScreenRatio*mInitScreenRatio;
1156
    }
1157

    
1158
///////////////////////////////////////////////////////////////////////////////////////////////////
1159

    
1160
  boolean isSolved()
1161
    {
1162
    if( mSolvedFunctionIndex==0 ) return isSolved0();
1163
    if( mSolvedFunctionIndex==1 ) return isSolved1();
1164
    if( mSolvedFunctionIndex==2 ) return isSolved2();
1165
    if( mSolvedFunctionIndex==3 ) return isSolved3();
1166

    
1167
    return false;
1168
    }
1169

    
1170
///////////////////////////////////////////////////////////////////////////////////////////////////
1171

    
1172
  int getCubit(float[] point3D)
1173
    {
1174
    float dist, minDist = Float.MAX_VALUE;
1175
    int currentBest=-1;
1176
    float multiplier = returnMultiplier();
1177

    
1178
    point3D[0] *= multiplier;
1179
    point3D[1] *= multiplier;
1180
    point3D[2] *= multiplier;
1181

    
1182
    for(int i=0; i<NUM_CUBITS; i++)
1183
      {
1184
      dist = CUBITS[i].getDistSquared(point3D);
1185
      if( dist<minDist )
1186
        {
1187
        minDist = dist;
1188
        currentBest = i;
1189
        }
1190
      }
1191

    
1192
    return currentBest;
1193
    }
1194

    
1195
///////////////////////////////////////////////////////////////////////////////////////////////////
1196

    
1197
  int computeNearestAngle(int axis, float angle, float speed)
1198
    {
1199
    int[] basicArray = getBasicAngle();
1200
    int basicAngle   = basicArray[axis>=basicArray.length ? 0 : axis];
1201
    int nearestAngle = 360/basicAngle;
1202

    
1203
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1204
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1205

    
1206
    if( tmp!=0 ) return nearestAngle*tmp;
1207

    
1208
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1209
    }
1210

    
1211
///////////////////////////////////////////////////////////////////////////////////////////////////
1212

    
1213
  float getCameraDist()
1214
    {
1215
    return mCameraDist;
1216
    }
1217

    
1218
///////////////////////////////////////////////////////////////////////////////////////////////////
1219
// INTERNAL API - those are called from 'effects' package
1220
///////////////////////////////////////////////////////////////////////////////////////////////////
1221

    
1222
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1223
    {
1224
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total);
1225
    }
1226

    
1227
///////////////////////////////////////////////////////////////////////////////////////////////////
1228

    
1229
  public int getNodeSize()
1230
    {
1231
    return mNodeSize;
1232
    }
1233

    
1234
///////////////////////////////////////////////////////////////////////////////////////////////////
1235

    
1236
  public Static4D getRotationQuat()
1237
      {
1238
      return mQuat;
1239
      }
1240

    
1241
///////////////////////////////////////////////////////////////////////////////////////////////////
1242

    
1243
  public void apply(Effect effect, int position)
1244
    {
1245
    mEffects.apply(effect, position);
1246
    }
1247

    
1248
///////////////////////////////////////////////////////////////////////////////////////////////////
1249

    
1250
  public void remove(long effectID)
1251
    {
1252
    mEffects.abortById(effectID);
1253
    }
1254

    
1255
///////////////////////////////////////////////////////////////////////////////////////////////////
1256
// PUBLIC API
1257
///////////////////////////////////////////////////////////////////////////////////////////////////
1258

    
1259
  public int getCubitFaceColorIndex(int cubit, int face)
1260
    {
1261
    Static4D texMap = mMesh.getTextureMap(NUM_FACE_COLORS*cubit + face);
1262

    
1263
    int x = (int)(texMap.get0()/texMap.get2());
1264
    int y = (int)(texMap.get1()/texMap.get3());
1265

    
1266
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1267
    }
1268

    
1269
///////////////////////////////////////////////////////////////////////////////////////////////////
1270

    
1271
  public int getNumLayers()
1272
    {
1273
    return mNumLayers;
1274
    }
1275

    
1276
///////////////////////////////////////////////////////////////////////////////////////////////////
1277

    
1278
  public synchronized void solve()
1279
    {
1280
    for(int i=0; i<NUM_CUBITS; i++)
1281
      {
1282
      CUBITS[i].solve();
1283
      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
1284
      }
1285
    }
1286

    
1287
///////////////////////////////////////////////////////////////////////////////////////////////////
1288

    
1289
  public ObjectType getObjectType()
1290
    {
1291
    return intGetObjectType(mNumLayers);
1292
    }
1293

    
1294
///////////////////////////////////////////////////////////////////////////////////////////////////
1295

    
1296
  protected abstract int getFOV();
1297
  protected abstract float returnMultiplier();
1298
  protected abstract float getScreenRatio();
1299
  protected abstract int getNumFaceColors();
1300
  protected abstract int getColor(int face);
1301
  protected abstract float[][] getCuts(int numLayers);
1302
  protected abstract int getNumCubitFaces();
1303
  protected abstract Static4D[] getQuats();
1304
  protected abstract float[][] getCubitPositions(int numLayers);
1305
  protected abstract int getCubitVariant(int cubit, int numLayers);
1306
  protected abstract int getNumCubitVariants(int numLayers);
1307
  protected abstract Static4D getQuat(int cubit, int numLayers);
1308
  protected abstract ObjectShape getObjectShape(int cubit, int numLayers);
1309
  protected abstract int[] getSolvedQuats(int cubit, int numLayers);
1310
  protected abstract int getSolvedFunctionIndex();
1311
  protected abstract ScrambleState[] getScrambleStates();
1312
  protected abstract int getNumStickerTypes(int numLayers);
1313
  protected abstract ObjectSticker retSticker(int face);
1314
  protected abstract int getFaceColor(int cubit, int cubitface, int numLayers);
1315
  protected abstract int getResource(int mNumLayers);
1316
  protected abstract ObjectType intGetObjectType(int numLayers);
1317
  protected abstract Movement getMovement();
1318

    
1319
  public abstract Static3D[] getRotationAxis();
1320
  public abstract int[] getBasicAngle();
1321
  public abstract int getObjectName(int numLayers);
1322
  public abstract int getInventor(int numLayers);
1323
  public abstract int getComplexity(int numLayers);
1324
  }
(14-14/15)