Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 3788d0cd

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