Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 19c8e760

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

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

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

    
58
import static org.distorted.objectlib.touchcontrol.TouchControl.*;
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

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

    
67
  public static final int MODE_ICON = 0;
68
  public static final int MODE_NORM = 1;
69

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

    
81
  private static final int STATE_NOTHING = 0;
82
  private static final int STATE_ROTATE  = 1;
83
  private static final int STATE_FINISH  = 2;
84

    
85
  public static final int TEXTURE_HEIGHT = 256;
86
  static final int NUM_STICKERS_IN_ROW = 4;
87

    
88
  public static final float SQ2 = (float)Math.sqrt(2);
89
  public static final float SQ3 = (float)Math.sqrt(3);
90
  public static final float SQ5 = (float)Math.sqrt(5);
91
  public static final float SQ6 = (float)Math.sqrt(6);
92

    
93
  private static final float MAX_SIZE_CHANGE = 1.35f;
94
  private static final float MIN_SIZE_CHANGE = 0.75f;
95

    
96
  private static final Static3D CENTER = new Static3D(0,0,0);
97
  private static final int POST_ROTATION_MILLISEC = 500;
98

    
99
  protected float[][] mStickerCoords;
100
  protected Static4D[] mObjectQuats;
101

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

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

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

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

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

    
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

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

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

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

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

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

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

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

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

    
247
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges);
248

    
249
    boolean bandaged=false;
250

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

    
262
    mRotationAngle= new Dynamic1D();
263
    mRotationAxis = new Static3D(1,0,0);
264
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
265

    
266
    mRotationAngleStatic = new Static1D(0);
267
    mRotationAngleMiddle = new Static1D(0);
268
    mRotationAngleFinal  = new Static1D(0);
269

    
270
    mObjectScale = new Static3D(scale,scale,scale);
271
    setObjectRatioNow(scale,720);
272

    
273
    mEffects = new DistortedEffects();
274
    createQuaternionEffects();
275

    
276
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
277
    MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER);
278
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
279

    
280
    boolean fromDMESH = (meshStream!=null && meshState==MESH_NICE);
281
    getQuatsAndShapes(fromDMESH,fromJSON);
282
    createMeshAndCubits(meshStream,meshState,fromDMESH);
283
    setUpTextures(fromDMESH,fromJSON);
284

    
285
    int index = getSolvedFunctionIndex();
286
    mSolved = new TwistyObjectSolved(this,mOrigPos,index);
287
    mSolved.setupSolvedQuats(getSolvedQuats());
288

    
289
    mEffects.apply(mRotateEffect);
290
    mEffects.apply(quatEffect);
291
    mEffects.apply(scaleEffect);
292
    mEffects.apply(moveEffect);
293

    
294
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
295
    }
296

    
297
///////////////////////////////////////////////////////////////////////////////////////////////////
298

    
299
  private void createQuaternionEffects()
300
    {
301
    if( mNumQuats<=ObjectControl.MAX_QUATS )
302
      {
303
      mIsInMixupMode = false;
304

    
305
      for( int q=0; q<mNumQuats; q++)
306
        {
307
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mObjectQuats[q],CENTER);
308
        vq.setMeshAssociation(0,q);
309
        mEffects.apply(vq);
310
        }
311
      }
312
    else if( mNumCubits<=ObjectControl.MAX_QUATS )
313
      {
314
      mIsInMixupMode = true;
315
      mMixupModeQuats = new Static4D[mNumCubits];
316

    
317
      for( int q=0; q<mNumCubits; q++)
318
        {
319
        mMixupModeQuats[q] = new Static4D(mObjectQuats[0]);
320
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mMixupModeQuats[q],CENTER);
321
        vq.setMeshAssociation(0,q);
322
        mEffects.apply(vq);
323
        }
324
      }
325
    else
326
      {
327
      android.util.Log.e("D", "object has too many quaternions ("+mNumQuats+") or too many cubits ("+mNumCubits+")");
328
      }
329
    }
330

    
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

    
333
  private Static3D getPos(float[] origPos)
334
    {
335
    int len = origPos.length/3;
336
    float sumX = 0.0f;
337
    float sumY = 0.0f;
338
    float sumZ = 0.0f;
339

    
340
    for(int i=0; i<len; i++)
341
      {
342
      sumX += origPos[3*i  ];
343
      sumY += origPos[3*i+1];
344
      sumZ += origPos[3*i+2];
345
      }
346

    
347
    sumX /= len;
348
    sumY /= len;
349
    sumZ /= len;
350

    
351
    return new Static3D(sumX,sumY,sumZ);
352
    }
353

    
354
///////////////////////////////////////////////////////////////////////////////////////////////////
355

    
356
  private void createOuterFaces()
357
    {
358
    for(int v=0; v<mNumCubitVariants; v++)
359
      {
360
      int[][] indices = mShapes[v].getVertIndices();
361
      int faces = indices.length;
362
      mVariantFaceIsOuter[v] = new int[faces];
363
      }
364

    
365
    for( int cubit=0; cubit<mNumCubits; cubit++)
366
      {
367
      int variant = getCubitVariant(cubit,mNumLayers);
368
      int[][] indices = mShapes[variant].getVertIndices();
369
      int numFaces = indices.length;
370

    
371
      for(int face=0; face<numFaces; face++)
372
        if( getCubitFaceColor(cubit,face)>=0 )
373
          {
374
          mVariantFaceIsOuter[variant][face] = 1;
375
          }
376
      }
377
    }
378

    
379
///////////////////////////////////////////////////////////////////////////////////////////////////
380

    
381
  private void getQuatsAndShapes(boolean fromDMESH, boolean fromJSON)
382
    {
383
    mNumCubitVariants = getNumCubitVariants(mNumLayers);
384

    
385
    if( !fromDMESH || !fromJSON )
386
      {
387
      FactoryCubit factory = FactoryCubit.getInstance();
388
      factory.clear();
389

    
390
      mOrigQuat = new Static4D[mNumCubits];
391
      for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers);
392

    
393
      mShapes = new ObjectShape[mNumCubitVariants];
394
      for(int i=0; i<mNumCubitVariants; i++) mShapes[i] = getObjectShape(i);
395
      mNumCubitFaces = ObjectShape.computeNumComponents(mShapes);
396
      mVariantFaceIsOuter = new int[mNumCubitVariants][];
397

    
398
      if( !fromJSON )
399
        {
400
        mCubitFaceColors = ObjectShape.computeColors(mShapes,mOrigPos,mOrigQuat,this);
401
        createOuterFaces();
402
        }
403

    
404
      if( fromDMESH )
405
        {
406
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i], mVariantFaceIsOuter[i]);
407
        }
408
      }
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  private void createMeshAndCubits(InputStream stream, int meshState, boolean fromDMESH)
414
    {
415
    mCubits = new TwistyObjectCubit[mNumCubits];
416

    
417
    if( fromDMESH )
418
      {
419
      DataInputStream dos = new DataInputStream(stream);
420
      mMesh = new MeshFile(dos);
421

    
422
      try
423
        {
424
        stream.close();
425
        }
426
      catch(IOException e)
427
        {
428
        android.util.Log.e("meshFile", "Error closing InputStream: "+e);
429
        }
430
      }
431
    else
432
      {
433
      MeshBase[] cubitMesh = new MeshBase[mNumCubits];
434

    
435
      for(int i=0; i<mNumCubits; i++)
436
        {
437
        cubitMesh[i] = createCubitMesh(i,mNumLayers,meshState,mNumCubitFaces);
438
        Static3D pos = getPos(mOrigPos[i]);
439
        cubitMesh[i].apply(new MatrixEffectMove(pos),1,0);
440
        }
441

    
442
      mMesh = new MeshJoined(cubitMesh);
443

    
444
      float pillowCoeff = getPillowCoeff();
445

    
446
      if( pillowCoeff!=1.0f )
447
        {
448
        float radius = getCircumscribedRadius();
449
        Static1D coeff = new Static1D(pillowCoeff);
450
        Static4D region= new Static4D(0,0,0,radius);
451
        VertexEffectSink sink = new VertexEffectSink(coeff,CENTER,region);
452
        mMesh.apply(sink);
453
        }
454
      }
455

    
456
    for(int i=0; i<mNumCubits; i++)
457
      {
458
      mCubits[i] = new TwistyObjectCubit(this,mOrigPos[i],mNumAxis,mMaxNumLayers,i);
459
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
460
      }
461
    }
462

    
463
///////////////////////////////////////////////////////////////////////////////////////////////////
464

    
465
  private MeshBase createCubitMesh(int cubit, int[] numLayers, int meshState, int numComponents)
466
    {
467
    int variant = getCubitVariant(cubit,numLayers);
468

    
469
    if( mMeshes==null ) mMeshes = new MeshBase[mNumCubitVariants];
470

    
471
    if( mMeshes[variant]==null )
472
      {
473
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
474
      ObjectVertexEffects effects = getVertexEffects(variant);
475
      FactoryCubit factory = FactoryCubit.getInstance();
476
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
477
      mMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects, meshState, numComponents);
478
      }
479

    
480
    MeshBase mesh = mMeshes[variant].copy(true);
481
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( mOrigQuat[cubit], CENTER );
482
    mesh.apply(quat,0xffffffff,0);
483

    
484
    return mesh;
485
    }
486

    
487
///////////////////////////////////////////////////////////////////////////////////////////////////
488

    
489
  private void setUpTextures(boolean fromDMESH, boolean fromJSON)
490
    {
491
    mTexture = new DistortedTexture();
492

    
493
    if( fromJSON )
494
      {
495
      mNumStickerTypes = getNumStickerTypes();
496
      mNumCubitFaces = getNumCubitFaces();
497
      }
498
    else
499
      {
500
      FactoryCubit factory = FactoryCubit.getInstance();
501
      mStickerCoords   = factory.getStickerCoords();
502
      mStickerVariants = factory.getStickerVariants();
503
      mStickerScales   = factory.getStickerScales();
504
      adjustStickerCoords();
505
      mNumStickerTypes = (mStickerCoords==null ? 0 : mStickerCoords.length);
506
      }
507

    
508
    mStickerOverrides = getStickerOverrides();
509
    mNumOverrides = mStickerOverrides==null ? 0 : mStickerOverrides.length;
510

    
511
    mNumTextures= mNumFaceColors*mNumStickerTypes + mNumOverrides;
512
    mNumTexCols = NUM_STICKERS_IN_ROW;
513
    mNumTexRows = (mNumTextures+1)/NUM_STICKERS_IN_ROW;
514
    if( mNumTexCols*mNumTexRows < mNumTextures+1 ) mNumTexRows++;
515

    
516
    if( !fromDMESH || shouldResetTextureMaps() ) resetAllTextureMaps();
517
    else overrideCubitFaceColor();
518

    
519
    setTexture();
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
  public InitData getInitData()
525
    {
526
    return mInitData;
527
    }
528

    
529
///////////////////////////////////////////////////////////////////////////////////////////////////
530

    
531
  public boolean isInIconMode()
532
    {
533
    return mIconMode==MODE_ICON;
534
    }
535

    
536
///////////////////////////////////////////////////////////////////////////////////////////////////
537

    
538
  public int getVariantStickerShape(int variant, int face)
539
    {
540
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
541
    }
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

    
545
  public boolean shouldResetTextureMaps()
546
    {
547
    return false;
548
    }
549

    
550
///////////////////////////////////////////////////////////////////////////////////////////////////
551

    
552
  public int[][] getScrambleAlgorithms()
553
    {
554
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngles);
555
    }
556

    
557
///////////////////////////////////////////////////////////////////////////////////////////////////
558

    
559
  private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z )
560
    {
561
    final float MAXERR = 0.05f;
562
    int numAxis = dist.length;
563

    
564
    for(int i=0; i<numAxis; i++)
565
      {
566
      Static3D ax = faceAxis[i];
567
      float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
568
      if( len>mSize*dist[i]+MAXERR ) return true;
569
      }
570

    
571
    return false;
572
    }
573

    
574
///////////////////////////////////////////////////////////////////////////////////////////////////
575

    
576
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
577
    {
578
    float[][] vertices = mShapes[variant].getVertices();
579
    Static3D[] axis = getFaceAxis();
580
    float[] dist3D = getDist3D(mNumLayers);
581

    
582
    for( float[] vertex : vertices)
583
      {
584
      float x = vertex[0];
585
      float y = vertex[1];
586
      float z = vertex[2];
587

    
588
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
589

    
590
      float mx = tmp[0] + px;
591
      float my = tmp[1] + py;
592
      float mz = tmp[2] + pz;
593

    
594
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
595
      }
596

    
597
    return true;
598
    }
599

    
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601

    
602
  private float computeAvg(float[] pos, int offset)
603
    {
604
    int len = pos.length/3;
605
    float ret=0.0f;
606
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
607
    ret /= len;
608

    
609
    return ret;
610
    }
611

    
612
///////////////////////////////////////////////////////////////////////////////////////////////////
613

    
614
  protected void displayCubitQuats()
615
    {
616
    StringBuilder builder = new StringBuilder();
617
    float[] tmp = new float[4];
618
    float ERR = 0.01f;
619

    
620
    for(int cubit=0; cubit<mNumCubits; cubit++)
621
      {
622
      builder.append(cubit);
623
      builder.append(" : ");
624

    
625
      int refCubit,variant = getCubitVariant(cubit,mNumLayers);
626

    
627
      for(refCubit=0; refCubit<mNumCubits; refCubit++)
628
        {
629
        if( getCubitVariant(refCubit,mNumLayers)==variant ) break;
630
        }
631

    
632
      float[] curpos = mOrigPos[cubit];
633
      float[] refpos = mOrigPos[refCubit];
634
      float refX = computeAvg(refpos,0);
635
      float refY = computeAvg(refpos,1);
636
      float refZ = computeAvg(refpos,2);
637
      float curX = computeAvg(curpos,0);
638
      float curY = computeAvg(curpos,1);
639
      float curZ = computeAvg(curpos,2);
640

    
641
      for(int quat=0; quat<mNumQuats; quat++)
642
        {
643
        QuatHelper.rotateVectorByQuat(tmp,refX,refY,refZ,0,mObjectQuats[quat]);
644

    
645
        float dx = tmp[0]-curX;
646
        float dy = tmp[1]-curY;
647
        float dz = tmp[2]-curZ;
648

    
649
        if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
650
          {
651
          if( doesNotStickOut(variant,curX,curY,curZ,tmp,mObjectQuats[quat]) )
652
            {
653
            builder.append(quat);
654
            builder.append(',');
655
            }
656
          else
657
            {
658
            android.util.Log.e("D", "cubit: "+cubit+" quat: "+quat+" : center correct, but shape sticks out");
659
            }
660
          }
661
        }
662

    
663
      builder.append('\n');
664
      }
665

    
666
    android.util.Log.e("D", "cubitQuats: \n"+builder );
667
    }
668

    
669
///////////////////////////////////////////////////////////////////////////////////////////////////
670

    
671
  public int getCubitRotationType(int cubit)
672
    {
673
    return TwistyObjectCubit.TYPE_NORMAL;
674
    }
675

    
676
///////////////////////////////////////////////////////////////////////////////////////////////////
677

    
678
  float[] getTrackingPoint(int cubitIndex, int cubitType)
679
    {
680
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
681
      {
682
      int variant = getCubitVariant(cubitIndex,mNumLayers);
683

    
684
      // object must have been created from JSON
685
      if( mVariantFaceIsOuter==null || mVariantFaceIsOuter[variant]==null )
686
        {
687
        mVariantFaceIsOuter = getVariantFaceIsOuter();
688
        }
689
      if( mShapes==null )
690
        {
691
        mShapes = new ObjectShape[mNumCubitVariants];
692
        }
693
      if( mShapes[variant]==null )
694
        {
695
        mShapes[variant] = getObjectShape(variant);
696
        }
697
      if( mOrigQuat==null )
698
        {
699
        mOrigQuat = new Static4D[mNumCubits];
700
        }
701
      if( mOrigQuat[cubitIndex]==null )
702
        {
703
        mOrigQuat[cubitIndex] = getCubitQuats(cubitIndex,mNumLayers);
704
        }
705

    
706
      int[][] indices = mShapes[variant].getVertIndices();
707
      int outer=-1, faces = indices.length;
708

    
709
      for(int i=0; i<faces; i++)
710
        {
711
        if( mVariantFaceIsOuter[variant][i]==1 )
712
          {
713
          outer=i;
714
          break;
715
          }
716
        }
717

    
718
      if( outer>=0 )
719
        {
720
        int vertIndex = indices[outer][0];
721
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
722
        float[] ret = new float[3];
723
        float[] curpos = mOrigPos[cubitIndex];
724
        Static4D quat = mOrigQuat[cubitIndex];
725
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
726

    
727
        ret[0] = mTmp[0]+computeAvg(curpos,0);
728
        ret[1] = mTmp[1]+computeAvg(curpos,1);
729
        ret[2] = mTmp[2]+computeAvg(curpos,2);
730

    
731
        return ret;
732
        }
733
      else
734
        {
735
        android.util.Log.e("D", "Error in getTrackingPoint: no outer face??");
736
        }
737
      }
738

    
739
    return null;
740
    }
741

    
742
///////////////////////////////////////////////////////////////////////////////////////////////////
743

    
744
  public int computeCurrentPuzzleFace(int type, float[] vertex)
745
    {
746
    if( type!=TwistyObjectCubit.TYPE_NORMAL )
747
      {
748
      Static3D[] axis = getFaceAxis();
749
      float[] dist3D = getDist3D(mNumLayers);
750
      final float MAXERR = 0.98f;
751
      int numAxis = axis.length;
752
      float x = vertex[0];
753
      float y = vertex[1];
754
      float z = vertex[2];
755

    
756
      for(int i=0; i<numAxis; i++)
757
        {
758
        Static3D ax = axis[i];
759
        float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
760
        if( len>mSize*dist3D[i]*MAXERR ) return i;
761
        }
762

    
763
      return -2;
764
      }
765

    
766
    return -1;
767
    }
768

    
769
///////////////////////////////////////////////////////////////////////////////////////////////////
770

    
771
  public float[] getCubitRowOffset(int cubitIndex)
772
    {
773
    return null;
774
    }
775

    
776
///////////////////////////////////////////////////////////////////////////////////////////////////
777

    
778
  void setRotationRowOffset(int puzzleFace, float[] offset)
779
    {
780
    mRowOffsets[puzzleFace][0] = offset[0];
781
    mRowOffsets[puzzleFace][1] = offset[1];
782
    mRowOffsets[puzzleFace][2] = offset[2];
783
    }
784

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

    
787
  int getNumAxis()
788
    {
789
    return mNumAxis;
790
    }
791

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

    
794
  public int[][] getSolvedQuats()
795
    {
796
    return mSolved.getSolvedQuats(mNumLayers,mNumCubitFaces,mCubitFaceColors);
797
    }
798

    
799
///////////////////////////////////////////////////////////////////////////////////////////////////
800

    
801
  public int getSolvedFunctionIndex()
802
    {
803
    return 0;
804
    }
805

    
806
///////////////////////////////////////////////////////////////////////////////////////////////////
807

    
808
  int computeRow(float[] pos, int axisIndex, int cubitType, int puzzleFace)
809
    {
810
    int ret=0;
811
    int len = pos.length / 3;
812
    Static3D axis = mAxis[axisIndex];
813
    float axisX = axis.get0();
814
    float axisY = axis.get1();
815
    float axisZ = axis.get2();
816
    float casted, xoff=0, yoff=0, zoff=0;
817

    
818
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
819
      {
820
      xoff = mRowOffsets[puzzleFace][0];
821
      yoff = mRowOffsets[puzzleFace][1];
822
      zoff = mRowOffsets[puzzleFace][2];
823
      }
824

    
825
    for(int i=0; i<len; i++)
826
      {
827
      casted = (pos[3*i]+xoff)*axisX + (pos[3*i+1]+yoff)*axisY + (pos[3*i+2]+zoff)*axisZ;
828
      ret |= computeSingleRow(axisIndex,casted);
829
      }
830

    
831
    return ret;
832
    }
833

    
834
///////////////////////////////////////////////////////////////////////////////////////////////////
835

    
836
  private int computeSingleRow(int axisIndex,float casted)
837
    {
838
    int num = mNumCuts[axisIndex];
839

    
840
    for(int i=0; i<num; i++)
841
      {
842
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
843
      }
844

    
845
    return (1<<num);
846
    }
847

    
848
///////////////////////////////////////////////////////////////////////////////////////////////////
849

    
850
  private boolean wasRotateApplied()
851
    {
852
    return mEffects.exists(mRotateEffect.getID());
853
    }
854

    
855
///////////////////////////////////////////////////////////////////////////////////////////////////
856

    
857
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
858
    {
859
    return (mCubits[cubit].getRotRow(axis) & rowBitmap) != 0;
860
    }
861

    
862
///////////////////////////////////////////////////////////////////////////////////////////////////
863
// note the minus in front of the sin() - we rotate counterclockwise
864
// when looking towards the direction where the axis increases in values.
865

    
866
  private Static4D makeQuaternion(float axisX, float axisY, float axisZ, int angleInDegrees)
867
    {
868
    while( angleInDegrees<0 ) angleInDegrees += 360;
869
    angleInDegrees %= 360;
870
    
871
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
872
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
873

    
874
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
875
    }
876

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

    
879
  private synchronized void setupPosition(int[][] moves)
880
    {
881
    if( moves!=null )
882
      {
883
      Static4D quat;
884
      int index, axisIndex, row, rowBitmap, basic, angle;
885

    
886
      for(int[] move: moves)
887
        {
888
        axisIndex= move[0];
889
        rowBitmap= computeBitmapFromRow( move[1],axisIndex);
890
        row      = computeRowFromBitmap( move[1] );
891
        basic    = mBasicAngles[axisIndex][row];
892
        angle    = move[2]*(360/basic);   // this assumes that all layers from
893
                                          // the bitmap have the same BasicAngle.
894
                                          // at the moment this is always true as
895
                                          // there are no bandaged objects with
896
                                          // different per-layer BasicAngles.
897
        Static3D axis = mAxis[axisIndex];
898
        float axisX = axis.get0();
899
        float axisY = axis.get1();
900
        float axisZ = axis.get2();
901
        quat = makeQuaternion(axisX,axisY,axisZ,angle);
902

    
903
        for(int i=0; i<mNumCubits; i++)
904
          {
905
          mBelongs[i] = belongsToRotation(i,axisIndex,rowBitmap);
906
          if( mBelongs[i] )
907
            {
908
            boolean result = mCubits[i].rotateCubit(quat);
909
            if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,1);
910
            }
911
          }
912

    
913
        recomputeFaceOffsets();
914

    
915
        for(int i=0; i<mNumCubits; i++)
916
          {
917
          if( mBelongs[i] )
918
            {
919
            index = mCubits[i].postRotateCubit(quat);
920
            setCubitQuat(i,mCubits[i].computeAssociation(),index);
921
            }
922
          else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
923
            {
924
            mCubits[i].computeRotationRow();
925
            setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
926
            }
927
          }
928
        }
929
      }
930
    }
931

    
932
///////////////////////////////////////////////////////////////////////////////////////////////////
933

    
934
  public int getScrambleType()
935
    {
936
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
937
    }
938

    
939
///////////////////////////////////////////////////////////////////////////////////////////////////
940

    
941
  int computeBitmapFromRow(int rowBitmap, int axis)
942
    {
943
    if( mIsBandaged )
944
      {
945
      int bitmap, initBitmap=0;
946

    
947
      while( initBitmap!=rowBitmap )
948
        {
949
        initBitmap = rowBitmap;
950

    
951
        for(int cubit=0; cubit<mNumCubits; cubit++)
952
          {
953
          bitmap = mCubits[cubit].getRotRow(axis);
954
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
955
          }
956
        }
957
      }
958

    
959
    return rowBitmap;
960
    }
961

    
962
///////////////////////////////////////////////////////////////////////////////////////////////////
963

    
964
  private int computeRowFromBitmap(int rowBitmap)
965
    {
966
    int index = 0;
967

    
968
    while(index<32)
969
      {
970
      if( (rowBitmap&0x1) != 0 ) return index;
971
      rowBitmap>>=1;
972
      index++;
973
      }
974
    return 0;
975
    }
976

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

    
981
  void clampPos(float[] pos, int offset)
982
    {
983
    float currError, minError = Float.MAX_VALUE;
984
    int minErrorIndex1 = -1;
985
    int minErrorIndex2 = -1;
986

    
987
    float x = pos[offset  ];
988
    float y = pos[offset+1];
989
    float z = pos[offset+2];
990

    
991
    float xo,yo,zo;
992

    
993
    for(int i=0; i<mNumCubits; i++)
994
      {
995
      int len = mOrigPos[i].length / 3;
996

    
997
      for(int j=0; j<len; j++)
998
        {
999
        xo = mOrigPos[i][3*j  ];
1000
        yo = mOrigPos[i][3*j+1];
1001
        zo = mOrigPos[i][3*j+2];
1002

    
1003
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1004

    
1005
        if( currError<minError )
1006
          {
1007
          minError = currError;
1008
          minErrorIndex1 = i;
1009
          minErrorIndex2 = j;
1010
          }
1011
        }
1012
      }
1013

    
1014
    if( minError< 0.05f ) // TODO: 0.05 ?
1015
      {
1016
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1017
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1018
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1019
      }
1020
    }
1021

    
1022
///////////////////////////////////////////////////////////////////////////////////////////////////
1023

    
1024
  private float getAngle()
1025
    {
1026
    mPointNum = mRotationAngle.getNumPoints();
1027
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1028
    }
1029

    
1030
///////////////////////////////////////////////////////////////////////////////////////////////////
1031

    
1032
  void setLibInterface(ObjectLibInterface inter)
1033
    {
1034
    mInterface = inter;
1035
    }
1036

    
1037
///////////////////////////////////////////////////////////////////////////////////////////////////
1038

    
1039
  void applyScrambles(int[][] moves)
1040
    {
1041
    setupPosition(moves);
1042
    }
1043

    
1044
///////////////////////////////////////////////////////////////////////////////////////////////////
1045

    
1046
  void initializeObject(int[][] moves)
1047
    {
1048
    solve();
1049
    setupPosition(moves);
1050
    }
1051

    
1052
///////////////////////////////////////////////////////////////////////////////////////////////////
1053

    
1054
  synchronized void removeRotationNow()
1055
    {
1056
    float angle = getAngle();
1057
    double nearestAngleInRadians = angle*Math.PI/180;
1058
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1059
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1060
    float axisX = mAxis[mCurrentRotAxis].get0();
1061
    float axisY = mAxis[mCurrentRotAxis].get1();
1062
    float axisZ = mAxis[mCurrentRotAxis].get2();
1063
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1064

    
1065
    mRotationAngleStatic.set0(0);
1066
    mRotationAngle.removeAll();
1067

    
1068
    for(int i=0; i<mNumCubits; i++)
1069
      {
1070
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1071
      if( mBelongs[i] )
1072
        {
1073
        boolean result = mCubits[i].rotateCubit(quat);
1074
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1075
        }
1076
      }
1077

    
1078
    recomputeFaceOffsets();
1079

    
1080
    for(int i=0; i<mNumCubits; i++)
1081
      {
1082
      if( mBelongs[i] )
1083
        {
1084
        int index = mCubits[i].postRotateCubit(quat);
1085
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1086
        }
1087
      else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
1088
        {
1089
        mCubits[i].computeRotationRow();
1090
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1091
        }
1092
      }
1093

    
1094
    mRotationState = STATE_NOTHING;
1095
    }
1096

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

    
1099
  private void recomputeFaceOffsets()
1100
    {
1101
    for(int i=0; i<mNumPuzzleFaces; i++)
1102
      {
1103
      mRowOffsets[i][0] =0;
1104
      mRowOffsets[i][1] =0;
1105
      mRowOffsets[i][2] =0;
1106
      }
1107

    
1108
    for(int i=0; i<mNumCubits; i++)
1109
      if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1110
        {
1111
        float[] offset = mCubits[i].getOffset();
1112
        int face = mCubits[i].getPuzzleFace();
1113
        mRowOffsets[face][0] = offset[0];
1114
        mRowOffsets[face][1] = offset[1];
1115
        mRowOffsets[face][2] = offset[2];
1116
        }
1117
    }
1118

    
1119
///////////////////////////////////////////////////////////////////////////////////////////////////
1120

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

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

    
1139
      return mRotateEffect.getID();
1140
      }
1141

    
1142
    return 0;
1143
    }
1144

    
1145
///////////////////////////////////////////////////////////////////////////////////////////////////
1146

    
1147
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1148
    {
1149
    int mult = 1;
1150

    
1151
    if( wasRotateApplied() )
1152
      {
1153
      if( mRotationState==STATE_ROTATE )
1154
        {
1155
        return 0;
1156
        }
1157
      if( mRotationState==STATE_FINISH )
1158
        {
1159
        removeRotationNow();
1160
        mult = -1;
1161
        }
1162

    
1163
      mRotationState = STATE_ROTATE;
1164
      mCurrentRotAxis = axis;
1165
      mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis );
1166
      mRotationAngleStatic.set0(0.0f);
1167
      mRotationAxis.set( mAxis[axis] );
1168
      mRotationAngle.setDuration(durationMillis);
1169
      mRotationAngle.resetToBeginning();
1170
      mRotationAngle.add(new Static1D(0));
1171
      mRotationAngle.add(new Static1D(angle));
1172
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1173
      mRotateEffect.notifyWhenFinished(listener);
1174
      return mult*mRotateEffect.getID();
1175
      }
1176

    
1177
    return 0;
1178
    }
1179

    
1180
///////////////////////////////////////////////////////////////////////////////////////////////////
1181

    
1182
  void continueRotation(float angleInDegrees)
1183
    {
1184
    mRotationAngleStatic.set0(angleInDegrees);
1185
    }
1186

    
1187
///////////////////////////////////////////////////////////////////////////////////////////////////
1188

    
1189
  synchronized boolean beginNewRotation(int axis, int row )
1190
    {
1191
    if( mRotationState==STATE_ROTATE )
1192
      {
1193
      return false;
1194
      }
1195
    if( mRotationState==STATE_FINISH )
1196
      {
1197
      removeRotationNow();
1198
      }
1199

    
1200
    if( axis<0 || axis>=mNumAxis )
1201
      {
1202
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1203
      return false;
1204
      }
1205
    if( row<0 || row>=mNumLayers[axis] )
1206
      {
1207
      android.util.Log.e("object", "invalid rotation row: "+row);
1208
      return false;
1209
      }
1210

    
1211
    mRotationState = STATE_ROTATE;
1212
    mCurrentRotAxis = axis;
1213
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
1214
    mRotationAngleStatic.set0(0.0f);
1215
    mRotationAxis.set( mAxis[axis] );
1216
    mRotationAngle.add(mRotationAngleStatic);
1217
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1218

    
1219
    return true;
1220
    }
1221

    
1222
///////////////////////////////////////////////////////////////////////////////////////////////////
1223

    
1224
  void setTextureMap(int cubit, int face, int color)
1225
    {
1226
    int variant  = getCubitVariant(cubit,mNumLayers);
1227
    int shape    = getVariantStickerShape(variant,face);
1228
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1229
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1230
    int col      = texIndex%mNumTexCols;
1231

    
1232
    final float ratioW = 1.0f/mNumTexCols;
1233
    final float ratioH = 1.0f/mNumTexRows;
1234
    final Static4D[] maps = new Static4D[1];
1235
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1236
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1237
    }
1238

    
1239
///////////////////////////////////////////////////////////////////////////////////////////////////
1240

    
1241
  private int getCubitFaceColor(int cubit, int face)
1242
    {
1243
    int puzzleFace = getCubitFaceMap(cubit,face);
1244
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1245
    return puzzleFace;
1246
    }
1247

    
1248
///////////////////////////////////////////////////////////////////////////////////////////////////
1249

    
1250
  public int getCubitFaceMap(int cubit, int face)
1251
    {
1252
    int numFaces = mCubitFaceColors[cubit].length;
1253
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1254
    return puzzleFace<0 ? -1 : puzzleFace;
1255
    }
1256

    
1257
///////////////////////////////////////////////////////////////////////////////////////////////////
1258

    
1259
  void resetAllTextureMaps()
1260
    {
1261
    final float ratioW = 1.0f/mNumTexCols;
1262
    final float ratioH = 1.0f/mNumTexRows;
1263
    int cubColor, stiShape, texIndex, variant, row, col;
1264

    
1265
    for(int cubit=0; cubit<mNumCubits; cubit++)
1266
      {
1267
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1268
      variant = getCubitVariant(cubit,mNumLayers);
1269

    
1270
      for(int face=0; face<mNumCubitFaces; face++)
1271
        {
1272
        cubColor = getCubitFaceColor(cubit,face);
1273
        stiShape = getVariantStickerShape(variant,face);
1274
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1275
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1276
        col      = texIndex%mNumTexCols;
1277

    
1278
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1279
        }
1280

    
1281
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1282
      }
1283

    
1284
    overrideCubitFaceColor();
1285
    }
1286

    
1287
///////////////////////////////////////////////////////////////////////////////////////////////////
1288

    
1289
  private void overrideCubitFaceColor()
1290
    {
1291
    final float ratioW = 1.0f/mNumTexCols;
1292
    final float ratioH = 1.0f/mNumTexRows;
1293

    
1294
    for(int i=0; i<mNumOverrides; i++)
1295
      {
1296
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1297
      int length = cubitFaces.length/2;
1298

    
1299
      for(int j=0; j<length; j++)
1300
        {
1301
        final Static4D[] maps = new Static4D[1];
1302
        int color = mNumTextures-mNumOverrides+1+i;
1303
        int row   = (mNumTexRows-1) - color/mNumTexCols;
1304
        int col   = color%mNumTexCols;
1305
        int cubit = cubitFaces[2*j];
1306
        int face  = cubitFaces[2*j+1];
1307
        maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1308
        mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1309
        }
1310
      }
1311
    }
1312

    
1313
///////////////////////////////////////////////////////////////////////////////////////////////////
1314

    
1315
  void releaseResources()
1316
    {
1317
    mTexture.markForDeletion();
1318
    mMesh.markForDeletion();
1319
    mEffects.markForDeletion();
1320

    
1321
    for(int j=0; j<mNumCubits; j++)
1322
      {
1323
      mCubits[j].releaseResources();
1324
      }
1325
    }
1326

    
1327
///////////////////////////////////////////////////////////////////////////////////////////////////
1328

    
1329
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1330
    {
1331
    if( !mIsInMixupMode )
1332
      {
1333
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1334
      }
1335
    else
1336
      {
1337
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1338
      Static4D tmp = mObjectQuats[equAssociation];
1339
      mMixupModeQuats[cubit].set(tmp);
1340
      }
1341
    }
1342

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

    
1345
  synchronized void restorePreferences(SharedPreferences preferences)
1346
    {
1347
    boolean error = false;
1348
    String key = getShortName();
1349

    
1350
    for(int i=0; i<mNumCubits; i++)
1351
      {
1352
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1353

    
1354
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1355
        {
1356
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1357
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1358
        }
1359
      else { error = true; break; }
1360
      }
1361

    
1362
    if( !error )
1363
      {
1364
      recomputeFaceOffsets();
1365

    
1366
      for(int i=0; i<mNumCubits; i++)
1367
        {
1368
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1369
          {
1370
          mCubits[i].computeRotationRow();
1371
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1372
          }
1373
        else { error = true; break; }
1374
        }
1375
      }
1376

    
1377
    if( error )
1378
      {
1379
      for(int i=0; i<mNumCubits; i++)
1380
        {
1381
        mCubits[i].solve();
1382
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1383
        }
1384
      }
1385
    }
1386

    
1387
///////////////////////////////////////////////////////////////////////////////////////////////////
1388

    
1389
  void savePreferences(SharedPreferences.Editor editor)
1390
    {
1391
    String key = getShortName();
1392
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1393
    }
1394

    
1395
///////////////////////////////////////////////////////////////////////////////////////////////////
1396

    
1397
  public void removePreferences(SharedPreferences.Editor editor)
1398
    {
1399
    String key = getShortName();
1400
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1401
    }
1402

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

    
1405
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1406
    {
1407
    final float A = 0.8f;  // 0<A<1
1408

    
1409
    int prev = curr>0 ? curr-1 : len-1;
1410
    int next = curr<len-1 ? curr+1 : 0;
1411

    
1412
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1413
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1414
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1415
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1416

    
1417
    float len1= v1x*v1x+v1y*v1y;
1418
    float len2= v2x*v2x+v2y*v2y;
1419

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

    
1422
    return 1-A*cos;
1423
    }
1424

    
1425
///////////////////////////////////////////////////////////////////////////////////////////////////
1426
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
1427
//
1428
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
1429
// to introduce the concept of a 'sink center' as well.
1430
//
1431
// public because needed in TouchControlShapemod
1432

    
1433
  public float getCircumscribedRadius()
1434
    {
1435
    switch(mNumPuzzleFaces)
1436
      {
1437
      case  4: return (SQ6/4)*mSize;
1438
      case  6: return (SQ3/2)*mSize;
1439
      case  8: return (SQ2/2)*mSize;
1440
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1441
      case 16: return 0.50f*mSize;
1442
      }
1443

    
1444
    return 0.0f;
1445
    }
1446

    
1447
///////////////////////////////////////////////////////////////////////////////////////////////////
1448

    
1449
  public ObjectSticker retSticker(int sticker)
1450
    {
1451
    if( mStickers==null )
1452
      {
1453
      float rad = getStickerRadius();
1454
      float str = getStickerStroke();
1455
      float[][] angles = getStickerAngles();
1456
      int numStickers = mStickerCoords.length;
1457
      mStickers = new ObjectSticker[numStickers];
1458

    
1459
      for(int s=0; s<numStickers; s++)
1460
        {
1461
        float scale = mStickerScales.length>s ? mStickerScales[s] : 1.0f;
1462
        float radius = rad / scale;
1463
        float stroke = str / scale;
1464
        int len = mStickerCoords[s].length/2;
1465
        float[] radii = new float[len];
1466
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
1467
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
1468
        }
1469
      }
1470

    
1471
    return mStickers[sticker];
1472
    }
1473

    
1474
///////////////////////////////////////////////////////////////////////////////////////////////////
1475
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1476

    
1477
  public void adjustStickerCoords()
1478
    {
1479

    
1480
    }
1481

    
1482
///////////////////////////////////////////////////////////////////////////////////////////////////
1483

    
1484
  public Static4D[] getQuats()
1485
    {
1486
    if( mObjectQuats==null )
1487
      {
1488
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1489
      }
1490

    
1491
    return mObjectQuats;
1492
    }
1493

    
1494
///////////////////////////////////////////////////////////////////////////////////////////////////
1495

    
1496
  public int[][] getVariantFaceIsOuter()
1497
    {
1498
    return mVariantFaceIsOuter;
1499
    }
1500

    
1501
///////////////////////////////////////////////////////////////////////////////////////////////////
1502

    
1503
  public int getInternalColor()
1504
    {
1505
    return COLOR_INTERNAL;
1506
    }
1507

    
1508
///////////////////////////////////////////////////////////////////////////////////////////////////
1509
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1510

    
1511
  private void createTexture()
1512
    {
1513
    Paint paint = new Paint();
1514
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1515
    Canvas canvas = new Canvas(mBitmap);
1516

    
1517
    paint.setAntiAlias(true);
1518
    paint.setTextAlign(Paint.Align.CENTER);
1519
    paint.setStyle(Paint.Style.FILL);
1520
    paint.setColor(getInternalColor());
1521
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1522

    
1523
    int texture = 0;
1524
    FactorySticker factory = FactorySticker.getInstance();
1525

    
1526
    for(int row=0; row<mNumTexRows; row++)
1527
      for(int col=0; col<mNumTexCols; col++)
1528
        {
1529
        if( texture<mNumTextures-mNumOverrides )
1530
          {
1531
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1532
          int color = getColor(texture%mNumFaceColors);
1533
          factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color, sticker);
1534
          }
1535
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1536
          {
1537
          int color = mStickerOverrides[mNumTextures-texture].getColor();
1538
          factory.drawSolidColor(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color);
1539
          }
1540

    
1541
        texture++;
1542
        }
1543
    }
1544

    
1545
///////////////////////////////////////////////////////////////////////////////////////////////////
1546

    
1547
  void setTexture()
1548
    {
1549
    if( mBitmap==null ) createTexture();
1550

    
1551
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1552
      {
1553
      int max = DistortedLibrary.getMaxTextureSize();
1554
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1555
      }
1556
    }
1557

    
1558
///////////////////////////////////////////////////////////////////////////////////////////////////
1559

    
1560
  void setObjectRatioNow(float sc, int nodeSize)
1561
    {
1562
    mObjectScreenRatio = sc;
1563
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1564
    mObjectScale.set(scale,scale,scale);
1565

    
1566
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1567
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1568
    }
1569

    
1570
///////////////////////////////////////////////////////////////////////////////////////////////////
1571

    
1572
  void setObjectRatio(float sizeChange, int nodeSize)
1573
    {
1574
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1575

    
1576
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1577
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1578

    
1579
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1580
    }
1581

    
1582
///////////////////////////////////////////////////////////////////////////////////////////////////
1583

    
1584
  void setNodeSize(int nodeSize)
1585
    {
1586
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1587
    }
1588

    
1589
///////////////////////////////////////////////////////////////////////////////////////////////////
1590

    
1591
  public float getRatio()
1592
    {
1593
    return mObjectScreenRatio;
1594
    }
1595

    
1596
///////////////////////////////////////////////////////////////////////////////////////////////////
1597

    
1598
  public float getObjectRatio()
1599
    {
1600
    return mObjectScreenRatio*mInitScreenRatio;
1601
    }
1602

    
1603
///////////////////////////////////////////////////////////////////////////////////////////////////
1604

    
1605
  boolean isSolved()
1606
    {
1607
    return mSolved.isSolved(mCubits);
1608
    }
1609

    
1610
///////////////////////////////////////////////////////////////////////////////////////////////////
1611

    
1612
  int computeNearestAngle(int basicAngle, float angle, float speed)
1613
    {
1614
    int nearestAngle = 360/basicAngle;
1615
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1616
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1617

    
1618
    if( tmp!=0 ) return nearestAngle*tmp;
1619

    
1620
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1621
    }
1622

    
1623
///////////////////////////////////////////////////////////////////////////////////////////////////
1624
// INTERNAL API - those are called from 'effects' package
1625
///////////////////////////////////////////////////////////////////////////////////////////////////
1626

    
1627
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1628
    {
1629
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1630
    }
1631

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

    
1634
  public Static4D getRotationQuat()
1635
    {
1636
    return mQuat;
1637
    }
1638

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

    
1641
  public float getSize()
1642
    {
1643
    return mSize;
1644
    }
1645

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

    
1648
  public void applyEffect(Effect effect, int position)
1649
    {
1650
    mEffects.apply(effect, position);
1651
    }
1652

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

    
1655
  public void removeEffect(long effectID)
1656
    {
1657
    mEffects.abortById(effectID);
1658
    }
1659

    
1660
///////////////////////////////////////////////////////////////////////////////////////////////////
1661

    
1662
  public MeshBase getObjectMesh()
1663
    {
1664
    return mMesh;
1665
    }
1666

    
1667
///////////////////////////////////////////////////////////////////////////////////////////////////
1668

    
1669
  public DistortedEffects getObjectEffects()
1670
    {
1671
    return mEffects;
1672
    }
1673

    
1674
///////////////////////////////////////////////////////////////////////////////////////////////////
1675

    
1676
  public int getCubitType(int cubit)
1677
    {
1678
    return mCubits[cubit].getType();
1679
    }
1680

    
1681
///////////////////////////////////////////////////////////////////////////////////////////////////
1682

    
1683
  public float[] getCubitOffset(int cubit)
1684
    {
1685
    return mCubits[cubit].getOffset();
1686
    }
1687

    
1688
///////////////////////////////////////////////////////////////////////////////////////////////////
1689

    
1690
  public ObjectStickerOverride[] getStickerOverrides()
1691
    {
1692
    return null;
1693
    }
1694

    
1695
///////////////////////////////////////////////////////////////////////////////////////////////////
1696

    
1697
  public boolean getError()
1698
    {
1699
    return mError;
1700
    }
1701

    
1702
///////////////////////////////////////////////////////////////////////////////////////////////////
1703

    
1704
  public String getErrorString()
1705
    {
1706
    return mErrorString;
1707
    }
1708

    
1709
///////////////////////////////////////////////////////////////////////////////////////////////////
1710
// PUBLIC API
1711
///////////////////////////////////////////////////////////////////////////////////////////////////
1712

    
1713
  public int getCubitFaceStickerIndex(int cubit, int face)
1714
    {
1715
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1716

    
1717
    int x = (int)(texMap.get0()/texMap.get2());
1718
    int y = (int)(texMap.get1()/texMap.get3());
1719

    
1720
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1721
    }
1722

    
1723
///////////////////////////////////////////////////////////////////////////////////////////////////
1724

    
1725
  public int[] getNumLayers()
1726
    {
1727
    return mNumLayers;
1728
    }
1729

    
1730
///////////////////////////////////////////////////////////////////////////////////////////////////
1731

    
1732
  public synchronized void solve()
1733
    {
1734
    for(int i=0; i<mNumCubits; i++)
1735
      {
1736
      mCubits[i].solve();
1737
      }
1738

    
1739
    recomputeFaceOffsets();
1740

    
1741
    for(int i=0; i<mNumCubits; i++)
1742
      {
1743
      mCubits[i].computeRotationRow();
1744
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1745
      }
1746
    }
1747

    
1748
///////////////////////////////////////////////////////////////////////////////////////////////////
1749

    
1750
  public int getCubitQuatIndex(int cubit)
1751
    {
1752
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1753
    }
1754

    
1755
///////////////////////////////////////////////////////////////////////////////////////////////////
1756

    
1757
  public int getCubitRotRow(int cubit, int axis)
1758
    {
1759
    return mCubits[cubit].getRotRow(axis);
1760
    }
1761

    
1762
///////////////////////////////////////////////////////////////////////////////////////////////////
1763

    
1764
  public Bitmap getStickerBitmap()
1765
    {
1766
    return mBitmap;
1767
    }
1768

    
1769
///////////////////////////////////////////////////////////////////////////////////////////////////
1770

    
1771
  public DistortedNode getNode()
1772
    {
1773
    return mNode;
1774
    }
1775

    
1776
///////////////////////////////////////////////////////////////////////////////////////////////////
1777

    
1778
  public int getNumStickerTypes()
1779
    {
1780
    return mNumStickerTypes;
1781
    }
1782

    
1783
///////////////////////////////////////////////////////////////////////////////////////////////////
1784

    
1785
  public String reportState()
1786
    {
1787
    StringBuilder builder = new StringBuilder();
1788

    
1789
    for(int i=0; i<mNumCubits; i++ )
1790
      {
1791
      if( i>0 ) builder.append('.');
1792
      builder.append(mCubits[i].mQuatIndex);
1793
      }
1794

    
1795
    return builder.toString();
1796
    }
1797

    
1798
///////////////////////////////////////////////////////////////////////////////////////////////////
1799
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1800

    
1801
  public int getNumCubitFaces()
1802
    {
1803
    return 0;
1804
    }
1805

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

    
1811
  public float getPillowCoeff()
1812
    {
1813
    return 1.0f;
1814
    }
1815

    
1816
///////////////////////////////////////////////////////////////////////////////////////////////////
1817

    
1818
  public TouchControl getTouchControl()
1819
    {
1820
    if( mTouchControl==null )
1821
      {
1822
      switch(getTouchControlType())
1823
        {
1824
        case TC_TETRAHEDRON      : mTouchControl = new TouchControlTetrahedron(this);
1825
                                   break;
1826
        case TC_HEXAHEDRON       : mTouchControl = new TouchControlHexahedron(this);
1827
                                   break;
1828
        case TC_OCTAHEDRON       : mTouchControl = new TouchControlOctahedron(this);
1829
                                   break;
1830
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
1831
                                   break;
1832
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
1833
                                   break;
1834
        case TC_CUBOID           : int[] numLayers = getNumLayers();
1835
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1836
                                   break;
1837
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
1838
                                   break;
1839
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
1840
                                   break;
1841
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
1842
                                   break;
1843
        case TC_CHANGING_SHAPEMOD: mTouchControl = new TouchControlShapemod(this);
1844
                                   break;
1845
        }
1846
      }
1847
    return mTouchControl;
1848
    }
1849

    
1850
///////////////////////////////////////////////////////////////////////////////////////////////////
1851

    
1852
  protected void setReader(JsonReader reader)
1853
    {
1854
    // empty
1855
    }
1856

    
1857
///////////////////////////////////////////////////////////////////////////////////////////////////
1858
  // for JSON only
1859
  public abstract int getTouchControlType();
1860
  public abstract int getTouchControlSplit();
1861
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1862
  public abstract int[][][] getEnabled();
1863
  public abstract float[] getDist3D(int[] numLayers);
1864
  public abstract Static3D[] getFaceAxis();
1865
  public abstract int[][] getScrambleEdges();
1866
  public abstract float[][] getCuts(int[] numLayers);
1867
  public abstract float getStickerRadius();
1868
  public abstract float getStickerStroke();
1869
  public abstract float[][] getStickerAngles();
1870
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1871
  public abstract ObjectShape getObjectShape(int variant);
1872
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1873
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1874
  public abstract int getNumCubitVariants(int[] numLayers);
1875
  public abstract float[][] getCubitPositions(int[] numLayers);
1876
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1877
  public abstract int getNumFaceColors();
1878
  public abstract float getScreenRatio();
1879
  public abstract int getColor(int face);
1880
  public abstract String getShortName();
1881
  public abstract ObjectSignature getSignature();
1882

    
1883
  // not only for JSON
1884
  public abstract Static3D[] getRotationAxis();
1885
  public abstract int[][] getBasicAngles();
1886
  public abstract int getNumFaces();
1887
  public abstract String getObjectName();
1888
  public abstract String getInventor();
1889
  public abstract int getYearOfInvention();
1890
  public abstract int getComplexity();
1891
  public abstract int getFOV();
1892
  public abstract String[][] getTutorials();
1893
  }
(8-8/11)