Project

General

Profile

Download (22.9 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / RubikObject.java @ 6b6504fe

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.objects;
21

    
22
import android.content.SharedPreferences;
23
import android.content.res.Resources;
24
import android.graphics.Bitmap;
25
import android.graphics.Canvas;
26
import android.graphics.Paint;
27

    
28
import com.google.firebase.crashlytics.FirebaseCrashlytics;
29

    
30
import org.distorted.library.effect.Effect;
31
import org.distorted.library.effect.MatrixEffectMove;
32
import org.distorted.library.effect.MatrixEffectQuaternion;
33
import org.distorted.library.effect.MatrixEffectScale;
34
import org.distorted.library.effect.VertexEffectQuaternion;
35
import org.distorted.library.effect.VertexEffectRotate;
36
import org.distorted.library.main.DistortedEffects;
37
import org.distorted.library.main.DistortedNode;
38
import org.distorted.library.main.DistortedTexture;
39
import org.distorted.library.mesh.MeshBase;
40
import org.distorted.library.mesh.MeshFile;
41
import org.distorted.library.mesh.MeshJoined;
42
import org.distorted.library.mesh.MeshRectangles;
43
import org.distorted.library.message.EffectListener;
44
import org.distorted.library.type.Dynamic1D;
45
import org.distorted.library.type.Static1D;
46
import org.distorted.library.type.Static3D;
47
import org.distorted.library.type.Static4D;
48

    
49
import java.io.DataInputStream;
50
import java.io.IOException;
51
import java.io.InputStream;
52
import java.util.Random;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
public abstract class RubikObject extends DistortedNode
57
  {
58
  private static final float NODE_RATIO = 1.32f;
59
  private static final float MAX_SIZE_CHANGE = 1.3f;
60
  private static final float MIN_SIZE_CHANGE = 0.8f;
61

    
62
  private static boolean mCreateFromDMesh = true;
63

    
64
  private static final Static3D CENTER = new Static3D(0,0,0);
65
  static final int INTERIOR_COLOR = 0xff000000;
66
  private static final int POST_ROTATION_MILLISEC = 500;
67
  private static final int TEXTURE_HEIGHT = 256;
68

    
69
  final Static3D[] ROTATION_AXIS;
70
  final Static4D[] QUATS;
71
  final Cubit[] CUBITS;
72
  final int NUM_FACES;
73
  final int NUM_CUBIT_FACES;
74
  final int NUM_AXIS;
75
  final int NUM_CUBITS;
76

    
77
  private static float mInitScreenRatio,mObjectScreenRatio;
78

    
79
  private final int mNodeSize;
80
  private int mRotRowBitmap;
81
  private int mRotAxis;
82
  private Static3D[] mOrigPos;
83
  private Static3D mNodeScale;
84
  private Static4D mQuat;
85
  private int mSize;
86
  private RubikObjectList mList;
87
  private MeshBase mMesh;
88
  private DistortedEffects mEffects;
89
  private VertexEffectRotate mRotateEffect;
90
  private Dynamic1D mRotationAngle;
91
  private Static3D mRotationAxis;
92
  private Static3D mObjectScale;
93

    
94
  float mStart, mStep;
95
  float[] mRowChances;
96

    
97
  Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
98
  DistortedTexture mTexture;
99

    
100
  MatrixEffectScale mScaleEffect;
101
  MatrixEffectQuaternion mQuatEffect;
102

    
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

    
105
  RubikObject(int size, int fov, Static4D quat, DistortedTexture nodeTexture, MeshRectangles nodeMesh,
106
              DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res, int screenWidth)
107
    {
108
    super(nodeTexture,nodeEffects,nodeMesh);
109

    
110
    mNodeSize = screenWidth;
111

    
112
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
113

    
114
    mList = list;
115
    mOrigPos = getCubitPositions(size);
116

    
117
    QUATS = getQuats();
118
    NUM_CUBITS  = mOrigPos.length;
119
    ROTATION_AXIS = getRotationAxis();
120
    NUM_AXIS = ROTATION_AXIS.length;
121
    mObjectScreenRatio = getScreenRatio();
122
    mInitScreenRatio = mObjectScreenRatio;
123
    NUM_FACES = getNumFaces();
124
    NUM_CUBIT_FACES = getNumCubitFaces();
125

    
126
    mSize = size;
127
    computeStartAndStep(mOrigPos);
128
    mNodeScale= new Static3D(1,NODE_RATIO,1);
129
    mQuat = quat;
130

    
131
    mRowChances = getRowChances();
132

    
133
    mRotationAngle= new Dynamic1D();
134
    mRotationAxis = new Static3D(1,0,0);
135
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
136

    
137
    mRotationAngleStatic = new Static1D(0);
138
    mRotationAngleMiddle = new Static1D(0);
139
    mRotationAngleFinal  = new Static1D(0);
140

    
141
    float scale  = mObjectScreenRatio*mNodeSize/mSize;
142
    mObjectScale = new Static3D(scale,scale,scale);
143
    mScaleEffect = new MatrixEffectScale(mObjectScale);
144
    mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
145

    
146
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
147
    nodeEffects.apply(nodeScaleEffect);
148

    
149
    CUBITS = new Cubit[NUM_CUBITS];
150
    createMeshAndCubits(list,res);
151

    
152
    mTexture = new DistortedTexture();
153
    mEffects = new DistortedEffects();
154

    
155
    int num_quats = QUATS.length;
156
    for(int q=0; q<num_quats; q++)
157
      {
158
      VertexEffectQuaternion vq = new VertexEffectQuaternion(QUATS[q],CENTER);
159
      vq.setMeshAssociation(0,q);
160
      mEffects.apply(vq);
161
      }
162

    
163
    mEffects.apply(mRotateEffect);
164
    mEffects.apply(mQuatEffect);
165
    mEffects.apply(mScaleEffect);
166

    
167
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
168

    
169
    setupPosition(moves);
170

    
171
    setProjection(fov, 0.1f);
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  private void createMeshAndCubits(RubikObjectList list, Resources res)
177
    {
178
    if( mCreateFromDMesh )
179
      {
180
      int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize);
181
      int resourceID= list.getResourceIDs()[sizeIndex];
182

    
183
      InputStream is = res.openRawResource(resourceID);
184
      DataInputStream dos = new DataInputStream(is);
185
      mMesh = new MeshFile(dos);
186

    
187
      try
188
        {
189
        is.close();
190
        }
191
      catch(IOException e)
192
        {
193
        android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
194
        }
195

    
196
      for(int i=0; i<NUM_CUBITS; i++)
197
        {
198
        CUBITS[i] = new Cubit(this,mOrigPos[i]);
199
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
200
        }
201
      }
202
    else
203
      {
204
      MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS];
205

    
206
      for(int i=0; i<NUM_CUBITS; i++)
207
        {
208
        CUBITS[i] = new Cubit(this,mOrigPos[i]);
209
        cubitMesh[i] = createCubitMesh(i);
210
        cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0);
211
        cubitMesh[i].setEffectAssociation(0, CUBITS[i].computeAssociation(), 0);
212
        }
213

    
214
      mMesh = new MeshJoined(cubitMesh);
215
      resetAllTextureMaps();
216
      }
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  public void setObjectRatio(float sizeChange)
222
    {
223
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
224

    
225
    if( mObjectScreenRatio > MAX_SIZE_CHANGE*mInitScreenRatio)
226
      {
227
      mObjectScreenRatio = MAX_SIZE_CHANGE*mInitScreenRatio;
228
      }
229
    if( mObjectScreenRatio < MIN_SIZE_CHANGE*mInitScreenRatio)
230
      {
231
      mObjectScreenRatio = MIN_SIZE_CHANGE*mInitScreenRatio;
232
      }
233

    
234
    float scale = mObjectScreenRatio*mNodeSize/mSize;
235
    mObjectScale.set(scale,scale,scale);
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  static float getObjectRatio()
241
    {
242
    return mObjectScreenRatio;
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246
// Cast centers of all Cubits on the first rotation Axis and compute the leftmost and rightmost
247
// one. From there compute the 'start' (i.e. the leftmost) and 'step' (i.e. distance between two
248
// consecutive).
249
// it is assumed that other rotation axis have the same 'start' and 'step' - this is the case with
250
// the Cube and the Pyraminx.
251
// Start and Step are then needed to compute which rotation row (with respect to a given axis) a
252
// given Cubit belongs to.
253

    
254
  private void computeStartAndStep(Static3D[] pos)
255
    {
256
    float min = Float.MAX_VALUE;
257
    float max = Float.MIN_VALUE;
258
    float axisX = ROTATION_AXIS[0].get0();
259
    float axisY = ROTATION_AXIS[0].get1();
260
    float axisZ = ROTATION_AXIS[0].get2();
261
    float tmp;
262

    
263
    for(int i=0; i<NUM_CUBITS; i++)
264
      {
265
      tmp = pos[i].get0()*axisX + pos[i].get1()*axisY + pos[i].get2()*axisZ;
266
      if( tmp<min ) min=tmp;
267
      if( tmp>max ) max=tmp;
268
      }
269

    
270
    mStart = min;
271
    mStep  = (max-min+1.0f)/mSize;
272
    }
273

    
274
///////////////////////////////////////////////////////////////////////////////////////////////////
275

    
276
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
277
    {
278
    int cubitRow = (int)(CUBITS[cubit].mRotationRow[axis]+0.5f);
279
    return ((1<<cubitRow)&rowBitmap)!=0;
280
    }
281

    
282
///////////////////////////////////////////////////////////////////////////////////////////////////
283
// note the minus in front of the sin() - we rotate counterclockwise
284
// when looking towards the direction where the axis increases in values.
285

    
286
  private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
287
    {
288
    Static3D axis = ROTATION_AXIS[axisIndex];
289

    
290
    while( angleInDegrees<0 ) angleInDegrees += 360;
291
    angleInDegrees %= 360;
292
    
293
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
294
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
295

    
296
    return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA);
297
    }
298

    
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300

    
301
  private synchronized void setupPosition(int[][] moves)
302
    {
303
    if( moves!=null )
304
      {
305
      Static4D quat;
306
      int index, axis, rowBitmap, angle;
307
      int corr = (360/getBasicAngle());
308

    
309
      for(int[] move: moves)
310
        {
311
        axis     = move[0];
312
        rowBitmap= move[1];
313
        angle    = move[2]*corr;
314
        quat     = makeQuaternion(axis,angle);
315

    
316
        for(int j=0; j<NUM_CUBITS; j++)
317
          if( belongsToRotation(j,axis,rowBitmap) )
318
            {
319
            index = CUBITS[j].removeRotationNow(quat);
320
            mMesh.setEffectAssociation(j, CUBITS[j].computeAssociation(),index);
321
            }
322
        }
323
      }
324
    }
325

    
326
///////////////////////////////////////////////////////////////////////////////////////////////////
327
// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
328
// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
329
// away from the face of the Pyraminx shouldn't be textured.
330

    
331
  boolean isOnFace( int cubit, int axis, int row)
332
    {
333
    final float MAX_ERROR = 0.0001f;
334
    float diff = CUBITS[cubit].mRotationRow[axis] - row;
335
    return diff*diff < MAX_ERROR;
336
    }
337

    
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

    
340
  int getCubitFaceColorIndex(int cubit, int face)
341
    {
342
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
343
    return (int)(texMap.get0() / texMap.get2());
344
    }
345

    
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
348

    
349
  void clampPos(Static3D pos)
350
    {
351
    float currError, minError = Float.MAX_VALUE;
352
    int minErrorIndex= -1;
353
    float x = pos.get0();
354
    float y = pos.get1();
355
    float z = pos.get2();
356
    float xo,yo,zo;
357

    
358
    for(int i=0; i<NUM_CUBITS; i++)
359
      {
360
      xo = mOrigPos[i].get0();
361
      yo = mOrigPos[i].get1();
362
      zo = mOrigPos[i].get2();
363

    
364
      currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
365

    
366
      if( currError<minError )
367
        {
368
        minError = currError;
369
        minErrorIndex = i;
370
        }
371
      }
372

    
373
    pos.set( mOrigPos[minErrorIndex] );
374
    }
375

    
376
///////////////////////////////////////////////////////////////////////////////////////////////////
377
// the getFaceColors + final black in a horizontal strip.
378

    
379
  public void createTexture()
380
    {
381
    Bitmap bitmap;
382

    
383
    Paint paint = new Paint();
384
    bitmap = Bitmap.createBitmap( (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
385
    Canvas canvas = new Canvas(bitmap);
386

    
387
    paint.setAntiAlias(true);
388
    paint.setTextAlign(Paint.Align.CENTER);
389
    paint.setStyle(Paint.Style.FILL);
390

    
391
    paint.setColor(INTERIOR_COLOR);
392
    canvas.drawRect(0, 0, (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
393

    
394
    for(int i=0; i<NUM_FACES; i++)
395
      {
396
      createFaceTexture(canvas, paint, i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
397
      }
398

    
399
    mTexture.setTexture(bitmap);
400
    }
401

    
402
///////////////////////////////////////////////////////////////////////////////////////////////////
403

    
404
  public int getSize()
405
    {
406
    return mSize;
407
    }
408

    
409
///////////////////////////////////////////////////////////////////////////////////////////////////
410

    
411
  public void continueRotation(float angleInDegrees)
412
    {
413
    mRotationAngleStatic.set0(angleInDegrees);
414
    }
415

    
416
///////////////////////////////////////////////////////////////////////////////////////////////////
417

    
418
  public Static4D getRotationQuat()
419
      {
420
      return mQuat;
421
      }
422

    
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

    
425
  public void recomputeScaleFactor(int scrWidth, int scrHeight)
426
    {
427
    float factor = Math.min(scrWidth,scrHeight);
428
    mNodeScale.set(factor,NODE_RATIO*factor,factor);
429
    }
430

    
431
///////////////////////////////////////////////////////////////////////////////////////////////////
432

    
433
  public void savePreferences(SharedPreferences.Editor editor)
434
    {
435
    for(int i=0; i<NUM_CUBITS; i++) CUBITS[i].savePreferences(editor);
436
    }
437

    
438
///////////////////////////////////////////////////////////////////////////////////////////////////
439

    
440
  public synchronized void restorePreferences(SharedPreferences preferences)
441
    {
442
    for(int i=0; i<NUM_CUBITS; i++)
443
      {
444
      int index = CUBITS[i].restorePreferences(preferences);
445
      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index);
446
      }
447
    }
448

    
449
///////////////////////////////////////////////////////////////////////////////////////////////////
450

    
451
  public void releaseResources()
452
    {
453
    mTexture.markForDeletion();
454
    }
455

    
456
///////////////////////////////////////////////////////////////////////////////////////////////////
457

    
458
  public void apply(Effect effect, int position)
459
    {
460
    mEffects.apply(effect, position);
461
    }
462

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

    
465
  public void remove(long effectID)
466
    {
467
    mEffects.abortById(effectID);
468
    }
469

    
470
///////////////////////////////////////////////////////////////////////////////////////////////////
471

    
472
  public synchronized void solve()
473
    {
474
    for(int i=0; i<NUM_CUBITS; i++)
475
      {
476
      CUBITS[i].solve();
477
      mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(), 0);
478
      }
479
    }
480

    
481
///////////////////////////////////////////////////////////////////////////////////////////////////
482

    
483
  public void resetAllTextureMaps()
484
    {
485
    final float ratio = 1.0f/(NUM_FACES+1);
486
    int color;
487

    
488
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
489
      {
490
      final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
491

    
492
      for(int cubitface=0; cubitface<NUM_CUBIT_FACES; cubitface++)
493
        {
494
        color = getFaceColor(cubit,cubitface,mSize);
495
        maps[cubitface] = new Static4D( color*ratio, 0.0f, ratio, 1.0f);
496
        }
497

    
498
      mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
499
      }
500
    }
501

    
502
///////////////////////////////////////////////////////////////////////////////////////////////////
503

    
504
  public void setTextureMap(int cubit, int face, int newColor)
505
    {
506
    final float ratio = 1.0f/(NUM_FACES+1);
507
    final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
508

    
509
    maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f);
510
    mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
511
    }
512

    
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514

    
515
  public synchronized void beginNewRotation(int axis, int row )
516
    {
517
    if( axis<0 || axis>=ROTATION_AXIS.length )
518
      {
519
      android.util.Log.e("object", "invalid rotation axis: "+axis);
520
      return;
521
      }
522
    if( row<0 || row>=mSize )
523
      {
524
      android.util.Log.e("object", "invalid rotation row: "+row);
525
      return;
526
      }
527

    
528
    mRotAxis     = axis;
529
    mRotRowBitmap= (1<<row);
530
    mRotationAngleStatic.set0(0.0f);
531
    mRotationAxis.set( ROTATION_AXIS[axis] );
532
    mRotationAngle.add(mRotationAngleStatic);
533
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
534
    }
535

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

    
538
  public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
539
    {
540
    mRotAxis     = axis;
541
    mRotRowBitmap= rowBitmap;
542

    
543
    mRotationAngleStatic.set0(0.0f);
544
    mRotationAxis.set( ROTATION_AXIS[axis] );
545
    mRotationAngle.setDuration(durationMillis);
546
    mRotationAngle.resetToBeginning();
547
    mRotationAngle.add(new Static1D(0));
548
    mRotationAngle.add(new Static1D(angle));
549
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
550
    mRotateEffect.notifyWhenFinished(listener);
551

    
552
    return mRotateEffect.getID();
553
    }
554

    
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556

    
557
  public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
558
    {
559
    float angle = getAngle();
560
    mRotationAngleStatic.set0(angle);
561
    mRotationAngleFinal.set0(nearestAngleInDegrees);
562
    mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
563

    
564
    mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
565
    mRotationAngle.resetToBeginning();
566
    mRotationAngle.removeAll();
567
    mRotationAngle.add(mRotationAngleStatic);
568
    mRotationAngle.add(mRotationAngleMiddle);
569
    mRotationAngle.add(mRotationAngleFinal);
570
    mRotateEffect.notifyWhenFinished(listener);
571

    
572
    return mRotateEffect.getID();
573
    }
574

    
575

    
576
///////////////////////////////////////////////////////////////////////////////////////////////////
577

    
578
  private float getAngle()
579
    {
580
    int pointNum = mRotationAngle.getNumPoints();
581

    
582
    if( pointNum>=1 )
583
      {
584
      return mRotationAngle.getPoint(pointNum-1).get0();
585
      }
586
    else
587
      {
588
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
589
      crashlytics.log("points in RotationAngle: "+pointNum);
590
      return 0;
591
      }
592
    }
593

    
594
///////////////////////////////////////////////////////////////////////////////////////////////////
595

    
596
  public synchronized void removeRotationNow()
597
    {
598
    float angle = getAngle();
599
    double nearestAngleInRadians = angle*Math.PI/180;
600
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
601
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
602
    float axisX = ROTATION_AXIS[mRotAxis].get0();
603
    float axisY = ROTATION_AXIS[mRotAxis].get1();
604
    float axisZ = ROTATION_AXIS[mRotAxis].get2();
605
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
606

    
607
    mRotationAngle.removeAll();
608
    mRotationAngleStatic.set0(0);
609

    
610
    for(int i=0; i<NUM_CUBITS; i++)
611
      if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
612
        {
613
        int index = CUBITS[i].removeRotationNow(quat);
614
        mMesh.setEffectAssociation(i, CUBITS[i].computeAssociation(),index);
615
        }
616
    }
617

    
618
///////////////////////////////////////////////////////////////////////////////////////////////////
619

    
620
  public void initializeObject(int[][] moves)
621
    {
622
    solve();
623
    setupPosition(moves);
624
    }
625

    
626
///////////////////////////////////////////////////////////////////////////////////////////////////
627

    
628
  public int getCubit(float[] point3D)
629
    {
630
    float dist, minDist = Float.MAX_VALUE;
631
    int currentBest=-1;
632
    float multiplier = returnMultiplier();
633

    
634
    point3D[0] *= multiplier;
635
    point3D[1] *= multiplier;
636
    point3D[2] *= multiplier;
637

    
638
    for(int i=0; i<NUM_CUBITS; i++)
639
      {
640
      dist = CUBITS[i].getDistSquared(point3D);
641
      if( dist<minDist )
642
        {
643
        minDist = dist;
644
        currentBest = i;
645
        }
646
      }
647

    
648
    return currentBest;
649
    }
650

    
651
///////////////////////////////////////////////////////////////////////////////////////////////////
652

    
653
  public int computeNearestAngle(float angle, float speed)
654
    {
655
    final int NEAREST = 360/getBasicAngle();
656

    
657
    int tmp = (int)((angle+NEAREST/2)/NEAREST);
658
    if( angle< -(NEAREST*0.5) ) tmp-=1;
659

    
660
    if( tmp!=0 ) return NEAREST*tmp;
661

    
662
    return speed> 1.2f ? NEAREST*(angle>0 ? 1:-1) : 0;
663
    }
664

    
665
///////////////////////////////////////////////////////////////////////////////////////////////////
666

    
667
  public int getNodeSize()
668
    {
669
    return mNodeSize;
670
    }
671

    
672
///////////////////////////////////////////////////////////////////////////////////////////////////
673

    
674
  public RubikObjectList getObjectList()
675
    {
676
    return mList;
677
    }
678

    
679
///////////////////////////////////////////////////////////////////////////////////////////////////
680

    
681
  abstract float getScreenRatio();
682
  abstract Static3D[] getCubitPositions(int size);
683
  abstract Static4D[] getQuats();
684
  abstract int getNumFaces();
685
  abstract int getNumCubitFaces();
686
  abstract MeshBase createCubitMesh(int cubit);
687
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
688
  abstract int getFaceColor(int cubit, int cubitface, int size);
689
  abstract float returnMultiplier();
690
  abstract float[] getRowChances();
691

    
692
  public abstract boolean isSolved();
693
  public abstract Static3D[] getRotationAxis();
694
  public abstract int getBasicAngle();
695
  public abstract int computeRowFromOffset(float offset);
696
  public abstract float returnRotationFactor(float offset);
697
  public abstract String retObjectString();
698
  public abstract int randomizeNewRotAxis(Random rnd, int oldRotAxis);
699
  public abstract int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis);
700
  }
(8-8/10)