Project

General

Profile

Download (40 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyObject.java @ 963921af

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

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

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

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

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

    
83
  private static final float NODE_RATIO = 1.40f;
84
  private static final float MAX_SIZE_CHANGE = 1.35f;
85
  private static final float MIN_SIZE_CHANGE = 0.75f;
86

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

    
90
  MeshBase[] mMeshes;
91
  final Static4D[] OBJECT_QUATS;
92
  final Cubit[] CUBITS;
93
  final int NUM_FACES;
94
  final int NUM_TEXTURES;
95
  final int NUM_CUBITS;
96
  final int NUM_AXIS;
97
  final int NUM_QUATS;
98

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

    
130
  //////////////////// SOLVED1 ////////////////////////
131

    
132
  private static final int[] mFaceMap = { 4, 2, 2, 4, 0, 2, 1, 4, 0, 0, 1, 1 };
133
  private static int[][] mScramble;
134
  private int[] mColors;
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  TwistyObject(int numLayers, int realSize, Static4D quat, DistortedTexture nodeTexture, MeshSquare nodeMesh,
139
               DistortedEffects nodeEffects, int[][] moves, ObjectList list, Resources res, int screenWidth)
140
    {
141
    super(nodeTexture,nodeEffects,nodeMesh);
142

    
143
    mNodeSize = screenWidth;
144

    
145
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
146

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

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

    
162
    OBJECT_QUATS = getQuats();
163
    NUM_CUBITS  = mOrigPos.length;
164
    NUM_FACES = getNumFaces();
165
    NUM_TEXTURES = getNumStickerTypes(mNumLayers)*NUM_FACES;
166
    NUM_AXIS = mAxis.length;
167
    NUM_QUATS = OBJECT_QUATS.length;
168

    
169
    boolean bandaged=false;
170

    
171
    for(int c=0; c<NUM_CUBITS; c++)
172
      {
173
      if( mOrigPos[c].length>3 )
174
        {
175
        bandaged=true;
176
        break;
177
        }
178
      }
179

    
180
    mIsBandaged = bandaged;
181

    
182
    mQuatDebug = new int[NUM_CUBITS];
183

    
184
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
185
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
186

    
187
    mNodeScale= new Static3D(1,NODE_RATIO,1);
188
    mQuat = quat;
189

    
190
    mRotationAngle= new Dynamic1D();
191
    mRotationAxis = new Static3D(1,0,0);
192
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
193

    
194
    mRotationAngleStatic = new Static1D(0);
195
    mRotationAngleMiddle = new Static1D(0);
196
    mRotationAngleFinal  = new Static1D(0);
197

    
198
    float scale  = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
199
    mObjectScale = new Static3D(scale,scale,scale);
200
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
201
    MatrixEffectQuaternion quatEffect  = new MatrixEffectQuaternion(quat, CENTER);
202

    
203
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
204
    nodeEffects.apply(nodeScaleEffect);
205

    
206
    mNumTexCols = NUM_STICKERS_IN_ROW;
207
    mNumTexRows = (NUM_TEXTURES+1)/NUM_STICKERS_IN_ROW;
208

    
209
    if( mNumTexCols*mNumTexRows < NUM_TEXTURES+1 ) mNumTexRows++;
210

    
211
    CUBITS = new Cubit[NUM_CUBITS];
212
    createMeshAndCubits(list,res);
213
    createDataStructuresForSolved(numLayers);
214

    
215
    mTexture = new DistortedTexture();
216
    mEffects = new DistortedEffects();
217

    
218
    for(int q=0; q<NUM_QUATS; q++)
219
      {
220
      VertexEffectQuaternion vq = new VertexEffectQuaternion(OBJECT_QUATS[q],CENTER);
221
      vq.setMeshAssociation(0,q);
222
      mEffects.apply(vq);
223
      }
224

    
225
    mEffects.apply(mRotateEffect);
226
    mEffects.apply(quatEffect);
227
    mEffects.apply(scaleEffect);
228

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

    
233
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
234

    
235
    setupPosition(moves);
236

    
237
    float fov = list.getFOV();
238
    double halfFOV = fov * (Math.PI/360);
239
    mCameraDist = 0.5f*NODE_RATIO / (float)Math.tan(halfFOV);
240

    
241
    setProjection( fov, 0.1f);
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
  private Static3D getPos(float[] origPos)
247
    {
248
    int len = origPos.length/3;
249
    float sumX = 0.0f;
250
    float sumY = 0.0f;
251
    float sumZ = 0.0f;
252

    
253
    for(int i=0; i<len; i++)
254
      {
255
      sumX += origPos[3*i  ];
256
      sumY += origPos[3*i+1];
257
      sumZ += origPos[3*i+2];
258
      }
259

    
260
    sumX /= len;
261
    sumY /= len;
262
    sumZ /= len;
263

    
264
    return new Static3D(sumX,sumY,sumZ);
265
    }
266

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

    
269
  private void createMeshAndCubits(ObjectList list, Resources res)
270
    {
271
    int sizeIndex = ObjectList.getSizeIndex(list.ordinal(),mNumLayers);
272
    int resourceID= list.getResourceIDs()[sizeIndex];
273

    
274
    if( resourceID!=0 )
275
      {
276
      InputStream is = res.openRawResource(resourceID);
277
      DataInputStream dos = new DataInputStream(is);
278
      mMesh = new MeshFile(dos);
279

    
280
      try
281
        {
282
        is.close();
283
        }
284
      catch(IOException e)
285
        {
286
        android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
287
        }
288

    
289
      for(int i=0; i<NUM_CUBITS; i++)
290
        {
291
        CUBITS[i] = new Cubit(this,mOrigPos[i], NUM_AXIS);
292
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
293
        }
294

    
295
      if( shouldResetTextureMaps() ) resetAllTextureMaps();
296
      }
297
    else
298
      {
299
      MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS];
300

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

    
310
      mMesh = new MeshJoined(cubitMesh);
311
      resetAllTextureMaps();
312
      }
313
    }
314

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

    
317
  private MeshBase createCubitMesh(int cubit, int numLayers)
318
    {
319
    int variant = getCubitVariant(cubit,numLayers);
320

    
321
    if( mMeshes==null )
322
      {
323
      FactoryCubit factory = FactoryCubit.getInstance();
324
      factory.clear();
325
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
326
      }
327

    
328
    if( mMeshes[variant]==null )
329
      {
330
      ObjectShape shape = getObjectShape(cubit,numLayers);
331
      FactoryCubit factory = FactoryCubit.getInstance();
332
      factory.createNewFaceTransform(shape);
333
      mMeshes[variant] = factory.createRoundedSolid(shape);
334
      }
335

    
336
    MeshBase mesh = mMeshes[variant].copy(true);
337
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
338
    mesh.apply(quat,0xffffffff,0);
339

    
340
    return mesh;
341
    }
342

    
343
///////////////////////////////////////////////////////////////////////////////////////////////////
344

    
345
  private void createDataStructuresForSolved(int numLayers)
346
    {
347
    mTmpQuats = new int[NUM_QUATS];
348
    mSolvedQuats = new int[NUM_CUBITS][];
349

    
350
    for(int c=0; c<NUM_CUBITS; c++)
351
      {
352
      mSolvedQuats[c] = getSolvedQuats(c,numLayers);
353
      }
354
    }
355

    
356
///////////////////////////////////////////////////////////////////////////////////////////////////
357
// This is used to build internal data structures for the generic 'isSolved()'
358
//
359
// if this is an internal cubit (all faces black): return -1
360
// if this is a face cubit (one non-black face): return the color index of the only non-black face.
361
// Color index, i.e. the index into the 'FACE_COLORS' table.
362
// else (edge or corner cubit, more than one non-black face): return -2.
363

    
364
  int retCubitSolvedStatus(int cubit, int numLayers)
365
    {
366
    int numNonBlack=0, nonBlackIndex=-1, color;
367

    
368
    for(int face=0; face<mNumCubitFaces; face++)
369
      {
370
      color = getFaceColor(cubit,face,numLayers);
371

    
372
      if( color<NUM_TEXTURES )
373
        {
374
        numNonBlack++;
375
        nonBlackIndex = color%NUM_FACES;
376
        }
377
      }
378

    
379
    if( numNonBlack==0 ) return -1;
380
    if( numNonBlack>=2 ) return -2;
381

    
382
    return nonBlackIndex;
383
    }
384

    
385
///////////////////////////////////////////////////////////////////////////////////////////////////
386

    
387
  int[] buildSolvedQuats(Static3D faceAx, Static4D[] quats)
388
    {
389
    final float MAXD = 0.0001f;
390
    float x = faceAx.get0();
391
    float y = faceAx.get1();
392
    float z = faceAx.get2();
393
    float a,dx,dy,dz,qx,qy,qz;
394
    Static4D quat;
395

    
396
    int len = quats.length;
397
    int place = 0;
398

    
399
    for(int q=1; q<len; q++)
400
      {
401
      quat = quats[q];
402
      qx = quat.get0();
403
      qy = quat.get1();
404
      qz = quat.get2();
405

    
406
           if( x!=0.0f ) { a = qx/x; }
407
      else if( y!=0.0f ) { a = qy/y; }
408
      else               { a = qz/z; }
409

    
410
      dx = a*x-qx;
411
      dy = a*y-qy;
412
      dz = a*z-qz;
413

    
414
      if( dx>-MAXD && dx<MAXD && dy>-MAXD && dy<MAXD && dz>-MAXD && dz<MAXD )
415
        {
416
        mTmpQuats[place++] = q;
417
        }
418
      }
419

    
420
    if( place!=0 )
421
      {
422
      int[] ret = new int[place];
423
      System.arraycopy(mTmpQuats,0,ret,0,place);
424
      return ret;
425
      }
426

    
427
    return null;
428
    }
429

    
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

    
432
  private int getMultQuat(int index1, int index2)
433
    {
434
    if( mQuatMult==null )
435
      {
436
      mQuatMult = new int[NUM_QUATS][NUM_QUATS];
437

    
438
      for(int i=0; i<NUM_QUATS; i++)
439
        for(int j=0; j<NUM_QUATS; j++) mQuatMult[i][j] = -1;
440
      }
441

    
442
    if( mQuatMult[index1][index2]==-1 )
443
      {
444
      mQuatMult[index1][index2] = mulQuat(index1,index2);
445
      }
446

    
447
    return mQuatMult[index1][index2];
448
    }
449

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

    
452
  public boolean isSolved()
453
    {
454
    if( mSolvedFunctionIndex==0 ) return isSolved0();
455
    if( mSolvedFunctionIndex==1 ) return isSolved1();
456
    if( mSolvedFunctionIndex==2 ) return isSolved2();
457
    if( mSolvedFunctionIndex==3 ) return isSolved3();
458

    
459
    return false;
460
    }
461

    
462
///////////////////////////////////////////////////////////////////////////////////////////////////
463

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

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

    
474
      if( q1==q ) continue;
475

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

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

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

    
492
    return true;
493
    }
494

    
495
///////////////////////////////////////////////////////////////////////////////////////////////////
496

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

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

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

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

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

    
521
    return -1;
522
    }
523

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

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

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

    
542
    for(int c=0; c<NUM_CUBITS; c++)
543
      {
544
      int index = mScramble[CUBITS[c].mQuatIndex][c];
545
      mColors[index] = mFaceMap[c];
546
      }
547

    
548
    if( mColors[0]==mColors[3] && mColors[0]==mColors[7] &&
549
        mColors[1]==mColors[2] && mColors[1]==mColors[5] &&
550
        mColors[4]==mColors[8] && mColors[4]==mColors[9]  ) return true;
551

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

    
556
    return false;
557
    }
558

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

    
577
  public boolean isSolved2()
578
    {
579
    int qX = CUBITS[0].mQuatIndex;
580
    int qY = CUBITS[1].mQuatIndex;
581
    int qZ = CUBITS[4].mQuatIndex;
582

    
583
    if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX ||
584
        CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY ||
585
        CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ  )
586
      {
587
      return false;
588
      }
589

    
590
    return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
591
    }
592

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

    
601
  public boolean isSolved3()
602
    {
603
    int index = CUBITS[0].mQuatIndex;
604

    
605
    if( CUBITS[1].mQuatIndex!=index ) return false;
606

    
607
    boolean solved = true;
608

    
609
    for(int i=2; i<NUM_CUBITS; i++)
610
      {
611
      if( CUBITS[i].mQuatIndex!=index )
612
        {
613
        solved = false;
614
        break;
615
        }
616
      }
617

    
618
    if( solved ) return true;
619

    
620
    int indexX = mulQuat(index,12);  // QUATS[12] = 180deg (1,0,0)
621
    int indexZ = mulQuat(index,18);  // QUATS[18] = 180deg (0,0,1)
622

    
623
    for(int i= 2; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
624
    for(int i= 3; i<        18; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
625
    for(int i=18; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexX ) return false;
626
    for(int i=19; i<NUM_CUBITS; i+=2) if( CUBITS[i].mQuatIndex != indexZ ) return false;
627

    
628
    return true;
629
    }
630

    
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632

    
633
  public void setObjectRatio(float sizeChange)
634
    {
635
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
636

    
637
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
638
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
639

    
640
    float scale = mObjectScreenRatio*mInitScreenRatio*mNodeSize/mRealSize;
641
    mObjectScale.set(scale,scale,scale);
642
    }
643

    
644
///////////////////////////////////////////////////////////////////////////////////////////////////
645

    
646
  public float getObjectRatio()
647
    {
648
    return mObjectScreenRatio*mInitScreenRatio;
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
  int computeRow(float[] pos, int axisIndex)
654
    {
655
    int ret=0;
656
    int len = pos.length / 3;
657
    Static3D axis = mAxis[axisIndex];
658
    float axisX = axis.get0();
659
    float axisY = axis.get1();
660
    float axisZ = axis.get2();
661
    float casted;
662

    
663
    for(int i=0; i<len; i++)
664
      {
665
      casted = pos[3*i]*axisX + pos[3*i+1]*axisY + pos[3*i+2]*axisZ;
666
      ret |= computeSingleRow(axisIndex,casted);
667
      }
668

    
669
    return ret;
670
    }
671

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////
673

    
674
  private int computeSingleRow(int axisIndex,float casted)
675
    {
676
    int num = mNumCuts[axisIndex];
677

    
678
    for(int i=0; i<num; i++)
679
      {
680
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
681
      }
682

    
683
    return (1<<num);
684
    }
685

    
686
///////////////////////////////////////////////////////////////////////////////////////////////////
687

    
688
  private boolean wasRotateApplied()
689
    {
690
    return mEffects.exists(mRotateEffect.getID());
691
    }
692

    
693
///////////////////////////////////////////////////////////////////////////////////////////////////
694

    
695
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
696
    {
697
    return (CUBITS[cubit].mRotationRow[axis] & rowBitmap) != 0;
698
    }
699

    
700
///////////////////////////////////////////////////////////////////////////////////////////////////
701
// note the minus in front of the sin() - we rotate counterclockwise
702
// when looking towards the direction where the axis increases in values.
703

    
704
  private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
705
    {
706
    Static3D axis = mAxis[axisIndex];
707

    
708
    while( angleInDegrees<0 ) angleInDegrees += 360;
709
    angleInDegrees %= 360;
710
    
711
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
712
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
713

    
714
    return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA);
715
    }
716

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

    
719
  private synchronized void setupPosition(int[][] moves)
720
    {
721
    if( moves!=null )
722
      {
723
      Static4D quat;
724
      int index, axis, rowBitmap, angle;
725
      int[] basic = getBasicAngle();
726

    
727
      for(int[] move: moves)
728
        {
729
        axis     = move[0];
730
        rowBitmap= move[1];
731
        angle    = move[2]*(360/basic[axis]);
732
        quat     = makeQuaternion(axis,angle);
733

    
734
        for(int j=0; j<NUM_CUBITS; j++)
735
          if( belongsToRotation(j,axis,rowBitmap) )
736
            {
737
            index = CUBITS[j].removeRotationNow(quat);
738
            mMesh.setEffectAssociation(j, CUBITS[j].computeAssociation(),index);
739
            }
740
        }
741
      }
742
    }
743

    
744
///////////////////////////////////////////////////////////////////////////////////////////////////
745

    
746
  int computeBitmapFromRow(int rowBitmap, int axis)
747
    {
748
    if( mIsBandaged )
749
      {
750
      int bitmap, initBitmap=0;
751

    
752
      while( initBitmap!=rowBitmap )
753
        {
754
        initBitmap = rowBitmap;
755

    
756
        for(int cubit=0; cubit<NUM_CUBITS; cubit++)
757
          {
758
          bitmap = CUBITS[cubit].mRotationRow[axis];
759
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
760
          }
761
        }
762
      }
763

    
764
    return rowBitmap;
765
    }
766

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

    
771
  void clampPos(float[] pos, int offset)
772
    {
773
    float currError, minError = Float.MAX_VALUE;
774
    int minErrorIndex1 = -1;
775
    int minErrorIndex2 = -1;
776

    
777
    float x = pos[offset  ];
778
    float y = pos[offset+1];
779
    float z = pos[offset+2];
780

    
781
    float xo,yo,zo;
782

    
783
    for(int i=0; i<NUM_CUBITS; i++)
784
      {
785
      int len = mOrigPos[i].length / 3;
786

    
787
      for(int j=0; j<len; j++)
788
        {
789
        xo = mOrigPos[i][3*j  ];
790
        yo = mOrigPos[i][3*j+1];
791
        zo = mOrigPos[i][3*j+2];
792

    
793
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
794

    
795
        if( currError<minError )
796
          {
797
          minError = currError;
798
          minErrorIndex1 = i;
799
          minErrorIndex2 = j;
800
          }
801
        }
802
      }
803

    
804
    if( minError< 0.1f ) // TODO: 0.1 ?
805
      {
806
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
807
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
808
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
809
      }
810
    }
811

    
812
///////////////////////////////////////////////////////////////////////////////////////////////////
813
// remember about the double cover or unit quaternions!
814

    
815
  int mulQuat(int q1, int q2)
816
    {
817
    Static4D result = QuatHelper.quatMultiply(OBJECT_QUATS[q1],OBJECT_QUATS[q2]);
818

    
819
    float rX = result.get0();
820
    float rY = result.get1();
821
    float rZ = result.get2();
822
    float rW = result.get3();
823

    
824
    final float MAX_ERROR = 0.1f;
825
    float dX,dY,dZ,dW;
826

    
827
    for(int i=0; i<NUM_QUATS; i++)
828
      {
829
      dX = OBJECT_QUATS[i].get0() - rX;
830
      dY = OBJECT_QUATS[i].get1() - rY;
831
      dZ = OBJECT_QUATS[i].get2() - rZ;
832
      dW = OBJECT_QUATS[i].get3() - rW;
833

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

    
839
      dX = OBJECT_QUATS[i].get0() + rX;
840
      dY = OBJECT_QUATS[i].get1() + rY;
841
      dZ = OBJECT_QUATS[i].get2() + rZ;
842
      dW = OBJECT_QUATS[i].get3() + rW;
843

    
844
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
845
          dY<MAX_ERROR && dY>-MAX_ERROR &&
846
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
847
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
848
      }
849

    
850
    return -1;
851
    }
852

    
853
///////////////////////////////////////////////////////////////////////////////////////////////////
854

    
855
  public int getCubitFaceColorIndex(int cubit, int face)
856
    {
857
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
858

    
859
    int x = (int)(texMap.get0()/texMap.get2());
860
    int y = (int)(texMap.get1()/texMap.get3());
861

    
862
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
863
    }
864

    
865
///////////////////////////////////////////////////////////////////////////////////////////////////
866
// the getFaceColors + final black in a grid (so that we do not exceed the maximum texture size)
867

    
868
  public void createTexture()
869
    {
870
    Bitmap bitmap;
871

    
872
    Paint paint = new Paint();
873
    bitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
874
    Canvas canvas = new Canvas(bitmap);
875

    
876
    paint.setAntiAlias(true);
877
    paint.setTextAlign(Paint.Align.CENTER);
878
    paint.setStyle(Paint.Style.FILL);
879

    
880
    paint.setColor(COLOR_BLACK);
881
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
882

    
883
    int face = 0;
884
    FactorySticker factory = FactorySticker.getInstance();
885

    
886
    for(int row=0; row<mNumTexRows; row++)
887
      for(int col=0; col<mNumTexCols; col++)
888
        {
889
        if( face>=NUM_TEXTURES ) break;
890
        ObjectSticker sticker = retSticker(face);
891
        factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, row*TEXTURE_HEIGHT, getColor(face%NUM_FACES), sticker);
892
        face++;
893
        }
894

    
895
    if( !mTexture.setTexture(bitmap) )
896
      {
897
      int max = DistortedLibrary.getMaxTextureSize();
898
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
899
      crashlytics.log("failed to set texture of size "+bitmap.getWidth()+"x"+bitmap.getHeight()+" max is "+max);
900
      }
901
    }
902

    
903
///////////////////////////////////////////////////////////////////////////////////////////////////
904

    
905
  public int getNumLayers()
906
    {
907
    return mNumLayers;
908
    }
909

    
910
///////////////////////////////////////////////////////////////////////////////////////////////////
911

    
912
  public void continueRotation(float angleInDegrees)
913
    {
914
    mRotationAngleStatic.set0(angleInDegrees);
915
    }
916

    
917
///////////////////////////////////////////////////////////////////////////////////////////////////
918

    
919
  public Static4D getRotationQuat()
920
      {
921
      return mQuat;
922
      }
923

    
924
///////////////////////////////////////////////////////////////////////////////////////////////////
925

    
926
  public void recomputeScaleFactor(int scrWidth)
927
    {
928
    mNodeScale.set(scrWidth,NODE_RATIO*scrWidth,scrWidth);
929
    }
930

    
931
///////////////////////////////////////////////////////////////////////////////////////////////////
932

    
933
  public void savePreferences(SharedPreferences.Editor editor)
934
    {
935
    for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
936
    }
937

    
938
///////////////////////////////////////////////////////////////////////////////////////////////////
939

    
940
  public synchronized void restorePreferences(SharedPreferences preferences)
941
    {
942
    boolean error = false;
943

    
944
    for(int i=0; i<NUM_CUBITS; i++)
945
      {
946
      mQuatDebug[i] = CUBITS[i].restorePreferences(preferences);
947

    
948
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<NUM_QUATS)
949
        {
950
        CUBITS[i].modifyCurrentPosition(OBJECT_QUATS[mQuatDebug[i]]);
951
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),mQuatDebug[i]);
952
        }
953
      else
954
        {
955
        error = true;
956
        }
957
      }
958

    
959
    if( error )
960
      {
961
      for(int i=0; i<NUM_CUBITS; i++)
962
        {
963
        CUBITS[i].solve();
964
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),0);
965
        }
966
      recordQuatsState("Failed to restorePreferences");
967
      }
968
    }
969

    
970
///////////////////////////////////////////////////////////////////////////////////////////////////
971

    
972
  public void recordQuatsState(String message)
973
    {
974
    StringBuilder quats = new StringBuilder();
975

    
976
    for(int j=0; j<NUM_CUBITS; j++)
977
      {
978
      quats.append(mQuatDebug[j]);
979
      quats.append(" ");
980
      }
981

    
982
    if( BuildConfig.DEBUG )
983
      {
984
      android.util.Log.e("quats" , quats.toString());
985
      android.util.Log.e("object", mList.name()+"_"+mNumLayers);
986
      }
987
    else
988
      {
989
      Exception ex = new Exception(message);
990
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
991
      crashlytics.setCustomKey("quats" , quats.toString());
992
      crashlytics.setCustomKey("object", mList.name()+"_"+mNumLayers );
993
      crashlytics.recordException(ex);
994
      }
995
    }
996

    
997
///////////////////////////////////////////////////////////////////////////////////////////////////
998

    
999
  public void releaseResources()
1000
    {
1001
    mTexture.markForDeletion();
1002
    mMesh.markForDeletion();
1003
    mEffects.markForDeletion();
1004

    
1005
    for(int j=0; j<NUM_CUBITS; j++)
1006
      {
1007
      CUBITS[j].releaseResources();
1008
      }
1009
    }
1010

    
1011
///////////////////////////////////////////////////////////////////////////////////////////////////
1012

    
1013
  public void apply(Effect effect, int position)
1014
    {
1015
    mEffects.apply(effect, position);
1016
    }
1017

    
1018
///////////////////////////////////////////////////////////////////////////////////////////////////
1019

    
1020
  public void remove(long effectID)
1021
    {
1022
    mEffects.abortById(effectID);
1023
    }
1024

    
1025
///////////////////////////////////////////////////////////////////////////////////////////////////
1026

    
1027
  public synchronized void solve()
1028
    {
1029
    for(int i=0; i<NUM_CUBITS; i++)
1030
      {
1031
      CUBITS[i].solve();
1032
      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
1033
      }
1034
    }
1035

    
1036
///////////////////////////////////////////////////////////////////////////////////////////////////
1037

    
1038
  public void resetAllTextureMaps()
1039
    {
1040
    final float ratioW = 1.0f/mNumTexCols;
1041
    final float ratioH = 1.0f/mNumTexRows;
1042
    int color, row, col;
1043

    
1044
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
1045
      {
1046
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1047

    
1048
      for(int cubitface=0; cubitface<mNumCubitFaces; cubitface++)
1049
        {
1050
        color = getFaceColor(cubit,cubitface,mNumLayers);
1051
        row = (mNumTexRows-1) - color/mNumTexCols;
1052
        col = color%mNumTexCols;
1053
        maps[cubitface] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1054
        }
1055

    
1056
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1057
      }
1058
    }
1059

    
1060
///////////////////////////////////////////////////////////////////////////////////////////////////
1061

    
1062
  public void setTextureMap(int cubit, int face, int newColor)
1063
    {
1064
    final float ratioW = 1.0f/mNumTexCols;
1065
    final float ratioH = 1.0f/mNumTexRows;
1066
    final Static4D[] maps = new Static4D[mNumCubitFaces];
1067
    int row = (mNumTexRows-1) - newColor/mNumTexCols;
1068
    int col = newColor%mNumTexCols;
1069

    
1070
    maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1071
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1072
    }
1073

    
1074
///////////////////////////////////////////////////////////////////////////////////////////////////
1075

    
1076
  public synchronized void beginNewRotation(int axis, int row )
1077
    {
1078
    if( axis<0 || axis>=NUM_AXIS )
1079
      {
1080
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1081
      return;
1082
      }
1083
    if( row<0 || row>=mNumLayers )
1084
      {
1085
      android.util.Log.e("object", "invalid rotation row: "+row);
1086
      return;
1087
      }
1088

    
1089
    mRotAxis     = axis;
1090
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
1091
    mRotationAngleStatic.set0(0.0f);
1092
    mRotationAxis.set( mAxis[axis] );
1093
    mRotationAngle.add(mRotationAngleStatic);
1094
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis* ObjectList.MAX_OBJECT_SIZE) , -1);
1095
    }
1096

    
1097
///////////////////////////////////////////////////////////////////////////////////////////////////
1098

    
1099
  public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1100
    {
1101
    if( wasRotateApplied() )
1102
      {
1103
      mRotAxis     = axis;
1104
      mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis );
1105

    
1106
      mRotationAngleStatic.set0(0.0f);
1107
      mRotationAxis.set( mAxis[axis] );
1108
      mRotationAngle.setDuration(durationMillis);
1109
      mRotationAngle.resetToBeginning();
1110
      mRotationAngle.add(new Static1D(0));
1111
      mRotationAngle.add(new Static1D(angle));
1112
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis* ObjectList.MAX_OBJECT_SIZE) , -1);
1113
      mRotateEffect.notifyWhenFinished(listener);
1114

    
1115
      return mRotateEffect.getID();
1116
      }
1117

    
1118
    return 0;
1119
    }
1120

    
1121
///////////////////////////////////////////////////////////////////////////////////////////////////
1122

    
1123
  public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1124
    {
1125
    if( wasRotateApplied() )
1126
      {
1127
      float angle = getAngle();
1128
      mRotationAngleStatic.set0(angle);
1129
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1130
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1131

    
1132
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1133
      mRotationAngle.resetToBeginning();
1134
      mRotationAngle.removeAll();
1135
      mRotationAngle.add(mRotationAngleStatic);
1136
      mRotationAngle.add(mRotationAngleMiddle);
1137
      mRotationAngle.add(mRotationAngleFinal);
1138
      mRotateEffect.notifyWhenFinished(listener);
1139

    
1140
      return mRotateEffect.getID();
1141
      }
1142

    
1143
    return 0;
1144
    }
1145

    
1146
///////////////////////////////////////////////////////////////////////////////////////////////////
1147

    
1148
  private float getAngle()
1149
    {
1150
    int pointNum = mRotationAngle.getNumPoints();
1151

    
1152
    if( pointNum>=1 )
1153
      {
1154
      return mRotationAngle.getPoint(pointNum-1).get0();
1155
      }
1156
    else
1157
      {
1158
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
1159
      crashlytics.log("points in RotationAngle: "+pointNum);
1160
      return 0;
1161
      }
1162
    }
1163

    
1164
///////////////////////////////////////////////////////////////////////////////////////////////////
1165

    
1166
  public synchronized void removeRotationNow()
1167
    {
1168
    float angle = getAngle();
1169
    double nearestAngleInRadians = angle*Math.PI/180;
1170
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1171
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1172
    float axisX = mAxis[mRotAxis].get0();
1173
    float axisY = mAxis[mRotAxis].get1();
1174
    float axisZ = mAxis[mRotAxis].get2();
1175
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1176

    
1177
    mRotationAngle.removeAll();
1178
    mRotationAngleStatic.set0(0);
1179

    
1180
    for(int i=0; i<NUM_CUBITS; i++)
1181
      if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
1182
        {
1183
        int index = CUBITS[i].removeRotationNow(quat);
1184
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index);
1185
        }
1186
    }
1187

    
1188
///////////////////////////////////////////////////////////////////////////////////////////////////
1189

    
1190
  public void initializeObject(int[][] moves)
1191
    {
1192
    solve();
1193
    setupPosition(moves);
1194
    }
1195

    
1196
///////////////////////////////////////////////////////////////////////////////////////////////////
1197

    
1198
  public int getCubit(float[] point3D)
1199
    {
1200
    float dist, minDist = Float.MAX_VALUE;
1201
    int currentBest=-1;
1202
    float multiplier = returnMultiplier();
1203

    
1204
    point3D[0] *= multiplier;
1205
    point3D[1] *= multiplier;
1206
    point3D[2] *= multiplier;
1207

    
1208
    for(int i=0; i<NUM_CUBITS; i++)
1209
      {
1210
      dist = CUBITS[i].getDistSquared(point3D);
1211
      if( dist<minDist )
1212
        {
1213
        minDist = dist;
1214
        currentBest = i;
1215
        }
1216
      }
1217

    
1218
    return currentBest;
1219
    }
1220

    
1221
///////////////////////////////////////////////////////////////////////////////////////////////////
1222

    
1223
  public int computeNearestAngle(int axis, float angle, float speed)
1224
    {
1225
    int[] basicArray = getBasicAngle();
1226
    int basicAngle   = basicArray[axis>=basicArray.length ? 0 : axis];
1227
    int nearestAngle = 360/basicAngle;
1228

    
1229
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1230
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1231

    
1232
    if( tmp!=0 ) return nearestAngle*tmp;
1233

    
1234
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1235
    }
1236

    
1237
///////////////////////////////////////////////////////////////////////////////////////////////////
1238

    
1239
  public float getCameraDist()
1240
    {
1241
    return mCameraDist;
1242
    }
1243

    
1244
///////////////////////////////////////////////////////////////////////////////////////////////////
1245

    
1246
  public int getNodeSize()
1247
    {
1248
    return mNodeSize;
1249
    }
1250

    
1251
///////////////////////////////////////////////////////////////////////////////////////////////////
1252

    
1253
  public ObjectList getObjectList()
1254
    {
1255
    return mList;
1256
    }
1257

    
1258
///////////////////////////////////////////////////////////////////////////////////////////////////
1259

    
1260
  abstract float getScreenRatio();
1261
  abstract float[][] getCubitPositions(int numLayers);
1262
  abstract Static4D[] getQuats();
1263
  abstract int getNumFaces();
1264
  abstract int getNumStickerTypes(int numLayers);
1265
  abstract int getNumCubitFaces();
1266
  abstract ObjectSticker retSticker(int face);
1267
  abstract int getColor(int face);
1268
  abstract int getFaceColor(int cubit, int cubitface, int numLayers);
1269
  abstract float returnMultiplier();
1270
  abstract float[][] getCuts(int numLayers);
1271
  abstract boolean shouldResetTextureMaps();
1272
  abstract int getCubitVariant(int cubit, int numLayers);
1273
  abstract int getNumCubitVariants(int numLayers);
1274
  abstract Static4D getQuat(int cubit, int numLayers);
1275
  abstract ObjectShape getObjectShape(int cubit, int numLayers);
1276
  abstract int[] getSolvedQuats(int cubit, int numLayers);
1277
  abstract int getSolvedFunctionIndex();
1278

    
1279
  public abstract Static3D[] getRotationAxis();
1280
  public abstract int[] getBasicAngle();
1281
  public abstract void randomizeNewScramble(int[][] scramble, Random rnd, int curScramble, int totScrambles);
1282
  public abstract int getObjectName(int numLayers);
1283
  public abstract int getInventor(int numLayers);
1284
  public abstract int getComplexity(int numLayers);
1285
  }
(33-33/41)