Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / TwistyObject.java @ 7e8750c9

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