Project

General

Profile

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

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

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

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

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

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

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

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

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

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

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

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

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

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

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

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

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

    
252
    boolean bandaged=false;
253

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

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

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

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

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

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

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

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

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

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

    
301
///////////////////////////////////////////////////////////////////////////////////////////////////
302

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

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

    
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314

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

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

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

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

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

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

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

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

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

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

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

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

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

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

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

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

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

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

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

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

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

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

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

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

    
458
      mMesh = new MeshJoined(cubitMesh);
459

    
460
      float pillowCoeff = getPillowCoeff();
461

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

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

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
  private MeshBase createCubitMesh(int cubit, int[] numLayers, int meshState, int numComponents)
482
    {
483
    int variant = getCubitVariant(cubit,numLayers);
484

    
485
    if( mMeshes==null ) mMeshes = new MeshBase[mNumCubitVariants];
486

    
487
    if( mMeshes[variant]==null )
488
      {
489
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
490
      ObjectVertexEffects effects = getVertexEffects(variant);
491
      FactoryCubit factory = FactoryCubit.getInstance();
492
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
493
      mMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects, meshState, numComponents);
494
      }
495

    
496
    MeshBase mesh = mMeshes[variant].copy(true);
497
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( mOrigQuat[cubit], CENTER );
498
    mesh.apply(quat,0xffffffff,0);
499

    
500
    return mesh;
501
    }
502

    
503
///////////////////////////////////////////////////////////////////////////////////////////////////
504

    
505
  private void setUpTextures(boolean fromDMESH, boolean fromJSON)
506
    {
507
    mTexture = new DistortedTexture();
508

    
509
    if( fromJSON )
510
      {
511
      mNumStickerTypes = getNumStickerTypes();
512
      mNumCubitFaces = getNumCubitFaces();
513
      }
514
    else
515
      {
516
      FactoryCubit factory = FactoryCubit.getInstance();
517
      mStickerCoords   = factory.getStickerCoords();
518
      mStickerVariants = factory.getStickerVariants();
519
      mStickerScales   = factory.getStickerScales();
520
      adjustStickerCoords();
521
      mNumStickerTypes = (mStickerCoords==null ? 0 : mStickerCoords.length);
522
      }
523

    
524
    mStickerOverrides = getStickerOverrides();
525
    mNumOverrides = mStickerOverrides==null ? 0 : mStickerOverrides.length;
526

    
527
    mNumTextures= mNumFaceColors*mNumStickerTypes + mNumOverrides;
528
    mNumTexCols = NUM_STICKERS_IN_ROW;
529
    mNumTexRows = (mNumTextures+1)/NUM_STICKERS_IN_ROW;
530
    if( mNumTexCols*mNumTexRows < mNumTextures+1 ) mNumTexRows++;
531

    
532
    if( !fromDMESH || shouldResetTextureMaps() ) resetAllTextureMaps();
533
    else overrideCubitFaceColor();
534

    
535
    setTexture();
536
    }
537

    
538
///////////////////////////////////////////////////////////////////////////////////////////////////
539

    
540
  public InitData getInitData()
541
    {
542
    return mInitData;
543
    }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

    
547
  public boolean isInIconMode()
548
    {
549
    return mIconMode==MODE_ICON;
550
    }
551

    
552
///////////////////////////////////////////////////////////////////////////////////////////////////
553

    
554
  public int getVariantStickerShape(int variant, int face)
555
    {
556
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
557
    }
558

    
559
///////////////////////////////////////////////////////////////////////////////////////////////////
560

    
561
  public boolean shouldResetTextureMaps()
562
    {
563
    return false;
564
    }
565

    
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

    
568
  public int[][] getScrambleAlgorithms()
569
    {
570
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngles);
571
    }
572

    
573
///////////////////////////////////////////////////////////////////////////////////////////////////
574

    
575
  private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z )
576
    {
577
    final float MAXERR = 0.05f;
578
    int numAxis = dist.length;
579

    
580
    for(int i=0; i<numAxis; i++)
581
      {
582
      Static3D ax = faceAxis[i];
583
      float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
584
      if( len>mSize*dist[i]+MAXERR ) return true;
585
      }
586

    
587
    return false;
588
    }
589

    
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591

    
592
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
593
    {
594
    float[][] vertices = mShapes[variant].getVertices();
595
    Static3D[] axis = getFaceAxis();
596
    float[] dist3D = getDist3D(mNumLayers);
597

    
598
    for( float[] vertex : vertices)
599
      {
600
      float x = vertex[0];
601
      float y = vertex[1];
602
      float z = vertex[2];
603

    
604
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
605

    
606
      float mx = tmp[0] + px;
607
      float my = tmp[1] + py;
608
      float mz = tmp[2] + pz;
609

    
610
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
611
      }
612

    
613
    return true;
614
    }
615

    
616
///////////////////////////////////////////////////////////////////////////////////////////////////
617

    
618
  private float computeAvg(float[] pos, int offset)
619
    {
620
    int len = pos.length/3;
621
    float ret=0.0f;
622
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
623
    ret /= len;
624

    
625
    return ret;
626
    }
627

    
628
///////////////////////////////////////////////////////////////////////////////////////////////////
629

    
630
  protected void displayCubitQuats()
631
    {
632
    StringBuilder builder = new StringBuilder();
633
    float[] tmp = new float[4];
634
    float ERR = 0.01f;
635

    
636
    for(int cubit=0; cubit<mNumCubits; cubit++)
637
      {
638
      builder.append(cubit);
639
      builder.append(" : ");
640

    
641
      int refCubit,variant = getCubitVariant(cubit,mNumLayers);
642

    
643
      for(refCubit=0; refCubit<mNumCubits; refCubit++)
644
        {
645
        if( getCubitVariant(refCubit,mNumLayers)==variant ) break;
646
        }
647

    
648
      float[] curpos = mOrigPos[cubit];
649
      float[] refpos = mOrigPos[refCubit];
650
      float refX = computeAvg(refpos,0);
651
      float refY = computeAvg(refpos,1);
652
      float refZ = computeAvg(refpos,2);
653
      float curX = computeAvg(curpos,0);
654
      float curY = computeAvg(curpos,1);
655
      float curZ = computeAvg(curpos,2);
656

    
657
      for(int quat=0; quat<mNumQuats; quat++)
658
        {
659
        QuatHelper.rotateVectorByQuat(tmp,refX,refY,refZ,0,mObjectQuats[quat]);
660

    
661
        float dx = tmp[0]-curX;
662
        float dy = tmp[1]-curY;
663
        float dz = tmp[2]-curZ;
664

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

    
679
      builder.append('\n');
680
      }
681

    
682
    android.util.Log.e("D", "cubitQuats: \n"+builder );
683
    }
684

    
685
///////////////////////////////////////////////////////////////////////////////////////////////////
686

    
687
  public int getCubitRotationType(int cubit)
688
    {
689
    return TwistyObjectCubit.TYPE_NORMAL;
690
    }
691

    
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693

    
694
  float[] getTrackingPoint(int cubitIndex, int cubitType)
695
    {
696
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
697
      {
698
      int variant = getCubitVariant(cubitIndex,mNumLayers);
699

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

    
722
      int[][] indices = mShapes[variant].getVertIndices();
723
      int outer=-1, faces = indices.length;
724

    
725
      for(int i=0; i<faces; i++)
726
        {
727
        if( mVariantFaceIsOuter[variant][i]==1 )
728
          {
729
          outer=i;
730
          break;
731
          }
732
        }
733

    
734
      if( outer>=0 )
735
        {
736
        int vertIndex = indices[outer][0];
737
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
738
        float[] ret = new float[3];
739
        float[] curpos = mOrigPos[cubitIndex];
740
        Static4D quat = mOrigQuat[cubitIndex];
741
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
742

    
743
        ret[0] = mTmp[0]+computeAvg(curpos,0);
744
        ret[1] = mTmp[1]+computeAvg(curpos,1);
745
        ret[2] = mTmp[2]+computeAvg(curpos,2);
746

    
747
        return ret;
748
        }
749
      else
750
        {
751
        android.util.Log.e("D", "Error in getTrackingPoint: no outer face??");
752
        }
753
      }
754

    
755
    return null;
756
    }
757

    
758
///////////////////////////////////////////////////////////////////////////////////////////////////
759

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

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

    
779
      return -2;
780
      }
781

    
782
    return -1;
783
    }
784

    
785
///////////////////////////////////////////////////////////////////////////////////////////////////
786

    
787
  public float[] getCubitRowOffset(int cubitIndex)
788
    {
789
    return null;
790
    }
791

    
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793

    
794
  void setRotationRowOffset(int puzzleFace, float[] offset)
795
    {
796
    mRowOffsets[puzzleFace][0] = offset[0];
797
    mRowOffsets[puzzleFace][1] = offset[1];
798
    mRowOffsets[puzzleFace][2] = offset[2];
799
    }
800

    
801
///////////////////////////////////////////////////////////////////////////////////////////////////
802

    
803
  int getNumAxis()
804
    {
805
    return mNumAxis;
806
    }
807

    
808
///////////////////////////////////////////////////////////////////////////////////////////////////
809

    
810
  public int[][] getSolvedQuats()
811
    {
812
    return mSolved.getSolvedQuats(mNumLayers,mNumCubitFaces,mCubitFaceColors);
813
    }
814

    
815
///////////////////////////////////////////////////////////////////////////////////////////////////
816

    
817
  public int getSolvedFunctionIndex()
818
    {
819
    return 0;
820
    }
821

    
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

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

    
834
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
835
      {
836
      xoff = mRowOffsets[puzzleFace][0];
837
      yoff = mRowOffsets[puzzleFace][1];
838
      zoff = mRowOffsets[puzzleFace][2];
839
      }
840

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

    
847
    return ret;
848
    }
849

    
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851

    
852
  private int computeSingleRow(int axisIndex,float casted)
853
    {
854
    int num = mNumCuts[axisIndex];
855

    
856
    for(int i=0; i<num; i++)
857
      {
858
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
859
      }
860

    
861
    return (1<<num);
862
    }
863

    
864
///////////////////////////////////////////////////////////////////////////////////////////////////
865

    
866
  private boolean wasRotateApplied()
867
    {
868
    return mEffects.exists(mRotateEffect.getID());
869
    }
870

    
871
///////////////////////////////////////////////////////////////////////////////////////////////////
872

    
873
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
874
    {
875
    return (mCubits[cubit].getRotRow(axis) & rowBitmap) != 0;
876
    }
877

    
878
///////////////////////////////////////////////////////////////////////////////////////////////////
879
// note the minus in front of the sin() - we rotate counterclockwise
880
// when looking towards the direction where the axis increases in values.
881

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

    
890
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
891
    }
892

    
893
///////////////////////////////////////////////////////////////////////////////////////////////////
894

    
895
  private synchronized void setupPosition(int[][] moves)
896
    {
897
    if( moves!=null )
898
      {
899
      Static4D quat;
900
      int index, axisIndex, row, banBitmap, basic, angle;
901

    
902
      for(int[] move: moves)
903
        {
904
        axisIndex= move[0];
905
        banBitmap= computeBandagedBitmap( move[1],axisIndex);
906
        row      = computeRowFromBitmap( move[1] );
907

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

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

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

    
940
        recomputeFaceOffsets();
941

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

    
959
///////////////////////////////////////////////////////////////////////////////////////////////////
960

    
961
  public int getScrambleType()
962
    {
963
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
964
    }
965

    
966
///////////////////////////////////////////////////////////////////////////////////////////////////
967

    
968
  int computeBandagedBitmap(int rowBitmap, int axis)
969
    {
970
    if( mIsBandaged )
971
      {
972
      int bitmap, initBitmap=0;
973

    
974
      while( initBitmap!=rowBitmap )
975
        {
976
        initBitmap = rowBitmap;
977

    
978
        for(int cubit=0; cubit<mNumCubits; cubit++)
979
          {
980
          bitmap = mCubits[cubit].getRotRow(axis);
981
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
982
          }
983
        }
984
      }
985

    
986
    return rowBitmap;
987
    }
988

    
989
///////////////////////////////////////////////////////////////////////////////////////////////////
990

    
991
  private int computeRowFromBitmap(int rowBitmap)
992
    {
993
    int index = 0;
994

    
995
    while(index<32)
996
      {
997
      if( (rowBitmap&0x1) != 0 ) return index;
998
      rowBitmap>>=1;
999
      index++;
1000
      }
1001
    return 0;
1002
    }
1003

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

    
1008
  void clampPos(float[] pos, int offset)
1009
    {
1010
    float currError, minError = Float.MAX_VALUE;
1011
    int minErrorIndex1 = -1;
1012
    int minErrorIndex2 = -1;
1013

    
1014
    float x = pos[offset  ];
1015
    float y = pos[offset+1];
1016
    float z = pos[offset+2];
1017

    
1018
    float xo,yo,zo;
1019

    
1020
    for(int i=0; i<mNumCubits; i++)
1021
      {
1022
      int len = mOrigPos[i].length / 3;
1023

    
1024
      for(int j=0; j<len; j++)
1025
        {
1026
        xo = mOrigPos[i][3*j  ];
1027
        yo = mOrigPos[i][3*j+1];
1028
        zo = mOrigPos[i][3*j+2];
1029

    
1030
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1031

    
1032
        if( currError<minError )
1033
          {
1034
          minError = currError;
1035
          minErrorIndex1 = i;
1036
          minErrorIndex2 = j;
1037
          }
1038
        }
1039
      }
1040

    
1041
    if( minError< 0.05f ) // TODO: 0.05 ?
1042
      {
1043
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1044
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1045
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1046
      }
1047
    }
1048

    
1049
///////////////////////////////////////////////////////////////////////////////////////////////////
1050

    
1051
  private float getAngle()
1052
    {
1053
    mPointNum = mRotationAngle.getNumPoints();
1054
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1055
    }
1056

    
1057
///////////////////////////////////////////////////////////////////////////////////////////////////
1058

    
1059
  void setLibInterface(ObjectLibInterface inter)
1060
    {
1061
    mInterface = inter;
1062
    }
1063

    
1064
///////////////////////////////////////////////////////////////////////////////////////////////////
1065

    
1066
  void applyScrambles(int[][] moves)
1067
    {
1068
    setupPosition(moves);
1069
    }
1070

    
1071
///////////////////////////////////////////////////////////////////////////////////////////////////
1072

    
1073
  void initializeObject(int[][] moves)
1074
    {
1075
    solve();
1076
    setupPosition(moves);
1077
    }
1078

    
1079
///////////////////////////////////////////////////////////////////////////////////////////////////
1080

    
1081
  synchronized void removeRotationNow()
1082
    {
1083
    float angle = getAngle();
1084
    double nearestAngleInRadians = angle*Math.PI/180;
1085
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1086
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1087
    float axisX = mAxis[mCurrentRotAxis].get0();
1088
    float axisY = mAxis[mCurrentRotAxis].get1();
1089
    float axisZ = mAxis[mCurrentRotAxis].get2();
1090
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1091

    
1092
    mRotationAngleStatic.set0(0);
1093
    mRotationAngle.removeAll();
1094

    
1095
    for(int i=0; i<mNumCubits; i++)
1096
      {
1097
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1098
      if( mBelongs[i] )
1099
        {
1100
        boolean result = mCubits[i].rotateCubit(quat);
1101
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1102
        }
1103
      }
1104

    
1105
    recomputeFaceOffsets();
1106

    
1107
    for(int i=0; i<mNumCubits; i++)
1108
      {
1109
      if( mBelongs[i] )
1110
        {
1111
        int index = mCubits[i].postRotateCubit(quat);
1112
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1113
        }
1114
      else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
1115
        {
1116
        mCubits[i].computeRotationRow();
1117
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1118
        }
1119
      }
1120

    
1121
    mRotationState = STATE_NOTHING;
1122
    }
1123

    
1124
///////////////////////////////////////////////////////////////////////////////////////////////////
1125

    
1126
  private void recomputeFaceOffsets()
1127
    {
1128
    for(int i=0; i<mNumPuzzleFaces; i++)
1129
      {
1130
      mRowOffsets[i][0] =0;
1131
      mRowOffsets[i][1] =0;
1132
      mRowOffsets[i][2] =0;
1133
      }
1134

    
1135
    for(int i=0; i<mNumCubits; i++)
1136
      if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1137
        {
1138
        float[] offset = mCubits[i].getOffset();
1139
        int face = mCubits[i].getPuzzleFace();
1140
        mRowOffsets[face][0] = offset[0];
1141
        mRowOffsets[face][1] = offset[1];
1142
        mRowOffsets[face][2] = offset[2];
1143
        }
1144
    }
1145

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

    
1148
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1149
    {
1150
    if( wasRotateApplied() )
1151
      {
1152
      mRotationState = STATE_FINISH;
1153
      float angle = getAngle();
1154
      mRotationAngleStatic.set0(angle);
1155
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1156
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1157

    
1158
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1159
      mRotationAngle.resetToBeginning();
1160
      mRotationAngle.removeAll();
1161
      mRotationAngle.add(mRotationAngleStatic);
1162
      mRotationAngle.add(mRotationAngleMiddle);
1163
      mRotationAngle.add(mRotationAngleFinal);
1164
      mRotateEffect.notifyWhenFinished(listener);
1165

    
1166
      return mRotateEffect.getID();
1167
      }
1168

    
1169
    return 0;
1170
    }
1171

    
1172
///////////////////////////////////////////////////////////////////////////////////////////////////
1173

    
1174
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1175
    {
1176
    int mult = 1;
1177

    
1178
    if( wasRotateApplied() )
1179
      {
1180
      if( mRotationState==STATE_ROTATE )
1181
        {
1182
        return 0;
1183
        }
1184
      if( mRotationState==STATE_FINISH )
1185
        {
1186
        removeRotationNow();
1187
        mult = -1;
1188
        }
1189

    
1190
      mRotationState = STATE_ROTATE;
1191
      mCurrentRotAxis = axis;
1192
      mRotRowBitmap= computeBandagedBitmap( rowBitmap,axis );
1193
      mRotationAngleStatic.set0(0.0f);
1194
      mRotationAxis.set( mAxis[axis] );
1195
      mRotationAngle.setDuration(durationMillis);
1196
      mRotationAngle.resetToBeginning();
1197
      mRotationAngle.add(new Static1D(0));
1198
      mRotationAngle.add(new Static1D(angle));
1199
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1200
      mRotateEffect.notifyWhenFinished(listener);
1201
      return mult*mRotateEffect.getID();
1202
      }
1203

    
1204
    return 0;
1205
    }
1206

    
1207
///////////////////////////////////////////////////////////////////////////////////////////////////
1208

    
1209
  void continueRotation(float angleInDegrees)
1210
    {
1211
    mRotationAngleStatic.set0(angleInDegrees);
1212
    }
1213

    
1214
///////////////////////////////////////////////////////////////////////////////////////////////////
1215

    
1216
  synchronized boolean beginNewRotation(int axis, int row )
1217
    {
1218
    if( mRotationState==STATE_ROTATE )
1219
      {
1220
      return false;
1221
      }
1222
    if( mRotationState==STATE_FINISH )
1223
      {
1224
      removeRotationNow();
1225
      }
1226

    
1227
    if( axis<0 || axis>=mNumAxis )
1228
      {
1229
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1230
      return false;
1231
      }
1232
    if( row<0 || row>=mNumLayers[axis] )
1233
      {
1234
      android.util.Log.e("object", "invalid rotation row: "+row);
1235
      return false;
1236
      }
1237

    
1238
    mRotationState = STATE_ROTATE;
1239
    mCurrentRotAxis = axis;
1240
    mRotRowBitmap= computeBandagedBitmap( (1<<row),axis );
1241
    mRotationAngleStatic.set0(0.0f);
1242
    mRotationAxis.set( mAxis[axis] );
1243
    mRotationAngle.add(mRotationAngleStatic);
1244
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1245

    
1246
    return true;
1247
    }
1248

    
1249
///////////////////////////////////////////////////////////////////////////////////////////////////
1250

    
1251
  void setTextureMap(int cubit, int face, int color)
1252
    {
1253
    int variant  = getCubitVariant(cubit,mNumLayers);
1254
    int shape    = getVariantStickerShape(variant,face);
1255
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1256
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1257
    int col      = texIndex%mNumTexCols;
1258

    
1259
    final float ratioW = 1.0f/mNumTexCols;
1260
    final float ratioH = 1.0f/mNumTexRows;
1261
    final Static4D[] maps = new Static4D[1];
1262
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1263
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1264
    }
1265

    
1266
///////////////////////////////////////////////////////////////////////////////////////////////////
1267

    
1268
  private int getCubitFaceColor(int cubit, int face)
1269
    {
1270
    int puzzleFace = getCubitFaceMap(cubit,face);
1271
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1272
    return puzzleFace;
1273
    }
1274

    
1275
///////////////////////////////////////////////////////////////////////////////////////////////////
1276

    
1277
  public int getCubitFaceMap(int cubit, int face)
1278
    {
1279
    int numFaces = mCubitFaceColors[cubit].length;
1280
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1281
    return puzzleFace<0 ? -1 : puzzleFace;
1282
    }
1283

    
1284
///////////////////////////////////////////////////////////////////////////////////////////////////
1285

    
1286
  void resetAllTextureMaps()
1287
    {
1288
    final float ratioW = 1.0f/mNumTexCols;
1289
    final float ratioH = 1.0f/mNumTexRows;
1290
    int cubColor, stiShape, texIndex, variant, row, col;
1291

    
1292
    for(int cubit=0; cubit<mNumCubits; cubit++)
1293
      {
1294
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1295
      variant = getCubitVariant(cubit,mNumLayers);
1296

    
1297
      for(int face=0; face<mNumCubitFaces; face++)
1298
        {
1299
        cubColor = getCubitFaceColor(cubit,face);
1300
        stiShape = getVariantStickerShape(variant,face);
1301
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1302
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1303
        col      = texIndex%mNumTexCols;
1304

    
1305
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1306
        }
1307

    
1308
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1309
      }
1310

    
1311
    overrideCubitFaceColor();
1312
    }
1313

    
1314
///////////////////////////////////////////////////////////////////////////////////////////////////
1315

    
1316
  private void overrideCubitFaceColor()
1317
    {
1318
    final float ratioW = 1.0f/mNumTexCols;
1319
    final float ratioH = 1.0f/mNumTexRows;
1320

    
1321
    for(int i=0; i<mNumOverrides; i++)
1322
      {
1323
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1324
      int length = cubitFaces.length/2;
1325

    
1326
      for(int j=0; j<length; j++)
1327
        {
1328
        final Static4D[] maps = new Static4D[1];
1329
        int color = mNumTextures-mNumOverrides+1+i;
1330
        int row   = (mNumTexRows-1) - color/mNumTexCols;
1331
        int col   = color%mNumTexCols;
1332
        int cubit = cubitFaces[2*j];
1333
        int face  = cubitFaces[2*j+1];
1334
        maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1335
        mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1336
        }
1337
      }
1338
    }
1339

    
1340
///////////////////////////////////////////////////////////////////////////////////////////////////
1341

    
1342
  void releaseResources()
1343
    {
1344
    mTexture.markForDeletion();
1345
    mMesh.markForDeletion();
1346
    mEffects.markForDeletion();
1347

    
1348
    for(int j=0; j<mNumCubits; j++)
1349
      {
1350
      mCubits[j].releaseResources();
1351
      }
1352
    }
1353

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

    
1356
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1357
    {
1358
    if( !mIsInMixupMode )
1359
      {
1360
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1361
      }
1362
    else
1363
      {
1364
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1365
      Static4D tmp = mObjectQuats[equAssociation];
1366
      mMixupModeQuats[cubit].set(tmp);
1367
      }
1368
    }
1369

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

    
1372
  synchronized void restorePreferences(SharedPreferences preferences)
1373
    {
1374
    boolean error = false;
1375
    String key = getShortName();
1376

    
1377
    for(int i=0; i<mNumCubits; i++)
1378
      {
1379
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1380

    
1381
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1382
        {
1383
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1384
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1385
        }
1386
      else { error = true; break; }
1387
      }
1388

    
1389
    if( !error )
1390
      {
1391
      recomputeFaceOffsets();
1392

    
1393
      for(int i=0; i<mNumCubits; i++)
1394
        {
1395
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1396
          {
1397
          mCubits[i].computeRotationRow();
1398
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1399
          }
1400
        else { error = true; break; }
1401
        }
1402
      }
1403

    
1404
    if( error )
1405
      {
1406
      for(int i=0; i<mNumCubits; i++)
1407
        {
1408
        mCubits[i].solve();
1409
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1410
        }
1411
      }
1412
    }
1413

    
1414
///////////////////////////////////////////////////////////////////////////////////////////////////
1415

    
1416
  void savePreferences(SharedPreferences.Editor editor)
1417
    {
1418
    String key = getShortName();
1419
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1420
    }
1421

    
1422
///////////////////////////////////////////////////////////////////////////////////////////////////
1423

    
1424
  public void removePreferences(SharedPreferences.Editor editor)
1425
    {
1426
    String key = getShortName();
1427
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1428
    }
1429

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

    
1432
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1433
    {
1434
    final float A = 0.8f;  // 0<A<1
1435

    
1436
    int prev = curr>0 ? curr-1 : len-1;
1437
    int next = curr<len-1 ? curr+1 : 0;
1438

    
1439
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1440
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1441
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1442
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1443

    
1444
    float len1= v1x*v1x+v1y*v1y;
1445
    float len2= v2x*v2x+v2y*v2y;
1446

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

    
1449
    return 1-A*cos;
1450
    }
1451

    
1452
///////////////////////////////////////////////////////////////////////////////////////////////////
1453
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
1454
//
1455
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
1456
// to introduce the concept of a 'sink center' as well.
1457
//
1458
// public because needed in TouchControlShapemod
1459

    
1460
  public float getCircumscribedRadius()
1461
    {
1462
    switch(mNumPuzzleFaces)
1463
      {
1464
      case  4: return (SQ6/4)*mSize;
1465
      case  6: return (SQ3/2)*mSize;
1466
      case  8: return (SQ2/2)*mSize;
1467
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1468
      case 16: return 0.50f*mSize;
1469
      }
1470

    
1471
    return 0.0f;
1472
    }
1473

    
1474
///////////////////////////////////////////////////////////////////////////////////////////////////
1475

    
1476
  public ObjectSticker retSticker(int sticker)
1477
    {
1478
    if( mStickers==null )
1479
      {
1480
      float rad = getStickerRadius();
1481
      float str = getStickerStroke();
1482
      float[][] angles = getStickerAngles();
1483
      int numStickers = mStickerCoords.length;
1484
      mStickers = new ObjectSticker[numStickers];
1485

    
1486
      for(int s=0; s<numStickers; s++)
1487
        {
1488
        float scale = mStickerScales.length>s ? mStickerScales[s] : 1.0f;
1489
        float radius = rad / scale;
1490
        float stroke = str / scale;
1491
        int len = mStickerCoords[s].length/2;
1492
        float[] radii = new float[len];
1493
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
1494
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
1495
        }
1496
      }
1497

    
1498
    return mStickers[sticker];
1499
    }
1500

    
1501
///////////////////////////////////////////////////////////////////////////////////////////////////
1502
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1503

    
1504
  public void adjustStickerCoords()
1505
    {
1506

    
1507
    }
1508

    
1509
///////////////////////////////////////////////////////////////////////////////////////////////////
1510

    
1511
  public Static4D[] getQuats()
1512
    {
1513
    if( mObjectQuats==null )
1514
      {
1515
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1516
      }
1517

    
1518
    return mObjectQuats;
1519
    }
1520

    
1521
///////////////////////////////////////////////////////////////////////////////////////////////////
1522

    
1523
  public int[][] getVariantFaceIsOuter()
1524
    {
1525
    return mVariantFaceIsOuter;
1526
    }
1527

    
1528
///////////////////////////////////////////////////////////////////////////////////////////////////
1529

    
1530
  public int getInternalColor()
1531
    {
1532
    return COLOR_INTERNAL;
1533
    }
1534

    
1535
///////////////////////////////////////////////////////////////////////////////////////////////////
1536
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1537

    
1538
  private void createTexture()
1539
    {
1540
    Paint paint = new Paint();
1541
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1542
    Canvas canvas = new Canvas(mBitmap);
1543

    
1544
    paint.setAntiAlias(true);
1545
    paint.setTextAlign(Paint.Align.CENTER);
1546
    paint.setStyle(Paint.Style.FILL);
1547
    paint.setColor(getInternalColor());
1548
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1549

    
1550
    int texture = 0;
1551
    FactorySticker factory = FactorySticker.getInstance();
1552

    
1553
    for(int row=0; row<mNumTexRows; row++)
1554
      for(int col=0; col<mNumTexCols; col++)
1555
        {
1556
        if( texture<mNumTextures-mNumOverrides )
1557
          {
1558
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1559
          int color = getColor(texture%mNumFaceColors);
1560
          factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color, sticker);
1561
          }
1562
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1563
          {
1564
          int color = mStickerOverrides[mNumTextures-texture].getColor();
1565
          factory.drawSolidColor(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color);
1566
          }
1567

    
1568
        texture++;
1569
        }
1570
    }
1571

    
1572
///////////////////////////////////////////////////////////////////////////////////////////////////
1573

    
1574
  void setTexture()
1575
    {
1576
    if( mBitmap==null ) createTexture();
1577

    
1578
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1579
      {
1580
      int max = DistortedLibrary.getMaxTextureSize();
1581
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1582
      }
1583
    }
1584

    
1585
///////////////////////////////////////////////////////////////////////////////////////////////////
1586

    
1587
  void setObjectRatioNow(float sc, int nodeSize)
1588
    {
1589
    mObjectScreenRatio = sc;
1590
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1591
    mObjectScale.set(scale,scale,scale);
1592

    
1593
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1594
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1595
    }
1596

    
1597
///////////////////////////////////////////////////////////////////////////////////////////////////
1598

    
1599
  void setObjectRatio(float sizeChange, int nodeSize)
1600
    {
1601
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1602

    
1603
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1604
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1605

    
1606
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1607
    }
1608

    
1609
///////////////////////////////////////////////////////////////////////////////////////////////////
1610

    
1611
  void setNodeSize(int nodeSize)
1612
    {
1613
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1614
    }
1615

    
1616
///////////////////////////////////////////////////////////////////////////////////////////////////
1617

    
1618
  public float getRatio()
1619
    {
1620
    return mObjectScreenRatio;
1621
    }
1622

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

    
1625
  public float getObjectRatio()
1626
    {
1627
    return mObjectScreenRatio*mInitScreenRatio;
1628
    }
1629

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

    
1632
  boolean isSolved()
1633
    {
1634
    return mSolved.isSolved(mCubits);
1635
    }
1636

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

    
1639
  int computeNearestAngle(int basicAngle, float angle, float speed)
1640
    {
1641
    int nearestAngle = 360/basicAngle;
1642
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1643
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1644

    
1645
    if( tmp!=0 ) return nearestAngle*tmp;
1646

    
1647
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1648
    }
1649

    
1650
///////////////////////////////////////////////////////////////////////////////////////////////////
1651
// INTERNAL API - those are called from 'effects' package
1652
///////////////////////////////////////////////////////////////////////////////////////////////////
1653

    
1654
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1655
    {
1656
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1657
    }
1658

    
1659
///////////////////////////////////////////////////////////////////////////////////////////////////
1660

    
1661
  public Static4D getRotationQuat()
1662
    {
1663
    return mQuat;
1664
    }
1665

    
1666
///////////////////////////////////////////////////////////////////////////////////////////////////
1667

    
1668
  public float getSize()
1669
    {
1670
    return mSize;
1671
    }
1672

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

    
1675
  public void applyEffect(Effect effect, int position)
1676
    {
1677
    mEffects.apply(effect, position);
1678
    }
1679

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

    
1682
  public void removeEffect(long effectID)
1683
    {
1684
    mEffects.abortById(effectID);
1685
    }
1686

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

    
1689
  public MeshBase getObjectMesh()
1690
    {
1691
    return mMesh;
1692
    }
1693

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

    
1696
  public DistortedEffects getObjectEffects()
1697
    {
1698
    return mEffects;
1699
    }
1700

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

    
1703
  public int getCubitType(int cubit)
1704
    {
1705
    return mCubits[cubit].getType();
1706
    }
1707

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

    
1710
  public float[] getCubitOffset(int cubit)
1711
    {
1712
    return mCubits[cubit].getOffset();
1713
    }
1714

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

    
1717
  public ObjectStickerOverride[] getStickerOverrides()
1718
    {
1719
    return null;
1720
    }
1721

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

    
1724
  public boolean getError()
1725
    {
1726
    return mError;
1727
    }
1728

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

    
1731
  public String getErrorString()
1732
    {
1733
    return mErrorString;
1734
    }
1735

    
1736
///////////////////////////////////////////////////////////////////////////////////////////////////
1737
// PUBLIC API
1738
///////////////////////////////////////////////////////////////////////////////////////////////////
1739

    
1740
  public int getCubitFaceStickerIndex(int cubit, int face)
1741
    {
1742
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1743

    
1744
    int x = (int)(texMap.get0()/texMap.get2());
1745
    int y = (int)(texMap.get1()/texMap.get3());
1746

    
1747
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1748
    }
1749

    
1750
///////////////////////////////////////////////////////////////////////////////////////////////////
1751

    
1752
  public int[] getNumLayers()
1753
    {
1754
    return mNumLayers;
1755
    }
1756

    
1757
///////////////////////////////////////////////////////////////////////////////////////////////////
1758

    
1759
  public synchronized void solve()
1760
    {
1761
    for(int i=0; i<mNumCubits; i++)
1762
      {
1763
      mCubits[i].solve();
1764
      }
1765

    
1766
    recomputeFaceOffsets();
1767

    
1768
    for(int i=0; i<mNumCubits; i++)
1769
      {
1770
      mCubits[i].computeRotationRow();
1771
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1772
      }
1773
    }
1774

    
1775
///////////////////////////////////////////////////////////////////////////////////////////////////
1776

    
1777
  public int getCubitQuatIndex(int cubit)
1778
    {
1779
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1780
    }
1781

    
1782
///////////////////////////////////////////////////////////////////////////////////////////////////
1783

    
1784
  public int getCubitRotRow(int cubit, int axis)
1785
    {
1786
    return mCubits[cubit].getRotRow(axis);
1787
    }
1788

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

    
1791
  public Bitmap getStickerBitmap()
1792
    {
1793
    return mBitmap;
1794
    }
1795

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

    
1798
  public DistortedNode getNode()
1799
    {
1800
    return mNode;
1801
    }
1802

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

    
1805
  public int getNumStickerTypes()
1806
    {
1807
    return mNumStickerTypes;
1808
    }
1809

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

    
1812
  public String reportState()
1813
    {
1814
    StringBuilder builder = new StringBuilder();
1815

    
1816
    for(int i=0; i<mNumCubits; i++ )
1817
      {
1818
      if( i>0 ) builder.append('.');
1819
      builder.append(mCubits[i].mQuatIndex);
1820
      }
1821

    
1822
    return builder.toString();
1823
    }
1824

    
1825
///////////////////////////////////////////////////////////////////////////////////////////////////
1826
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1827

    
1828
  public int getNumCubitFaces()
1829
    {
1830
    return 0;
1831
    }
1832

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

    
1838
  public float getPillowCoeff()
1839
    {
1840
    return 1.0f;
1841
    }
1842

    
1843
///////////////////////////////////////////////////////////////////////////////////////////////////
1844

    
1845
  public TouchControl getTouchControl()
1846
    {
1847
    if( mTouchControl==null )
1848
      {
1849
      switch(getTouchControlType())
1850
        {
1851
        case TC_TETRAHEDRON      : mTouchControl = new TouchControlTetrahedron(this);
1852
                                   break;
1853
        case TC_HEXAHEDRON       : mTouchControl = new TouchControlHexahedron(this);
1854
                                   break;
1855
        case TC_OCTAHEDRON       : mTouchControl = new TouchControlOctahedron(this);
1856
                                   break;
1857
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
1858
                                   break;
1859
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
1860
                                   break;
1861
        case TC_CUBOID           : int[] numLayers = getNumLayers();
1862
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1863
                                   break;
1864
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
1865
                                   break;
1866
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
1867
                                   break;
1868
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
1869
                                   break;
1870
        case TC_CHANGING_SHAPEMOD: mTouchControl = new TouchControlShapemod(this);
1871
                                   break;
1872
        }
1873
      }
1874
    return mTouchControl;
1875
    }
1876

    
1877
///////////////////////////////////////////////////////////////////////////////////////////////////
1878

    
1879
  protected void setReader(JsonReader reader)
1880
    {
1881
    // empty
1882
    }
1883

    
1884
///////////////////////////////////////////////////////////////////////////////////////////////////
1885
  // for JSON only
1886
  public abstract int getTouchControlType();
1887
  public abstract int getTouchControlSplit();
1888
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1889
  public abstract int[][][] getEnabled();
1890
  public abstract float[] getDist3D(int[] numLayers);
1891
  public abstract Static3D[] getFaceAxis();
1892
  public abstract int[][] getScrambleEdges();
1893
  public abstract float[][] getCuts(int[] numLayers);
1894
  public abstract float getStickerRadius();
1895
  public abstract float getStickerStroke();
1896
  public abstract float[][] getStickerAngles();
1897
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1898
  public abstract ObjectShape getObjectShape(int variant);
1899
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1900
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1901
  public abstract int getNumCubitVariants(int[] numLayers);
1902
  public abstract float[][] getCubitPositions(int[] numLayers);
1903
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1904
  public abstract int getNumFaceColors();
1905
  public abstract float getScreenRatio();
1906
  public abstract int getColor(int face);
1907
  public abstract String getShortName();
1908
  public abstract ObjectSignature getSignature();
1909

    
1910
  // not only for JSON
1911
  public abstract Static3D[] getRotationAxis();
1912
  public abstract int[][] getBasicAngles();
1913
  public abstract int getNumFaces();
1914
  public abstract String getObjectName();
1915
  public abstract String getInventor();
1916
  public abstract int getYearOfInvention();
1917
  public abstract int getComplexity();
1918
  public abstract int getFOV();
1919
  public abstract String[][] getTutorials();
1920
  }
(8-8/11)