Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 716f5517

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, rowBitmap, basic, angle;
901

    
902
      for(int[] move: moves)
903
        {
904
        axisIndex= move[0];
905
        rowBitmap= computeBitmapFromRow( move[1],axisIndex);
906
        row      = computeRowFromBitmap( move[1] );
907
        basic    = mBasicAngles[axisIndex][row];
908
        angle    = move[2]*(360/basic);   // this assumes that all layers from
909
                                          // the bitmap have the same BasicAngle.
910
                                          // at the moment this is always true as
911
                                          // there are no bandaged objects with
912
                                          // different per-layer BasicAngles.
913
        Static3D axis = mAxis[axisIndex];
914
        float axisX = axis.get0();
915
        float axisY = axis.get1();
916
        float axisZ = axis.get2();
917
        quat = makeQuaternion(axisX,axisY,axisZ,angle);
918

    
919
        for(int i=0; i<mNumCubits; i++)
920
          {
921
          mBelongs[i] = belongsToRotation(i,axisIndex,rowBitmap);
922
          if( mBelongs[i] )
923
            {
924
            boolean result = mCubits[i].rotateCubit(quat);
925
            if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,1);
926
            }
927
          }
928

    
929
        recomputeFaceOffsets();
930

    
931
        for(int i=0; i<mNumCubits; i++)
932
          {
933
          if( mBelongs[i] )
934
            {
935
            index = mCubits[i].postRotateCubit(quat);
936
            setCubitQuat(i,mCubits[i].computeAssociation(),index);
937
            }
938
          else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
939
            {
940
            mCubits[i].computeRotationRow();
941
            setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
942
            }
943
          }
944
        }
945
      }
946
    }
947

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

    
950
  public int getScrambleType()
951
    {
952
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
953
    }
954

    
955
///////////////////////////////////////////////////////////////////////////////////////////////////
956

    
957
  int computeBitmapFromRow(int rowBitmap, int axis)
958
    {
959
    if( mIsBandaged )
960
      {
961
      int bitmap, initBitmap=0;
962

    
963
      while( initBitmap!=rowBitmap )
964
        {
965
        initBitmap = rowBitmap;
966

    
967
        for(int cubit=0; cubit<mNumCubits; cubit++)
968
          {
969
          bitmap = mCubits[cubit].getRotRow(axis);
970
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
971
          }
972
        }
973
      }
974

    
975
    return rowBitmap;
976
    }
977

    
978
///////////////////////////////////////////////////////////////////////////////////////////////////
979

    
980
  private int computeRowFromBitmap(int rowBitmap)
981
    {
982
    int index = 0;
983

    
984
    while(index<32)
985
      {
986
      if( (rowBitmap&0x1) != 0 ) return index;
987
      rowBitmap>>=1;
988
      index++;
989
      }
990
    return 0;
991
    }
992

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

    
997
  void clampPos(float[] pos, int offset)
998
    {
999
    float currError, minError = Float.MAX_VALUE;
1000
    int minErrorIndex1 = -1;
1001
    int minErrorIndex2 = -1;
1002

    
1003
    float x = pos[offset  ];
1004
    float y = pos[offset+1];
1005
    float z = pos[offset+2];
1006

    
1007
    float xo,yo,zo;
1008

    
1009
    for(int i=0; i<mNumCubits; i++)
1010
      {
1011
      int len = mOrigPos[i].length / 3;
1012

    
1013
      for(int j=0; j<len; j++)
1014
        {
1015
        xo = mOrigPos[i][3*j  ];
1016
        yo = mOrigPos[i][3*j+1];
1017
        zo = mOrigPos[i][3*j+2];
1018

    
1019
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1020

    
1021
        if( currError<minError )
1022
          {
1023
          minError = currError;
1024
          minErrorIndex1 = i;
1025
          minErrorIndex2 = j;
1026
          }
1027
        }
1028
      }
1029

    
1030
    if( minError< 0.05f ) // TODO: 0.05 ?
1031
      {
1032
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1033
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1034
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1035
      }
1036
    }
1037

    
1038
///////////////////////////////////////////////////////////////////////////////////////////////////
1039

    
1040
  private float getAngle()
1041
    {
1042
    mPointNum = mRotationAngle.getNumPoints();
1043
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1044
    }
1045

    
1046
///////////////////////////////////////////////////////////////////////////////////////////////////
1047

    
1048
  void setLibInterface(ObjectLibInterface inter)
1049
    {
1050
    mInterface = inter;
1051
    }
1052

    
1053
///////////////////////////////////////////////////////////////////////////////////////////////////
1054

    
1055
  void applyScrambles(int[][] moves)
1056
    {
1057
    setupPosition(moves);
1058
    }
1059

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

    
1062
  void initializeObject(int[][] moves)
1063
    {
1064
    solve();
1065
    setupPosition(moves);
1066
    }
1067

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

    
1070
  synchronized void removeRotationNow()
1071
    {
1072
    float angle = getAngle();
1073
    double nearestAngleInRadians = angle*Math.PI/180;
1074
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1075
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1076
    float axisX = mAxis[mCurrentRotAxis].get0();
1077
    float axisY = mAxis[mCurrentRotAxis].get1();
1078
    float axisZ = mAxis[mCurrentRotAxis].get2();
1079
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1080

    
1081
    mRotationAngleStatic.set0(0);
1082
    mRotationAngle.removeAll();
1083

    
1084
    for(int i=0; i<mNumCubits; i++)
1085
      {
1086
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1087
      if( mBelongs[i] )
1088
        {
1089
        boolean result = mCubits[i].rotateCubit(quat);
1090
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1091
        }
1092
      }
1093

    
1094
    recomputeFaceOffsets();
1095

    
1096
    for(int i=0; i<mNumCubits; i++)
1097
      {
1098
      if( mBelongs[i] )
1099
        {
1100
        int index = mCubits[i].postRotateCubit(quat);
1101
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1102
        }
1103
      else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
1104
        {
1105
        mCubits[i].computeRotationRow();
1106
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1107
        }
1108
      }
1109

    
1110
    mRotationState = STATE_NOTHING;
1111
    }
1112

    
1113
///////////////////////////////////////////////////////////////////////////////////////////////////
1114

    
1115
  private void recomputeFaceOffsets()
1116
    {
1117
    for(int i=0; i<mNumPuzzleFaces; i++)
1118
      {
1119
      mRowOffsets[i][0] =0;
1120
      mRowOffsets[i][1] =0;
1121
      mRowOffsets[i][2] =0;
1122
      }
1123

    
1124
    for(int i=0; i<mNumCubits; i++)
1125
      if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1126
        {
1127
        float[] offset = mCubits[i].getOffset();
1128
        int face = mCubits[i].getPuzzleFace();
1129
        mRowOffsets[face][0] = offset[0];
1130
        mRowOffsets[face][1] = offset[1];
1131
        mRowOffsets[face][2] = offset[2];
1132
        }
1133
    }
1134

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

    
1137
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1138
    {
1139
    if( wasRotateApplied() )
1140
      {
1141
      mRotationState = STATE_FINISH;
1142
      float angle = getAngle();
1143
      mRotationAngleStatic.set0(angle);
1144
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1145
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1146

    
1147
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1148
      mRotationAngle.resetToBeginning();
1149
      mRotationAngle.removeAll();
1150
      mRotationAngle.add(mRotationAngleStatic);
1151
      mRotationAngle.add(mRotationAngleMiddle);
1152
      mRotationAngle.add(mRotationAngleFinal);
1153
      mRotateEffect.notifyWhenFinished(listener);
1154

    
1155
      return mRotateEffect.getID();
1156
      }
1157

    
1158
    return 0;
1159
    }
1160

    
1161
///////////////////////////////////////////////////////////////////////////////////////////////////
1162

    
1163
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1164
    {
1165
    int mult = 1;
1166

    
1167
    if( wasRotateApplied() )
1168
      {
1169
      if( mRotationState==STATE_ROTATE )
1170
        {
1171
        return 0;
1172
        }
1173
      if( mRotationState==STATE_FINISH )
1174
        {
1175
        removeRotationNow();
1176
        mult = -1;
1177
        }
1178

    
1179
      mRotationState = STATE_ROTATE;
1180
      mCurrentRotAxis = axis;
1181
      mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis );
1182
      mRotationAngleStatic.set0(0.0f);
1183
      mRotationAxis.set( mAxis[axis] );
1184
      mRotationAngle.setDuration(durationMillis);
1185
      mRotationAngle.resetToBeginning();
1186
      mRotationAngle.add(new Static1D(0));
1187
      mRotationAngle.add(new Static1D(angle));
1188
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1189
      mRotateEffect.notifyWhenFinished(listener);
1190
      return mult*mRotateEffect.getID();
1191
      }
1192

    
1193
    return 0;
1194
    }
1195

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

    
1198
  void continueRotation(float angleInDegrees)
1199
    {
1200
    mRotationAngleStatic.set0(angleInDegrees);
1201
    }
1202

    
1203
///////////////////////////////////////////////////////////////////////////////////////////////////
1204

    
1205
  synchronized boolean beginNewRotation(int axis, int row )
1206
    {
1207
    if( mRotationState==STATE_ROTATE )
1208
      {
1209
      return false;
1210
      }
1211
    if( mRotationState==STATE_FINISH )
1212
      {
1213
      removeRotationNow();
1214
      }
1215

    
1216
    if( axis<0 || axis>=mNumAxis )
1217
      {
1218
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1219
      return false;
1220
      }
1221
    if( row<0 || row>=mNumLayers[axis] )
1222
      {
1223
      android.util.Log.e("object", "invalid rotation row: "+row);
1224
      return false;
1225
      }
1226

    
1227
    mRotationState = STATE_ROTATE;
1228
    mCurrentRotAxis = axis;
1229
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
1230
    mRotationAngleStatic.set0(0.0f);
1231
    mRotationAxis.set( mAxis[axis] );
1232
    mRotationAngle.add(mRotationAngleStatic);
1233
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1234

    
1235
    return true;
1236
    }
1237

    
1238
///////////////////////////////////////////////////////////////////////////////////////////////////
1239

    
1240
  void setTextureMap(int cubit, int face, int color)
1241
    {
1242
    int variant  = getCubitVariant(cubit,mNumLayers);
1243
    int shape    = getVariantStickerShape(variant,face);
1244
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1245
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1246
    int col      = texIndex%mNumTexCols;
1247

    
1248
    final float ratioW = 1.0f/mNumTexCols;
1249
    final float ratioH = 1.0f/mNumTexRows;
1250
    final Static4D[] maps = new Static4D[1];
1251
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1252
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1253
    }
1254

    
1255
///////////////////////////////////////////////////////////////////////////////////////////////////
1256

    
1257
  private int getCubitFaceColor(int cubit, int face)
1258
    {
1259
    int puzzleFace = getCubitFaceMap(cubit,face);
1260
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1261
    return puzzleFace;
1262
    }
1263

    
1264
///////////////////////////////////////////////////////////////////////////////////////////////////
1265

    
1266
  public int getCubitFaceMap(int cubit, int face)
1267
    {
1268
    int numFaces = mCubitFaceColors[cubit].length;
1269
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1270
    return puzzleFace<0 ? -1 : puzzleFace;
1271
    }
1272

    
1273
///////////////////////////////////////////////////////////////////////////////////////////////////
1274

    
1275
  void resetAllTextureMaps()
1276
    {
1277
    final float ratioW = 1.0f/mNumTexCols;
1278
    final float ratioH = 1.0f/mNumTexRows;
1279
    int cubColor, stiShape, texIndex, variant, row, col;
1280

    
1281
    for(int cubit=0; cubit<mNumCubits; cubit++)
1282
      {
1283
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1284
      variant = getCubitVariant(cubit,mNumLayers);
1285

    
1286
      for(int face=0; face<mNumCubitFaces; face++)
1287
        {
1288
        cubColor = getCubitFaceColor(cubit,face);
1289
        stiShape = getVariantStickerShape(variant,face);
1290
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1291
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1292
        col      = texIndex%mNumTexCols;
1293

    
1294
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1295
        }
1296

    
1297
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1298
      }
1299

    
1300
    overrideCubitFaceColor();
1301
    }
1302

    
1303
///////////////////////////////////////////////////////////////////////////////////////////////////
1304

    
1305
  private void overrideCubitFaceColor()
1306
    {
1307
    final float ratioW = 1.0f/mNumTexCols;
1308
    final float ratioH = 1.0f/mNumTexRows;
1309

    
1310
    for(int i=0; i<mNumOverrides; i++)
1311
      {
1312
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1313
      int length = cubitFaces.length/2;
1314

    
1315
      for(int j=0; j<length; j++)
1316
        {
1317
        final Static4D[] maps = new Static4D[1];
1318
        int color = mNumTextures-mNumOverrides+1+i;
1319
        int row   = (mNumTexRows-1) - color/mNumTexCols;
1320
        int col   = color%mNumTexCols;
1321
        int cubit = cubitFaces[2*j];
1322
        int face  = cubitFaces[2*j+1];
1323
        maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1324
        mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1325
        }
1326
      }
1327
    }
1328

    
1329
///////////////////////////////////////////////////////////////////////////////////////////////////
1330

    
1331
  void releaseResources()
1332
    {
1333
    mTexture.markForDeletion();
1334
    mMesh.markForDeletion();
1335
    mEffects.markForDeletion();
1336

    
1337
    for(int j=0; j<mNumCubits; j++)
1338
      {
1339
      mCubits[j].releaseResources();
1340
      }
1341
    }
1342

    
1343
///////////////////////////////////////////////////////////////////////////////////////////////////
1344

    
1345
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1346
    {
1347
    if( !mIsInMixupMode )
1348
      {
1349
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1350
      }
1351
    else
1352
      {
1353
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1354
      Static4D tmp = mObjectQuats[equAssociation];
1355
      mMixupModeQuats[cubit].set(tmp);
1356
      }
1357
    }
1358

    
1359
///////////////////////////////////////////////////////////////////////////////////////////////////
1360

    
1361
  synchronized void restorePreferences(SharedPreferences preferences)
1362
    {
1363
    boolean error = false;
1364
    String key = getShortName();
1365

    
1366
    for(int i=0; i<mNumCubits; i++)
1367
      {
1368
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1369

    
1370
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1371
        {
1372
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1373
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1374
        }
1375
      else { error = true; break; }
1376
      }
1377

    
1378
    if( !error )
1379
      {
1380
      recomputeFaceOffsets();
1381

    
1382
      for(int i=0; i<mNumCubits; i++)
1383
        {
1384
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1385
          {
1386
          mCubits[i].computeRotationRow();
1387
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1388
          }
1389
        else { error = true; break; }
1390
        }
1391
      }
1392

    
1393
    if( error )
1394
      {
1395
      for(int i=0; i<mNumCubits; i++)
1396
        {
1397
        mCubits[i].solve();
1398
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1399
        }
1400
      }
1401
    }
1402

    
1403
///////////////////////////////////////////////////////////////////////////////////////////////////
1404

    
1405
  void savePreferences(SharedPreferences.Editor editor)
1406
    {
1407
    String key = getShortName();
1408
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1409
    }
1410

    
1411
///////////////////////////////////////////////////////////////////////////////////////////////////
1412

    
1413
  public void removePreferences(SharedPreferences.Editor editor)
1414
    {
1415
    String key = getShortName();
1416
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1417
    }
1418

    
1419
///////////////////////////////////////////////////////////////////////////////////////////////////
1420

    
1421
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1422
    {
1423
    final float A = 0.8f;  // 0<A<1
1424

    
1425
    int prev = curr>0 ? curr-1 : len-1;
1426
    int next = curr<len-1 ? curr+1 : 0;
1427

    
1428
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1429
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1430
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1431
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1432

    
1433
    float len1= v1x*v1x+v1y*v1y;
1434
    float len2= v2x*v2x+v2y*v2y;
1435

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

    
1438
    return 1-A*cos;
1439
    }
1440

    
1441
///////////////////////////////////////////////////////////////////////////////////////////////////
1442
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
1443
//
1444
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
1445
// to introduce the concept of a 'sink center' as well.
1446
//
1447
// public because needed in TouchControlShapemod
1448

    
1449
  public float getCircumscribedRadius()
1450
    {
1451
    switch(mNumPuzzleFaces)
1452
      {
1453
      case  4: return (SQ6/4)*mSize;
1454
      case  6: return (SQ3/2)*mSize;
1455
      case  8: return (SQ2/2)*mSize;
1456
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1457
      case 16: return 0.50f*mSize;
1458
      }
1459

    
1460
    return 0.0f;
1461
    }
1462

    
1463
///////////////////////////////////////////////////////////////////////////////////////////////////
1464

    
1465
  public ObjectSticker retSticker(int sticker)
1466
    {
1467
    if( mStickers==null )
1468
      {
1469
      float rad = getStickerRadius();
1470
      float str = getStickerStroke();
1471
      float[][] angles = getStickerAngles();
1472
      int numStickers = mStickerCoords.length;
1473
      mStickers = new ObjectSticker[numStickers];
1474

    
1475
      for(int s=0; s<numStickers; s++)
1476
        {
1477
        float scale = mStickerScales.length>s ? mStickerScales[s] : 1.0f;
1478
        float radius = rad / scale;
1479
        float stroke = str / scale;
1480
        int len = mStickerCoords[s].length/2;
1481
        float[] radii = new float[len];
1482
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
1483
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
1484
        }
1485
      }
1486

    
1487
    return mStickers[sticker];
1488
    }
1489

    
1490
///////////////////////////////////////////////////////////////////////////////////////////////////
1491
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1492

    
1493
  public void adjustStickerCoords()
1494
    {
1495

    
1496
    }
1497

    
1498
///////////////////////////////////////////////////////////////////////////////////////////////////
1499

    
1500
  public Static4D[] getQuats()
1501
    {
1502
    if( mObjectQuats==null )
1503
      {
1504
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1505
      }
1506

    
1507
    return mObjectQuats;
1508
    }
1509

    
1510
///////////////////////////////////////////////////////////////////////////////////////////////////
1511

    
1512
  public int[][] getVariantFaceIsOuter()
1513
    {
1514
    return mVariantFaceIsOuter;
1515
    }
1516

    
1517
///////////////////////////////////////////////////////////////////////////////////////////////////
1518

    
1519
  public int getInternalColor()
1520
    {
1521
    return COLOR_INTERNAL;
1522
    }
1523

    
1524
///////////////////////////////////////////////////////////////////////////////////////////////////
1525
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1526

    
1527
  private void createTexture()
1528
    {
1529
    Paint paint = new Paint();
1530
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1531
    Canvas canvas = new Canvas(mBitmap);
1532

    
1533
    paint.setAntiAlias(true);
1534
    paint.setTextAlign(Paint.Align.CENTER);
1535
    paint.setStyle(Paint.Style.FILL);
1536
    paint.setColor(getInternalColor());
1537
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1538

    
1539
    int texture = 0;
1540
    FactorySticker factory = FactorySticker.getInstance();
1541

    
1542
    for(int row=0; row<mNumTexRows; row++)
1543
      for(int col=0; col<mNumTexCols; col++)
1544
        {
1545
        if( texture<mNumTextures-mNumOverrides )
1546
          {
1547
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1548
          int color = getColor(texture%mNumFaceColors);
1549
          factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color, sticker);
1550
          }
1551
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1552
          {
1553
          int color = mStickerOverrides[mNumTextures-texture].getColor();
1554
          factory.drawSolidColor(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color);
1555
          }
1556

    
1557
        texture++;
1558
        }
1559
    }
1560

    
1561
///////////////////////////////////////////////////////////////////////////////////////////////////
1562

    
1563
  void setTexture()
1564
    {
1565
    if( mBitmap==null ) createTexture();
1566

    
1567
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1568
      {
1569
      int max = DistortedLibrary.getMaxTextureSize();
1570
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1571
      }
1572
    }
1573

    
1574
///////////////////////////////////////////////////////////////////////////////////////////////////
1575

    
1576
  void setObjectRatioNow(float sc, int nodeSize)
1577
    {
1578
    mObjectScreenRatio = sc;
1579
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1580
    mObjectScale.set(scale,scale,scale);
1581

    
1582
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1583
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1584
    }
1585

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

    
1588
  void setObjectRatio(float sizeChange, int nodeSize)
1589
    {
1590
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1591

    
1592
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1593
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1594

    
1595
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1596
    }
1597

    
1598
///////////////////////////////////////////////////////////////////////////////////////////////////
1599

    
1600
  void setNodeSize(int nodeSize)
1601
    {
1602
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1603
    }
1604

    
1605
///////////////////////////////////////////////////////////////////////////////////////////////////
1606

    
1607
  public float getRatio()
1608
    {
1609
    return mObjectScreenRatio;
1610
    }
1611

    
1612
///////////////////////////////////////////////////////////////////////////////////////////////////
1613

    
1614
  public float getObjectRatio()
1615
    {
1616
    return mObjectScreenRatio*mInitScreenRatio;
1617
    }
1618

    
1619
///////////////////////////////////////////////////////////////////////////////////////////////////
1620

    
1621
  boolean isSolved()
1622
    {
1623
    return mSolved.isSolved(mCubits);
1624
    }
1625

    
1626
///////////////////////////////////////////////////////////////////////////////////////////////////
1627

    
1628
  int computeNearestAngle(int basicAngle, float angle, float speed)
1629
    {
1630
    int nearestAngle = 360/basicAngle;
1631
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1632
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1633

    
1634
    if( tmp!=0 ) return nearestAngle*tmp;
1635

    
1636
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1637
    }
1638

    
1639
///////////////////////////////////////////////////////////////////////////////////////////////////
1640
// INTERNAL API - those are called from 'effects' package
1641
///////////////////////////////////////////////////////////////////////////////////////////////////
1642

    
1643
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1644
    {
1645
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1646
    }
1647

    
1648
///////////////////////////////////////////////////////////////////////////////////////////////////
1649

    
1650
  public Static4D getRotationQuat()
1651
    {
1652
    return mQuat;
1653
    }
1654

    
1655
///////////////////////////////////////////////////////////////////////////////////////////////////
1656

    
1657
  public float getSize()
1658
    {
1659
    return mSize;
1660
    }
1661

    
1662
///////////////////////////////////////////////////////////////////////////////////////////////////
1663

    
1664
  public void applyEffect(Effect effect, int position)
1665
    {
1666
    mEffects.apply(effect, position);
1667
    }
1668

    
1669
///////////////////////////////////////////////////////////////////////////////////////////////////
1670

    
1671
  public void removeEffect(long effectID)
1672
    {
1673
    mEffects.abortById(effectID);
1674
    }
1675

    
1676
///////////////////////////////////////////////////////////////////////////////////////////////////
1677

    
1678
  public MeshBase getObjectMesh()
1679
    {
1680
    return mMesh;
1681
    }
1682

    
1683
///////////////////////////////////////////////////////////////////////////////////////////////////
1684

    
1685
  public DistortedEffects getObjectEffects()
1686
    {
1687
    return mEffects;
1688
    }
1689

    
1690
///////////////////////////////////////////////////////////////////////////////////////////////////
1691

    
1692
  public int getCubitType(int cubit)
1693
    {
1694
    return mCubits[cubit].getType();
1695
    }
1696

    
1697
///////////////////////////////////////////////////////////////////////////////////////////////////
1698

    
1699
  public float[] getCubitOffset(int cubit)
1700
    {
1701
    return mCubits[cubit].getOffset();
1702
    }
1703

    
1704
///////////////////////////////////////////////////////////////////////////////////////////////////
1705

    
1706
  public ObjectStickerOverride[] getStickerOverrides()
1707
    {
1708
    return null;
1709
    }
1710

    
1711
///////////////////////////////////////////////////////////////////////////////////////////////////
1712

    
1713
  public boolean getError()
1714
    {
1715
    return mError;
1716
    }
1717

    
1718
///////////////////////////////////////////////////////////////////////////////////////////////////
1719

    
1720
  public String getErrorString()
1721
    {
1722
    return mErrorString;
1723
    }
1724

    
1725
///////////////////////////////////////////////////////////////////////////////////////////////////
1726
// PUBLIC API
1727
///////////////////////////////////////////////////////////////////////////////////////////////////
1728

    
1729
  public int getCubitFaceStickerIndex(int cubit, int face)
1730
    {
1731
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1732

    
1733
    int x = (int)(texMap.get0()/texMap.get2());
1734
    int y = (int)(texMap.get1()/texMap.get3());
1735

    
1736
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1737
    }
1738

    
1739
///////////////////////////////////////////////////////////////////////////////////////////////////
1740

    
1741
  public int[] getNumLayers()
1742
    {
1743
    return mNumLayers;
1744
    }
1745

    
1746
///////////////////////////////////////////////////////////////////////////////////////////////////
1747

    
1748
  public synchronized void solve()
1749
    {
1750
    for(int i=0; i<mNumCubits; i++)
1751
      {
1752
      mCubits[i].solve();
1753
      }
1754

    
1755
    recomputeFaceOffsets();
1756

    
1757
    for(int i=0; i<mNumCubits; i++)
1758
      {
1759
      mCubits[i].computeRotationRow();
1760
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1761
      }
1762
    }
1763

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

    
1766
  public int getCubitQuatIndex(int cubit)
1767
    {
1768
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1769
    }
1770

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

    
1773
  public int getCubitRotRow(int cubit, int axis)
1774
    {
1775
    return mCubits[cubit].getRotRow(axis);
1776
    }
1777

    
1778
///////////////////////////////////////////////////////////////////////////////////////////////////
1779

    
1780
  public Bitmap getStickerBitmap()
1781
    {
1782
    return mBitmap;
1783
    }
1784

    
1785
///////////////////////////////////////////////////////////////////////////////////////////////////
1786

    
1787
  public DistortedNode getNode()
1788
    {
1789
    return mNode;
1790
    }
1791

    
1792
///////////////////////////////////////////////////////////////////////////////////////////////////
1793

    
1794
  public int getNumStickerTypes()
1795
    {
1796
    return mNumStickerTypes;
1797
    }
1798

    
1799
///////////////////////////////////////////////////////////////////////////////////////////////////
1800

    
1801
  public String reportState()
1802
    {
1803
    StringBuilder builder = new StringBuilder();
1804

    
1805
    for(int i=0; i<mNumCubits; i++ )
1806
      {
1807
      if( i>0 ) builder.append('.');
1808
      builder.append(mCubits[i].mQuatIndex);
1809
      }
1810

    
1811
    return builder.toString();
1812
    }
1813

    
1814
///////////////////////////////////////////////////////////////////////////////////////////////////
1815
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1816

    
1817
  public int getNumCubitFaces()
1818
    {
1819
    return 0;
1820
    }
1821

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

    
1827
  public float getPillowCoeff()
1828
    {
1829
    return 1.0f;
1830
    }
1831

    
1832
///////////////////////////////////////////////////////////////////////////////////////////////////
1833

    
1834
  public TouchControl getTouchControl()
1835
    {
1836
    if( mTouchControl==null )
1837
      {
1838
      switch(getTouchControlType())
1839
        {
1840
        case TC_TETRAHEDRON      : mTouchControl = new TouchControlTetrahedron(this);
1841
                                   break;
1842
        case TC_HEXAHEDRON       : mTouchControl = new TouchControlHexahedron(this);
1843
                                   break;
1844
        case TC_OCTAHEDRON       : mTouchControl = new TouchControlOctahedron(this);
1845
                                   break;
1846
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
1847
                                   break;
1848
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
1849
                                   break;
1850
        case TC_CUBOID           : int[] numLayers = getNumLayers();
1851
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1852
                                   break;
1853
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
1854
                                   break;
1855
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
1856
                                   break;
1857
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
1858
                                   break;
1859
        case TC_CHANGING_SHAPEMOD: mTouchControl = new TouchControlShapemod(this);
1860
                                   break;
1861
        }
1862
      }
1863
    return mTouchControl;
1864
    }
1865

    
1866
///////////////////////////////////////////////////////////////////////////////////////////////////
1867

    
1868
  protected void setReader(JsonReader reader)
1869
    {
1870
    // empty
1871
    }
1872

    
1873
///////////////////////////////////////////////////////////////////////////////////////////////////
1874
  // for JSON only
1875
  public abstract int getTouchControlType();
1876
  public abstract int getTouchControlSplit();
1877
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1878
  public abstract int[][][] getEnabled();
1879
  public abstract float[] getDist3D(int[] numLayers);
1880
  public abstract Static3D[] getFaceAxis();
1881
  public abstract int[][] getScrambleEdges();
1882
  public abstract float[][] getCuts(int[] numLayers);
1883
  public abstract float getStickerRadius();
1884
  public abstract float getStickerStroke();
1885
  public abstract float[][] getStickerAngles();
1886
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1887
  public abstract ObjectShape getObjectShape(int variant);
1888
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1889
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1890
  public abstract int getNumCubitVariants(int[] numLayers);
1891
  public abstract float[][] getCubitPositions(int[] numLayers);
1892
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1893
  public abstract int getNumFaceColors();
1894
  public abstract float getScreenRatio();
1895
  public abstract int getColor(int face);
1896
  public abstract String getShortName();
1897
  public abstract ObjectSignature getSignature();
1898

    
1899
  // not only for JSON
1900
  public abstract Static3D[] getRotationAxis();
1901
  public abstract int[][] getBasicAngles();
1902
  public abstract int getNumFaces();
1903
  public abstract String getObjectName();
1904
  public abstract String getInventor();
1905
  public abstract int getYearOfInvention();
1906
  public abstract int getComplexity();
1907
  public abstract int getFOV();
1908
  public abstract String[][] getTutorials();
1909
  }
(8-8/11)