Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 3788d0cd

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.objectlib.main;
11

    
12
import java.io.DataInputStream;
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.Random;
16

    
17
import android.content.SharedPreferences;
18
import android.content.res.Resources;
19
import android.graphics.Bitmap;
20
import android.graphics.Canvas;
21
import android.graphics.Paint;
22

    
23
import org.distorted.library.effect.Effect;
24
import org.distorted.library.effect.MatrixEffectMove;
25
import org.distorted.library.effect.MatrixEffectQuaternion;
26
import org.distorted.library.effect.MatrixEffectScale;
27
import org.distorted.library.effect.VertexEffectQuaternion;
28
import org.distorted.library.effect.VertexEffectRotate;
29
import org.distorted.library.effect.VertexEffectSink;
30
import org.distorted.library.main.DistortedEffects;
31
import org.distorted.library.main.DistortedLibrary;
32
import org.distorted.library.main.DistortedNode;
33
import org.distorted.library.main.DistortedTexture;
34
import org.distorted.library.main.QuatHelper;
35
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshFile;
37
import org.distorted.library.mesh.MeshJoined;
38
import org.distorted.library.message.EffectListener;
39
import org.distorted.library.type.Dynamic1D;
40
import org.distorted.library.type.Static1D;
41
import org.distorted.library.type.Static3D;
42
import org.distorted.library.type.Static4D;
43

    
44
import org.distorted.objectlib.helpers.FactoryCubit;
45
import org.distorted.objectlib.helpers.FactorySticker;
46
import org.distorted.objectlib.helpers.ObjectFaceShape;
47
import org.distorted.objectlib.helpers.ObjectLibInterface;
48
import org.distorted.objectlib.helpers.ObjectShape;
49
import org.distorted.objectlib.helpers.ObjectSignature;
50
import org.distorted.objectlib.helpers.ObjectSticker;
51
import org.distorted.objectlib.helpers.ObjectStickerOverride;
52
import org.distorted.objectlib.helpers.ObjectVertexEffects;
53
import org.distorted.objectlib.helpers.QuatGroupGenerator;
54
import org.distorted.objectlib.scrambling.ObjectScrambler;
55
import org.distorted.objectlib.json.JsonReader;
56
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
57
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
58
import org.distorted.objectlib.tablebases.TablebasesAbstract;
59
import org.distorted.objectlib.touchcontrol.*;
60

    
61
import static org.distorted.objectlib.touchcontrol.TouchControl.*;
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
public abstract class TwistyObject
66
  {
67
  public static final int MESH_NICE = 0;
68
  public static final int MESH_FAST = 1;
69

    
70
  public static final int MODE_ICON = 0;
71
  public static final int MODE_NORM = 1;
72

    
73
  public static final int COLOR_YELLOW   = 0xffffff00;
74
  public static final int COLOR_WHITE    = 0xffffffff;
75
  public static final int COLOR_BLUE     = 0xff0000ff;
76
  public static final int COLOR_GREEN    = 0xff00bb00;
77
  public static final int COLOR_RED      = 0xff990000;
78
  public static final int COLOR_ORANGE   = 0xffff6200;
79
  public static final int COLOR_GREY     = 0xff727c7b;
80
  public static final int COLOR_VIOLET   = 0xff7700bb;
81
  public static final int COLOR_STROKE   = 0xff000000;
82
  public static final int COLOR_INTERNAL = 0xff000000;
83

    
84
  private static final int STATE_NOTHING = 0;
85
  private static final int STATE_ROTATE  = 1;
86
  private static final int STATE_FINISH  = 2;
87

    
88
  public static final int TEXTURE_HEIGHT = 256;
89
  static final int NUM_STICKERS_IN_ROW = 4;
90

    
91
  public static final float SQ2 = (float)Math.sqrt(2);
92
  public static final float SQ3 = (float)Math.sqrt(3);
93
  public static final float SQ5 = (float)Math.sqrt(5);
94
  public static final float SQ6 = (float)Math.sqrt(6);
95

    
96
  private static final float MAX_SIZE_CHANGE = 1.35f;
97
  private static final float MIN_SIZE_CHANGE = 0.75f;
98

    
99
  private static final Static3D CENTER = new Static3D(0,0,0);
100
  private static final int POST_ROTATION_MILLISEC = 500;
101

    
102
  protected float[][] mStickerCoords;
103
  protected Static4D[] mObjectQuats;
104

    
105
  private int[][] mStickerVariants;
106
  private float[] mStickerScales;
107
  private TwistyObjectCubit[] mCubits;
108
  private TwistyObjectSolved mSolved;
109
  private MeshBase[] mMeshes;
110
  private int mNumCubits, mNumQuats, mNumFaceColors, mNumTextures, mNumOverrides;
111
  private int mNumCubitFaces, mNumStickerTypes;
112
  private Static3D[] mAxis;
113
  private float[][] mCuts;
114
  private int[] mNumCuts;
115
  private float[][] mOrigPos;
116
  private Static4D[] mOrigQuat;
117
  private Static4D[] mMixupModeQuats;
118
  private boolean mIsInMixupMode;
119
  private Static4D mQuat;
120
  private int[] mNumLayers;
121
  private float mSize;
122
  private DistortedEffects mEffects;
123
  private VertexEffectRotate mRotateEffect;
124
  private Dynamic1D mRotationAngle;
125
  private Static3D mRotationAxis;
126
  private Static3D mObjectScale;
127
  private int[] mQuatDebug;
128
  private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
129
  private DistortedTexture mTexture;
130
  private float mInitScreenRatio;
131
  private boolean mIsBandaged;
132
  private float mObjectScreenRatio;
133
  private int mNumTexRows, mNumTexCols;
134
  private int mRotRowBitmap;
135
  private int mCurrentRotAxis;
136
  private MeshBase mMesh;
137
  private ObjectScrambler mScrambler;
138
  private TouchControl mTouchControl;
139
  private DistortedNode mNode;
140
  private ObjectLibInterface mInterface;
141
  private Bitmap mBitmap;
142
  private ObjectSticker[] mStickers;
143
  private ObjectShape[] mShapes;
144
  private int mNumCubitVariants;
145
  private int[][] mCubitFaceColors;
146
  private int[][] mVariantFaceIsOuter;
147
  private int[][] mBasicAngles;
148
  private int mIconMode;
149
  private InitData mInitData;
150
  private float[][] mRowOffsets;
151
  private boolean[] mBelongs;
152
  private float[] mTmp;
153
  private int mNumPuzzleFaces;
154
  private ObjectStickerOverride[] mStickerOverrides;
155
  private boolean mError;
156
  private String mErrorString;
157
  private int mMaxNumLayers;
158
  private int mNumAxis;
159
  private int mPointNum;
160
  private int mRotationState;
161
  private boolean mThereAreDeciders;
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  TwistyObject(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
166
    {
167
    try
168
      {
169
      InputStream jsonStream = asset!=null ? asset.getJsonStream(): null;
170
      JsonReader reader = new JsonReader();
171
      reader.parseJsonFile(jsonStream);
172
      setReader(reader);
173
      mNumLayers = reader.getNumLayers();
174
      mSize      = reader.getSize();
175
      mInitData  = null;
176
      initialize(meshState,iconMode,quat,move,scale,asset,true);
177
      if( asset!=null ) asset.close();
178
      mError = false;
179
      mErrorString=null;
180
      }
181
    catch(Exception ex)
182
      {
183
      mError = true;
184
      mErrorString = ex.getMessage();
185
      }
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  public TwistyObject(int meshState, int iconMode, float size, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
191
    {
192
    mNumLayers = data.getNumLayers();
193
    mSize      = size;
194
    mInitData  = data;
195
    initialize(meshState,iconMode,quat,move,scale,asset,false);
196
    if( asset!=null ) asset.close();
197
    mError = false;
198
    mErrorString = null;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  private void debugQuat(Static4D quat, int cubitIndex, float axisX, float axisY, float axisZ, float angle, int place)
204
    {
205
    float[] tracking = mCubits[cubitIndex].getTrackingPoint();
206

    
207
    String problem = (getShortName()+" "+cubitIndex+" "+quat.get0()+" "+quat.get1()+" "+quat.get2()+" "+quat.get3());
208
    problem += (" "+angle+" "+place+" "+tracking[0]+" "+tracking[1]+" "+tracking[2]);
209
    problem += (" "+axisX+" "+axisY+" "+axisZ)+" "+mPointNum;
210

    
211
    mInterface.reportProblem(problem,true);
212
    }
213

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

    
216
  private void initialize(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset, boolean fromJSON)
217
    {
218
    mRotationState = STATE_NOTHING;
219
    mIconMode = iconMode;
220
    mQuat = quat;
221
    mAxis = getRotationAxis();
222
    mInitScreenRatio = getScreenRatio();
223
    mBasicAngles = getBasicAngles();
224
    mObjectQuats = getQuats();
225
    mNumQuats = mObjectQuats.length;
226
    mOrigPos = getCubitPositions(mNumLayers);
227
    mNumPuzzleFaces = getNumFaces();
228
    mRowOffsets = new float[mNumPuzzleFaces][3];
229
    mTmp = new float[4];
230

    
231
    mNumAxis = mAxis.length;
232
    mCuts = getCuts(mNumLayers);
233
    mNumCuts = new int[mNumAxis];
234
    mMaxNumLayers = -1;
235
    for(int i=0; i<mNumAxis; i++)
236
      {
237
      if( mMaxNumLayers<mNumLayers[i] ) mMaxNumLayers = mNumLayers[i];
238
      mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length);
239
      }
240

    
241
    mNumCubits = mOrigPos.length;
242
    mNumFaceColors = getNumFaceColors();
243
    mBelongs = new boolean[mNumCubits];
244

    
245
    int scramblingType = getScrambleType();
246
    int[][] edges = getScrambleEdges();
247
    int[][] algorithms = getScrambleAlgorithms();
248

    
249
    Resources res = asset==null ? null : asset.getResources();
250
    TablebasesAbstract tablebase = res!=null ? getTablebase(res) : null;
251
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges,tablebase);
252

    
253
    boolean bandaged=false;
254

    
255
    for( int c=0; c<mNumCubits; c++)
256
      {
257
      if( mOrigPos[c].length>3 )
258
        {
259
        bandaged=true;
260
        break;
261
        }
262
      }
263
    mIsBandaged = bandaged;
264
    mQuatDebug = new int[mNumCubits];
265

    
266
    mRotationAngle= new Dynamic1D();
267
    mRotationAxis = new Static3D(1,0,0);
268
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
269

    
270
    mRotationAngleStatic = new Static1D(0);
271
    mRotationAngleMiddle = new Static1D(0);
272
    mRotationAngleFinal  = new Static1D(0);
273

    
274
    mObjectScale = new Static3D(scale,scale,scale);
275
    setObjectRatioNow(scale,720);
276

    
277
    mEffects = new DistortedEffects();
278
    createQuaternionEffects();
279

    
280
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
281
    MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER);
282
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
283

    
284
    InputStream meshStream = asset!=null ? asset.getMeshStream(): null;
285
    boolean fromDMESH = (meshStream!=null && meshState==MESH_NICE);
286
    getQuatsAndShapes(fromDMESH,fromJSON);
287
    createMeshAndCubits(meshStream,meshState,fromDMESH);
288
    setUpTextures(fromDMESH,fromJSON);
289

    
290
    int index = getSolvedFunctionIndex();
291
    mSolved = new TwistyObjectSolved(this,mOrigPos,index);
292
    mSolved.setupSolvedQuats(getSolvedQuats());
293

    
294
    mEffects.apply(mRotateEffect);
295
    mEffects.apply(quatEffect);
296
    mEffects.apply(scaleEffect);
297
    mEffects.apply(moveEffect);
298

    
299
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
300
    }
301

    
302
///////////////////////////////////////////////////////////////////////////////////////////////////
303

    
304
  private TablebasesAbstract getTablebase(Resources res)
305
    {
306
    ObjectSignature signature = getSignature();
307
    long[] array = signature.getArray();
308
    int len = array.length;
309
    int sig = (int)array[len-1];
310

    
311
    return ImplementedTablebasesList.createPacked(res,sig);
312
    }
313

    
314
///////////////////////////////////////////////////////////////////////////////////////////////////
315

    
316
  private void createQuaternionEffects()
317
    {
318
    if( mNumQuats<=ObjectControl.MAX_QUATS )
319
      {
320
      mIsInMixupMode = false;
321

    
322
      for( int q=0; q<mNumQuats; q++)
323
        {
324
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mObjectQuats[q],CENTER);
325
        vq.setMeshAssociation(0,q);
326
        mEffects.apply(vq);
327
        }
328
      }
329
    else if( mNumCubits<=ObjectControl.MAX_QUATS )
330
      {
331
      mIsInMixupMode = true;
332
      mMixupModeQuats = new Static4D[mNumCubits];
333

    
334
      for( int q=0; q<mNumCubits; q++)
335
        {
336
        mMixupModeQuats[q] = new Static4D(mObjectQuats[0]);
337
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mMixupModeQuats[q],CENTER);
338
        vq.setMeshAssociation(0,q);
339
        mEffects.apply(vq);
340
        }
341
      }
342
    else
343
      {
344
      android.util.Log.e("D", "object has too many quaternions ("+mNumQuats+") or too many cubits ("+mNumCubits+")");
345
      }
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  private Static3D getPos(float[] origPos)
351
    {
352
    int len = origPos.length/3;
353
    float sumX = 0.0f;
354
    float sumY = 0.0f;
355
    float sumZ = 0.0f;
356

    
357
    for(int i=0; i<len; i++)
358
      {
359
      sumX += origPos[3*i  ];
360
      sumY += origPos[3*i+1];
361
      sumZ += origPos[3*i+2];
362
      }
363

    
364
    sumX /= len;
365
    sumY /= len;
366
    sumZ /= len;
367

    
368
    return new Static3D(sumX,sumY,sumZ);
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372

    
373
  private void createOuterFaces()
374
    {
375
    for(int v=0; v<mNumCubitVariants; v++)
376
      {
377
      int[][] indices = mShapes[v].getVertIndices();
378
      int faces = indices.length;
379
      mVariantFaceIsOuter[v] = new int[faces];
380
      }
381

    
382
    for( int cubit=0; cubit<mNumCubits; cubit++)
383
      {
384
      int variant = getCubitVariant(cubit,mNumLayers);
385
      int[][] indices = mShapes[variant].getVertIndices();
386
      int numFaces = indices.length;
387

    
388
      for(int face=0; face<numFaces; face++)
389
        if( getCubitFaceColor(cubit,face)>=0 )
390
          {
391
          mVariantFaceIsOuter[variant][face] = 1;
392
          }
393
      }
394
    }
395

    
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397

    
398
  private void getQuatsAndShapes(boolean fromDMESH, boolean fromJSON)
399
    {
400
    mNumCubitVariants = getNumCubitVariants(mNumLayers);
401

    
402
    if( !fromDMESH || !fromJSON )
403
      {
404
      FactoryCubit factory = FactoryCubit.getInstance();
405
      factory.clear();
406

    
407
      mShapes = new ObjectShape[mNumCubitVariants];
408
      for(int i=0; i<mNumCubitVariants; i++) mShapes[i] = getObjectShape(i);
409
      mNumCubitFaces = ObjectShape.computeNumComponents(mShapes);
410
      mVariantFaceIsOuter = new int[mNumCubitVariants][];
411

    
412
      mOrigQuat = new Static4D[mNumCubits];
413
      for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers);
414

    
415
      if( !fromJSON )
416
        {
417
        mCubitFaceColors = ObjectShape.computeColors(mShapes,mOrigPos,mOrigQuat,this);
418
        createOuterFaces();
419
        }
420

    
421
      if( fromDMESH )
422
        {
423
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i], mVariantFaceIsOuter[i]);
424
        }
425
      }
426
    }
427

    
428
///////////////////////////////////////////////////////////////////////////////////////////////////
429

    
430
  private void createMeshAndCubits(InputStream stream, int meshState, boolean fromDMESH)
431
    {
432
    mCubits = new TwistyObjectCubit[mNumCubits];
433

    
434
    if( fromDMESH )
435
      {
436
      DataInputStream dos = new DataInputStream(stream);
437
      mMesh = new MeshFile(dos);
438

    
439
      try
440
        {
441
        stream.close();
442
        }
443
      catch(IOException e)
444
        {
445
        android.util.Log.e("meshFile", "Error closing InputStream: "+e);
446
        }
447
      }
448
    else
449
      {
450
      MeshBase[] cubitMesh = new MeshBase[mNumCubits];
451

    
452
      for(int i=0; i<mNumCubits; i++)
453
        {
454
        cubitMesh[i] = createCubitMesh(i,mNumLayers,meshState,mNumCubitFaces);
455
        Static3D pos = getPos(mOrigPos[i]);
456
        cubitMesh[i].apply(new MatrixEffectMove(pos),1,0);
457
        }
458

    
459
      mMesh = new MeshJoined(cubitMesh);
460

    
461
      float pillowCoeff = getPillowCoeff();
462

    
463
      if( pillowCoeff!=1.0f )
464
        {
465
        float radius = getCircumscribedRadius();
466
        Static1D coeff = new Static1D(pillowCoeff);
467
        Static4D region= new Static4D(0,0,0,radius);
468
        VertexEffectSink sink = new VertexEffectSink(coeff,CENTER,region);
469
        mMesh.apply(sink);
470
        }
471
      }
472

    
473
    for(int i=0; i<mNumCubits; i++)
474
      {
475
      mCubits[i] = new TwistyObjectCubit(this,mOrigPos[i],mNumAxis,mMaxNumLayers,i);
476
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
477

    
478
      if( !mThereAreDeciders && mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
479
        {
480
        mThereAreDeciders = true;
481
        }
482
      }
483
    }
484

    
485
///////////////////////////////////////////////////////////////////////////////////////////////////
486

    
487
  private MeshBase createCubitMesh(int cubit, int[] numLayers, int meshState, int numComponents)
488
    {
489
    int variant = getCubitVariant(cubit,numLayers);
490

    
491
    if( mMeshes==null ) mMeshes = new MeshBase[mNumCubitVariants];
492

    
493
    if( mMeshes[variant]==null )
494
      {
495
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
496
      ObjectVertexEffects effects = getVertexEffects(variant);
497
      FactoryCubit factory = FactoryCubit.getInstance();
498
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
499
      mMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects, meshState, numComponents);
500
      }
501

    
502
    MeshBase mesh = mMeshes[variant].copy(true);
503
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( mOrigQuat[cubit], CENTER );
504
    mesh.apply(quat,0xffffffff,0);
505

    
506
    return mesh;
507
    }
508

    
509
///////////////////////////////////////////////////////////////////////////////////////////////////
510

    
511
  private void setUpTextures(boolean fromDMESH, boolean fromJSON)
512
    {
513
    mTexture = new DistortedTexture();
514

    
515
    if( fromJSON )
516
      {
517
      mNumStickerTypes = getNumStickerTypes();
518
      mNumCubitFaces = getNumCubitFaces();
519
      }
520
    else
521
      {
522
      FactoryCubit factory = FactoryCubit.getInstance();
523
      mStickerCoords   = factory.getStickerCoords();
524
      mStickerVariants = factory.getStickerVariants();
525
      mStickerScales   = factory.getStickerScales();
526
      adjustStickerCoords();
527
      mNumStickerTypes = (mStickerCoords==null ? 0 : mStickerCoords.length);
528
      }
529

    
530
    mStickerOverrides = getStickerOverrides();
531
    mNumOverrides = mStickerOverrides==null ? 0 : mStickerOverrides.length;
532

    
533
    mNumTextures= mNumFaceColors*mNumStickerTypes + mNumOverrides;
534
    mNumTexCols = NUM_STICKERS_IN_ROW;
535
    mNumTexRows = (mNumTextures+1)/NUM_STICKERS_IN_ROW;
536
    if( mNumTexCols*mNumTexRows < mNumTextures+1 ) mNumTexRows++;
537

    
538
    if( !fromDMESH || shouldResetTextureMaps() ) resetAllTextureMaps();
539
    else overrideCubitFaceColor();
540

    
541
    setTexture();
542
    }
543

    
544
///////////////////////////////////////////////////////////////////////////////////////////////////
545

    
546
  public InitData getInitData()
547
    {
548
    return mInitData;
549
    }
550

    
551
///////////////////////////////////////////////////////////////////////////////////////////////////
552

    
553
  public boolean isInIconMode()
554
    {
555
    return mIconMode==MODE_ICON;
556
    }
557

    
558
///////////////////////////////////////////////////////////////////////////////////////////////////
559

    
560
  public int getVariantStickerShape(int variant, int face)
561
    {
562
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
563
    }
564

    
565
///////////////////////////////////////////////////////////////////////////////////////////////////
566

    
567
  public boolean shouldResetTextureMaps()
568
    {
569
    return false;
570
    }
571

    
572
///////////////////////////////////////////////////////////////////////////////////////////////////
573

    
574
  public int[][] getScrambleAlgorithms()
575
    {
576
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngles);
577
    }
578

    
579
///////////////////////////////////////////////////////////////////////////////////////////////////
580

    
581
  private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z )
582
    {
583
    final float MAXERR = 0.05f;
584
    int numAxis = dist.length;
585

    
586
    for(int i=0; i<numAxis; i++)
587
      {
588
      Static3D ax = faceAxis[i];
589
      float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
590
      if( len>mSize*dist[i]+MAXERR ) return true;
591
      }
592

    
593
    return false;
594
    }
595

    
596
///////////////////////////////////////////////////////////////////////////////////////////////////
597

    
598
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
599
    {
600
    float[][] vertices = mShapes[variant].getVertices();
601
    Static3D[] axis = getFaceAxis();
602
    float[] dist3D = getDist3D(mNumLayers);
603

    
604
    for( float[] vertex : vertices)
605
      {
606
      float x = vertex[0];
607
      float y = vertex[1];
608
      float z = vertex[2];
609

    
610
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
611

    
612
      float mx = tmp[0] + px;
613
      float my = tmp[1] + py;
614
      float mz = tmp[2] + pz;
615

    
616
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
617
      }
618

    
619
    return true;
620
    }
621

    
622
///////////////////////////////////////////////////////////////////////////////////////////////////
623

    
624
  private float computeAvg(float[] pos, int offset)
625
    {
626
    int len = pos.length/3;
627
    float ret=0.0f;
628
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
629
    ret /= len;
630

    
631
    return ret;
632
    }
633

    
634
///////////////////////////////////////////////////////////////////////////////////////////////////
635

    
636
  protected void displayCubitQuats()
637
    {
638
    StringBuilder builder = new StringBuilder();
639
    float[] tmp = new float[4];
640
    float ERR = 0.01f;
641

    
642
    for(int cubit=0; cubit<mNumCubits; cubit++)
643
      {
644
      builder.append(cubit);
645
      builder.append(" : ");
646

    
647
      int refCubit,variant = getCubitVariant(cubit,mNumLayers);
648

    
649
      for(refCubit=0; refCubit<mNumCubits; refCubit++)
650
        {
651
        if( getCubitVariant(refCubit,mNumLayers)==variant ) break;
652
        }
653

    
654
      float[] curpos = mOrigPos[cubit];
655
      float[] refpos = mOrigPos[refCubit];
656
      float refX = computeAvg(refpos,0);
657
      float refY = computeAvg(refpos,1);
658
      float refZ = computeAvg(refpos,2);
659
      float curX = computeAvg(curpos,0);
660
      float curY = computeAvg(curpos,1);
661
      float curZ = computeAvg(curpos,2);
662

    
663
      for(int quat=0; quat<mNumQuats; quat++)
664
        {
665
        QuatHelper.rotateVectorByQuat(tmp,refX,refY,refZ,0,mObjectQuats[quat]);
666

    
667
        float dx = tmp[0]-curX;
668
        float dy = tmp[1]-curY;
669
        float dz = tmp[2]-curZ;
670

    
671
        if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
672
          {
673
          if( doesNotStickOut(variant,curX,curY,curZ,tmp,mObjectQuats[quat]) )
674
            {
675
            builder.append(quat);
676
            builder.append(',');
677
            }
678
          else
679
            {
680
            android.util.Log.e("D", "cubit: "+cubit+" quat: "+quat+" : center correct, but shape sticks out");
681
            }
682
          }
683
        }
684

    
685
      builder.append('\n');
686
      }
687

    
688
    android.util.Log.e("D", "cubitQuats: \n"+builder );
689
    }
690

    
691
///////////////////////////////////////////////////////////////////////////////////////////////////
692

    
693
  public int getCubitRotationType(int cubit)
694
    {
695
    return TwistyObjectCubit.TYPE_NORMAL;
696
    }
697

    
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

    
700
  float[] getTrackingPoint(int cubitIndex, int cubitType)
701
    {
702
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
703
      {
704
      int variant = getCubitVariant(cubitIndex,mNumLayers);
705

    
706
      // object must have been created from JSON
707
      if( mVariantFaceIsOuter==null || mVariantFaceIsOuter[variant]==null )
708
        {
709
        mVariantFaceIsOuter = getVariantFaceIsOuter();
710
        }
711
      if( mShapes==null )
712
        {
713
        mShapes = new ObjectShape[mNumCubitVariants];
714
        }
715
      if( mShapes[variant]==null )
716
        {
717
        mShapes[variant] = getObjectShape(variant);
718
        }
719
      if( mOrigQuat==null )
720
        {
721
        mOrigQuat = new Static4D[mNumCubits];
722
        }
723
      if( mOrigQuat[cubitIndex]==null )
724
        {
725
        mOrigQuat[cubitIndex] = getCubitQuats(cubitIndex,mNumLayers);
726
        }
727

    
728
      int[][] indices = mShapes[variant].getVertIndices();
729
      int outer=-1, faces = indices.length;
730

    
731
      for(int i=0; i<faces; i++)
732
        {
733
        if( mVariantFaceIsOuter[variant][i]==1 )
734
          {
735
          outer=i;
736
          break;
737
          }
738
        }
739

    
740
      if( outer>=0 )
741
        {
742
        int vertIndex = indices[outer][0];
743
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
744
        float[] ret = new float[3];
745
        float[] curpos = mOrigPos[cubitIndex];
746
        Static4D quat = mOrigQuat[cubitIndex];
747
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
748

    
749
        ret[0] = mTmp[0]+computeAvg(curpos,0);
750
        ret[1] = mTmp[1]+computeAvg(curpos,1);
751
        ret[2] = mTmp[2]+computeAvg(curpos,2);
752

    
753
        return ret;
754
        }
755
      else
756
        {
757
        android.util.Log.e("D", "Error in getTrackingPoint: no outer face??");
758
        }
759
      }
760

    
761
    return null;
762
    }
763

    
764
///////////////////////////////////////////////////////////////////////////////////////////////////
765

    
766
  public int computeCurrentPuzzleFace(int type, float[] vertex)
767
    {
768
    if( type!=TwistyObjectCubit.TYPE_NORMAL )
769
      {
770
      Static3D[] axis = getFaceAxis();
771
      float[] dist3D = getDist3D(mNumLayers);
772
      final float MAXERR = 0.98f;
773
      int numAxis = axis.length;
774
      float x = vertex[0];
775
      float y = vertex[1];
776
      float z = vertex[2];
777

    
778
      for(int i=0; i<numAxis; i++)
779
        {
780
        Static3D ax = axis[i];
781
        float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
782
        if( len>mSize*dist3D[i]*MAXERR ) return i;
783
        }
784

    
785
      return -2;
786
      }
787

    
788
    return -1;
789
    }
790

    
791
///////////////////////////////////////////////////////////////////////////////////////////////////
792

    
793
  public float[] getCubitRowOffset(int cubitIndex)
794
    {
795
    return null;
796
    }
797

    
798
///////////////////////////////////////////////////////////////////////////////////////////////////
799

    
800
  void setRotationRowOffset(int puzzleFace, float[] offset)
801
    {
802
    mRowOffsets[puzzleFace][0] = offset[0];
803
    mRowOffsets[puzzleFace][1] = offset[1];
804
    mRowOffsets[puzzleFace][2] = offset[2];
805
    }
806

    
807
///////////////////////////////////////////////////////////////////////////////////////////////////
808

    
809
  int getNumAxis()
810
    {
811
    return mNumAxis;
812
    }
813

    
814
///////////////////////////////////////////////////////////////////////////////////////////////////
815

    
816
  public int[][] getSolvedQuats()
817
    {
818
    return mSolved.getSolvedQuats(mNumLayers,mNumCubitFaces,mCubitFaceColors);
819
    }
820

    
821
///////////////////////////////////////////////////////////////////////////////////////////////////
822

    
823
  public int getSolvedFunctionIndex()
824
    {
825
    return 0;
826
    }
827

    
828
///////////////////////////////////////////////////////////////////////////////////////////////////
829

    
830
  int computeRow(float[] pos, int axisIndex, int cubitType, int puzzleFace)
831
    {
832
    int ret=0;
833
    int len = pos.length / 3;
834
    Static3D axis = mAxis[axisIndex];
835
    float axisX = axis.get0();
836
    float axisY = axis.get1();
837
    float axisZ = axis.get2();
838
    float casted, xoff=0, yoff=0, zoff=0;
839

    
840
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
841
      {
842
      xoff = mRowOffsets[puzzleFace][0];
843
      yoff = mRowOffsets[puzzleFace][1];
844
      zoff = mRowOffsets[puzzleFace][2];
845
      }
846

    
847
    for(int i=0; i<len; i++)
848
      {
849
      casted = (pos[3*i]+xoff)*axisX + (pos[3*i+1]+yoff)*axisY + (pos[3*i+2]+zoff)*axisZ;
850
      ret |= computeSingleRow(axisIndex,casted);
851
      }
852

    
853
    return ret;
854
    }
855

    
856
///////////////////////////////////////////////////////////////////////////////////////////////////
857

    
858
  private int computeSingleRow(int axisIndex,float casted)
859
    {
860
    int num = mNumCuts[axisIndex];
861

    
862
    for(int i=0; i<num; i++)
863
      {
864
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
865
      }
866

    
867
    return (1<<num);
868
    }
869

    
870
///////////////////////////////////////////////////////////////////////////////////////////////////
871

    
872
  private boolean wasRotateApplied()
873
    {
874
    return mEffects.exists(mRotateEffect.getID());
875
    }
876

    
877
///////////////////////////////////////////////////////////////////////////////////////////////////
878

    
879
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
880
    {
881
    return (mCubits[cubit].getRotRow(axis) & rowBitmap) != 0;
882
    }
883

    
884
///////////////////////////////////////////////////////////////////////////////////////////////////
885
// note the minus in front of the sin() - we rotate counterclockwise
886
// when looking towards the direction where the axis increases in values.
887

    
888
  private Static4D makeQuaternion(float axisX, float axisY, float axisZ, int angleInDegrees)
889
    {
890
    while( angleInDegrees<0 ) angleInDegrees += 360;
891
    angleInDegrees %= 360;
892
    
893
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
894
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
895

    
896
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
897
    }
898

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

    
901
  private synchronized void setupPosition(int[][] moves)
902
    {
903
    if( moves!=null )
904
      {
905
      Static4D quat;
906
      int index, axisIndex, row, banBitmap, basic, angle;
907

    
908
      for(int[] move: moves)
909
        {
910
        axisIndex= move[0];
911
        banBitmap= computeBandagedBitmap( move[1],axisIndex);
912
        row      = computeRowFromBitmap( move[1] );
913

    
914
        // Firebase says that it crashes here in case of the Pyraminx Diamond. No idea why.
915
        if( axisIndex >= mBasicAngles.length || row >= mBasicAngles[axisIndex].length )
916
          {
917
          String problem = getShortName()+" "+axisIndex+" "+mBasicAngles.length+" "+row+" "+mBasicAngles[0].length;
918
          mInterface.reportProblem(problem,true);
919
          axisIndex=0;
920
          row = 0;
921
          move[2] = 0;
922
          }
923

    
924
        basic    = mBasicAngles[axisIndex][row];
925
        angle    = move[2]*(360/basic);   // this assumes that all layers from
926
                                          // the bitmap have the same BasicAngle.
927
                                          // at the moment this is always true as
928
                                          // there are no bandaged objects with
929
                                          // different per-layer BasicAngles.
930
        Static3D axis = mAxis[axisIndex];
931
        float axisX = axis.get0();
932
        float axisY = axis.get1();
933
        float axisZ = axis.get2();
934
        quat = makeQuaternion(axisX,axisY,axisZ,angle);
935

    
936
        for(int i=0; i<mNumCubits; i++)
937
          {
938
          mBelongs[i] = belongsToRotation(i,axisIndex,banBitmap);
939
          if( mBelongs[i] )
940
            {
941
            boolean result = mCubits[i].rotateCubit(quat,false);
942
            if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,1);
943
            }
944
          }
945

    
946
        recomputeFaceOffsets();
947

    
948
        for(int i=0; i<mNumCubits; i++)
949
          {
950
          if( mBelongs[i] )
951
            {
952
            index = mCubits[i].postRotateCubit(quat);
953
            setCubitQuat(i,mCubits[i].computeAssociation(),index);
954
            }
955
          else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
956
            {
957
            mCubits[i].computeRotationRow();
958
            setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
959
            }
960
          }
961
        }
962

    
963
      for(int i=0; i<mNumCubits; i++)
964
        {
965
        float[] pos = mCubits[i].getCurrentPos();
966
        int len = pos.length/3;
967
        for(int j=0; j<len; j++) clampPos(pos,3*j);
968
        }
969
      }
970
    }
971

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

    
974
  public int getScrambleType()
975
    {
976
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
977
    }
978

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

    
981
  int computeBandagedBitmap(int rowBitmap, int axis)
982
    {
983
    if( mIsBandaged )
984
      {
985
      int bitmap, initBitmap=0;
986

    
987
      while( initBitmap!=rowBitmap )
988
        {
989
        initBitmap = rowBitmap;
990

    
991
        for(int cubit=0; cubit<mNumCubits; cubit++)
992
          {
993
          bitmap = mCubits[cubit].getRotRow(axis);
994
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
995
          }
996
        }
997
      }
998

    
999
    return rowBitmap;
1000
    }
1001

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

    
1004
  private int computeRowFromBitmap(int rowBitmap)
1005
    {
1006
    int index = 0;
1007

    
1008
    while(index<32)
1009
      {
1010
      if( (rowBitmap&0x1) != 0 ) return index;
1011
      rowBitmap>>=1;
1012
      index++;
1013
      }
1014
    return 0;
1015
    }
1016

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

    
1021
  void clampPos(float[] pos, int offset)
1022
    {
1023
    float currError, minError = Float.MAX_VALUE;
1024
    int minErrorIndex1 = -1;
1025
    int minErrorIndex2 = -1;
1026

    
1027
    float x = pos[offset  ];
1028
    float y = pos[offset+1];
1029
    float z = pos[offset+2];
1030

    
1031
    float xo,yo,zo;
1032

    
1033
    for(int i=0; i<mNumCubits; i++)
1034
      {
1035
      int len = mOrigPos[i].length / 3;
1036

    
1037
      for(int j=0; j<len; j++)
1038
        {
1039
        xo = mOrigPos[i][3*j  ];
1040
        yo = mOrigPos[i][3*j+1];
1041
        zo = mOrigPos[i][3*j+2];
1042

    
1043
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1044

    
1045
        if( currError<minError )
1046
          {
1047
          minError = currError;
1048
          minErrorIndex1 = i;
1049
          minErrorIndex2 = j;
1050
          }
1051
        }
1052
      }
1053

    
1054
    if( minError< 0.05f ) // TODO: 0.05 ?
1055
      {
1056
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1057
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1058
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1059
      }
1060
    }
1061

    
1062
///////////////////////////////////////////////////////////////////////////////////////////////////
1063

    
1064
  private float getAngle()
1065
    {
1066
    mPointNum = mRotationAngle.getNumPoints();
1067
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1068
    }
1069

    
1070
///////////////////////////////////////////////////////////////////////////////////////////////////
1071

    
1072
  void setLibInterface(ObjectLibInterface inter)
1073
    {
1074
    mInterface = inter;
1075
    }
1076

    
1077
///////////////////////////////////////////////////////////////////////////////////////////////////
1078

    
1079
  void applyScrambles(int[][] moves)
1080
    {
1081
    setupPosition(moves);
1082
    }
1083

    
1084
///////////////////////////////////////////////////////////////////////////////////////////////////
1085

    
1086
  void initializeObject(int[][] moves)
1087
    {
1088
    solve();
1089
    setupPosition(moves);
1090
    }
1091

    
1092
///////////////////////////////////////////////////////////////////////////////////////////////////
1093

    
1094
  synchronized void removeRotationNow()
1095
    {
1096
    float angle = getAngle();
1097
    double nearestAngleInRadians = angle*Math.PI/180;
1098
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1099
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1100
    float axisX = mAxis[mCurrentRotAxis].get0();
1101
    float axisY = mAxis[mCurrentRotAxis].get1();
1102
    float axisZ = mAxis[mCurrentRotAxis].get2();
1103
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1104

    
1105
    mRotationAngleStatic.set0(0);
1106
    mRotationAngle.removeAll();
1107

    
1108
    for(int i=0; i<mNumCubits; i++)
1109
      {
1110
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1111
      if( mBelongs[i] )
1112
        {
1113
        boolean result = mCubits[i].rotateCubit(quat,true);
1114
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1115
        }
1116
      }
1117

    
1118
    recomputeFaceOffsets();
1119

    
1120
    for(int i=0; i<mNumCubits; i++)
1121
      {
1122
      if( mBelongs[i] )
1123
        {
1124
        int index = mCubits[i].postRotateCubit(quat);
1125
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1126
        }
1127
      else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
1128
        {
1129
        mCubits[i].computeRotationRow();
1130
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1131
        }
1132
      }
1133

    
1134
    mRotationState = STATE_NOTHING;
1135
    }
1136

    
1137
///////////////////////////////////////////////////////////////////////////////////////////////////
1138

    
1139
  private void recomputeFaceOffsets()
1140
    {
1141
    if( mThereAreDeciders )
1142
      {
1143
      for(int i=0; i<mNumPuzzleFaces; i++)
1144
        {
1145
        mRowOffsets[i][0] =0;
1146
        mRowOffsets[i][1] =0;
1147
        mRowOffsets[i][2] =0;
1148
        }
1149

    
1150
      for(int i=0; i<mNumCubits; i++)
1151
        if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1152
          {
1153
          float[] offset = mCubits[i].getOffset();
1154
          int face = mCubits[i].getPuzzleFace();
1155
          mRowOffsets[face][0] = offset[0];
1156
          mRowOffsets[face][1] = offset[1];
1157
          mRowOffsets[face][2] = offset[2];
1158
          }
1159
      }
1160
    }
1161

    
1162
///////////////////////////////////////////////////////////////////////////////////////////////////
1163

    
1164
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1165
    {
1166
    if( wasRotateApplied() )
1167
      {
1168
      mRotationState = STATE_FINISH;
1169
      float angle = getAngle();
1170
      mRotationAngleStatic.set0(angle);
1171
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1172
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1173

    
1174
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1175
      mRotationAngle.resetToBeginning();
1176
      mRotationAngle.removeAll();
1177
      mRotationAngle.add(mRotationAngleStatic);
1178
      mRotationAngle.add(mRotationAngleMiddle);
1179
      mRotationAngle.add(mRotationAngleFinal);
1180
      mRotateEffect.notifyWhenFinished(listener);
1181

    
1182
      return mRotateEffect.getID();
1183
      }
1184

    
1185
    return 0;
1186
    }
1187

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

    
1190
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1191
    {
1192
    int mult = 1;
1193

    
1194
    if( wasRotateApplied() )
1195
      {
1196
      if( mRotationState==STATE_ROTATE )
1197
        {
1198
        return 0;
1199
        }
1200
      if( mRotationState==STATE_FINISH )
1201
        {
1202
        removeRotationNow();
1203
        mult = -1;
1204
        }
1205

    
1206
      mRotationState = STATE_ROTATE;
1207
      mCurrentRotAxis = axis;
1208
      mRotRowBitmap= computeBandagedBitmap( rowBitmap,axis );
1209
      mRotationAngleStatic.set0(0.0f);
1210
      mRotationAxis.set( mAxis[axis] );
1211
      mRotationAngle.setDuration(durationMillis);
1212
      mRotationAngle.resetToBeginning();
1213
      mRotationAngle.add(new Static1D(0));
1214
      mRotationAngle.add(new Static1D(angle));
1215
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1216
      mRotateEffect.notifyWhenFinished(listener);
1217
      return mult*mRotateEffect.getID();
1218
      }
1219

    
1220
    return 0;
1221
    }
1222

    
1223
///////////////////////////////////////////////////////////////////////////////////////////////////
1224

    
1225
  void continueRotation(float angleInDegrees)
1226
    {
1227
    mRotationAngleStatic.set0(angleInDegrees);
1228
    }
1229

    
1230
///////////////////////////////////////////////////////////////////////////////////////////////////
1231

    
1232
  synchronized boolean beginNewRotation(int axis, int row )
1233
    {
1234
    if( mRotationState==STATE_ROTATE )
1235
      {
1236
      return false;
1237
      }
1238
    if( mRotationState==STATE_FINISH )
1239
      {
1240
      removeRotationNow();
1241
      }
1242

    
1243
    if( axis<0 || axis>=mNumAxis )
1244
      {
1245
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1246
      return false;
1247
      }
1248
    if( row<0 || row>=mNumLayers[axis] )
1249
      {
1250
      android.util.Log.e("object", "invalid rotation row: "+row);
1251
      return false;
1252
      }
1253

    
1254
    mRotationState = STATE_ROTATE;
1255
    mCurrentRotAxis = axis;
1256
    mRotRowBitmap= computeBandagedBitmap( (1<<row),axis );
1257
    mRotationAngleStatic.set0(0.0f);
1258
    mRotationAxis.set( mAxis[axis] );
1259
    mRotationAngle.add(mRotationAngleStatic);
1260
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1261

    
1262
    return true;
1263
    }
1264

    
1265
///////////////////////////////////////////////////////////////////////////////////////////////////
1266

    
1267
  void setTextureMap(int cubit, int face, int color)
1268
    {
1269
    int variant  = getCubitVariant(cubit,mNumLayers);
1270
    int shape    = getVariantStickerShape(variant,face);
1271
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1272
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1273
    int col      = texIndex%mNumTexCols;
1274

    
1275
    final float ratioW = 1.0f/mNumTexCols;
1276
    final float ratioH = 1.0f/mNumTexRows;
1277
    final Static4D[] maps = new Static4D[1];
1278
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1279
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1280
    }
1281

    
1282
///////////////////////////////////////////////////////////////////////////////////////////////////
1283

    
1284
  private int getCubitFaceColor(int cubit, int face)
1285
    {
1286
    int puzzleFace = getCubitFaceMap(cubit,face);
1287
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1288
    return puzzleFace;
1289
    }
1290

    
1291
///////////////////////////////////////////////////////////////////////////////////////////////////
1292

    
1293
  public int getCubitFaceMap(int cubit, int face)
1294
    {
1295
    int numFaces = mCubitFaceColors[cubit].length;
1296
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1297
    return puzzleFace<0 ? -1 : puzzleFace;
1298
    }
1299

    
1300
///////////////////////////////////////////////////////////////////////////////////////////////////
1301

    
1302
  void resetAllTextureMaps()
1303
    {
1304
    final float ratioW = 1.0f/mNumTexCols;
1305
    final float ratioH = 1.0f/mNumTexRows;
1306
    int cubColor, stiShape, texIndex, variant, row, col;
1307

    
1308
    for(int cubit=0; cubit<mNumCubits; cubit++)
1309
      {
1310
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1311
      variant = getCubitVariant(cubit,mNumLayers);
1312

    
1313
      for(int face=0; face<mNumCubitFaces; face++)
1314
        {
1315
        cubColor = getCubitFaceColor(cubit,face);
1316
        stiShape = getVariantStickerShape(variant,face);
1317
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1318
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1319
        col      = texIndex%mNumTexCols;
1320

    
1321
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1322
        }
1323

    
1324
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1325
      }
1326

    
1327
    overrideCubitFaceColor();
1328
    }
1329

    
1330
///////////////////////////////////////////////////////////////////////////////////////////////////
1331

    
1332
  private void overrideCubitFaceColor()
1333
    {
1334
    final float ratioW = 1.0f/mNumTexCols;
1335
    final float ratioH = 1.0f/mNumTexRows;
1336

    
1337
    for(int i=0; i<mNumOverrides; i++)
1338
      {
1339
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1340
      int length = cubitFaces.length/2;
1341

    
1342
      for(int j=0; j<length; j++)
1343
        {
1344
        final Static4D[] maps = new Static4D[1];
1345
        int color = mNumTextures-mNumOverrides+1+i;
1346
        int row   = (mNumTexRows-1) - color/mNumTexCols;
1347
        int col   = color%mNumTexCols;
1348
        int cubit = cubitFaces[2*j];
1349
        int face  = cubitFaces[2*j+1];
1350
        maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1351
        mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1352
        }
1353
      }
1354
    }
1355

    
1356
///////////////////////////////////////////////////////////////////////////////////////////////////
1357

    
1358
  void releaseResources()
1359
    {
1360
    mTexture.markForDeletion();
1361
    mMesh.markForDeletion();
1362
    mEffects.markForDeletion();
1363

    
1364
    for(int j=0; j<mNumCubits; j++)
1365
      {
1366
      mCubits[j].releaseResources();
1367
      }
1368
    }
1369

    
1370
///////////////////////////////////////////////////////////////////////////////////////////////////
1371

    
1372
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1373
    {
1374
    if( !mIsInMixupMode )
1375
      {
1376
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1377
      }
1378
    else
1379
      {
1380
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1381
      Static4D tmp = mObjectQuats[equAssociation];
1382
      mMixupModeQuats[cubit].set(tmp);
1383
      }
1384
    }
1385

    
1386
///////////////////////////////////////////////////////////////////////////////////////////////////
1387

    
1388
  synchronized void restorePreferences(SharedPreferences preferences)
1389
    {
1390
    boolean error = false;
1391
    String key = getShortName();
1392

    
1393
    for(int i=0; i<mNumCubits; i++)
1394
      {
1395
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1396

    
1397
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1398
        {
1399
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]],true);
1400
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1401
        }
1402
      else { error = true; break; }
1403
      }
1404

    
1405
    if( !error )
1406
      {
1407
      recomputeFaceOffsets();
1408

    
1409
      for(int i=0; i<mNumCubits; i++)
1410
        {
1411
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1412
          {
1413
          mCubits[i].computeRotationRow();
1414
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1415
          }
1416
        else { error = true; break; }
1417
        }
1418
      }
1419

    
1420
    if( error )
1421
      {
1422
      for(int i=0; i<mNumCubits; i++)
1423
        {
1424
        mCubits[i].solve();
1425
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1426
        }
1427
      }
1428
    }
1429

    
1430
///////////////////////////////////////////////////////////////////////////////////////////////////
1431

    
1432
  void savePreferences(SharedPreferences.Editor editor)
1433
    {
1434
    String key = getShortName();
1435
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1436
    }
1437

    
1438
///////////////////////////////////////////////////////////////////////////////////////////////////
1439

    
1440
  public void removePreferences(SharedPreferences.Editor editor)
1441
    {
1442
    String key = getShortName();
1443
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1444
    }
1445

    
1446
///////////////////////////////////////////////////////////////////////////////////////////////////
1447

    
1448
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1449
    {
1450
    final float A = 0.8f;  // 0<A<1
1451

    
1452
    int prev = curr>0 ? curr-1 : len-1;
1453
    int next = curr<len-1 ? curr+1 : 0;
1454

    
1455
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1456
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1457
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1458
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1459

    
1460
    float len1= v1x*v1x+v1y*v1y;
1461
    float len2= v2x*v2x+v2y*v2y;
1462

    
1463
    float cos = (v1x*v2x+v1y*v2y) / ( (float)Math.sqrt(len1*len2) );
1464

    
1465
    return 1-A*cos;
1466
    }
1467

    
1468
///////////////////////////////////////////////////////////////////////////////////////////////////
1469
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
1470
//
1471
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
1472
// to introduce the concept of a 'sink center' as well.
1473
//
1474
// public because needed in TouchControlShapemod
1475

    
1476
  public float getCircumscribedRadius()
1477
    {
1478
    switch(mNumPuzzleFaces)
1479
      {
1480
      case  4: return (SQ6/4)*mSize;
1481
      case  6: return (SQ3/2)*mSize;
1482
      case  8: return (SQ2/2)*mSize;
1483
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1484
      case 16: return 0.50f*mSize;
1485
      }
1486

    
1487
    return 0.0f;
1488
    }
1489

    
1490
///////////////////////////////////////////////////////////////////////////////////////////////////
1491

    
1492
  public ObjectSticker retSticker(int sticker)
1493
    {
1494
    if( mStickers==null )
1495
      {
1496
      float rad = getStickerRadius();
1497
      float str = getStickerStroke();
1498
      float[][] angles = getStickerAngles();
1499
      int numStickers = mStickerCoords.length;
1500
      mStickers = new ObjectSticker[numStickers];
1501

    
1502
      for(int s=0; s<numStickers; s++)
1503
        {
1504
        float scale = mStickerScales.length>s ? mStickerScales[s] : 1.0f;
1505
        float radius = rad / scale;
1506
        float stroke = str / scale;
1507
        int len = mStickerCoords[s].length/2;
1508
        float[] radii = new float[len];
1509
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
1510
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
1511
        }
1512
      }
1513

    
1514
    return mStickers[sticker];
1515
    }
1516

    
1517
///////////////////////////////////////////////////////////////////////////////////////////////////
1518
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1519

    
1520
  public void adjustStickerCoords()
1521
    {
1522

    
1523
    }
1524

    
1525
///////////////////////////////////////////////////////////////////////////////////////////////////
1526

    
1527
  public Static4D[] getQuats()
1528
    {
1529
    if( mObjectQuats==null )
1530
      {
1531
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1532
      }
1533

    
1534
    return mObjectQuats;
1535
    }
1536

    
1537
///////////////////////////////////////////////////////////////////////////////////////////////////
1538

    
1539
  public int[][] getVariantFaceIsOuter()
1540
    {
1541
    return mVariantFaceIsOuter;
1542
    }
1543

    
1544
///////////////////////////////////////////////////////////////////////////////////////////////////
1545

    
1546
  public int getInternalColor()
1547
    {
1548
    return COLOR_INTERNAL;
1549
    }
1550

    
1551
///////////////////////////////////////////////////////////////////////////////////////////////////
1552
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1553

    
1554
  private void createTexture()
1555
    {
1556
    Paint paint = new Paint();
1557
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1558
    Canvas canvas = new Canvas(mBitmap);
1559

    
1560
    paint.setAntiAlias(true);
1561
    paint.setTextAlign(Paint.Align.CENTER);
1562
    paint.setStyle(Paint.Style.FILL);
1563
    paint.setColor(getInternalColor());
1564
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1565

    
1566
    int texture = 0;
1567
    FactorySticker factory = FactorySticker.getInstance();
1568

    
1569
    for(int row=0; row<mNumTexRows; row++)
1570
      for(int col=0; col<mNumTexCols; col++)
1571
        {
1572
        if( texture<mNumTextures-mNumOverrides )
1573
          {
1574
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1575
          int color = getColor(texture%mNumFaceColors);
1576
          factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color, sticker);
1577
          }
1578
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1579
          {
1580
          int color = mStickerOverrides[mNumTextures-texture].getColor();
1581
          factory.drawSolidColor(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color);
1582
          }
1583

    
1584
        texture++;
1585
        }
1586
    }
1587

    
1588
///////////////////////////////////////////////////////////////////////////////////////////////////
1589

    
1590
  void setTexture()
1591
    {
1592
    if( mBitmap==null ) createTexture();
1593

    
1594
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1595
      {
1596
      int max = DistortedLibrary.getMaxTextureSize();
1597
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1598
      }
1599
    }
1600

    
1601
///////////////////////////////////////////////////////////////////////////////////////////////////
1602

    
1603
  void setObjectRatioNow(float sc, int nodeSize)
1604
    {
1605
    mObjectScreenRatio = sc;
1606
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1607
    mObjectScale.set(scale,scale,scale);
1608

    
1609
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1610
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1611
    }
1612

    
1613
///////////////////////////////////////////////////////////////////////////////////////////////////
1614

    
1615
  void setObjectRatio(float sizeChange, int nodeSize)
1616
    {
1617
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1618

    
1619
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1620
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1621

    
1622
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1623
    }
1624

    
1625
///////////////////////////////////////////////////////////////////////////////////////////////////
1626

    
1627
  void setNodeSize(int nodeSize)
1628
    {
1629
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1630
    }
1631

    
1632
///////////////////////////////////////////////////////////////////////////////////////////////////
1633

    
1634
  public float getRatio()
1635
    {
1636
    return mObjectScreenRatio;
1637
    }
1638

    
1639
///////////////////////////////////////////////////////////////////////////////////////////////////
1640

    
1641
  public float getObjectRatio()
1642
    {
1643
    return mObjectScreenRatio*mInitScreenRatio;
1644
    }
1645

    
1646
///////////////////////////////////////////////////////////////////////////////////////////////////
1647

    
1648
  boolean isSolved()
1649
    {
1650
    return mSolved.isSolved(mCubits);
1651
    }
1652

    
1653
///////////////////////////////////////////////////////////////////////////////////////////////////
1654

    
1655
  int computeNearestAngle(int basicAngle, float angle, float speed)
1656
    {
1657
    int nearestAngle = 360/basicAngle;
1658
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1659
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1660

    
1661
    if( tmp!=0 ) return nearestAngle*tmp;
1662

    
1663
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1664
    }
1665

    
1666
///////////////////////////////////////////////////////////////////////////////////////////////////
1667
// INTERNAL API - those are called from 'effects' package
1668
///////////////////////////////////////////////////////////////////////////////////////////////////
1669

    
1670
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1671
    {
1672
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1673
    }
1674

    
1675
///////////////////////////////////////////////////////////////////////////////////////////////////
1676

    
1677
  public Static4D getRotationQuat()
1678
    {
1679
    return mQuat;
1680
    }
1681

    
1682
///////////////////////////////////////////////////////////////////////////////////////////////////
1683

    
1684
  public float getSize()
1685
    {
1686
    return mSize;
1687
    }
1688

    
1689
///////////////////////////////////////////////////////////////////////////////////////////////////
1690

    
1691
  public void applyEffect(Effect effect, int position)
1692
    {
1693
    mEffects.apply(effect, position);
1694
    }
1695

    
1696
///////////////////////////////////////////////////////////////////////////////////////////////////
1697

    
1698
  public void removeEffect(long effectID)
1699
    {
1700
    mEffects.abortById(effectID);
1701
    }
1702

    
1703
///////////////////////////////////////////////////////////////////////////////////////////////////
1704

    
1705
  public MeshBase getObjectMesh()
1706
    {
1707
    return mMesh;
1708
    }
1709

    
1710
///////////////////////////////////////////////////////////////////////////////////////////////////
1711

    
1712
  public DistortedEffects getObjectEffects()
1713
    {
1714
    return mEffects;
1715
    }
1716

    
1717
///////////////////////////////////////////////////////////////////////////////////////////////////
1718

    
1719
  public int getCubitType(int cubit)
1720
    {
1721
    return mCubits[cubit].getType();
1722
    }
1723

    
1724
///////////////////////////////////////////////////////////////////////////////////////////////////
1725

    
1726
  public float[] getCubitOffset(int cubit)
1727
    {
1728
    return mCubits[cubit].getOffset();
1729
    }
1730

    
1731
///////////////////////////////////////////////////////////////////////////////////////////////////
1732

    
1733
  public ObjectStickerOverride[] getStickerOverrides()
1734
    {
1735
    return null;
1736
    }
1737

    
1738
///////////////////////////////////////////////////////////////////////////////////////////////////
1739

    
1740
  public boolean getError()
1741
    {
1742
    return mError;
1743
    }
1744

    
1745
///////////////////////////////////////////////////////////////////////////////////////////////////
1746

    
1747
  public String getErrorString()
1748
    {
1749
    return mErrorString;
1750
    }
1751

    
1752
///////////////////////////////////////////////////////////////////////////////////////////////////
1753
// PUBLIC API
1754
///////////////////////////////////////////////////////////////////////////////////////////////////
1755

    
1756
  public int getCubitFaceStickerIndex(int cubit, int face)
1757
    {
1758
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1759

    
1760
    int x = (int)(texMap.get0()/texMap.get2());
1761
    int y = (int)(texMap.get1()/texMap.get3());
1762

    
1763
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1764
    }
1765

    
1766
///////////////////////////////////////////////////////////////////////////////////////////////////
1767

    
1768
  public int[] getNumLayers()
1769
    {
1770
    return mNumLayers;
1771
    }
1772

    
1773
///////////////////////////////////////////////////////////////////////////////////////////////////
1774

    
1775
  public synchronized void solve()
1776
    {
1777
    for(int i=0; i<mNumCubits; i++)
1778
      {
1779
      mCubits[i].solve();
1780
      }
1781

    
1782
    recomputeFaceOffsets();
1783

    
1784
    for(int i=0; i<mNumCubits; i++)
1785
      {
1786
      mCubits[i].computeRotationRow();
1787
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1788
      }
1789
    }
1790

    
1791
///////////////////////////////////////////////////////////////////////////////////////////////////
1792

    
1793
  public int getCubitQuatIndex(int cubit)
1794
    {
1795
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1796
    }
1797

    
1798
///////////////////////////////////////////////////////////////////////////////////////////////////
1799

    
1800
  public int getCubitRotRow(int cubit, int axis)
1801
    {
1802
    return mCubits[cubit].getRotRow(axis);
1803
    }
1804

    
1805
///////////////////////////////////////////////////////////////////////////////////////////////////
1806

    
1807
  public Bitmap getStickerBitmap()
1808
    {
1809
    return mBitmap;
1810
    }
1811

    
1812
///////////////////////////////////////////////////////////////////////////////////////////////////
1813

    
1814
  public DistortedNode getNode()
1815
    {
1816
    return mNode;
1817
    }
1818

    
1819
///////////////////////////////////////////////////////////////////////////////////////////////////
1820

    
1821
  public int getNumStickerTypes()
1822
    {
1823
    return mNumStickerTypes;
1824
    }
1825

    
1826
///////////////////////////////////////////////////////////////////////////////////////////////////
1827

    
1828
  public String reportState()
1829
    {
1830
    StringBuilder builder = new StringBuilder();
1831

    
1832
    for(int i=0; i<mNumCubits; i++ )
1833
      {
1834
      if( i>0 ) builder.append('.');
1835
      builder.append(mCubits[i].mQuatIndex);
1836
      }
1837

    
1838
    return builder.toString();
1839
    }
1840

    
1841
///////////////////////////////////////////////////////////////////////////////////////////////////
1842
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1843

    
1844
  public int getNumCubitFaces()
1845
    {
1846
    return 0;
1847
    }
1848

    
1849
///////////////////////////////////////////////////////////////////////////////////////////////////
1850
// 1.0 - i.e. no pillowing - by default.
1851
// The coeff is really param of the 'sink' vertex effect - if it is not equal to 1.0, we apply the
1852
// sink effect [centered at (0,0,0)] to the whole mesh as the last step of composing it.
1853

    
1854
  public float getPillowCoeff()
1855
    {
1856
    return 1.0f;
1857
    }
1858

    
1859
///////////////////////////////////////////////////////////////////////////////////////////////////
1860

    
1861
  public TouchControl getTouchControl()
1862
    {
1863
    if( mTouchControl==null )
1864
      {
1865
      switch(getTouchControlType())
1866
        {
1867
        case TC_TETRAHEDRON      : mTouchControl = new TouchControlTetrahedron(this);
1868
                                   break;
1869
        case TC_HEXAHEDRON       : mTouchControl = new TouchControlHexahedron(this);
1870
                                   break;
1871
        case TC_OCTAHEDRON       : mTouchControl = new TouchControlOctahedron(this);
1872
                                   break;
1873
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
1874
                                   break;
1875
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
1876
                                   break;
1877
        case TC_CUBOID           : int[] numLayers = getNumLayers();
1878
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1879
                                   break;
1880
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
1881
                                   break;
1882
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
1883
                                   break;
1884
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
1885
                                   break;
1886
        case TC_CHANGING_SHAPEMOD: mTouchControl = new TouchControlShapemod(this);
1887
                                   break;
1888
        }
1889
      }
1890
    return mTouchControl;
1891
    }
1892

    
1893
///////////////////////////////////////////////////////////////////////////////////////////////////
1894

    
1895
  protected void setReader(JsonReader reader)
1896
    {
1897
    // empty
1898
    }
1899

    
1900
///////////////////////////////////////////////////////////////////////////////////////////////////
1901
  // for JSON only
1902
  public abstract int getTouchControlType();
1903
  public abstract int getTouchControlSplit();
1904
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1905
  public abstract int[][][] getEnabled();
1906
  public abstract float[] getDist3D(int[] numLayers);
1907
  public abstract Static3D[] getFaceAxis();
1908
  public abstract int[][] getScrambleEdges();
1909
  public abstract float[][] getCuts(int[] numLayers);
1910
  public abstract float getStickerRadius();
1911
  public abstract float getStickerStroke();
1912
  public abstract float[][] getStickerAngles();
1913
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1914
  public abstract ObjectShape getObjectShape(int variant);
1915
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1916
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1917
  public abstract int getNumCubitVariants(int[] numLayers);
1918
  public abstract float[][] getCubitPositions(int[] numLayers);
1919
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1920
  public abstract int getNumFaceColors();
1921
  public abstract float getScreenRatio();
1922
  public abstract int getColor(int face);
1923
  public abstract String getShortName();
1924
  public abstract ObjectSignature getSignature();
1925

    
1926
  // not only for JSON
1927
  public abstract Static3D[] getRotationAxis();
1928
  public abstract int[][] getBasicAngles();
1929
  public abstract int getNumFaces();
1930
  public abstract String getObjectName();
1931
  public abstract String getInventor();
1932
  public abstract int getYearOfInvention();
1933
  public abstract int getComplexity();
1934
  public abstract int getFOV();
1935
  public abstract String[][] getTutorials();
1936
  }
(8-8/11)