Project

General

Profile

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

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

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.graphics.Bitmap;
18
import android.graphics.Canvas;
19
import android.graphics.Paint;
20

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

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

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

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

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

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

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

    
83
  public static final int COLOR_RED_TET  = 0xffff1111;
84
  public static final int COLOR_BLUE_TET = 0xff4444ff;
85

    
86
  private static final int STATE_NOTHING = 0;
87
  private static final int STATE_ROTATE  = 1;
88
  private static final int STATE_FINISH  = 2;
89

    
90
  public static final int TEXTURE_HEIGHT = 256;
91
  static final int NUM_STICKERS_IN_ROW = 4;
92

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

    
98
  private static final float MAX_SIZE_CHANGE = 1.35f;
99
  private static final float MIN_SIZE_CHANGE = 0.75f;
100

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

    
104
  protected float[][] mStickerCoords;
105
  protected Static4D[] mObjectQuats;
106

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

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

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

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

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

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

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

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

    
213
    mInterface.reportProblem(problem,true);
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

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

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

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

    
247
    int scramblingType = getScrambleType();
248
    int[][] edges = getScrambleEdges();
249
    int[][] algorithms = getScrambleAlgorithms();
250

    
251
    OperatingSystemInterface os = asset==null ? null : asset.getOS();
252
    TablebasesAbstract tablebase = os!=null ? getTablebase(os) : null;
253
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges,tablebase);
254

    
255
    boolean bandaged=false;
256

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

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

    
272
    mRotationAngleStatic = new Static1D(0);
273
    mRotationAngleMiddle = new Static1D(0);
274
    mRotationAngleFinal  = new Static1D(0);
275

    
276
    mObjectScale = new Static3D(scale,scale,scale);
277
    setObjectRatioNow(scale,720);
278

    
279
    mEffects = new DistortedEffects();
280
    createQuaternionEffects();
281

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

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

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

    
296
    mEffects.apply(mRotateEffect);
297
    mEffects.apply(quatEffect);
298
    mEffects.apply(scaleEffect);
299
    mEffects.apply(moveEffect);
300

    
301
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
302
    }
303

    
304
///////////////////////////////////////////////////////////////////////////////////////////////////
305

    
306
  private TablebasesAbstract getTablebase(OperatingSystemInterface os)
307
    {
308
    ObjectSignature signature = getSignature();
309
    long[] array = signature.getArray();
310
    int len = array.length;
311
    int sig = (int)array[len-1];
312

    
313
    return ImplementedTablebasesList.createPacked(os,sig);
314
    }
315

    
316
///////////////////////////////////////////////////////////////////////////////////////////////////
317

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

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

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

    
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351

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

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

    
366
    sumX /= len;
367
    sumY /= len;
368
    sumZ /= len;
369

    
370
    return new Static3D(sumX,sumY,sumZ);
371
    }
372

    
373
///////////////////////////////////////////////////////////////////////////////////////////////////
374

    
375
  private void createOuterFaces()
376
    {
377
    for(int v=0; v<mNumCubitVariants; v++)
378
      {
379
      int numFaces = mShapes[v].getNumFaces();
380
      mVariantFaceIsOuter[v] = new int[numFaces];
381
      }
382

    
383
    for( int cubit=0; cubit<mNumCubits; cubit++)
384
      {
385
      int variant = getCubitVariant(cubit,mNumLayers);
386
      int numFaces = mShapes[variant].getNumFaces();
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 outer=-1, faces = mShapes[variant].getNumFaces();
729

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

    
739
      if( outer>=0 )
740
        {
741
        float[] v = mShapes[variant].getFirstVertexInFace(outer);
742
        float[] ret = new float[3];
743
        float[] curpos = mOrigPos[cubitIndex];
744
        Static4D quat = mOrigQuat[cubitIndex];
745
        QuatHelper.rotateVectorByQuat(mTmp, v[0], v[1], v[2], 1, quat);
746

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

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

    
759
    return null;
760
    }
761

    
762
///////////////////////////////////////////////////////////////////////////////////////////////////
763

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

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

    
783
      return -2;
784
      }
785

    
786
    return -1;
787
    }
788

    
789
///////////////////////////////////////////////////////////////////////////////////////////////////
790

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

    
796
///////////////////////////////////////////////////////////////////////////////////////////////////
797

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

    
805
///////////////////////////////////////////////////////////////////////////////////////////////////
806

    
807
  int getNumAxis()
808
    {
809
    return mNumAxis;
810
    }
811

    
812
///////////////////////////////////////////////////////////////////////////////////////////////////
813

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

    
819
///////////////////////////////////////////////////////////////////////////////////////////////////
820

    
821
  public int getSolvedFunctionIndex()
822
    {
823
    return 0;
824
    }
825

    
826
///////////////////////////////////////////////////////////////////////////////////////////////////
827

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

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

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

    
851
    return ret;
852
    }
853

    
854
///////////////////////////////////////////////////////////////////////////////////////////////////
855

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

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

    
865
    return (1<<num);
866
    }
867

    
868
///////////////////////////////////////////////////////////////////////////////////////////////////
869

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

    
875
///////////////////////////////////////////////////////////////////////////////////////////////////
876

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

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

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

    
894
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
895
    }
896

    
897
///////////////////////////////////////////////////////////////////////////////////////////////////
898

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

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

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

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

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

    
944
        recomputeFaceOffsets();
945

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

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

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

    
972
  public int getScrambleType()
973
    {
974
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
975
    }
976

    
977
///////////////////////////////////////////////////////////////////////////////////////////////////
978

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

    
985
      while( initBitmap!=rowBitmap )
986
        {
987
        initBitmap = rowBitmap;
988

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

    
997
    return rowBitmap;
998
    }
999

    
1000
///////////////////////////////////////////////////////////////////////////////////////////////////
1001

    
1002
  private int computeRowFromBitmap(int rowBitmap)
1003
    {
1004
    int index = 0;
1005

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

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

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

    
1025
    float x = pos[offset  ];
1026
    float y = pos[offset+1];
1027
    float z = pos[offset+2];
1028

    
1029
    float xo,yo,zo;
1030

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

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

    
1041
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1042

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

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

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

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

    
1068
///////////////////////////////////////////////////////////////////////////////////////////////////
1069

    
1070
  void setLibInterface(ObjectLibInterface inter)
1071
    {
1072
    mInterface = inter;
1073
    }
1074

    
1075
///////////////////////////////////////////////////////////////////////////////////////////////////
1076

    
1077
  void applyScrambles(int[][] moves)
1078
    {
1079
    setupPosition(moves);
1080
    }
1081

    
1082
///////////////////////////////////////////////////////////////////////////////////////////////////
1083

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

    
1090
///////////////////////////////////////////////////////////////////////////////////////////////////
1091

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

    
1103
    mRotationAngleStatic.set0(0);
1104
    mRotationAngle.removeAll();
1105

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

    
1116
    recomputeFaceOffsets();
1117

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

    
1132
    mRotationState = STATE_NOTHING;
1133
    }
1134

    
1135
///////////////////////////////////////////////////////////////////////////////////////////////////
1136

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

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

    
1160
///////////////////////////////////////////////////////////////////////////////////////////////////
1161

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

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

    
1180
      return mRotateEffect.getID();
1181
      }
1182

    
1183
    return 0;
1184
    }
1185

    
1186
///////////////////////////////////////////////////////////////////////////////////////////////////
1187

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

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

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

    
1218
    return 0;
1219
    }
1220

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

    
1223
  void continueRotation(float angleInDegrees)
1224
    {
1225
    mRotationAngleStatic.set0(angleInDegrees);
1226
    }
1227

    
1228
///////////////////////////////////////////////////////////////////////////////////////////////////
1229

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

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

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

    
1260
    return true;
1261
    }
1262

    
1263
///////////////////////////////////////////////////////////////////////////////////////////////////
1264

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

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

    
1280
///////////////////////////////////////////////////////////////////////////////////////////////////
1281

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

    
1289
///////////////////////////////////////////////////////////////////////////////////////////////////
1290

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

    
1298
///////////////////////////////////////////////////////////////////////////////////////////////////
1299

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

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

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

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

    
1322
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1323
      }
1324

    
1325
    overrideCubitFaceColor();
1326
    }
1327

    
1328
///////////////////////////////////////////////////////////////////////////////////////////////////
1329

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

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

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

    
1354
///////////////////////////////////////////////////////////////////////////////////////////////////
1355

    
1356
  void releaseResources()
1357
    {
1358
    mTexture.markForDeletion();
1359
    mMesh.markForDeletion();
1360
    mEffects.markForDeletion();
1361

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

    
1368
///////////////////////////////////////////////////////////////////////////////////////////////////
1369

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

    
1384
///////////////////////////////////////////////////////////////////////////////////////////////////
1385

    
1386
  synchronized void restorePreferences(OperatingSystemInterface os)
1387
    {
1388
    boolean error = false;
1389
    String key = getShortName();
1390

    
1391
    for(int i=0; i<mNumCubits; i++)
1392
      {
1393
      mQuatDebug[i] = mCubits[i].restorePreferences(key,os);
1394

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

    
1403
    if( !error )
1404
      {
1405
      recomputeFaceOffsets();
1406

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

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

    
1428
///////////////////////////////////////////////////////////////////////////////////////////////////
1429

    
1430
  void savePreferences(OperatingSystemInterface os)
1431
    {
1432
    String key = getShortName();
1433
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,os);
1434
    }
1435

    
1436
///////////////////////////////////////////////////////////////////////////////////////////////////
1437

    
1438
  public void removePreferences(OperatingSystemInterface os)
1439
    {
1440
    String key = getShortName();
1441
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,os);
1442
    }
1443

    
1444
///////////////////////////////////////////////////////////////////////////////////////////////////
1445

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

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

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

    
1458
    float len1= v1x*v1x+v1y*v1y;
1459
    float len2= v2x*v2x+v2y*v2y;
1460

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

    
1463
    return 1-A*cos;
1464
    }
1465

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

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

    
1485
    return 0.0f;
1486
    }
1487

    
1488
///////////////////////////////////////////////////////////////////////////////////////////////////
1489

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

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

    
1512
    return mStickers[sticker];
1513
    }
1514

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

    
1518
  public void adjustStickerCoords()
1519
    {
1520

    
1521
    }
1522

    
1523
///////////////////////////////////////////////////////////////////////////////////////////////////
1524

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

    
1532
    return mObjectQuats;
1533
    }
1534

    
1535
///////////////////////////////////////////////////////////////////////////////////////////////////
1536

    
1537
  public int[][] getVariantFaceIsOuter()
1538
    {
1539
    return mVariantFaceIsOuter;
1540
    }
1541

    
1542
///////////////////////////////////////////////////////////////////////////////////////////////////
1543

    
1544
  public int getInternalColor()
1545
    {
1546
    return COLOR_INTERNAL;
1547
    }
1548

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

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

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

    
1564
    int texture = 0;
1565
    FactorySticker factory = FactorySticker.getInstance();
1566

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

    
1582
        texture++;
1583
        }
1584
    }
1585

    
1586
///////////////////////////////////////////////////////////////////////////////////////////////////
1587

    
1588
  void setTexture()
1589
    {
1590
    if( mBitmap==null ) createTexture();
1591

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

    
1599
///////////////////////////////////////////////////////////////////////////////////////////////////
1600

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

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

    
1611
///////////////////////////////////////////////////////////////////////////////////////////////////
1612

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

    
1617
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1618
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1619

    
1620
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1621
    }
1622

    
1623
///////////////////////////////////////////////////////////////////////////////////////////////////
1624

    
1625
  void setNodeSize(int nodeSize)
1626
    {
1627
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1628
    }
1629

    
1630
///////////////////////////////////////////////////////////////////////////////////////////////////
1631

    
1632
  public float getRatio()
1633
    {
1634
    return mObjectScreenRatio;
1635
    }
1636

    
1637
///////////////////////////////////////////////////////////////////////////////////////////////////
1638

    
1639
  public float getObjectRatio()
1640
    {
1641
    return mObjectScreenRatio*mInitScreenRatio;
1642
    }
1643

    
1644
///////////////////////////////////////////////////////////////////////////////////////////////////
1645

    
1646
  boolean isSolved()
1647
    {
1648
    return mSolved.isSolved(mCubits);
1649
    }
1650

    
1651
///////////////////////////////////////////////////////////////////////////////////////////////////
1652

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

    
1659
    if( tmp!=0 ) return nearestAngle*tmp;
1660

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

    
1664
///////////////////////////////////////////////////////////////////////////////////////////////////
1665
// INTERNAL API - those are called from 'effects' package
1666
///////////////////////////////////////////////////////////////////////////////////////////////////
1667

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

    
1673
///////////////////////////////////////////////////////////////////////////////////////////////////
1674

    
1675
  public Static4D getRotationQuat()
1676
    {
1677
    return mQuat;
1678
    }
1679

    
1680
///////////////////////////////////////////////////////////////////////////////////////////////////
1681

    
1682
  public float getSize()
1683
    {
1684
    return mSize;
1685
    }
1686

    
1687
///////////////////////////////////////////////////////////////////////////////////////////////////
1688

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

    
1694
///////////////////////////////////////////////////////////////////////////////////////////////////
1695

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

    
1701
///////////////////////////////////////////////////////////////////////////////////////////////////
1702

    
1703
  public MeshBase getObjectMesh()
1704
    {
1705
    return mMesh;
1706
    }
1707

    
1708
///////////////////////////////////////////////////////////////////////////////////////////////////
1709

    
1710
  public DistortedEffects getObjectEffects()
1711
    {
1712
    return mEffects;
1713
    }
1714

    
1715
///////////////////////////////////////////////////////////////////////////////////////////////////
1716

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

    
1722
///////////////////////////////////////////////////////////////////////////////////////////////////
1723

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

    
1729
///////////////////////////////////////////////////////////////////////////////////////////////////
1730

    
1731
  public ObjectStickerOverride[] getStickerOverrides()
1732
    {
1733
    return null;
1734
    }
1735

    
1736
///////////////////////////////////////////////////////////////////////////////////////////////////
1737

    
1738
  public boolean getError()
1739
    {
1740
    return mError;
1741
    }
1742

    
1743
///////////////////////////////////////////////////////////////////////////////////////////////////
1744

    
1745
  public String getErrorString()
1746
    {
1747
    return mErrorString;
1748
    }
1749

    
1750
///////////////////////////////////////////////////////////////////////////////////////////////////
1751
// PUBLIC API
1752
///////////////////////////////////////////////////////////////////////////////////////////////////
1753

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

    
1758
    int x = (int)(texMap.get0()/texMap.get2());
1759
    int y = (int)(texMap.get1()/texMap.get3());
1760

    
1761
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1762
    }
1763

    
1764
///////////////////////////////////////////////////////////////////////////////////////////////////
1765

    
1766
  public int[] getNumLayers()
1767
    {
1768
    return mNumLayers;
1769
    }
1770

    
1771
///////////////////////////////////////////////////////////////////////////////////////////////////
1772

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

    
1780
    recomputeFaceOffsets();
1781

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

    
1789
///////////////////////////////////////////////////////////////////////////////////////////////////
1790

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

    
1796
///////////////////////////////////////////////////////////////////////////////////////////////////
1797

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

    
1803
///////////////////////////////////////////////////////////////////////////////////////////////////
1804

    
1805
  public Bitmap getStickerBitmap()
1806
    {
1807
    return mBitmap;
1808
    }
1809

    
1810
///////////////////////////////////////////////////////////////////////////////////////////////////
1811

    
1812
  public DistortedNode getNode()
1813
    {
1814
    return mNode;
1815
    }
1816

    
1817
///////////////////////////////////////////////////////////////////////////////////////////////////
1818

    
1819
  public int getNumStickerTypes()
1820
    {
1821
    return mNumStickerTypes;
1822
    }
1823

    
1824
///////////////////////////////////////////////////////////////////////////////////////////////////
1825

    
1826
  public String reportState()
1827
    {
1828
    StringBuilder builder = new StringBuilder();
1829

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

    
1836
    return builder.toString();
1837
    }
1838

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

    
1842
  public int getNumCubitFaces()
1843
    {
1844
    return 0;
1845
    }
1846

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

    
1852
  public float getPillowCoeff()
1853
    {
1854
    return 1.0f;
1855
    }
1856

    
1857
///////////////////////////////////////////////////////////////////////////////////////////////////
1858

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

    
1891
///////////////////////////////////////////////////////////////////////////////////////////////////
1892

    
1893
  public float[][] returnRotationFactor()
1894
    {
1895
    float[][] factor = new float[mNumAxis][];
1896

    
1897
    for(int ax=0; ax<mNumAxis; ax++)
1898
      {
1899
      int numL = mNumLayers[ax];
1900
      factor[ax] = new float[numL];
1901
      for(int la=0; la<numL; la++) factor[ax][la] = 1.0f;
1902
      }
1903

    
1904
    return factor;
1905
    }
1906

    
1907
///////////////////////////////////////////////////////////////////////////////////////////////////
1908

    
1909
  protected void setReader(JsonReader reader)
1910
    {
1911
    // empty
1912
    }
1913

    
1914
///////////////////////////////////////////////////////////////////////////////////////////////////
1915
  // for JSON only
1916
  public abstract int getTouchControlType();
1917
  public abstract int getTouchControlSplit();
1918
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1919
  public abstract int[][][] getEnabled();
1920
  public abstract float[] getDist3D(int[] numLayers);
1921
  public abstract Static3D[] getFaceAxis();
1922
  public abstract int[][] getScrambleEdges();
1923
  public abstract float[][] getCuts(int[] numLayers);
1924
  public abstract float getStickerRadius();
1925
  public abstract float getStickerStroke();
1926
  public abstract float[][] getStickerAngles();
1927
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1928
  public abstract ObjectShape getObjectShape(int variant);
1929
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1930
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1931
  public abstract int getNumCubitVariants(int[] numLayers);
1932
  public abstract float[][] getCubitPositions(int[] numLayers);
1933
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1934
  public abstract int getNumFaceColors();
1935
  public abstract float getScreenRatio();
1936
  public abstract int getColor(int face);
1937
  public abstract String getShortName();
1938
  public abstract ObjectSignature getSignature();
1939

    
1940
  // not only for JSON
1941
  public abstract Static3D[] getRotationAxis();
1942
  public abstract int[][] getBasicAngles();
1943
  public abstract int getNumFaces();
1944
  public abstract String getObjectName();
1945
  public abstract String getInventor();
1946
  public abstract int getYearOfInvention();
1947
  public abstract int getComplexity();
1948
  public abstract int getFOV();
1949
  public abstract String[][] getTutorials();
1950
  }
(8-8/11)