Project

General

Profile

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

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

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 4c87f159 Leszek Koltunski
// 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 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.objectlib.main;
11
12 3a1efb32 Leszek Koltunski
import java.io.DataInputStream;
13
import java.io.IOException;
14
import java.io.InputStream;
15
import java.util.Random;
16
17 29b82486 Leszek Koltunski
import android.content.SharedPreferences;
18 c0266cb1 Leszek Koltunski
import android.content.res.Resources;
19 29b82486 Leszek Koltunski
import android.graphics.Bitmap;
20
import android.graphics.Canvas;
21
import android.graphics.Paint;
22
23
import org.distorted.library.effect.Effect;
24
import org.distorted.library.effect.MatrixEffectMove;
25
import org.distorted.library.effect.MatrixEffectQuaternion;
26
import org.distorted.library.effect.MatrixEffectScale;
27
import org.distorted.library.effect.VertexEffectQuaternion;
28
import org.distorted.library.effect.VertexEffectRotate;
29 a0b0795b Leszek Koltunski
import org.distorted.library.effect.VertexEffectSink;
30 29b82486 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
31
import org.distorted.library.main.DistortedLibrary;
32
import org.distorted.library.main.DistortedNode;
33
import org.distorted.library.main.DistortedTexture;
34 a706f8e0 Leszek Koltunski
import org.distorted.library.main.QuatHelper;
35 29b82486 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
36
import org.distorted.library.mesh.MeshFile;
37
import org.distorted.library.mesh.MeshJoined;
38
import org.distorted.library.message.EffectListener;
39
import org.distorted.library.type.Dynamic1D;
40
import org.distorted.library.type.Static1D;
41
import org.distorted.library.type.Static3D;
42
import org.distorted.library.type.Static4D;
43 a57e6870 Leszek Koltunski
44 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.FactoryCubit;
45
import org.distorted.objectlib.helpers.FactorySticker;
46 3ee1d662 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectFaceShape;
47 d887aa16 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectLibInterface;
48 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
49 1d581993 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSignature;
50 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectSticker;
51 3a0a23bf Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectStickerOverride;
52 84a17011 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectVertexEffects;
53 802fe251 Leszek Koltunski
import org.distorted.objectlib.helpers.QuatGroupGenerator;
54 10b7e306 Leszek Koltunski
import org.distorted.objectlib.scrambling.ObjectScrambler;
55 82eb152a Leszek Koltunski
import org.distorted.objectlib.json.JsonReader;
56 731280f7 Leszek Koltunski
import org.distorted.objectlib.scrambling.ScrambleEdgeGenerator;
57 c0266cb1 Leszek Koltunski
import org.distorted.objectlib.tablebases.ImplementedTablebasesList;
58
import org.distorted.objectlib.tablebases.TablebasesAbstract;
59 3a1efb32 Leszek Koltunski
import org.distorted.objectlib.touchcontrol.*;
60 29b82486 Leszek Koltunski
61 3a1efb32 Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.*;
62 59c20632 Leszek Koltunski
63 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65 7ba38dd4 Leszek Koltunski
public abstract class TwistyObject
66 29b82486 Leszek Koltunski
  {
67 c3a033e9 Leszek Koltunski
  public static final int MESH_NICE = 0;
68
  public static final int MESH_FAST = 1;
69
70 3bf19410 Leszek Koltunski
  public static final int MODE_ICON = 0;
71
  public static final int MODE_NORM = 1;
72
73 7ec32155 Leszek Koltunski
  public static final int COLOR_YELLOW   = 0xffffff00;
74
  public static final int COLOR_WHITE    = 0xffffffff;
75
  public static final int COLOR_BLUE     = 0xff0000ff;
76
  public static final int COLOR_GREEN    = 0xff00bb00;
77
  public static final int COLOR_RED      = 0xff990000;
78
  public static final int COLOR_ORANGE   = 0xffff6200;
79
  public static final int COLOR_GREY     = 0xff727c7b;
80
  public static final int COLOR_VIOLET   = 0xff7700bb;
81
  public static final int COLOR_STROKE   = 0xff000000;
82 c60d98c4 Leszek Koltunski
  public static final int COLOR_INTERNAL = 0xff000000;
83 29b82486 Leszek Koltunski
84 605f319b Leszek Koltunski
  private static final int STATE_NOTHING = 0;
85
  private static final int STATE_ROTATE  = 1;
86
  private static final int STATE_FINISH  = 2;
87
88 29b82486 Leszek Koltunski
  public static final int TEXTURE_HEIGHT = 256;
89
  static final int NUM_STICKERS_IN_ROW = 4;
90
91
  public static final float SQ2 = (float)Math.sqrt(2);
92
  public static final float SQ3 = (float)Math.sqrt(3);
93
  public static final float SQ5 = (float)Math.sqrt(5);
94
  public static final float SQ6 = (float)Math.sqrt(6);
95
96
  private static final float MAX_SIZE_CHANGE = 1.35f;
97
  private static final float MIN_SIZE_CHANGE = 0.75f;
98
99
  private static final Static3D CENTER = new Static3D(0,0,0);
100
  private static final int POST_ROTATION_MILLISEC = 500;
101
102 7af68038 Leszek Koltunski
  protected float[][] mStickerCoords;
103 802fe251 Leszek Koltunski
  protected Static4D[] mObjectQuats;
104 82eb152a Leszek Koltunski
105 a05b6e06 Leszek Koltunski
  private int[][] mStickerVariants;
106
  private float[] mStickerScales;
107 5618c5a9 Leszek Koltunski
  private TwistyObjectCubit[] mCubits;
108
  private TwistyObjectSolved mSolved;
109 a05b6e06 Leszek Koltunski
  private MeshBase[] mMeshes;
110 3a0a23bf Leszek Koltunski
  private int mNumCubits, mNumQuats, mNumFaceColors, mNumTextures, mNumOverrides;
111 7af68038 Leszek Koltunski
  private int mNumCubitFaces, mNumStickerTypes;
112 82eb152a Leszek Koltunski
  private Static3D[] mAxis;
113
  private float[][] mCuts;
114
  private int[] mNumCuts;
115
  private float[][] mOrigPos;
116 5931ae4d Leszek Koltunski
  private Static4D[] mOrigQuat;
117 00a28d71 Leszek Koltunski
  private Static4D[] mMixupModeQuats;
118
  private boolean mIsInMixupMode;
119 82eb152a Leszek Koltunski
  private Static4D mQuat;
120 3ce95490 Leszek Koltunski
  private int[] mNumLayers;
121
  private float mSize;
122 82eb152a Leszek Koltunski
  private DistortedEffects mEffects;
123
  private VertexEffectRotate mRotateEffect;
124
  private Dynamic1D mRotationAngle;
125
  private Static3D mRotationAxis;
126
  private Static3D mObjectScale;
127
  private int[] mQuatDebug;
128
  private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
129
  private DistortedTexture mTexture;
130
  private float mInitScreenRatio;
131
  private boolean mIsBandaged;
132 29b82486 Leszek Koltunski
  private float mObjectScreenRatio;
133
  private int mNumTexRows, mNumTexCols;
134
  private int mRotRowBitmap;
135 59c20632 Leszek Koltunski
  private int mCurrentRotAxis;
136 29b82486 Leszek Koltunski
  private MeshBase mMesh;
137 10b7e306 Leszek Koltunski
  private ObjectScrambler mScrambler;
138 c9c71c3f Leszek Koltunski
  private TouchControl mTouchControl;
139 7ba38dd4 Leszek Koltunski
  private DistortedNode mNode;
140 d887aa16 Leszek Koltunski
  private ObjectLibInterface mInterface;
141 d5c71d02 Leszek Koltunski
  private Bitmap mBitmap;
142 d53fb890 Leszek Koltunski
  private ObjectSticker[] mStickers;
143 b968d359 Leszek Koltunski
  private ObjectShape[] mShapes;
144
  private int mNumCubitVariants;
145 9b1fe915 Leszek Koltunski
  private int[][] mCubitFaceColors;
146 59a971c1 Leszek Koltunski
  private int[][] mVariantFaceIsOuter;
147 beee90ab Leszek Koltunski
  private int[][] mBasicAngles;
148 3bf19410 Leszek Koltunski
  private int mIconMode;
149 3ce95490 Leszek Koltunski
  private InitData mInitData;
150 fbd18fc7 Leszek Koltunski
  private float[][] mRowOffsets;
151
  private boolean[] mBelongs;
152
  private float[] mTmp;
153 5a20f7a1 Leszek Koltunski
  private int mNumPuzzleFaces;
154 3a0a23bf Leszek Koltunski
  private ObjectStickerOverride[] mStickerOverrides;
155 3ce95490 Leszek Koltunski
  private boolean mError;
156
  private String mErrorString;
157 d85de775 Leszek Koltunski
  private int mMaxNumLayers;
158
  private int mNumAxis;
159 37959420 Leszek Koltunski
  private int mPointNum;
160 605f319b Leszek Koltunski
  private int mRotationState;
161 29b82486 Leszek Koltunski
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163
164 c0266cb1 Leszek Koltunski
  TwistyObject(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset)
165 82eb152a Leszek Koltunski
    {
166 3ce95490 Leszek Koltunski
    try
167
      {
168 c0266cb1 Leszek Koltunski
      InputStream jsonStream = asset!=null ? asset.getJsonStream(): null;
169 958a6e81 Leszek Koltunski
      JsonReader reader = new JsonReader();
170 3ce95490 Leszek Koltunski
      reader.parseJsonFile(jsonStream);
171
      setReader(reader);
172
      mNumLayers = reader.getNumLayers();
173
      mSize      = reader.getSize();
174
      mInitData  = null;
175 c0266cb1 Leszek Koltunski
      initialize(meshState,iconMode,quat,move,scale,asset,true);
176
      if( asset!=null ) asset.close();
177 3ce95490 Leszek Koltunski
      mError = false;
178
      mErrorString=null;
179
      }
180
    catch(Exception ex)
181
      {
182
      mError = true;
183
      mErrorString = ex.getMessage();
184
      }
185 82eb152a Leszek Koltunski
    }
186
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
189 c0266cb1 Leszek Koltunski
  public TwistyObject(int meshState, int iconMode, float size, Static4D quat, Static3D move, float scale, InitData data, InitAssets asset)
190 29b82486 Leszek Koltunski
    {
191 a8295031 Leszek Koltunski
    mNumLayers = data.getNumLayers();
192 82eb152a Leszek Koltunski
    mSize      = size;
193 a8295031 Leszek Koltunski
    mInitData  = data;
194 c0266cb1 Leszek Koltunski
    initialize(meshState,iconMode,quat,move,scale,asset,false);
195
    if( asset!=null ) asset.close();
196 3ce95490 Leszek Koltunski
    mError = false;
197
    mErrorString = null;
198 82eb152a Leszek Koltunski
    }
199
200 1f329dcc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202
  private void debugQuat(Static4D quat, int cubitIndex, float axisX, float axisY, float axisZ, float angle, int place)
203
    {
204
    float[] tracking = mCubits[cubitIndex].getTrackingPoint();
205
206 37959420 Leszek Koltunski
    String problem = (getShortName()+" "+cubitIndex+" "+quat.get0()+" "+quat.get1()+" "+quat.get2()+" "+quat.get3());
207 1f329dcc Leszek Koltunski
    problem += (" "+angle+" "+place+" "+tracking[0]+" "+tracking[1]+" "+tracking[2]);
208 37959420 Leszek Koltunski
    problem += (" "+axisX+" "+axisY+" "+axisZ)+" "+mPointNum;
209 1f329dcc Leszek Koltunski
210
    mInterface.reportProblem(problem,true);
211
    }
212
213 82eb152a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
214
215 c0266cb1 Leszek Koltunski
  private void initialize(int meshState, int iconMode, Static4D quat, Static3D move, float scale, InitAssets asset, boolean fromJSON)
216 82eb152a Leszek Koltunski
    {
217 605f319b Leszek Koltunski
    mRotationState = STATE_NOTHING;
218 3bf19410 Leszek Koltunski
    mIconMode = iconMode;
219 82eb152a Leszek Koltunski
    mQuat = quat;
220 29b82486 Leszek Koltunski
    mAxis = getRotationAxis();
221
    mInitScreenRatio = getScreenRatio();
222 802fe251 Leszek Koltunski
    mBasicAngles = getBasicAngles();
223 89a00832 Leszek Koltunski
    mObjectQuats = getQuats();
224
    mNumQuats = mObjectQuats.length;
225
    mOrigPos = getCubitPositions(mNumLayers);
226 5a20f7a1 Leszek Koltunski
    mNumPuzzleFaces = getNumFaces();
227
    mRowOffsets = new float[mNumPuzzleFaces][3];
228 fbd18fc7 Leszek Koltunski
    mTmp = new float[4];
229 29b82486 Leszek Koltunski
230 d85de775 Leszek Koltunski
    mNumAxis = mAxis.length;
231 29b82486 Leszek Koltunski
    mCuts = getCuts(mNumLayers);
232 d85de775 Leszek Koltunski
    mNumCuts = new int[mNumAxis];
233
    mMaxNumLayers = -1;
234
    for(int i=0; i<mNumAxis; i++)
235 dfdb26a9 Leszek Koltunski
      {
236 d55d2c6a Leszek Koltunski
      if( mMaxNumLayers<mNumLayers[i] ) mMaxNumLayers = mNumLayers[i];
237 dfdb26a9 Leszek Koltunski
      mNumCuts[i] = (mCuts==null || mCuts[i]==null ? 0 : mCuts[i].length);
238
      }
239 29b82486 Leszek Koltunski
240 a05b6e06 Leszek Koltunski
    mNumCubits = mOrigPos.length;
241
    mNumFaceColors = getNumFaceColors();
242 fbd18fc7 Leszek Koltunski
    mBelongs = new boolean[mNumCubits];
243 a05b6e06 Leszek Koltunski
244 29b82486 Leszek Koltunski
    int scramblingType = getScrambleType();
245 9ba7f3f6 Leszek Koltunski
    int[][] edges = getScrambleEdges();
246
    int[][] algorithms = getScrambleAlgorithms();
247
248 c0266cb1 Leszek Koltunski
    Resources res = asset==null ? null : asset.getResources();
249
    TablebasesAbstract tablebase = res!=null ? getTablebase(res) : null;
250
    mScrambler = new ObjectScrambler(scramblingType,mNumAxis,mNumLayers,algorithms,edges,tablebase);
251 29b82486 Leszek Koltunski
252
    boolean bandaged=false;
253
254 a05b6e06 Leszek Koltunski
    for( int c=0; c<mNumCubits; c++)
255 29b82486 Leszek Koltunski
      {
256
      if( mOrigPos[c].length>3 )
257
        {
258
        bandaged=true;
259
        break;
260
        }
261
      }
262
    mIsBandaged = bandaged;
263 a05b6e06 Leszek Koltunski
    mQuatDebug = new int[mNumCubits];
264 29b82486 Leszek Koltunski
265
    mRotationAngle= new Dynamic1D();
266
    mRotationAxis = new Static3D(1,0,0);
267
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
268
269
    mRotationAngleStatic = new Static1D(0);
270
    mRotationAngleMiddle = new Static1D(0);
271
    mRotationAngleFinal  = new Static1D(0);
272
273 64c209f5 Leszek Koltunski
    mObjectScale = new Static3D(scale,scale,scale);
274
    setObjectRatioNow(scale,720);
275 e7daa161 Leszek Koltunski
276 00a28d71 Leszek Koltunski
    mEffects = new DistortedEffects();
277
    createQuaternionEffects();
278
279 29b82486 Leszek Koltunski
    MatrixEffectScale scaleEffect = new MatrixEffectScale(mObjectScale);
280 57ef6378 Leszek Koltunski
    MatrixEffectQuaternion quatEffect = new MatrixEffectQuaternion(mQuat, CENTER);
281 b80e6524 Leszek Koltunski
    MatrixEffectMove moveEffect = new MatrixEffectMove(move);
282 29b82486 Leszek Koltunski
283 c0266cb1 Leszek Koltunski
    InputStream meshStream = asset!=null ? asset.getMeshStream(): null;
284 6db8fe2e Leszek Koltunski
    boolean fromDMESH = (meshStream!=null && meshState==MESH_NICE);
285 4c9ca251 Leszek Koltunski
    getQuatsAndShapes(fromDMESH,fromJSON);
286 6db8fe2e Leszek Koltunski
    createMeshAndCubits(meshStream,meshState,fromDMESH);
287 e16fd960 Leszek Koltunski
    setUpTextures(fromDMESH,fromJSON);
288 5618c5a9 Leszek Koltunski
289
    int index = getSolvedFunctionIndex();
290
    mSolved = new TwistyObjectSolved(this,mOrigPos,index);
291 be95dbf5 Leszek Koltunski
    mSolved.setupSolvedQuats(getSolvedQuats());
292 29b82486 Leszek Koltunski
293
    mEffects.apply(mRotateEffect);
294
    mEffects.apply(quatEffect);
295
    mEffects.apply(scaleEffect);
296 b80e6524 Leszek Koltunski
    mEffects.apply(moveEffect);
297 29b82486 Leszek Koltunski
298 7ba38dd4 Leszek Koltunski
    mNode = new DistortedNode(mTexture,mEffects,mMesh);
299 29b82486 Leszek Koltunski
    }
300
301 c0266cb1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
302
303
  private TablebasesAbstract getTablebase(Resources res)
304
    {
305
    ObjectSignature signature = getSignature();
306
    long[] array = signature.getArray();
307
    int len = array.length;
308
    int sig = (int)array[len-1];
309
310
    return ImplementedTablebasesList.createPacked(res,sig);
311
    }
312
313 00a28d71 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
314
315
  private void createQuaternionEffects()
316
    {
317
    if( mNumQuats<=ObjectControl.MAX_QUATS )
318
      {
319
      mIsInMixupMode = false;
320
321
      for( int q=0; q<mNumQuats; q++)
322
        {
323
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mObjectQuats[q],CENTER);
324
        vq.setMeshAssociation(0,q);
325
        mEffects.apply(vq);
326
        }
327
      }
328
    else if( mNumCubits<=ObjectControl.MAX_QUATS )
329
      {
330
      mIsInMixupMode = true;
331
      mMixupModeQuats = new Static4D[mNumCubits];
332
333
      for( int q=0; q<mNumCubits; q++)
334
        {
335
        mMixupModeQuats[q] = new Static4D(mObjectQuats[0]);
336
        VertexEffectQuaternion vq = new VertexEffectQuaternion(mMixupModeQuats[q],CENTER);
337
        vq.setMeshAssociation(0,q);
338
        mEffects.apply(vq);
339
        }
340
      }
341
    else
342
      {
343
      android.util.Log.e("D", "object has too many quaternions ("+mNumQuats+") or too many cubits ("+mNumCubits+")");
344
      }
345
    }
346
347 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
348
349
  private Static3D getPos(float[] origPos)
350
    {
351
    int len = origPos.length/3;
352
    float sumX = 0.0f;
353
    float sumY = 0.0f;
354
    float sumZ = 0.0f;
355
356
    for(int i=0; i<len; i++)
357
      {
358
      sumX += origPos[3*i  ];
359
      sumY += origPos[3*i+1];
360
      sumZ += origPos[3*i+2];
361
      }
362
363
    sumX /= len;
364
    sumY /= len;
365
    sumZ /= len;
366
367
    return new Static3D(sumX,sumY,sumZ);
368
    }
369
370 59a971c1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
371
372
  private void createOuterFaces()
373
    {
374
    for(int v=0; v<mNumCubitVariants; v++)
375
      {
376
      int[][] indices = mShapes[v].getVertIndices();
377
      int faces = indices.length;
378
      mVariantFaceIsOuter[v] = new int[faces];
379
      }
380
381 a05b6e06 Leszek Koltunski
    for( int cubit=0; cubit<mNumCubits; cubit++)
382 59a971c1 Leszek Koltunski
      {
383
      int variant = getCubitVariant(cubit,mNumLayers);
384
      int[][] indices = mShapes[variant].getVertIndices();
385
      int numFaces = indices.length;
386
387
      for(int face=0; face<numFaces; face++)
388 d4105efe Leszek Koltunski
        if( getCubitFaceColor(cubit,face)>=0 )
389 59a971c1 Leszek Koltunski
          {
390
          mVariantFaceIsOuter[variant][face] = 1;
391
          }
392
      }
393
    }
394
395 4c9ca251 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
396
397
  private void getQuatsAndShapes(boolean fromDMESH, boolean fromJSON)
398
    {
399
    mNumCubitVariants = getNumCubitVariants(mNumLayers);
400
401
    if( !fromDMESH || !fromJSON )
402
      {
403
      FactoryCubit factory = FactoryCubit.getInstance();
404
      factory.clear();
405
406
      mShapes = new ObjectShape[mNumCubitVariants];
407
      for(int i=0; i<mNumCubitVariants; i++) mShapes[i] = getObjectShape(i);
408
      mNumCubitFaces = ObjectShape.computeNumComponents(mShapes);
409 59a971c1 Leszek Koltunski
      mVariantFaceIsOuter = new int[mNumCubitVariants][];
410 4c9ca251 Leszek Koltunski
411 716f5517 Leszek Koltunski
      mOrigQuat = new Static4D[mNumCubits];
412
      for(int i=0; i<mNumCubits; i++) mOrigQuat[i] = getCubitQuats(i,mNumLayers);
413
414 59a971c1 Leszek Koltunski
      if( !fromJSON )
415 4c9ca251 Leszek Koltunski
        {
416 59a971c1 Leszek Koltunski
        mCubitFaceColors = ObjectShape.computeColors(mShapes,mOrigPos,mOrigQuat,this);
417
        createOuterFaces();
418 4c9ca251 Leszek Koltunski
        }
419 9b1fe915 Leszek Koltunski
420 59a971c1 Leszek Koltunski
      if( fromDMESH )
421 9b1fe915 Leszek Koltunski
        {
422 59a971c1 Leszek Koltunski
        for(int i=0; i<mNumCubitVariants; i++) factory.createNewFaceTransform(mShapes[i], mVariantFaceIsOuter[i]);
423 9b1fe915 Leszek Koltunski
        }
424 4c9ca251 Leszek Koltunski
      }
425
    }
426
427 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
428
429 3afd2fe4 Leszek Koltunski
  private void createMeshAndCubits(InputStream stream, int meshState, boolean fromDMESH)
430 29b82486 Leszek Koltunski
    {
431 5618c5a9 Leszek Koltunski
    mCubits = new TwistyObjectCubit[mNumCubits];
432 4c9ca251 Leszek Koltunski
433 e16fd960 Leszek Koltunski
    if( fromDMESH )
434 29b82486 Leszek Koltunski
      {
435 82eb152a Leszek Koltunski
      DataInputStream dos = new DataInputStream(stream);
436 29b82486 Leszek Koltunski
      mMesh = new MeshFile(dos);
437
438
      try
439
        {
440 82eb152a Leszek Koltunski
        stream.close();
441 29b82486 Leszek Koltunski
        }
442
      catch(IOException e)
443
        {
444 9cb7d66f Leszek Koltunski
        android.util.Log.e("meshFile", "Error closing InputStream: "+e);
445 29b82486 Leszek Koltunski
        }
446
      }
447
    else
448
      {
449 a05b6e06 Leszek Koltunski
      MeshBase[] cubitMesh = new MeshBase[mNumCubits];
450 5931ae4d Leszek Koltunski
451 a05b6e06 Leszek Koltunski
      for(int i=0; i<mNumCubits; i++)
452 29b82486 Leszek Koltunski
        {
453 ac97ecc0 Leszek Koltunski
        cubitMesh[i] = createCubitMesh(i,mNumLayers,meshState,mNumCubitFaces);
454 29b82486 Leszek Koltunski
        Static3D pos = getPos(mOrigPos[i]);
455
        cubitMesh[i].apply(new MatrixEffectMove(pos),1,0);
456
        }
457
458
      mMesh = new MeshJoined(cubitMesh);
459 a0b0795b Leszek Koltunski
460
      float pillowCoeff = getPillowCoeff();
461
462
      if( pillowCoeff!=1.0f )
463
        {
464
        float radius = getCircumscribedRadius();
465
        Static1D coeff = new Static1D(pillowCoeff);
466
        Static4D region= new Static4D(0,0,0,radius);
467
        VertexEffectSink sink = new VertexEffectSink(coeff,CENTER,region);
468
        mMesh.apply(sink);
469
        }
470 29b82486 Leszek Koltunski
      }
471 00a28d71 Leszek Koltunski
472
    for(int i=0; i<mNumCubits; i++)
473
      {
474 5618c5a9 Leszek Koltunski
      mCubits[i] = new TwistyObjectCubit(this,mOrigPos[i],mNumAxis,mMaxNumLayers,i);
475 00a28d71 Leszek Koltunski
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
476
      }
477 29b82486 Leszek Koltunski
    }
478
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481 ac97ecc0 Leszek Koltunski
  private MeshBase createCubitMesh(int cubit, int[] numLayers, int meshState, int numComponents)
482 29b82486 Leszek Koltunski
    {
483
    int variant = getCubitVariant(cubit,numLayers);
484
485 b968d359 Leszek Koltunski
    if( mMeshes==null ) mMeshes = new MeshBase[mNumCubitVariants];
486 29b82486 Leszek Koltunski
487
    if( mMeshes[variant]==null )
488
      {
489 3ee1d662 Leszek Koltunski
      ObjectFaceShape faceShape = getObjectFaceShape(variant);
490 84a17011 Leszek Koltunski
      ObjectVertexEffects effects = getVertexEffects(variant);
491 29b82486 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
492 59a971c1 Leszek Koltunski
      factory.createNewFaceTransform(mShapes[variant],mVariantFaceIsOuter[variant]);
493 84a17011 Leszek Koltunski
      mMeshes[variant] = factory.createRoundedSolid(mShapes[variant],faceShape,effects, meshState, numComponents);
494 29b82486 Leszek Koltunski
      }
495
496
    MeshBase mesh = mMeshes[variant].copy(true);
497 5931ae4d Leszek Koltunski
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( mOrigQuat[cubit], CENTER );
498 29b82486 Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
499
500
    return mesh;
501
    }
502
503 7994b456 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
504
505
  private void setUpTextures(boolean fromDMESH, boolean fromJSON)
506
    {
507
    mTexture = new DistortedTexture();
508
509
    if( fromJSON )
510
      {
511
      mNumStickerTypes = getNumStickerTypes();
512
      mNumCubitFaces = getNumCubitFaces();
513
      }
514
    else
515
      {
516
      FactoryCubit factory = FactoryCubit.getInstance();
517 3d2493ea Leszek Koltunski
      mStickerCoords   = factory.getStickerCoords();
518 7994b456 Leszek Koltunski
      mStickerVariants = factory.getStickerVariants();
519 3d2493ea Leszek Koltunski
      mStickerScales   = factory.getStickerScales();
520 7994b456 Leszek Koltunski
      adjustStickerCoords();
521 325a17e0 Leszek Koltunski
      mNumStickerTypes = (mStickerCoords==null ? 0 : mStickerCoords.length);
522 7994b456 Leszek Koltunski
      }
523
524 3a0a23bf Leszek Koltunski
    mStickerOverrides = getStickerOverrides();
525
    mNumOverrides = mStickerOverrides==null ? 0 : mStickerOverrides.length;
526
527
    mNumTextures= mNumFaceColors*mNumStickerTypes + mNumOverrides;
528 7994b456 Leszek Koltunski
    mNumTexCols = NUM_STICKERS_IN_ROW;
529 a05b6e06 Leszek Koltunski
    mNumTexRows = (mNumTextures+1)/NUM_STICKERS_IN_ROW;
530
    if( mNumTexCols*mNumTexRows < mNumTextures+1 ) mNumTexRows++;
531 7994b456 Leszek Koltunski
532
    if( !fromDMESH || shouldResetTextureMaps() ) resetAllTextureMaps();
533 b0c97683 Leszek Koltunski
    else overrideCubitFaceColor();
534
535 7994b456 Leszek Koltunski
    setTexture();
536
    }
537
538 a8295031 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
539
540
  public InitData getInitData()
541
    {
542
    return mInitData;
543
    }
544
545 3bf19410 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
546
547
  public boolean isInIconMode()
548
    {
549
    return mIconMode==MODE_ICON;
550
    }
551
552 ec42a6fe Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
553
554 51262d81 Leszek Koltunski
  public int getVariantStickerShape(int variant, int face)
555 ec42a6fe Leszek Koltunski
    {
556
    return face>=mStickerVariants[variant].length ? -1 : mStickerVariants[variant][face];
557
    }
558
559 19595510 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
560
561
  public boolean shouldResetTextureMaps()
562
    {
563
    return false;
564
    }
565
566 9ba7f3f6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
567
568
  public int[][] getScrambleAlgorithms()
569
    {
570 731280f7 Leszek Koltunski
    return ScrambleEdgeGenerator.getScramblingAlgorithms(mBasicAngles);
571 9ba7f3f6 Leszek Koltunski
    }
572
573 a4af26c1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
574
575
  private boolean sticksOut(Static3D[] faceAxis, float[] dist, float x, float y, float z )
576
    {
577
    final float MAXERR = 0.05f;
578
    int numAxis = dist.length;
579
580
    for(int i=0; i<numAxis; i++)
581
      {
582
      Static3D ax = faceAxis[i];
583
      float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
584 dcce7b29 Leszek Koltunski
      if( len>mSize*dist[i]+MAXERR ) return true;
585 a4af26c1 Leszek Koltunski
      }
586
587
    return false;
588
    }
589
590
///////////////////////////////////////////////////////////////////////////////////////////////////
591
592 9554f5d4 Leszek Koltunski
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
593 a4af26c1 Leszek Koltunski
    {
594 fbd18fc7 Leszek Koltunski
    float[][] vertices = mShapes[variant].getVertices();
595 a4af26c1 Leszek Koltunski
    Static3D[] axis = getFaceAxis();
596
    float[] dist3D = getDist3D(mNumLayers);
597
598
    for( float[] vertex : vertices)
599
      {
600
      float x = vertex[0];
601
      float y = vertex[1];
602
      float z = vertex[2];
603
604
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
605
606 9554f5d4 Leszek Koltunski
      float mx = tmp[0] + px;
607
      float my = tmp[1] + py;
608
      float mz = tmp[2] + pz;
609 a4af26c1 Leszek Koltunski
610
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
611
      }
612
613
    return true;
614
    }
615
616 9554f5d4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
617
618
  private float computeAvg(float[] pos, int offset)
619
    {
620
    int len = pos.length/3;
621
    float ret=0.0f;
622
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
623
    ret /= len;
624
625
    return ret;
626
    }
627
628 97a6aa87 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
629
630
  protected void displayCubitQuats()
631
    {
632
    StringBuilder builder = new StringBuilder();
633
    float[] tmp = new float[4];
634 a4af26c1 Leszek Koltunski
    float ERR = 0.01f;
635 97a6aa87 Leszek Koltunski
636
    for(int cubit=0; cubit<mNumCubits; cubit++)
637
      {
638 a4af26c1 Leszek Koltunski
      builder.append(cubit);
639
      builder.append(" : ");
640
641 97a6aa87 Leszek Koltunski
      int refCubit,variant = getCubitVariant(cubit,mNumLayers);
642
643
      for(refCubit=0; refCubit<mNumCubits; refCubit++)
644
        {
645
        if( getCubitVariant(refCubit,mNumLayers)==variant ) break;
646
        }
647
648
      float[] curpos = mOrigPos[cubit];
649
      float[] refpos = mOrigPos[refCubit];
650 9554f5d4 Leszek Koltunski
      float refX = computeAvg(refpos,0);
651
      float refY = computeAvg(refpos,1);
652
      float refZ = computeAvg(refpos,2);
653
      float curX = computeAvg(curpos,0);
654
      float curY = computeAvg(curpos,1);
655
      float curZ = computeAvg(curpos,2);
656 97a6aa87 Leszek Koltunski
657
      for(int quat=0; quat<mNumQuats; quat++)
658
        {
659
        QuatHelper.rotateVectorByQuat(tmp,refX,refY,refZ,0,mObjectQuats[quat]);
660
661
        float dx = tmp[0]-curX;
662
        float dy = tmp[1]-curY;
663
        float dz = tmp[2]-curZ;
664
665 a4af26c1 Leszek Koltunski
        if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
666 97a6aa87 Leszek Koltunski
          {
667 9554f5d4 Leszek Koltunski
          if( doesNotStickOut(variant,curX,curY,curZ,tmp,mObjectQuats[quat]) )
668 a4af26c1 Leszek Koltunski
            {
669
            builder.append(quat);
670
            builder.append(',');
671
            }
672
          else
673
            {
674
            android.util.Log.e("D", "cubit: "+cubit+" quat: "+quat+" : center correct, but shape sticks out");
675
            }
676 97a6aa87 Leszek Koltunski
          }
677
        }
678
679
      builder.append('\n');
680
      }
681
682 9cb7d66f Leszek Koltunski
    android.util.Log.e("D", "cubitQuats: \n"+builder );
683 97a6aa87 Leszek Koltunski
    }
684
685 bc008758 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
686
687 fbd18fc7 Leszek Koltunski
  public int getCubitRotationType(int cubit)
688 bc008758 Leszek Koltunski
    {
689 5618c5a9 Leszek Koltunski
    return TwistyObjectCubit.TYPE_NORMAL;
690 fbd18fc7 Leszek Koltunski
    }
691
692
///////////////////////////////////////////////////////////////////////////////////////////////////
693
694 d844220f Leszek Koltunski
  float[] getTrackingPoint(int cubitIndex, int cubitType)
695 fbd18fc7 Leszek Koltunski
    {
696 5618c5a9 Leszek Koltunski
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
697 fbd18fc7 Leszek Koltunski
      {
698
      int variant = getCubitVariant(cubitIndex,mNumLayers);
699 40e77224 Leszek Koltunski
700
      // object must have been created from JSON
701
      if( mVariantFaceIsOuter==null || mVariantFaceIsOuter[variant]==null )
702
        {
703
        mVariantFaceIsOuter = getVariantFaceIsOuter();
704
        }
705 39c6b370 Leszek Koltunski
      if( mShapes==null )
706
        {
707
        mShapes = new ObjectShape[mNumCubitVariants];
708
        }
709
      if( mShapes[variant]==null )
710
        {
711
        mShapes[variant] = getObjectShape(variant);
712
        }
713
      if( mOrigQuat==null )
714
        {
715
        mOrigQuat = new Static4D[mNumCubits];
716
        }
717
      if( mOrigQuat[cubitIndex]==null )
718
        {
719
        mOrigQuat[cubitIndex] = getCubitQuats(cubitIndex,mNumLayers);
720
        }
721
722
      int[][] indices = mShapes[variant].getVertIndices();
723
      int outer=-1, faces = indices.length;
724 fbd18fc7 Leszek Koltunski
725
      for(int i=0; i<faces; i++)
726
        {
727
        if( mVariantFaceIsOuter[variant][i]==1 )
728
          {
729
          outer=i;
730
          break;
731
          }
732
        }
733
734
      if( outer>=0 )
735
        {
736
        int vertIndex = indices[outer][0];
737
        float[] vertices = mShapes[variant].getVertices()[vertIndex];
738
        float[] ret = new float[3];
739
        float[] curpos = mOrigPos[cubitIndex];
740
        Static4D quat = mOrigQuat[cubitIndex];
741
        QuatHelper.rotateVectorByQuat(mTmp, vertices[0], vertices[1], vertices[2], 1, quat);
742
743
        ret[0] = mTmp[0]+computeAvg(curpos,0);
744
        ret[1] = mTmp[1]+computeAvg(curpos,1);
745
        ret[2] = mTmp[2]+computeAvg(curpos,2);
746
747
        return ret;
748
        }
749
      else
750
        {
751 d844220f Leszek Koltunski
        android.util.Log.e("D", "Error in getTrackingPoint: no outer face??");
752 fbd18fc7 Leszek Koltunski
        }
753
      }
754
755
    return null;
756
    }
757
758
///////////////////////////////////////////////////////////////////////////////////////////////////
759
760 1f329dcc Leszek Koltunski
  public int computeCurrentPuzzleFace(int type, float[] vertex)
761 fbd18fc7 Leszek Koltunski
    {
762 5618c5a9 Leszek Koltunski
    if( type!=TwistyObjectCubit.TYPE_NORMAL )
763 fbd18fc7 Leszek Koltunski
      {
764
      Static3D[] axis = getFaceAxis();
765
      float[] dist3D = getDist3D(mNumLayers);
766
      final float MAXERR = 0.98f;
767
      int numAxis = axis.length;
768
      float x = vertex[0];
769
      float y = vertex[1];
770
      float z = vertex[2];
771
772
      for(int i=0; i<numAxis; i++)
773
        {
774
        Static3D ax = axis[i];
775
        float len = ax.get0()*x + ax.get1()*y + ax.get2()*z;
776
        if( len>mSize*dist3D[i]*MAXERR ) return i;
777
        }
778 4e1f3a8e Leszek Koltunski
779 1f329dcc Leszek Koltunski
      return -2;
780 fbd18fc7 Leszek Koltunski
      }
781
782
    return -1;
783
    }
784
785
///////////////////////////////////////////////////////////////////////////////////////////////////
786
787
  public float[] getCubitRowOffset(int cubitIndex)
788
    {
789
    return null;
790
    }
791
792
///////////////////////////////////////////////////////////////////////////////////////////////////
793
794
  void setRotationRowOffset(int puzzleFace, float[] offset)
795
    {
796
    mRowOffsets[puzzleFace][0] = offset[0];
797
    mRowOffsets[puzzleFace][1] = offset[1];
798
    mRowOffsets[puzzleFace][2] = offset[2];
799 bc008758 Leszek Koltunski
    }
800
801 d85de775 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
802
803
  int getNumAxis()
804
    {
805
    return mNumAxis;
806
    }
807
808 f5426a4c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
809
810 19595510 Leszek Koltunski
  public int[][] getSolvedQuats()
811 f5426a4c Leszek Koltunski
    {
812 5618c5a9 Leszek Koltunski
    return mSolved.getSolvedQuats(mNumLayers,mNumCubitFaces,mCubitFaceColors);
813 f5426a4c Leszek Koltunski
    }
814
815
///////////////////////////////////////////////////////////////////////////////////////////////////
816
817
  public int getSolvedFunctionIndex()
818
    {
819
    return 0;
820
    }
821
822 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
823
824 fbd18fc7 Leszek Koltunski
  int computeRow(float[] pos, int axisIndex, int cubitType, int puzzleFace)
825 29b82486 Leszek Koltunski
    {
826
    int ret=0;
827
    int len = pos.length / 3;
828
    Static3D axis = mAxis[axisIndex];
829
    float axisX = axis.get0();
830
    float axisY = axis.get1();
831
    float axisZ = axis.get2();
832 fbd18fc7 Leszek Koltunski
    float casted, xoff=0, yoff=0, zoff=0;
833 29b82486 Leszek Koltunski
834 5618c5a9 Leszek Koltunski
    if( cubitType!=TwistyObjectCubit.TYPE_NORMAL )
835 fbd18fc7 Leszek Koltunski
      {
836
      xoff = mRowOffsets[puzzleFace][0];
837
      yoff = mRowOffsets[puzzleFace][1];
838
      zoff = mRowOffsets[puzzleFace][2];
839
      }
840 bc008758 Leszek Koltunski
841 29b82486 Leszek Koltunski
    for(int i=0; i<len; i++)
842
      {
843 bc008758 Leszek Koltunski
      casted = (pos[3*i]+xoff)*axisX + (pos[3*i+1]+yoff)*axisY + (pos[3*i+2]+zoff)*axisZ;
844 29b82486 Leszek Koltunski
      ret |= computeSingleRow(axisIndex,casted);
845
      }
846
847
    return ret;
848
    }
849
850
///////////////////////////////////////////////////////////////////////////////////////////////////
851
852
  private int computeSingleRow(int axisIndex,float casted)
853
    {
854
    int num = mNumCuts[axisIndex];
855
856
    for(int i=0; i<num; i++)
857
      {
858
      if( casted<mCuts[axisIndex][i] ) return (1<<i);
859
      }
860
861
    return (1<<num);
862
    }
863
864
///////////////////////////////////////////////////////////////////////////////////////////////////
865
866
  private boolean wasRotateApplied()
867
    {
868
    return mEffects.exists(mRotateEffect.getID());
869
    }
870
871
///////////////////////////////////////////////////////////////////////////////////////////////////
872
873
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
874
    {
875 a05b6e06 Leszek Koltunski
    return (mCubits[cubit].getRotRow(axis) & rowBitmap) != 0;
876 29b82486 Leszek Koltunski
    }
877
878
///////////////////////////////////////////////////////////////////////////////////////////////////
879
// note the minus in front of the sin() - we rotate counterclockwise
880
// when looking towards the direction where the axis increases in values.
881
882 1f329dcc Leszek Koltunski
  private Static4D makeQuaternion(float axisX, float axisY, float axisZ, int angleInDegrees)
883 29b82486 Leszek Koltunski
    {
884
    while( angleInDegrees<0 ) angleInDegrees += 360;
885
    angleInDegrees %= 360;
886
    
887
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
888
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
889
890 1f329dcc Leszek Koltunski
    return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
891 29b82486 Leszek Koltunski
    }
892
893
///////////////////////////////////////////////////////////////////////////////////////////////////
894
895
  private synchronized void setupPosition(int[][] moves)
896
    {
897
    if( moves!=null )
898
      {
899
      Static4D quat;
900 1f329dcc Leszek Koltunski
      int index, axisIndex, row, rowBitmap, basic, angle;
901 29b82486 Leszek Koltunski
902
      for(int[] move: moves)
903
        {
904 1f329dcc Leszek Koltunski
        axisIndex= move[0];
905
        rowBitmap= computeBitmapFromRow( move[1],axisIndex);
906 c9e40dfc Leszek Koltunski
        row      = computeRowFromBitmap( move[1] );
907 1f329dcc Leszek Koltunski
        basic    = mBasicAngles[axisIndex][row];
908 40e76ea4 Leszek Koltunski
        angle    = move[2]*(360/basic);   // this assumes that all layers from
909
                                          // the bitmap have the same BasicAngle.
910
                                          // at the moment this is always true as
911
                                          // there are no bandaged objects with
912
                                          // different per-layer BasicAngles.
913 1f329dcc Leszek Koltunski
        Static3D axis = mAxis[axisIndex];
914
        float axisX = axis.get0();
915
        float axisY = axis.get1();
916
        float axisZ = axis.get2();
917
        quat = makeQuaternion(axisX,axisY,axisZ,angle);
918 fbd18fc7 Leszek Koltunski
919 7cd287b9 Leszek Koltunski
        for(int i=0; i<mNumCubits; i++)
920 fbd18fc7 Leszek Koltunski
          {
921 1f329dcc Leszek Koltunski
          mBelongs[i] = belongsToRotation(i,axisIndex,rowBitmap);
922
          if( mBelongs[i] )
923
            {
924
            boolean result = mCubits[i].rotateCubit(quat);
925
            if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,1);
926
            }
927 fbd18fc7 Leszek Koltunski
          }
928 29b82486 Leszek Koltunski
929 5a20f7a1 Leszek Koltunski
        recomputeFaceOffsets();
930
931 7cd287b9 Leszek Koltunski
        for(int i=0; i<mNumCubits; i++)
932 fbd18fc7 Leszek Koltunski
          {
933 7cd287b9 Leszek Koltunski
          if( mBelongs[i] )
934 29b82486 Leszek Koltunski
            {
935 7cd287b9 Leszek Koltunski
            index = mCubits[i].postRotateCubit(quat);
936
            setCubitQuat(i,mCubits[i].computeAssociation(),index);
937 29b82486 Leszek Koltunski
            }
938 5618c5a9 Leszek Koltunski
          else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
939 fbd18fc7 Leszek Koltunski
            {
940 7cd287b9 Leszek Koltunski
            mCubits[i].computeRotationRow();
941
            setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
942 fbd18fc7 Leszek Koltunski
            }
943
          }
944 29b82486 Leszek Koltunski
        }
945
      }
946
    }
947
948
///////////////////////////////////////////////////////////////////////////////////////////////////
949
950 f9a81f52 Leszek Koltunski
  public int getScrambleType()
951 29b82486 Leszek Koltunski
    {
952 9283a268 Leszek Koltunski
    return ObjectScrambler.SCRAMBLING_ALGORITHMS;
953 29b82486 Leszek Koltunski
    }
954
955
///////////////////////////////////////////////////////////////////////////////////////////////////
956
957
  int computeBitmapFromRow(int rowBitmap, int axis)
958
    {
959
    if( mIsBandaged )
960
      {
961
      int bitmap, initBitmap=0;
962
963
      while( initBitmap!=rowBitmap )
964
        {
965
        initBitmap = rowBitmap;
966
967 a05b6e06 Leszek Koltunski
        for(int cubit=0; cubit<mNumCubits; cubit++)
968 29b82486 Leszek Koltunski
          {
969 a05b6e06 Leszek Koltunski
          bitmap = mCubits[cubit].getRotRow(axis);
970 29b82486 Leszek Koltunski
          if( (rowBitmap & bitmap) != 0 ) rowBitmap |= bitmap;
971
          }
972
        }
973
      }
974
975
    return rowBitmap;
976
    }
977
978 c9e40dfc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
979
980
  private int computeRowFromBitmap(int rowBitmap)
981
    {
982
    int index = 0;
983
984
    while(index<32)
985
      {
986
      if( (rowBitmap&0x1) != 0 ) return index;
987
      rowBitmap>>=1;
988
      index++;
989
      }
990
    return 0;
991
    }
992
993 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
994
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
995
// Do so only if minimal Error is appropriately low (shape-shifting puzzles - Square-1)
996
997 fbd18fc7 Leszek Koltunski
  void clampPos(float[] pos, int offset)
998 29b82486 Leszek Koltunski
    {
999
    float currError, minError = Float.MAX_VALUE;
1000
    int minErrorIndex1 = -1;
1001
    int minErrorIndex2 = -1;
1002
1003
    float x = pos[offset  ];
1004
    float y = pos[offset+1];
1005
    float z = pos[offset+2];
1006
1007
    float xo,yo,zo;
1008
1009 a05b6e06 Leszek Koltunski
    for(int i=0; i<mNumCubits; i++)
1010 29b82486 Leszek Koltunski
      {
1011
      int len = mOrigPos[i].length / 3;
1012
1013
      for(int j=0; j<len; j++)
1014
        {
1015
        xo = mOrigPos[i][3*j  ];
1016
        yo = mOrigPos[i][3*j+1];
1017
        zo = mOrigPos[i][3*j+2];
1018
1019
        currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
1020
1021
        if( currError<minError )
1022
          {
1023
          minError = currError;
1024
          minErrorIndex1 = i;
1025
          minErrorIndex2 = j;
1026
          }
1027
        }
1028
      }
1029
1030 4bd1b3d6 Leszek Koltunski
    if( minError< 0.05f ) // TODO: 0.05 ?
1031 29b82486 Leszek Koltunski
      {
1032
      pos[offset  ] = mOrigPos[minErrorIndex1][3*minErrorIndex2  ];
1033
      pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1];
1034
      pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
1035
      }
1036
    }
1037
1038 c8bc83d9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1039
1040
  private float getAngle()
1041
    {
1042 37959420 Leszek Koltunski
    mPointNum = mRotationAngle.getNumPoints();
1043
    return mPointNum>=1 ? mRotationAngle.getPoint(mPointNum-1).get0() : 0;
1044 c8bc83d9 Leszek Koltunski
    }
1045
1046 d887aa16 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1047
1048
  void setLibInterface(ObjectLibInterface inter)
1049
    {
1050
    mInterface = inter;
1051 c8bc83d9 Leszek Koltunski
    }
1052
1053 d356eecc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1054
1055
  void applyScrambles(int[][] moves)
1056
    {
1057
    setupPosition(moves);
1058
    }
1059
1060 7c111294 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1061 198c5bf0 Leszek Koltunski
1062 880beeea Leszek Koltunski
  void initializeObject(int[][] moves)
1063 7c111294 Leszek Koltunski
    {
1064
    solve();
1065
    setupPosition(moves);
1066
    }
1067 198c5bf0 Leszek Koltunski
1068 7c111294 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1069 198c5bf0 Leszek Koltunski
1070 880beeea Leszek Koltunski
  synchronized void removeRotationNow()
1071 7c111294 Leszek Koltunski
    {
1072
    float angle = getAngle();
1073
    double nearestAngleInRadians = angle*Math.PI/180;
1074
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
1075
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
1076 59c20632 Leszek Koltunski
    float axisX = mAxis[mCurrentRotAxis].get0();
1077
    float axisY = mAxis[mCurrentRotAxis].get1();
1078
    float axisZ = mAxis[mCurrentRotAxis].get2();
1079 7c111294 Leszek Koltunski
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
1080 198c5bf0 Leszek Koltunski
1081 31ed545f Leszek Koltunski
    mRotationAngleStatic.set0(0);
1082
    mRotationAngle.removeAll();
1083
1084 a05b6e06 Leszek Koltunski
    for(int i=0; i<mNumCubits; i++)
1085 fbd18fc7 Leszek Koltunski
      {
1086
      mBelongs[i] = belongsToRotation(i, mCurrentRotAxis,mRotRowBitmap);
1087 1f329dcc Leszek Koltunski
      if( mBelongs[i] )
1088
        {
1089
        boolean result = mCubits[i].rotateCubit(quat);
1090
        if( !result ) debugQuat(quat,i,axisX,axisY,axisZ,angle,2);
1091
        }
1092 fbd18fc7 Leszek Koltunski
      }
1093
1094 5a20f7a1 Leszek Koltunski
    recomputeFaceOffsets();
1095
1096 fbd18fc7 Leszek Koltunski
    for(int i=0; i<mNumCubits; i++)
1097
      {
1098
      if( mBelongs[i] )
1099 198c5bf0 Leszek Koltunski
        {
1100 fbd18fc7 Leszek Koltunski
        int index = mCubits[i].postRotateCubit(quat);
1101 00a28d71 Leszek Koltunski
        setCubitQuat(i,mCubits[i].computeAssociation(),index);
1102 198c5bf0 Leszek Koltunski
        }
1103 5618c5a9 Leszek Koltunski
      else if( mCubits[i].getType()==TwistyObjectCubit.TYPE_FOLLOWER )
1104 fbd18fc7 Leszek Koltunski
        {
1105 7d2fe403 Leszek Koltunski
        mCubits[i].computeRotationRow();
1106 fbd18fc7 Leszek Koltunski
        setCubitQuat(i,mCubits[i].computeAssociation(),mCubits[i].mQuatIndex);
1107
        }
1108
      }
1109 605f319b Leszek Koltunski
1110
    mRotationState = STATE_NOTHING;
1111 198c5bf0 Leszek Koltunski
    }
1112
1113 5a20f7a1 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1114
1115
  private void recomputeFaceOffsets()
1116
    {
1117
    for(int i=0; i<mNumPuzzleFaces; i++)
1118
      {
1119
      mRowOffsets[i][0] =0;
1120
      mRowOffsets[i][1] =0;
1121
      mRowOffsets[i][2] =0;
1122
      }
1123
1124
    for(int i=0; i<mNumCubits; i++)
1125 5618c5a9 Leszek Koltunski
      if( mCubits[i].getType()==TwistyObjectCubit.TYPE_DECIDER )
1126 5a20f7a1 Leszek Koltunski
        {
1127
        float[] offset = mCubits[i].getOffset();
1128
        int face = mCubits[i].getPuzzleFace();
1129
        mRowOffsets[face][0] = offset[0];
1130
        mRowOffsets[face][1] = offset[1];
1131
        mRowOffsets[face][2] = offset[2];
1132
        }
1133
    }
1134
1135 c8bc83d9 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1136
1137 880beeea Leszek Koltunski
  long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
1138 c8bc83d9 Leszek Koltunski
    {
1139 7c111294 Leszek Koltunski
    if( wasRotateApplied() )
1140
      {
1141 605f319b Leszek Koltunski
      mRotationState = STATE_FINISH;
1142 7c111294 Leszek Koltunski
      float angle = getAngle();
1143
      mRotationAngleStatic.set0(angle);
1144
      mRotationAngleFinal.set0(nearestAngleInDegrees);
1145
      mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
1146 c8bc83d9 Leszek Koltunski
1147 7c111294 Leszek Koltunski
      mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
1148
      mRotationAngle.resetToBeginning();
1149
      mRotationAngle.removeAll();
1150
      mRotationAngle.add(mRotationAngleStatic);
1151
      mRotationAngle.add(mRotationAngleMiddle);
1152
      mRotationAngle.add(mRotationAngleFinal);
1153
      mRotateEffect.notifyWhenFinished(listener);
1154 c8bc83d9 Leszek Koltunski
1155 7c111294 Leszek Koltunski
      return mRotateEffect.getID();
1156
      }
1157 c8bc83d9 Leszek Koltunski
1158 7c111294 Leszek Koltunski
    return 0;
1159 c8bc83d9 Leszek Koltunski
    }
1160
1161
///////////////////////////////////////////////////////////////////////////////////////////////////
1162
1163 880beeea Leszek Koltunski
  synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
1164 c8bc83d9 Leszek Koltunski
    {
1165 605f319b Leszek Koltunski
    int mult = 1;
1166
1167 7c111294 Leszek Koltunski
    if( wasRotateApplied() )
1168
      {
1169 605f319b Leszek Koltunski
      if( mRotationState==STATE_ROTATE )
1170
        {
1171
        return 0;
1172
        }
1173
      if( mRotationState==STATE_FINISH )
1174
        {
1175
        removeRotationNow();
1176
        mult = -1;
1177
        }
1178
1179
      mRotationState = STATE_ROTATE;
1180 31ed545f Leszek Koltunski
      mCurrentRotAxis = axis;
1181
      mRotRowBitmap= computeBitmapFromRow( rowBitmap,axis );
1182
      mRotationAngleStatic.set0(0.0f);
1183
      mRotationAxis.set( mAxis[axis] );
1184
      mRotationAngle.setDuration(durationMillis);
1185
      mRotationAngle.resetToBeginning();
1186
      mRotationAngle.add(new Static1D(0));
1187
      mRotationAngle.add(new Static1D(angle));
1188
      mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1189
      mRotateEffect.notifyWhenFinished(listener);
1190 605f319b Leszek Koltunski
      return mult*mRotateEffect.getID();
1191 7c111294 Leszek Koltunski
      }
1192
1193
    return 0;
1194 c8bc83d9 Leszek Koltunski
    }
1195
1196 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1197
1198 880beeea Leszek Koltunski
  void continueRotation(float angleInDegrees)
1199
    {
1200
    mRotationAngleStatic.set0(angleInDegrees);
1201
    }
1202
1203
///////////////////////////////////////////////////////////////////////////////////////////////////
1204
1205 605f319b Leszek Koltunski
  synchronized boolean beginNewRotation(int axis, int row )
1206 880beeea Leszek Koltunski
    {
1207 605f319b Leszek Koltunski
    if( mRotationState==STATE_ROTATE )
1208
      {
1209
      return false;
1210
      }
1211
    if( mRotationState==STATE_FINISH )
1212
      {
1213
      removeRotationNow();
1214
      }
1215
1216 d55d2c6a Leszek Koltunski
    if( axis<0 || axis>=mNumAxis )
1217 880beeea Leszek Koltunski
      {
1218
      android.util.Log.e("object", "invalid rotation axis: "+axis);
1219 605f319b Leszek Koltunski
      return false;
1220 880beeea Leszek Koltunski
      }
1221 a57e6870 Leszek Koltunski
    if( row<0 || row>=mNumLayers[axis] )
1222 880beeea Leszek Koltunski
      {
1223
      android.util.Log.e("object", "invalid rotation row: "+row);
1224 605f319b Leszek Koltunski
      return false;
1225 880beeea Leszek Koltunski
      }
1226
1227 605f319b Leszek Koltunski
    mRotationState = STATE_ROTATE;
1228 31ed545f Leszek Koltunski
    mCurrentRotAxis = axis;
1229
    mRotRowBitmap= computeBitmapFromRow( (1<<row),axis );
1230
    mRotationAngleStatic.set0(0.0f);
1231
    mRotationAxis.set( mAxis[axis] );
1232
    mRotationAngle.add(mRotationAngleStatic);
1233
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*mMaxNumLayers) , -1);
1234 605f319b Leszek Koltunski
1235
    return true;
1236 880beeea Leszek Koltunski
    }
1237
1238
///////////////////////////////////////////////////////////////////////////////////////////////////
1239
1240 51262d81 Leszek Koltunski
  void setTextureMap(int cubit, int face, int color)
1241 29b82486 Leszek Koltunski
    {
1242 51262d81 Leszek Koltunski
    int variant  = getCubitVariant(cubit,mNumLayers);
1243
    int shape    = getVariantStickerShape(variant,face);
1244
    int texIndex = color<0 || shape<0 ? mNumTextures-mNumOverrides : shape*mNumFaceColors + color;
1245
    int row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1246
    int col      = texIndex%mNumTexCols;
1247
1248 7c111294 Leszek Koltunski
    final float ratioW = 1.0f/mNumTexCols;
1249
    final float ratioH = 1.0f/mNumTexRows;
1250 51262d81 Leszek Koltunski
    final Static4D[] maps = new Static4D[1];
1251
    maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1252
    mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1253 29b82486 Leszek Koltunski
    }
1254
1255 9b1fe915 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1256
1257 ed0988c0 Leszek Koltunski
  private int getCubitFaceColor(int cubit, int face)
1258 9b1fe915 Leszek Koltunski
    {
1259 ed0988c0 Leszek Koltunski
    int puzzleFace = getCubitFaceMap(cubit,face);
1260
    if( puzzleFace>=0 ) puzzleFace %= mNumFaceColors;
1261
    return puzzleFace;
1262 1b7ece90 Leszek Koltunski
    }
1263
1264
///////////////////////////////////////////////////////////////////////////////////////////////////
1265
1266 ed0988c0 Leszek Koltunski
  public int getCubitFaceMap(int cubit, int face)
1267 1b7ece90 Leszek Koltunski
    {
1268
    int numFaces = mCubitFaceColors[cubit].length;
1269
    int puzzleFace = face<numFaces ? mCubitFaceColors[cubit][face] : -1;
1270
    return puzzleFace<0 ? -1 : puzzleFace;
1271
    }
1272
1273 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1274
1275 880beeea Leszek Koltunski
  void resetAllTextureMaps()
1276 29b82486 Leszek Koltunski
    {
1277 7c111294 Leszek Koltunski
    final float ratioW = 1.0f/mNumTexCols;
1278
    final float ratioH = 1.0f/mNumTexRows;
1279 51262d81 Leszek Koltunski
    int cubColor, stiShape, texIndex, variant, row, col;
1280 29b82486 Leszek Koltunski
1281 a05b6e06 Leszek Koltunski
    for(int cubit=0; cubit<mNumCubits; cubit++)
1282 29b82486 Leszek Koltunski
      {
1283 7c111294 Leszek Koltunski
      final Static4D[] maps = new Static4D[mNumCubitFaces];
1284 a75ae1ee Leszek Koltunski
      variant = getCubitVariant(cubit,mNumLayers);
1285 29b82486 Leszek Koltunski
1286 a75ae1ee Leszek Koltunski
      for(int face=0; face<mNumCubitFaces; face++)
1287 7c111294 Leszek Koltunski
        {
1288 d4105efe Leszek Koltunski
        cubColor = getCubitFaceColor(cubit,face);
1289 51262d81 Leszek Koltunski
        stiShape = getVariantStickerShape(variant,face);
1290
        texIndex = cubColor<0 || stiShape<0 ? mNumTextures-mNumOverrides : stiShape*mNumFaceColors + cubColor;
1291
        row      = (mNumTexRows-1) - texIndex/mNumTexCols;
1292
        col      = texIndex%mNumTexCols;
1293 a75ae1ee Leszek Koltunski
1294
        maps[face] = new Static4D( col*ratioW, row*ratioH, ratioW, ratioH);
1295 7c111294 Leszek Koltunski
        }
1296 29b82486 Leszek Koltunski
1297 7c111294 Leszek Koltunski
      mMesh.setTextureMap(maps,mNumCubitFaces*cubit);
1298
      }
1299 0b050556 Leszek Koltunski
1300 b0c97683 Leszek Koltunski
    overrideCubitFaceColor();
1301
    }
1302
1303
///////////////////////////////////////////////////////////////////////////////////////////////////
1304
1305
  private void overrideCubitFaceColor()
1306
    {
1307
    final float ratioW = 1.0f/mNumTexCols;
1308
    final float ratioH = 1.0f/mNumTexRows;
1309
1310 0b050556 Leszek Koltunski
    for(int i=0; i<mNumOverrides; i++)
1311
      {
1312
      int[] cubitFaces = mStickerOverrides[i].getCubitFaces();
1313
      int length = cubitFaces.length/2;
1314
1315
      for(int j=0; j<length; j++)
1316 b0c97683 Leszek Koltunski
        {
1317
        final Static4D[] maps = new Static4D[1];
1318
        int color = mNumTextures-mNumOverrides+1+i;
1319
        int row   = (mNumTexRows-1) - color/mNumTexCols;
1320
        int col   = color%mNumTexCols;
1321
        int cubit = cubitFaces[2*j];
1322
        int face  = cubitFaces[2*j+1];
1323
        maps[0] = new Static4D(col*ratioW, row*ratioH, ratioW, ratioH);
1324
        mMesh.setTextureMap(maps,mNumCubitFaces*cubit+face);
1325
        }
1326 0b050556 Leszek Koltunski
      }
1327
    }
1328
1329 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1330
1331 880beeea Leszek Koltunski
  void releaseResources()
1332 29b82486 Leszek Koltunski
    {
1333 7c111294 Leszek Koltunski
    mTexture.markForDeletion();
1334
    mMesh.markForDeletion();
1335
    mEffects.markForDeletion();
1336
1337 a05b6e06 Leszek Koltunski
    for(int j=0; j<mNumCubits; j++)
1338 7c111294 Leszek Koltunski
      {
1339 a05b6e06 Leszek Koltunski
      mCubits[j].releaseResources();
1340 7c111294 Leszek Koltunski
      }
1341 29b82486 Leszek Koltunski
    }
1342
1343 00a28d71 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1344
1345
  private void setCubitQuat(int cubit, int andAssociation, int equAssociation)
1346
    {
1347
    if( !mIsInMixupMode )
1348
      {
1349
      mMesh.setEffectAssociation(cubit,andAssociation,equAssociation);
1350
      }
1351
    else
1352
      {
1353
      mMesh.setEffectAssociation(cubit,andAssociation,cubit);
1354
      Static4D tmp = mObjectQuats[equAssociation];
1355
      mMixupModeQuats[cubit].set(tmp);
1356
      }
1357
    }
1358
1359 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1360
1361 880beeea Leszek Koltunski
  synchronized void restorePreferences(SharedPreferences preferences)
1362 29b82486 Leszek Koltunski
    {
1363
    boolean error = false;
1364 8b5894af Leszek Koltunski
    String key = getShortName();
1365 29b82486 Leszek Koltunski
1366 a05b6e06 Leszek Koltunski
    for(int i=0; i<mNumCubits; i++)
1367 29b82486 Leszek Koltunski
      {
1368 405b22da Leszek Koltunski
      mQuatDebug[i] = mCubits[i].restorePreferences(key,preferences);
1369 29b82486 Leszek Koltunski
1370 a05b6e06 Leszek Koltunski
      if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1371 29b82486 Leszek Koltunski
        {
1372 1f329dcc Leszek Koltunski
        boolean result = mCubits[i].rotateCubit(mObjectQuats[mQuatDebug[i]]);
1373
        if( !result ) debugQuat(mObjectQuats[mQuatDebug[i]],i,0,0,0,mQuatDebug[i],3);
1374 fbd18fc7 Leszek Koltunski
        }
1375 7cd287b9 Leszek Koltunski
      else { error = true; break; }
1376 fbd18fc7 Leszek Koltunski
      }
1377
1378 7cd287b9 Leszek Koltunski
    if( !error )
1379 fbd18fc7 Leszek Koltunski
      {
1380 7cd287b9 Leszek Koltunski
      recomputeFaceOffsets();
1381
1382
      for(int i=0; i<mNumCubits; i++)
1383 29b82486 Leszek Koltunski
        {
1384 7cd287b9 Leszek Koltunski
        if( mQuatDebug[i]>=0 && mQuatDebug[i]<mNumQuats )
1385
          {
1386
          mCubits[i].computeRotationRow();
1387
          setCubitQuat(i,mCubits[i].computeAssociation(),mQuatDebug[i]);
1388
          }
1389
        else { error = true; break; }
1390 29b82486 Leszek Koltunski
        }
1391
      }
1392
1393
    if( error )
1394
      {
1395 a05b6e06 Leszek Koltunski
      for(int i=0; i<mNumCubits; i++)
1396 29b82486 Leszek Koltunski
        {
1397 a05b6e06 Leszek Koltunski
        mCubits[i].solve();
1398 00a28d71 Leszek Koltunski
        setCubitQuat(i,mCubits[i].computeAssociation(),0);
1399 29b82486 Leszek Koltunski
        }
1400
      }
1401
    }
1402
1403
///////////////////////////////////////////////////////////////////////////////////////////////////
1404
1405 880beeea Leszek Koltunski
  void savePreferences(SharedPreferences.Editor editor)
1406 29b82486 Leszek Koltunski
    {
1407 8b5894af Leszek Koltunski
    String key = getShortName();
1408 405b22da Leszek Koltunski
    for(int i=0; i<mNumCubits; i++) mCubits[i].savePreferences(key,editor);
1409 29b82486 Leszek Koltunski
    }
1410
1411 ea739ec8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1412
1413
  public void removePreferences(SharedPreferences.Editor editor)
1414
    {
1415
    String key = getShortName();
1416
    for(int i=0; i<mNumCubits; i++) mCubits[i].removePreferences(key,editor);
1417
    }
1418
1419 00f4980d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1420
1421 d53fb890 Leszek Koltunski
  private float computeRadiusCorrection(float[] sticker, int curr, int len)
1422 00f4980d Leszek Koltunski
    {
1423
    final float A = 0.8f;  // 0<A<1
1424
1425
    int prev = curr>0 ? curr-1 : len-1;
1426
    int next = curr<len-1 ? curr+1 : 0;
1427
1428
    float v1x = sticker[2*prev  ]-sticker[2*curr  ];
1429
    float v1y = sticker[2*prev+1]-sticker[2*curr+1];
1430
    float v2x = sticker[2*next  ]-sticker[2*curr  ];
1431
    float v2y = sticker[2*next+1]-sticker[2*curr+1];
1432
1433
    float len1= v1x*v1x+v1y*v1y;
1434
    float len2= v2x*v2x+v2y*v2y;
1435
1436
    float cos = (v1x*v2x+v1y*v2y) / ( (float)Math.sqrt(len1*len2) );
1437
1438
    return 1-A*cos;
1439
    }
1440
1441 b9c861cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1442
// Radius of the sphere circumscribed on the puzzle. Needed for pillowing.
1443
//
1444
// This won't work correctly for pillowing off-center puzzles (e.g. mirrors) - for those we'd need
1445
// to introduce the concept of a 'sink center' as well.
1446
//
1447
// public because needed in TouchControlShapemod
1448
1449
  public float getCircumscribedRadius()
1450
    {
1451
    switch(mNumPuzzleFaces)
1452
      {
1453
      case  4: return (SQ6/4)*mSize;
1454
      case  6: return (SQ3/2)*mSize;
1455
      case  8: return (SQ2/2)*mSize;
1456
      case 12: return (SQ3/2)*((SQ5+1)/2)*mSize;
1457 c1452814 Leszek Koltunski
      case 16: return 0.50f*mSize;
1458 b9c861cf Leszek Koltunski
      }
1459
1460
    return 0.0f;
1461
    }
1462
1463 d53fb890 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1464
1465
  public ObjectSticker retSticker(int sticker)
1466
    {
1467
    if( mStickers==null )
1468
      {
1469
      float rad = getStickerRadius();
1470
      float str = getStickerStroke();
1471
      float[][] angles = getStickerAngles();
1472
      int numStickers = mStickerCoords.length;
1473
      mStickers = new ObjectSticker[numStickers];
1474
1475
      for(int s=0; s<numStickers; s++)
1476
        {
1477 bc008758 Leszek Koltunski
        float scale = mStickerScales.length>s ? mStickerScales[s] : 1.0f;
1478 d53fb890 Leszek Koltunski
        float radius = rad / scale;
1479
        float stroke = str / scale;
1480
        int len = mStickerCoords[s].length/2;
1481
        float[] radii = new float[len];
1482
        for(int r=0; r<len; r++) radii[r] = radius*computeRadiusCorrection(mStickerCoords[s],r,len);
1483
        mStickers[s] = new ObjectSticker(mStickerCoords[s],angles==null ? null : angles[s],radii,stroke);
1484
        }
1485
      }
1486
1487
    return mStickers[sticker];
1488
    }
1489
1490 3d766df3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1491 e3937019 Leszek Koltunski
// some objects (currently Kilominx,Ivy,Rex) might want to change the stickers.
1492 3d766df3 Leszek Koltunski
1493
  public void adjustStickerCoords()
1494
    {
1495
1496
    }
1497
1498 802fe251 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1499
1500
  public Static4D[] getQuats()
1501
    {
1502
    if( mObjectQuats==null )
1503
      {
1504
      mObjectQuats = QuatGroupGenerator.computeGroup(mAxis,mBasicAngles);
1505
      }
1506
1507
    return mObjectQuats;
1508
    }
1509
1510 40e77224 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1511
1512
  public int[][] getVariantFaceIsOuter()
1513
    {
1514
    return mVariantFaceIsOuter;
1515
    }
1516
1517 253e440f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1518
1519
  public int getInternalColor()
1520
    {
1521
    return COLOR_INTERNAL;
1522
    }
1523
1524 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1525 3a0a23bf Leszek Koltunski
// the getFaceColors + final INTERNAL_COLOR in a grid (so that we do not exceed the maximum texture size)
1526 29b82486 Leszek Koltunski
1527 d5c71d02 Leszek Koltunski
  private void createTexture()
1528 29b82486 Leszek Koltunski
    {
1529 7c111294 Leszek Koltunski
    Paint paint = new Paint();
1530 3afd2fe4 Leszek Koltunski
    mBitmap = Bitmap.createBitmap( mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, Bitmap.Config.ARGB_4444);
1531 d5c71d02 Leszek Koltunski
    Canvas canvas = new Canvas(mBitmap);
1532 29b82486 Leszek Koltunski
1533 7c111294 Leszek Koltunski
    paint.setAntiAlias(true);
1534
    paint.setTextAlign(Paint.Align.CENTER);
1535
    paint.setStyle(Paint.Style.FILL);
1536 253e440f Leszek Koltunski
    paint.setColor(getInternalColor());
1537 7c111294 Leszek Koltunski
    canvas.drawRect(0, 0, mNumTexCols*TEXTURE_HEIGHT, mNumTexRows*TEXTURE_HEIGHT, paint);
1538
1539 43a4ccff Leszek Koltunski
    int texture = 0;
1540 7c111294 Leszek Koltunski
    FactorySticker factory = FactorySticker.getInstance();
1541
1542
    for(int row=0; row<mNumTexRows; row++)
1543
      for(int col=0; col<mNumTexCols; col++)
1544 29b82486 Leszek Koltunski
        {
1545 3a0a23bf Leszek Koltunski
        if( texture<mNumTextures-mNumOverrides )
1546
          {
1547
          ObjectSticker sticker = retSticker(texture/mNumFaceColors);
1548 ff60e713 Leszek Koltunski
          int color = getColor(texture%mNumFaceColors);
1549 3a0a23bf Leszek Koltunski
          factory.drawRoundedPolygon(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color, sticker);
1550
          }
1551 ff60e713 Leszek Koltunski
        else if( texture>mNumTextures-mNumOverrides && texture<=mNumTextures )
1552 3a0a23bf Leszek Koltunski
          {
1553 ff60e713 Leszek Koltunski
          int color = mStickerOverrides[mNumTextures-texture].getColor();
1554
          factory.drawSolidColor(canvas, paint, col*TEXTURE_HEIGHT, (mNumTexRows-row)*TEXTURE_HEIGHT, color);
1555 3a0a23bf Leszek Koltunski
          }
1556 ff60e713 Leszek Koltunski
1557
        texture++;
1558 29b82486 Leszek Koltunski
        }
1559 d5c71d02 Leszek Koltunski
    }
1560
1561
///////////////////////////////////////////////////////////////////////////////////////////////////
1562
1563
  void setTexture()
1564
    {
1565
    if( mBitmap==null ) createTexture();
1566 29b82486 Leszek Koltunski
1567 a0ccffb4 Leszek Koltunski
    if( !mTexture.setTextureAlreadyInverted(mBitmap) )
1568 7c111294 Leszek Koltunski
      {
1569
      int max = DistortedLibrary.getMaxTextureSize();
1570 32c1697e Leszek Koltunski
      mInterface.reportProblem("failed to set texture of size "+mBitmap.getWidth()+"x"+mBitmap.getHeight()+" max is "+max, true);
1571 29b82486 Leszek Koltunski
      }
1572
    }
1573
1574 ee6bb8d7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1575
1576 45e0065d Leszek Koltunski
  void setObjectRatioNow(float sc, int nodeSize)
1577 ee6bb8d7 Leszek Koltunski
    {
1578 64c209f5 Leszek Koltunski
    mObjectScreenRatio = sc;
1579 45e0065d Leszek Koltunski
    float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize;
1580 ee6bb8d7 Leszek Koltunski
    mObjectScale.set(scale,scale,scale);
1581 23afe4c4 Leszek Koltunski
1582 11fa413d Leszek Koltunski
    if( mTouchControl ==null ) mTouchControl = getTouchControl();
1583 c9c71c3f Leszek Koltunski
    mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
1584 ee6bb8d7 Leszek Koltunski
    }
1585
1586 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1587
1588 45e0065d Leszek Koltunski
  void setObjectRatio(float sizeChange, int nodeSize)
1589 29b82486 Leszek Koltunski
    {
1590 7c111294 Leszek Koltunski
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
1591 29b82486 Leszek Koltunski
1592 7c111294 Leszek Koltunski
    if( mObjectScreenRatio>MAX_SIZE_CHANGE) mObjectScreenRatio = MAX_SIZE_CHANGE;
1593
    if( mObjectScreenRatio<MIN_SIZE_CHANGE) mObjectScreenRatio = MIN_SIZE_CHANGE;
1594
1595 45e0065d Leszek Koltunski
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1596
    }
1597
1598
///////////////////////////////////////////////////////////////////////////////////////////////////
1599
1600
  void setNodeSize(int nodeSize)
1601
    {
1602
    setObjectRatioNow(mObjectScreenRatio, nodeSize);
1603 29b82486 Leszek Koltunski
    }
1604
1605 02d80fe6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1606
1607
  public float getRatio()
1608
    {
1609
    return mObjectScreenRatio;
1610
    }
1611
1612 11fa413d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1613
1614
  public float getObjectRatio()
1615
    {
1616
    return mObjectScreenRatio*mInitScreenRatio;
1617
    }
1618
1619 7c111294 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1620 29b82486 Leszek Koltunski
1621 880beeea Leszek Koltunski
  boolean isSolved()
1622 7c111294 Leszek Koltunski
    {
1623 5618c5a9 Leszek Koltunski
    return mSolved.isSolved(mCubits);
1624 29b82486 Leszek Koltunski
    }
1625
1626 7c111294 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1627 29b82486 Leszek Koltunski
1628 beee90ab Leszek Koltunski
  int computeNearestAngle(int basicAngle, float angle, float speed)
1629 7c111294 Leszek Koltunski
    {
1630 880beeea Leszek Koltunski
    int nearestAngle = 360/basicAngle;
1631
    int tmp = (int)((angle+nearestAngle/2)/nearestAngle);
1632
    if( angle< -(nearestAngle*0.5) ) tmp-=1;
1633
1634
    if( tmp!=0 ) return nearestAngle*tmp;
1635
1636
    return speed> 1.2f ? nearestAngle*(angle>0 ? 1:-1) : 0;
1637 7c111294 Leszek Koltunski
    }
1638 29b82486 Leszek Koltunski
1639 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1640
// INTERNAL API - those are called from 'effects' package
1641 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1642
1643 880beeea Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int total)
1644 29b82486 Leszek Koltunski
    {
1645 a72a4b6a Leszek Koltunski
    mScrambler.randomizeNewScramble(scramble,rnd,curr,total, getSignature() );
1646 7c111294 Leszek Koltunski
    }
1647 29b82486 Leszek Koltunski
1648
///////////////////////////////////////////////////////////////////////////////////////////////////
1649
1650 880beeea Leszek Koltunski
  public Static4D getRotationQuat()
1651 59c20632 Leszek Koltunski
    {
1652
    return mQuat;
1653
    }
1654
1655
///////////////////////////////////////////////////////////////////////////////////////////////////
1656
1657
  public float getSize()
1658
    {
1659
    return mSize;
1660
    }
1661 7c111294 Leszek Koltunski
1662 2df35810 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1663
1664 826d293e Leszek Koltunski
  public void applyEffect(Effect effect, int position)
1665 2df35810 Leszek Koltunski
    {
1666
    mEffects.apply(effect, position);
1667
    }
1668
1669
///////////////////////////////////////////////////////////////////////////////////////////////////
1670
1671 826d293e Leszek Koltunski
  public void removeEffect(long effectID)
1672 2df35810 Leszek Koltunski
    {
1673
    mEffects.abortById(effectID);
1674
    }
1675
1676 3e9df6aa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1677
1678 758b028d Leszek Koltunski
  public MeshBase getObjectMesh()
1679 3e9df6aa Leszek Koltunski
    {
1680
    return mMesh;
1681
    }
1682
1683 758b028d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1684
1685
  public DistortedEffects getObjectEffects()
1686
    {
1687
    return mEffects;
1688
    }
1689
1690 7aae846c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1691
1692
  public int getCubitType(int cubit)
1693
    {
1694
    return mCubits[cubit].getType();
1695
    }
1696
1697
///////////////////////////////////////////////////////////////////////////////////////////////////
1698
1699
  public float[] getCubitOffset(int cubit)
1700
    {
1701
    return mCubits[cubit].getOffset();
1702
    }
1703
1704 3a0a23bf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1705
1706
  public ObjectStickerOverride[] getStickerOverrides()
1707
    {
1708
    return null;
1709
    }
1710
1711 3ce95490 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1712
1713
  public boolean getError()
1714
    {
1715
    return mError;
1716
    }
1717
1718
///////////////////////////////////////////////////////////////////////////////////////////////////
1719
1720
  public String getErrorString()
1721
    {
1722
    return mErrorString;
1723
    }
1724
1725 880beeea Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1726
// PUBLIC API
1727 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1728
1729 a1f8dc90 Leszek Koltunski
  public int getCubitFaceStickerIndex(int cubit, int face)
1730 29b82486 Leszek Koltunski
    {
1731 a1f8dc90 Leszek Koltunski
    Static4D texMap = mMesh.getTextureMap(mNumCubitFaces*cubit + face);
1732 29b82486 Leszek Koltunski
1733 880beeea Leszek Koltunski
    int x = (int)(texMap.get0()/texMap.get2());
1734
    int y = (int)(texMap.get1()/texMap.get3());
1735 29b82486 Leszek Koltunski
1736 880beeea Leszek Koltunski
    return (mNumTexRows-1-y)*NUM_STICKERS_IN_ROW + x;
1737 29b82486 Leszek Koltunski
    }
1738
1739
///////////////////////////////////////////////////////////////////////////////////////////////////
1740
1741 a57e6870 Leszek Koltunski
  public int[] getNumLayers()
1742 29b82486 Leszek Koltunski
    {
1743 880beeea Leszek Koltunski
    return mNumLayers;
1744
    }
1745 29b82486 Leszek Koltunski
1746
///////////////////////////////////////////////////////////////////////////////////////////////////
1747
1748 880beeea Leszek Koltunski
  public synchronized void solve()
1749 29b82486 Leszek Koltunski
    {
1750 a05b6e06 Leszek Koltunski
    for(int i=0; i<mNumCubits; i++)
1751 880beeea Leszek Koltunski
      {
1752 a05b6e06 Leszek Koltunski
      mCubits[i].solve();
1753 7d2fe403 Leszek Koltunski
      }
1754
1755
    recomputeFaceOffsets();
1756
1757
    for(int i=0; i<mNumCubits; i++)
1758
      {
1759
      mCubits[i].computeRotationRow();
1760 00a28d71 Leszek Koltunski
      setCubitQuat(i,mCubits[i].computeAssociation(),0);
1761 880beeea Leszek Koltunski
      }
1762 29b82486 Leszek Koltunski
    }
1763
1764 57ef6378 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1765
1766
  public int getCubitQuatIndex(int cubit)
1767
    {
1768 05b0a7dd Leszek Koltunski
    return (cubit>=0 && cubit<mNumCubits) ? mCubits[cubit].mQuatIndex : 0;
1769 57ef6378 Leszek Koltunski
    }
1770
1771 92a6fc8b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1772
1773
  public int getCubitRotRow(int cubit, int axis)
1774
    {
1775 a05b6e06 Leszek Koltunski
    return mCubits[cubit].getRotRow(axis);
1776 92a6fc8b Leszek Koltunski
    }
1777
1778 d5c71d02 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1779
1780
  public Bitmap getStickerBitmap()
1781
    {
1782
    return mBitmap;
1783
    }
1784
1785 7ba38dd4 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1786
1787
  public DistortedNode getNode()
1788
    {
1789
    return mNode;
1790
    }
1791
1792 7af68038 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1793
1794
  public int getNumStickerTypes()
1795
    {
1796
    return mNumStickerTypes;
1797
    }
1798
1799 93743a22 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1800
1801
  public String reportState()
1802
    {
1803
    StringBuilder builder = new StringBuilder();
1804
1805
    for(int i=0; i<mNumCubits; i++ )
1806
      {
1807
      if( i>0 ) builder.append('.');
1808
      builder.append(mCubits[i].mQuatIndex);
1809
      }
1810
1811
    return builder.toString();
1812
    }
1813
1814 d66e98d7 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1815 a0b0795b Leszek Koltunski
// this is here only so it can be overridden in TwistyJSON so that we can get this from JSON.
1816 d66e98d7 Leszek Koltunski
1817
  public int getNumCubitFaces()
1818
    {
1819
    return 0;
1820
    }
1821
1822 a0b0795b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1823
// 1.0 - i.e. no pillowing - by default.
1824
// The coeff is really param of the 'sink' vertex effect - if it is not equal to 1.0, we apply the
1825
// sink effect [centered at (0,0,0)] to the whole mesh as the last step of composing it.
1826
1827
  public float getPillowCoeff()
1828
    {
1829
    return 1.0f;
1830
    }
1831
1832 59c20632 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1833
1834 11fa413d Leszek Koltunski
  public TouchControl getTouchControl()
1835 59c20632 Leszek Koltunski
    {
1836 57ef6378 Leszek Koltunski
    if( mTouchControl==null )
1837 59c20632 Leszek Koltunski
      {
1838 11fa413d Leszek Koltunski
      switch(getTouchControlType())
1839 59c20632 Leszek Koltunski
        {
1840 cd2e8d4c Leszek Koltunski
        case TC_TETRAHEDRON      : mTouchControl = new TouchControlTetrahedron(this);
1841
                                   break;
1842
        case TC_HEXAHEDRON       : mTouchControl = new TouchControlHexahedron(this);
1843
                                   break;
1844
        case TC_OCTAHEDRON       : mTouchControl = new TouchControlOctahedron(this);
1845
                                   break;
1846
        case TC_DODECAHEDRON     : mTouchControl = new TouchControlDodecahedron(this);
1847
                                   break;
1848 5caf2641 Leszek Koltunski
        case TC_ICOSAHEDRON      : mTouchControl = new TouchControlIcosahedron(this);
1849
                                   break;
1850 cd2e8d4c Leszek Koltunski
        case TC_CUBOID           : int[] numLayers = getNumLayers();
1851
                                   mTouchControl = new TouchControlCuboids(this,getDist3D(numLayers));
1852
                                   break;
1853 5caf2641 Leszek Koltunski
        case TC_BALL             : mTouchControl = new TouchControlBall(this);
1854
                                   break;
1855 cd2e8d4c Leszek Koltunski
        case TC_CHANGING_MIRROR  : mTouchControl = new TouchControlMirror(this);
1856
                                   break;
1857
        case TC_CHANGING_SQUARE  : mTouchControl = new TouchControlSquare(this);
1858
                                   break;
1859
        case TC_CHANGING_SHAPEMOD: mTouchControl = new TouchControlShapemod(this);
1860
                                   break;
1861 59c20632 Leszek Koltunski
        }
1862
      }
1863 c9c71c3f Leszek Koltunski
    return mTouchControl;
1864 59c20632 Leszek Koltunski
    }
1865
1866 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
1867
1868 82eb152a Leszek Koltunski
  protected void setReader(JsonReader reader)
1869
    {
1870
    // empty
1871
    }
1872
1873
///////////////////////////////////////////////////////////////////////////////////////////////////
1874 59c20632 Leszek Koltunski
  // for JSON only
1875 11fa413d Leszek Koltunski
  public abstract int getTouchControlType();
1876
  public abstract int getTouchControlSplit();
1877 59c20632 Leszek Koltunski
  public abstract boolean[][] getLayerRotatable(int[] numLayers);
1878
  public abstract int[][][] getEnabled();
1879
  public abstract float[] getDist3D(int[] numLayers);
1880 4c9ca251 Leszek Koltunski
  public abstract Static3D[] getFaceAxis();
1881 9ba7f3f6 Leszek Koltunski
  public abstract int[][] getScrambleEdges();
1882 7bbfc84f Leszek Koltunski
  public abstract float[][] getCuts(int[] numLayers);
1883 d53fb890 Leszek Koltunski
  public abstract float getStickerRadius();
1884
  public abstract float getStickerStroke();
1885
  public abstract float[][] getStickerAngles();
1886 e30c522a Leszek Koltunski
  public abstract int getCubitVariant(int cubit, int[] numLayers);
1887
  public abstract ObjectShape getObjectShape(int variant);
1888 3ee1d662 Leszek Koltunski
  public abstract ObjectFaceShape getObjectFaceShape(int variant);
1889 84a17011 Leszek Koltunski
  public abstract ObjectVertexEffects getVertexEffects(int variant);
1890 e30c522a Leszek Koltunski
  public abstract int getNumCubitVariants(int[] numLayers);
1891 7b832206 Leszek Koltunski
  public abstract float[][] getCubitPositions(int[] numLayers);
1892 d0e6cf7f Leszek Koltunski
  public abstract Static4D getCubitQuats(int cubit, int[] numLayers);
1893 a75ae1ee Leszek Koltunski
  public abstract int getNumFaceColors();
1894 82eb152a Leszek Koltunski
  public abstract float getScreenRatio();
1895
  public abstract int getColor(int face);
1896 5f54927b Leszek Koltunski
  public abstract String getShortName();
1897 1d581993 Leszek Koltunski
  public abstract ObjectSignature getSignature();
1898 7b832206 Leszek Koltunski
1899 a75ae1ee Leszek Koltunski
  // not only for JSON
1900 29b82486 Leszek Koltunski
  public abstract Static3D[] getRotationAxis();
1901 beee90ab Leszek Koltunski
  public abstract int[][] getBasicAngles();
1902 2289cab1 Leszek Koltunski
  public abstract int getNumFaces();
1903 e26eb4e7 Leszek Koltunski
  public abstract String getObjectName();
1904
  public abstract String getInventor();
1905
  public abstract int getYearOfInvention();
1906
  public abstract int getComplexity();
1907 7ba38dd4 Leszek Koltunski
  public abstract int getFOV();
1908 052e0362 Leszek Koltunski
  public abstract String[][] getTutorials();
1909 29b82486 Leszek Koltunski
  }