Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 9283a268

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(InputStream jsonStream, int meshState, int iconMode, Static4D quat, Static3D move, float scale, InputStream meshStream)
162
    {
163
    try
164
      {
165
      JsonReader reader = new JsonReader();
166
      reader.parseJsonFile(jsonStream);
167
      setReader(reader);
168
      mNumLayers = reader.getNumLayers();
169
      mSize      = reader.getSize();
170
      mInitData  = null;
171
      initialize(meshState,iconMode,quat,move,scale,meshStream,true);
172
      mError = false;
173
      mErrorString=null;
174
      }
175
    catch(Exception ex)
176
      {
177
      mError = true;
178
      mErrorString = ex.getMessage();
179
      }
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public TwistyObject(InitData data, int meshState, int iconMode, float size, Static4D quat, Static3D move, float scale, InputStream meshStream)
185
    {
186
    mNumLayers = data.getNumLayers();
187
    mSize      = size;
188
    mInitData  = data;
189
    initialize(meshState,iconMode,quat,move,scale,meshStream,false);
190
    mError = false;
191
    mErrorString = null;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  private void debugQuat(Static4D quat, int cubitIndex, float axisX, float axisY, float axisZ, float angle, int place)
197
    {
198
    float[] tracking = mCubits[cubitIndex].getTrackingPoint();
199

    
200
    String problem = (getShortName()+" "+cubitIndex+" "+quat.get0()+" "+quat.get1()+" "+quat.get2()+" "+quat.get3());
201
    problem += (" "+angle+" "+place+" "+tracking[0]+" "+tracking[1]+" "+tracking[2]);
202
    problem += (" "+axisX+" "+axisY+" "+axisZ)+" "+mPointNum;
203

    
204
    mInterface.reportProblem(problem,true);
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

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

    
224
    mNumAxis = mAxis.length;
225
    mCuts = getCuts(mNumLayers);
226
    mNumCuts = new int[mNumAxis];
227
    mMaxNumLayers = -1;
228
    for(int i=0; i<mNumAxis; i++)
229
      {
230
      if( mMaxNumLayers<mNumLayers[i] ) mMaxNumLayers = mNumLayers[i];
231
      mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length);
232
      }
233

    
234
    mNumCubits = mOrigPos.length;
235
    mNumFaceColors = getNumFaceColors();
236
    mBelongs = new boolean[mNumCubits];
237

    
238
    int scramblingType = getScrambleType();
239
    int[][] edges = getScrambleEdges();
240
    int[][] algorithms = getScrambleAlgorithms();
241

    
242
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges);
243

    
244
    boolean bandaged=false;
245

    
246
    for( int c=0; c<mNumCubits; c++)
247
      {
248
      if( mOrigPos[c].length>3 )
249
        {
250
        bandaged=true;
251
        break;
252
        }
253
      }
254
    mIsBandaged = bandaged;
255
    mQuatDebug = new int[mNumCubits];
256

    
257
    mRotationAngle= new Dynamic1D();
258
    mRotationAxis = new Static3D(1,0,0);
259
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
260

    
261
    mRotationAngleStatic = new Static1D(0);
262
    mRotationAngleMiddle = new Static1D(0);
263
    mRotationAngleFinal  = new Static1D(0);
264

    
265
    mObjectScale = new Static3D(scale,scale,scale);
266
    setObjectRatioNow(scale,720);
267

    
268
    mEffects = new DistortedEffects();
269
    createQuaternionEffects();
270

    
271
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
272
    MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER);
273
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
274

    
275
    boolean fromDMESH = (meshStream!=null && meshState==MESH_NICE);
276
    getQuatsAndShapes(fromDMESH,fromJSON);
277
    createMeshAndCubits(meshStream,meshState,fromDMESH);
278
    setUpTextures(fromDMESH,fromJSON);
279

    
280
    int index = getSolvedFunctionIndex();
281
    mSolved = new TwistyObjectSolved(this,mOrigPos,index);
282
    mSolved.setupSolvedQuats(getSolvedQuats());
283

    
284
    mEffects.apply(mRotateEffect);
285
    mEffects.apply(quatEffect);
286
    mEffects.apply(scaleEffect);
287
    mEffects.apply(moveEffect);
288

    
289
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
290
    }
291

    
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293

    
294
  private void createQuaternionEffects()
295
    {
296
    if( mNumQuats<=ObjectControl.MAX_QUATS )
297
      {
298
      mIsInMixupMode = false;
299

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

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

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327

    
328
  private Static3D getPos(float[] origPos)
329
    {
330
    int len = origPos.length/3;
331
    float sumX = 0.0f;
332
    float sumY = 0.0f;
333
    float sumZ = 0.0f;
334

    
335
    for(int i=0; i<len; i++)
336
      {
337
      sumX += origPos[3*i  ];
338
      sumY += origPos[3*i+1];
339
      sumZ += origPos[3*i+2];
340
      }
341

    
342
    sumX /= len;
343
    sumY /= len;
344
    sumZ /= len;
345

    
346
    return new Static3D(sumX,sumY,sumZ);
347
    }
348

    
349
///////////////////////////////////////////////////////////////////////////////////////////////////
350

    
351
  private void createOuterFaces()
352
    {
353
    for(int v=0; v<mNumCubitVariants; v++)
354
      {
355
      int[][] indices = mShapes[v].getVertIndices();
356
      int faces = indices.length;
357
      mVariantFaceIsOuter[v] = new int[faces];
358
      }
359

    
360
    for( int cubit=0; cubit<mNumCubits; cubit++)
361
      {
362
      int variant = getCubitVariant(cubit,mNumLayers);
363
      int[][] indices = mShapes[variant].getVertIndices();
364
      int numFaces = indices.length;
365

    
366
      for(int face=0; face<numFaces; face++)
367
        if( getCubitFaceColor(cubit,face)>=0 )
368
          {
369
          mVariantFaceIsOuter[variant][face] = 1;
370
          }
371
      }
372
    }
373

    
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375

    
376
  private void getQuatsAndShapes(boolean fromDMESH, boolean fromJSON)
377
    {
378
    mNumCubitVariants = getNumCubitVariants(mNumLayers);
379

    
380
    if( !fromDMESH || !fromJSON )
381
      {
382
      FactoryCubit factory = FactoryCubit.getInstance();
383
      factory.clear();
384

    
385
      mOrigQuat = new Static4D[mNumCubits];
386
      for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers);
387

    
388
      mShapes = new ObjectShape[mNumCubitVariants];
389
      for(int i=0; i<mNumCubitVariants; i++) mShapes[i] = getObjectShape(i);
390
      mNumCubitFaces = ObjectShape.computeNumComponents(mShapes);
391
      mVariantFaceIsOuter = new int[mNumCubitVariants][];
392

    
393
      if( !fromJSON )
394
        {
395
        mCubitFaceColors = ObjectShape.computeColors(mShapes,mOrigPos,mOrigQuat,this);
396
        createOuterFaces();
397
        }
398

    
399
      if( fromDMESH )
400
        {
401
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i], mVariantFaceIsOuter[i]);
402
        }
403
      }
404
    }
405

    
406
///////////////////////////////////////////////////////////////////////////////////////////////////
407

    
408
  private void createMeshAndCubits(InputStream stream, int meshState, boolean fromDMESH)
409
    {
410
    mCubits = new TwistyObjectCubit[mNumCubits];
411

    
412
    if( fromDMESH )
413
      {
414
      DataInputStream dos = new DataInputStream(stream);
415
      mMesh = new MeshFile(dos);
416

    
417
      try
418
        {
419
        stream.close();
420
        }
421
      catch(IOException e)
422
        {
423
        android.util.Log.e("meshFile", "Error closing InputStream: "+e);
424
        }
425
      }
426
    else
427
      {
428
      MeshBase[] cubitMesh = new MeshBase[mNumCubits];
429

    
430
      for(int i=0; i<mNumCubits; i++)
431
        {
432
        cubitMesh[i] = createCubitMesh(i,mNumLayers,meshState,mNumCubitFaces);
433
        Static3D pos = getPos(mOrigPos[i]);
434
        cubitMesh[i].apply(new MatrixEffectMove(pos),1,0);
435
        }
436

    
437
      mMesh = new MeshJoined(cubitMesh);
438

    
439
      float pillowCoeff = getPillowCoeff();
440

    
441
      if( pillowCoeff!=1.0f )
442
        {
443
        float radius = getCircumscribedRadius();
444
        Static1D coeff = new Static1D(pillowCoeff);
445
        Static4D region= new Static4D(0,0,0,radius);
446
        VertexEffectSink sink = new VertexEffectSink(coeff,CENTER,region);
447
        mMesh.apply(sink);
448
        }
449
      }
450

    
451
    for(int i=0; i<mNumCubits; i++)
452
      {
453
      mCubits[i] = new TwistyObjectCubit(this,mOrigPos[i],mNumAxis,mMaxNumLayers,i);
454
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
455
      }
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  private MeshBase createCubitMesh(int cubit, int[] numLayers, int meshState, int numComponents)
461
    {
462
    int variant = getCubitVariant(cubit,numLayers);
463

    
464
    if( mMeshes==null ) mMeshes = new MeshBase[mNumCubitVariants];
465

    
466
    if( mMeshes[variant]==null )
467
      {
468
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
469
      ObjectVertexEffects effects = getVertexEffects(variant);
470
      FactoryCubit factory = FactoryCubit.getInstance();
471
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
472
      mMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects, meshState, numComponents);
473
      }
474

    
475
    MeshBase mesh = mMeshes[variant].copy(true);
476
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( mOrigQuat[cubit], CENTER );
477
    mesh.apply(quat,0xffffffff,0);
478

    
479
    return mesh;
480
    }
481

    
482
///////////////////////////////////////////////////////////////////////////////////////////////////
483

    
484
  private void setUpTextures(boolean fromDMESH, boolean fromJSON)
485
    {
486
    mTexture = new DistortedTexture();
487

    
488
    if( fromJSON )
489
      {
490
      mNumStickerTypes = getNumStickerTypes();
491
      mNumCubitFaces = getNumCubitFaces();
492
      }
493
    else
494
      {
495
      FactoryCubit factory = FactoryCubit.getInstance();
496
      mStickerCoords   = factory.getStickerCoords();
497
      mStickerVariants = factory.getStickerVariants();
498
      mStickerScales   = factory.getStickerScales();
499
      adjustStickerCoords();
500
      mNumStickerTypes = (mStickerCoords==null ? 0 : mStickerCoords.length);
501
      }
502

    
503
    mStickerOverrides = getStickerOverrides();
504
    mNumOverrides = mStickerOverrides==null ? 0 : mStickerOverrides.length;
505

    
506
    mNumTextures= mNumFaceColors*mNumStickerTypes + mNumOverrides;
507
    mNumTexCols = NUM_STICKERS_IN_ROW;
508
    mNumTexRows = (mNumTextures+1)/NUM_STICKERS_IN_ROW;
509
    if( mNumTexCols*mNumTexRows < mNumTextures+1 ) mNumTexRows++;
510

    
511
    if( !fromDMESH || shouldResetTextureMaps() ) resetAllTextureMaps();
512
    else overrideCubitFaceColor();
513

    
514
    setTexture();
515
    }
516

    
517
///////////////////////////////////////////////////////////////////////////////////////////////////
518

    
519
  public InitData getInitData()
520
    {
521
    return mInitData;
522
    }
523

    
524
///////////////////////////////////////////////////////////////////////////////////////////////////
525

    
526
  public boolean isInIconMode()
527
    {
528
    return mIconMode==MODE_ICON;
529
    }
530

    
531
///////////////////////////////////////////////////////////////////////////////////////////////////
532

    
533
  public int getVariantStickerShape(int variant, int face)
534
    {
535
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
536
    }
537

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

    
540
  public boolean shouldResetTextureMaps()
541
    {
542
    return false;
543
    }
544

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

    
547
  public int[][] getScrambleAlgorithms()
548
    {
549
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngles);
550
    }
551

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

    
554
  private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z )
555
    {
556
    final float MAXERR = 0.05f;
557
    int numAxis = dist.length;
558

    
559
    for(int i=0; i<numAxis; i++)
560
      {
561
      Static3D ax = faceAxis[i];
562
      float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
563
      if( len>mSize*dist[i]+MAXERR ) return true;
564
      }
565

    
566
    return false;
567
    }
568

    
569
///////////////////////////////////////////////////////////////////////////////////////////////////
570

    
571
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
572
    {
573
    float[][] vertices = mShapes[variant].getVertices();
574
    Static3D[] axis = getFaceAxis();
575
    float[] dist3D = getDist3D(mNumLayers);
576

    
577
    for( float[] vertex : vertices)
578
      {
579
      float x = vertex[0];
580
      float y = vertex[1];
581
      float z = vertex[2];
582

    
583
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
584

    
585
      float mx = tmp[0] + px;
586
      float my = tmp[1] + py;
587
      float mz = tmp[2] + pz;
588

    
589
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
590
      }
591

    
592
    return true;
593
    }
594

    
595
///////////////////////////////////////////////////////////////////////////////////////////////////
596

    
597
  private float computeAvg(float[] pos, int offset)
598
    {
599
    int len = pos.length/3;
600
    float ret=0.0f;
601
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
602
    ret /= len;
603

    
604
    return ret;
605
    }
606

    
607
///////////////////////////////////////////////////////////////////////////////////////////////////
608

    
609
  protected void displayCubitQuats()
610
    {
611
    StringBuilder builder = new StringBuilder();
612
    float[] tmp = new float[4];
613
    float ERR = 0.01f;
614

    
615
    for(int cubit=0; cubit<mNumCubits; cubit++)
616
      {
617
      builder.append(cubit);
618
      builder.append(" : ");
619

    
620
      int refCubit,variant = getCubitVariant(cubit,mNumLayers);
621

    
622
      for(refCubit=0; refCubit<mNumCubits; refCubit++)
623
        {
624
        if( getCubitVariant(refCubit,mNumLayers)==variant ) break;
625
        }
626

    
627
      float[] curpos = mOrigPos[cubit];
628
      float[] refpos = mOrigPos[refCubit];
629
      float refX = computeAvg(refpos,0);
630
      float refY = computeAvg(refpos,1);
631
      float refZ = computeAvg(refpos,2);
632
      float curX = computeAvg(curpos,0);
633
      float curY = computeAvg(curpos,1);
634
      float curZ = computeAvg(curpos,2);
635

    
636
      for(int quat=0; quat<mNumQuats; quat++)
637
        {
638
        QuatHelper.rotateVectorByQuat(tmp,refX,refY,refZ,0,mObjectQuats[quat]);
639

    
640
        float dx = tmp[0]-curX;
641
        float dy = tmp[1]-curY;
642
        float dz = tmp[2]-curZ;
643

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

    
658
      builder.append('\n');
659
      }
660

    
661
    android.util.Log.e("D", "cubitQuats: \n"+builder );
662
    }
663

    
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665

    
666
  public int getCubitRotationType(int cubit)
667
    {
668
    return TwistyObjectCubit.TYPE_NORMAL;
669
    }
670

    
671
///////////////////////////////////////////////////////////////////////////////////////////////////
672

    
673
  float[] getTrackingPoint(int cubitIndex, int cubitType)
674
    {
675
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
676
      {
677
      int variant = getCubitVariant(cubitIndex,mNumLayers);
678

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

    
701
      int[][] indices = mShapes[variant].getVertIndices();
702
      int outer=-1, faces = indices.length;
703

    
704
      for(int i=0; i<faces; i++)
705
        {
706
        if( mVariantFaceIsOuter[variant][i]==1 )
707
          {
708
          outer=i;
709
          break;
710
          }
711
        }
712

    
713
      if( outer>=0 )
714
        {
715
        int vertIndex = indices[outer][0];
716
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
717
        float[] ret = new float[3];
718
        float[] curpos = mOrigPos[cubitIndex];
719
        Static4D quat = mOrigQuat[cubitIndex];
720
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
721

    
722
        ret[0] = mTmp[0]+computeAvg(curpos,0);
723
        ret[1] = mTmp[1]+computeAvg(curpos,1);
724
        ret[2] = mTmp[2]+computeAvg(curpos,2);
725

    
726
        return ret;
727
        }
728
      else
729
        {
730
        android.util.Log.e("D", "Error in getTrackingPoint: no outer face??");
731
        }
732
      }
733

    
734
    return null;
735
    }
736

    
737
///////////////////////////////////////////////////////////////////////////////////////////////////
738

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

    
751
      for(int i=0; i<numAxis; i++)
752
        {
753
        Static3D ax = axis[i];
754
        float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
755
        if( len>mSize*dist3D[i]*MAXERR ) return i;
756
        }
757

    
758
      return -2;
759
      }
760

    
761
    return -1;
762
    }
763

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

    
766
  public float[] getCubitRowOffset(int cubitIndex)
767
    {
768
    return null;
769
    }
770

    
771
///////////////////////////////////////////////////////////////////////////////////////////////////
772

    
773
  void setRotationRowOffset(int puzzleFace, float[] offset)
774
    {
775
    mRowOffsets[puzzleFace][0] = offset[0];
776
    mRowOffsets[puzzleFace][1] = offset[1];
777
    mRowOffsets[puzzleFace][2] = offset[2];
778
    }
779

    
780
///////////////////////////////////////////////////////////////////////////////////////////////////
781

    
782
  int getNumAxis()
783
    {
784
    return mNumAxis;
785
    }
786

    
787
///////////////////////////////////////////////////////////////////////////////////////////////////
788

    
789
  public int[][] getSolvedQuats()
790
    {
791
    return mSolved.getSolvedQuats(mNumLayers,mNumCubitFaces,mCubitFaceColors);
792
    }
793

    
794
///////////////////////////////////////////////////////////////////////////////////////////////////
795

    
796
  public int getSolvedFunctionIndex()
797
    {
798
    return 0;
799
    }
800

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

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

    
813
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
814
      {
815
      xoff = mRowOffsets[puzzleFace][0];
816
      yoff = mRowOffsets[puzzleFace][1];
817
      zoff = mRowOffsets[puzzleFace][2];
818
      }
819

    
820
    for(int i=0; i<len; i++)
821
      {
822
      casted = (pos[3*i]+xoff)*axisX + (pos[3*i+1]+yoff)*axisY + (pos[3*i+2]+zoff)*axisZ;
823
      ret |= computeSingleRow(axisIndex,casted);
824
      }
825

    
826
    return ret;
827
    }
828

    
829
///////////////////////////////////////////////////////////////////////////////////////////////////
830

    
831
  private int computeSingleRow(int axisIndex,float casted)
832
    {
833
    int num = mNumCuts[axisIndex];
834

    
835
    for(int i=0; i<num; i++)
836
      {
837
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
838
      }
839

    
840
    return (1<<num);
841
    }
842

    
843
///////////////////////////////////////////////////////////////////////////////////////////////////
844

    
845
  private boolean wasRotateApplied()
846
    {
847
    return mEffects.exists(mRotateEffect.getID());
848
    }
849

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

    
852
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
853
    {
854
    return (mCubits[cubit].getRotRow(axis) & rowBitmap) != 0;
855
    }
856

    
857
///////////////////////////////////////////////////////////////////////////////////////////////////
858
// note the minus in front of the sin() - we rotate counterclockwise
859
// when looking towards the direction where the axis increases in values.
860

    
861
  private Static4D makeQuaternion(float axisX, float axisY, float axisZ, int angleInDegrees)
862
    {
863
    while( angleInDegrees<0 ) angleInDegrees += 360;
864
    angleInDegrees %= 360;
865
    
866
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
867
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
868

    
869
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
870
    }
871

    
872
///////////////////////////////////////////////////////////////////////////////////////////////////
873

    
874
  private synchronized void setupPosition(int[][] moves)
875
    {
876
    if( moves!=null )
877
      {
878
      Static4D quat;
879
      int index, axisIndex, row, rowBitmap, basic, angle;
880

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

    
898
        for(int i=0; i<mNumCubits; i++)
899
          {
900
          mBelongs[i] = belongsToRotation(i,axisIndex,rowBitmap);
901
          if( mBelongs[i] )
902
            {
903
            boolean result = mCubits[i].rotateCubit(quat);
904
            if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,1);
905
            }
906
          }
907

    
908
        recomputeFaceOffsets();
909

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

    
927
///////////////////////////////////////////////////////////////////////////////////////////////////
928

    
929
  public int getScrambleType()
930
    {
931
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
932
    }
933

    
934
///////////////////////////////////////////////////////////////////////////////////////////////////
935

    
936
  int computeBitmapFromRow(int rowBitmap, int axis)
937
    {
938
    if( mIsBandaged )
939
      {
940
      int bitmap, initBitmap=0;
941

    
942
      while( initBitmap!=rowBitmap )
943
        {
944
        initBitmap = rowBitmap;
945

    
946
        for(int cubit=0; cubit<mNumCubits; cubit++)
947
          {
948
          bitmap = mCubits[cubit].getRotRow(axis);
949
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
950
          }
951
        }
952
      }
953

    
954
    return rowBitmap;
955
    }
956

    
957
///////////////////////////////////////////////////////////////////////////////////////////////////
958

    
959
  private int computeRowFromBitmap(int rowBitmap)
960
    {
961
    int index = 0;
962

    
963
    while(index<32)
964
      {
965
      if( (rowBitmap&0x1) != 0 ) return index;
966
      rowBitmap>>=1;
967
      index++;
968
      }
969
    return 0;
970
    }
971

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

    
976
  void clampPos(float[] pos, int offset)
977
    {
978
    float currError, minError = Float.MAX_VALUE;
979
    int minErrorIndex1 = -1;
980
    int minErrorIndex2 = -1;
981

    
982
    float x = pos[offset  ];
983
    float y = pos[offset+1];
984
    float z = pos[offset+2];
985

    
986
    float xo,yo,zo;
987

    
988
    for(int i=0; i<mNumCubits; i++)
989
      {
990
      int len = mOrigPos[i].length / 3;
991

    
992
      for(int j=0; j<len; j++)
993
        {
994
        xo = mOrigPos[i][3*j  ];
995
        yo = mOrigPos[i][3*j+1];
996
        zo = mOrigPos[i][3*j+2];
997

    
998
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
999

    
1000
        if( currError<minError )
1001
          {
1002
          minError = currError;
1003
          minErrorIndex1 = i;
1004
          minErrorIndex2 = j;
1005
          }
1006
        }
1007
      }
1008

    
1009
    if( minError< 0.05f ) // TODO: 0.05 ?
1010
      {
1011
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1012
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1013
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1014
      }
1015
    }
1016

    
1017
///////////////////////////////////////////////////////////////////////////////////////////////////
1018

    
1019
  private float getAngle()
1020
    {
1021
    mPointNum = mRotationAngle.getNumPoints();
1022
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1023
    }
1024

    
1025
///////////////////////////////////////////////////////////////////////////////////////////////////
1026

    
1027
  void setLibInterface(ObjectLibInterface inter)
1028
    {
1029
    mInterface = inter;
1030
    }
1031

    
1032
///////////////////////////////////////////////////////////////////////////////////////////////////
1033

    
1034
  void applyScrambles(int[][] moves)
1035
    {
1036
    setupPosition(moves);
1037
    }
1038

    
1039
///////////////////////////////////////////////////////////////////////////////////////////////////
1040

    
1041
  void initializeObject(int[][] moves)
1042
    {
1043
    solve();
1044
    setupPosition(moves);
1045
    }
1046

    
1047
///////////////////////////////////////////////////////////////////////////////////////////////////
1048

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

    
1060
    mRotationAngleStatic.set0(0);
1061
    mRotationAngle.removeAll();
1062

    
1063
    for(int i=0; i<mNumCubits; i++)
1064
      {
1065
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1066
      if( mBelongs[i] )
1067
        {
1068
        boolean result = mCubits[i].rotateCubit(quat);
1069
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1070
        }
1071
      }
1072

    
1073
    recomputeFaceOffsets();
1074

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

    
1089
    mRotationState = STATE_NOTHING;
1090
    }
1091

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

    
1094
  private void recomputeFaceOffsets()
1095
    {
1096
    for(int i=0; i<mNumPuzzleFaces; i++)
1097
      {
1098
      mRowOffsets[i][0] =0;
1099
      mRowOffsets[i][1] =0;
1100
      mRowOffsets[i][2] =0;
1101
      }
1102

    
1103
    for(int i=0; i<mNumCubits; i++)
1104
      if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1105
        {
1106
        float[] offset = mCubits[i].getOffset();
1107
        int face = mCubits[i].getPuzzleFace();
1108
        mRowOffsets[face][0] = offset[0];
1109
        mRowOffsets[face][1] = offset[1];
1110
        mRowOffsets[face][2] = offset[2];
1111
        }
1112
    }
1113

    
1114
///////////////////////////////////////////////////////////////////////////////////////////////////
1115

    
1116
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1117
    {
1118
    if( wasRotateApplied() )
1119
      {
1120
      mRotationState = STATE_FINISH;
1121
      float angle = getAngle();
1122
      mRotationAngleStatic.set0(angle);
1123
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1124
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1125

    
1126
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1127
      mRotationAngle.resetToBeginning();
1128
      mRotationAngle.removeAll();
1129
      mRotationAngle.add(mRotationAngleStatic);
1130
      mRotationAngle.add(mRotationAngleMiddle);
1131
      mRotationAngle.add(mRotationAngleFinal);
1132
      mRotateEffect.notifyWhenFinished(listener);
1133

    
1134
      return mRotateEffect.getID();
1135
      }
1136

    
1137
    return 0;
1138
    }
1139

    
1140
///////////////////////////////////////////////////////////////////////////////////////////////////
1141

    
1142
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1143
    {
1144
    int mult = 1;
1145

    
1146
    if( wasRotateApplied() )
1147
      {
1148
      if( mRotationState==STATE_ROTATE )
1149
        {
1150
        return 0;
1151
        }
1152
      if( mRotationState==STATE_FINISH )
1153
        {
1154
        removeRotationNow();
1155
        mult = -1;
1156
        }
1157

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

    
1172
    return 0;
1173
    }
1174

    
1175
///////////////////////////////////////////////////////////////////////////////////////////////////
1176

    
1177
  void continueRotation(float angleInDegrees)
1178
    {
1179
    mRotationAngleStatic.set0(angleInDegrees);
1180
    }
1181

    
1182
///////////////////////////////////////////////////////////////////////////////////////////////////
1183

    
1184
  synchronized boolean beginNewRotation(int axis, int row )
1185
    {
1186
    if( mRotationState==STATE_ROTATE )
1187
      {
1188
      return false;
1189
      }
1190
    if( mRotationState==STATE_FINISH )
1191
      {
1192
      removeRotationNow();
1193
      }
1194

    
1195
    if( axis<0 || axis>=mNumAxis )
1196
      {
1197
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1198
      return false;
1199
      }
1200
    if( row<0 || row>=mNumLayers[axis] )
1201
      {
1202
      android.util.Log.e("object", "invalid rotation row: "+row);
1203
      return false;
1204
      }
1205

    
1206
    mRotationState = STATE_ROTATE;
1207
    mCurrentRotAxis = axis;
1208
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
1209
    mRotationAngleStatic.set0(0.0f);
1210
    mRotationAxis.set( mAxis[axis] );
1211
    mRotationAngle.add(mRotationAngleStatic);
1212
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1213

    
1214
    return true;
1215
    }
1216

    
1217
///////////////////////////////////////////////////////////////////////////////////////////////////
1218

    
1219
  void setTextureMap(int cubit, int face, int color)
1220
    {
1221
    int variant  = getCubitVariant(cubit,mNumLayers);
1222
    int shape    = getVariantStickerShape(variant,face);
1223
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1224
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1225
    int col      = texIndex%mNumTexCols;
1226

    
1227
    final float ratioW = 1.0f/mNumTexCols;
1228
    final float ratioH = 1.0f/mNumTexRows;
1229
    final Static4D[] maps = new Static4D[1];
1230
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1231
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1232
    }
1233

    
1234
///////////////////////////////////////////////////////////////////////////////////////////////////
1235

    
1236
  private int getCubitFaceColor(int cubit, int face)
1237
    {
1238
    int puzzleFace = getCubitFaceMap(cubit,face);
1239
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1240
    return puzzleFace;
1241
    }
1242

    
1243
///////////////////////////////////////////////////////////////////////////////////////////////////
1244

    
1245
  public int getCubitFaceMap(int cubit, int face)
1246
    {
1247
    int numFaces = mCubitFaceColors[cubit].length;
1248
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1249
    return puzzleFace<0 ? -1 : puzzleFace;
1250
    }
1251

    
1252
///////////////////////////////////////////////////////////////////////////////////////////////////
1253

    
1254
  void resetAllTextureMaps()
1255
    {
1256
    final float ratioW = 1.0f/mNumTexCols;
1257
    final float ratioH = 1.0f/mNumTexRows;
1258
    int cubColor, stiShape, texIndex, variant, row, col;
1259

    
1260
    for(int cubit=0; cubit<mNumCubits; cubit++)
1261
      {
1262
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1263
      variant = getCubitVariant(cubit,mNumLayers);
1264

    
1265
      for(int face=0; face<mNumCubitFaces; face++)
1266
        {
1267
        cubColor = getCubitFaceColor(cubit,face);
1268
        stiShape = getVariantStickerShape(variant,face);
1269
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1270
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1271
        col      = texIndex%mNumTexCols;
1272

    
1273
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1274
        }
1275

    
1276
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1277
      }
1278

    
1279
    overrideCubitFaceColor();
1280
    }
1281

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

    
1284
  private void overrideCubitFaceColor()
1285
    {
1286
    final float ratioW = 1.0f/mNumTexCols;
1287
    final float ratioH = 1.0f/mNumTexRows;
1288

    
1289
    for(int i=0; i<mNumOverrides; i++)
1290
      {
1291
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1292
      int length = cubitFaces.length/2;
1293

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

    
1308
///////////////////////////////////////////////////////////////////////////////////////////////////
1309

    
1310
  void releaseResources()
1311
    {
1312
    mTexture.markForDeletion();
1313
    mMesh.markForDeletion();
1314
    mEffects.markForDeletion();
1315

    
1316
    for(int j=0; j<mNumCubits; j++)
1317
      {
1318
      mCubits[j].releaseResources();
1319
      }
1320
    }
1321

    
1322
///////////////////////////////////////////////////////////////////////////////////////////////////
1323

    
1324
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1325
    {
1326
    if( !mIsInMixupMode )
1327
      {
1328
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1329
      }
1330
    else
1331
      {
1332
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1333
      Static4D tmp = mObjectQuats[equAssociation];
1334
      mMixupModeQuats[cubit].set(tmp);
1335
      }
1336
    }
1337

    
1338
///////////////////////////////////////////////////////////////////////////////////////////////////
1339

    
1340
  synchronized void restorePreferences(SharedPreferences preferences)
1341
    {
1342
    boolean error = false;
1343
    String key = getShortName();
1344

    
1345
    for(int i=0; i<mNumCubits; i++)
1346
      {
1347
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1348

    
1349
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1350
        {
1351
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1352
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1353
        }
1354
      else { error = true; break; }
1355
      }
1356

    
1357
    if( !error )
1358
      {
1359
      recomputeFaceOffsets();
1360

    
1361
      for(int i=0; i<mNumCubits; i++)
1362
        {
1363
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1364
          {
1365
          mCubits[i].computeRotationRow();
1366
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1367
          }
1368
        else { error = true; break; }
1369
        }
1370
      }
1371

    
1372
    if( error )
1373
      {
1374
      for(int i=0; i<mNumCubits; i++)
1375
        {
1376
        mCubits[i].solve();
1377
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1378
        }
1379
      }
1380
    }
1381

    
1382
///////////////////////////////////////////////////////////////////////////////////////////////////
1383

    
1384
  void savePreferences(SharedPreferences.Editor editor)
1385
    {
1386
    String key = getShortName();
1387
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1388
    }
1389

    
1390
///////////////////////////////////////////////////////////////////////////////////////////////////
1391

    
1392
  public void removePreferences(SharedPreferences.Editor editor)
1393
    {
1394
    String key = getShortName();
1395
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1396
    }
1397

    
1398
///////////////////////////////////////////////////////////////////////////////////////////////////
1399

    
1400
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1401
    {
1402
    final float A = 0.8f;  // 0<A<1
1403

    
1404
    int prev = curr>0 ? curr-1 : len-1;
1405
    int next = curr<len-1 ? curr+1 : 0;
1406

    
1407
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1408
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1409
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1410
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1411

    
1412
    float len1= v1x*v1x+v1y*v1y;
1413
    float len2= v2x*v2x+v2y*v2y;
1414

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

    
1417
    return 1-A*cos;
1418
    }
1419

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

    
1428
  public float getCircumscribedRadius()
1429
    {
1430
    switch(mNumPuzzleFaces)
1431
      {
1432
      case  4: return (SQ6/4)*mSize;
1433
      case  6: return (SQ3/2)*mSize;
1434
      case  8: return (SQ2/2)*mSize;
1435
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1436
      case 16: return 0.50f*mSize;
1437
      }
1438

    
1439
    return 0.0f;
1440
    }
1441

    
1442
///////////////////////////////////////////////////////////////////////////////////////////////////
1443

    
1444
  public ObjectSticker retSticker(int sticker)
1445
    {
1446
    if( mStickers==null )
1447
      {
1448
      float rad = getStickerRadius();
1449
      float str = getStickerStroke();
1450
      float[][] angles = getStickerAngles();
1451
      int numStickers = mStickerCoords.length;
1452
      mStickers = new ObjectSticker[numStickers];
1453

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

    
1466
    return mStickers[sticker];
1467
    }
1468

    
1469
///////////////////////////////////////////////////////////////////////////////////////////////////
1470
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1471

    
1472
  public void adjustStickerCoords()
1473
    {
1474

    
1475
    }
1476

    
1477
///////////////////////////////////////////////////////////////////////////////////////////////////
1478

    
1479
  public Static4D[] getQuats()
1480
    {
1481
    if( mObjectQuats==null )
1482
      {
1483
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1484
      }
1485

    
1486
    return mObjectQuats;
1487
    }
1488

    
1489
///////////////////////////////////////////////////////////////////////////////////////////////////
1490

    
1491
  public int[][] getVariantFaceIsOuter()
1492
    {
1493
    return mVariantFaceIsOuter;
1494
    }
1495

    
1496
///////////////////////////////////////////////////////////////////////////////////////////////////
1497

    
1498
  public int getInternalColor()
1499
    {
1500
    return COLOR_INTERNAL;
1501
    }
1502

    
1503
///////////////////////////////////////////////////////////////////////////////////////////////////
1504
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1505

    
1506
  private void createTexture()
1507
    {
1508
    Paint paint = new Paint();
1509
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1510
    Canvas canvas = new Canvas(mBitmap);
1511

    
1512
    paint.setAntiAlias(true);
1513
    paint.setTextAlign(Paint.Align.CENTER);
1514
    paint.setStyle(Paint.Style.FILL);
1515
    paint.setColor(getInternalColor());
1516
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1517

    
1518
    int texture = 0;
1519
    FactorySticker factory = FactorySticker.getInstance();
1520

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

    
1536
        texture++;
1537
        }
1538
    }
1539

    
1540
///////////////////////////////////////////////////////////////////////////////////////////////////
1541

    
1542
  void setTexture()
1543
    {
1544
    if( mBitmap==null ) createTexture();
1545

    
1546
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1547
      {
1548
      int max = DistortedLibrary.getMaxTextureSize();
1549
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1550
      }
1551
    }
1552

    
1553
///////////////////////////////////////////////////////////////////////////////////////////////////
1554

    
1555
  void setObjectRatioNow(float sc, int nodeSize)
1556
    {
1557
    mObjectScreenRatio = sc;
1558
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1559
    mObjectScale.set(scale,scale,scale);
1560

    
1561
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1562
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1563
    }
1564

    
1565
///////////////////////////////////////////////////////////////////////////////////////////////////
1566

    
1567
  void setObjectRatio(float sizeChange, int nodeSize)
1568
    {
1569
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1570

    
1571
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1572
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1573

    
1574
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1575
    }
1576

    
1577
///////////////////////////////////////////////////////////////////////////////////////////////////
1578

    
1579
  void setNodeSize(int nodeSize)
1580
    {
1581
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1582
    }
1583

    
1584
///////////////////////////////////////////////////////////////////////////////////////////////////
1585

    
1586
  public float getRatio()
1587
    {
1588
    return mObjectScreenRatio;
1589
    }
1590

    
1591
///////////////////////////////////////////////////////////////////////////////////////////////////
1592

    
1593
  public float getObjectRatio()
1594
    {
1595
    return mObjectScreenRatio*mInitScreenRatio;
1596
    }
1597

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

    
1600
  boolean isSolved()
1601
    {
1602
    return mSolved.isSolved(mCubits);
1603
    }
1604

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

    
1607
  int computeNearestAngle(int basicAngle, float angle, float speed)
1608
    {
1609
    int nearestAngle = 360/basicAngle;
1610
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1611
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1612

    
1613
    if( tmp!=0 ) return nearestAngle*tmp;
1614

    
1615
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1616
    }
1617

    
1618
///////////////////////////////////////////////////////////////////////////////////////////////////
1619
// INTERNAL API - those are called from 'effects' package
1620
///////////////////////////////////////////////////////////////////////////////////////////////////
1621

    
1622
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1623
    {
1624
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1625
    }
1626

    
1627
///////////////////////////////////////////////////////////////////////////////////////////////////
1628

    
1629
  public Static4D getRotationQuat()
1630
    {
1631
    return mQuat;
1632
    }
1633

    
1634
///////////////////////////////////////////////////////////////////////////////////////////////////
1635

    
1636
  public float getSize()
1637
    {
1638
    return mSize;
1639
    }
1640

    
1641
///////////////////////////////////////////////////////////////////////////////////////////////////
1642

    
1643
  public void applyEffect(Effect effect, int position)
1644
    {
1645
    mEffects.apply(effect, position);
1646
    }
1647

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

    
1650
  public void removeEffect(long effectID)
1651
    {
1652
    mEffects.abortById(effectID);
1653
    }
1654

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

    
1657
  public MeshBase getObjectMesh()
1658
    {
1659
    return mMesh;
1660
    }
1661

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

    
1664
  public DistortedEffects getObjectEffects()
1665
    {
1666
    return mEffects;
1667
    }
1668

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

    
1671
  public int getCubitType(int cubit)
1672
    {
1673
    return mCubits[cubit].getType();
1674
    }
1675

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

    
1678
  public float[] getCubitOffset(int cubit)
1679
    {
1680
    return mCubits[cubit].getOffset();
1681
    }
1682

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

    
1685
  public ObjectStickerOverride[] getStickerOverrides()
1686
    {
1687
    return null;
1688
    }
1689

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

    
1692
  public boolean getError()
1693
    {
1694
    return mError;
1695
    }
1696

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

    
1699
  public String getErrorString()
1700
    {
1701
    return mErrorString;
1702
    }
1703

    
1704
///////////////////////////////////////////////////////////////////////////////////////////////////
1705
// PUBLIC API
1706
///////////////////////////////////////////////////////////////////////////////////////////////////
1707

    
1708
  public int getCubitFaceStickerIndex(int cubit, int face)
1709
    {
1710
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1711

    
1712
    int x = (int)(texMap.get0()/texMap.get2());
1713
    int y = (int)(texMap.get1()/texMap.get3());
1714

    
1715
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1716
    }
1717

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

    
1720
  public int[] getNumLayers()
1721
    {
1722
    return mNumLayers;
1723
    }
1724

    
1725
///////////////////////////////////////////////////////////////////////////////////////////////////
1726

    
1727
  public synchronized void solve()
1728
    {
1729
    for(int i=0; i<mNumCubits; i++)
1730
      {
1731
      mCubits[i].solve();
1732
      }
1733

    
1734
    recomputeFaceOffsets();
1735

    
1736
    for(int i=0; i<mNumCubits; i++)
1737
      {
1738
      mCubits[i].computeRotationRow();
1739
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1740
      }
1741
    }
1742

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

    
1745
  public int getCubitQuatIndex(int cubit)
1746
    {
1747
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1748
    }
1749

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

    
1752
  public int getCubitRotRow(int cubit, int axis)
1753
    {
1754
    return mCubits[cubit].getRotRow(axis);
1755
    }
1756

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

    
1759
  public Bitmap getStickerBitmap()
1760
    {
1761
    return mBitmap;
1762
    }
1763

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

    
1766
  public DistortedNode getNode()
1767
    {
1768
    return mNode;
1769
    }
1770

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

    
1773
  public int getNumStickerTypes()
1774
    {
1775
    return mNumStickerTypes;
1776
    }
1777

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

    
1780
  public String reportState()
1781
    {
1782
    StringBuilder builder = new StringBuilder();
1783

    
1784
    for(int i=0; i<mNumCubits; i++ )
1785
      {
1786
      if( i>0 ) builder.append('.');
1787
      builder.append(mCubits[i].mQuatIndex);
1788
      }
1789

    
1790
    return builder.toString();
1791
    }
1792

    
1793
///////////////////////////////////////////////////////////////////////////////////////////////////
1794
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1795

    
1796
  public int getNumCubitFaces()
1797
    {
1798
    return 0;
1799
    }
1800

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

    
1806
  public float getPillowCoeff()
1807
    {
1808
    return 1.0f;
1809
    }
1810

    
1811
///////////////////////////////////////////////////////////////////////////////////////////////////
1812

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

    
1845
///////////////////////////////////////////////////////////////////////////////////////////////////
1846

    
1847
  protected void setReader(JsonReader reader)
1848
    {
1849
    // empty
1850
    }
1851

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

    
1878
  // not only for JSON
1879
  public abstract Static3D[] getRotationAxis();
1880
  public abstract int[][] getBasicAngles();
1881
  public abstract int getNumFaces();
1882
  public abstract String getObjectName();
1883
  public abstract String getInventor();
1884
  public abstract int getYearOfInvention();
1885
  public abstract int getComplexity();
1886
  public abstract int getFOV();
1887
  public abstract String[][] getTutorials();
1888
  }
(7-7/10)