Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / RubikObject.java @ ccf9fec5

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.MatrixEffectQuaternion;
32
import org.distorted.library.effect.MatrixEffectScale;
33
import org.distorted.library.effect.VertexEffectQuaternion;
34
import org.distorted.library.effect.VertexEffectRotate;
35
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedNode;
37
import org.distorted.library.main.DistortedTexture;
38
import org.distorted.library.mesh.MeshBase;
39
import org.distorted.library.mesh.MeshFile;
40
import org.distorted.library.mesh.MeshRectangles;
41
import org.distorted.library.message.EffectListener;
42
import org.distorted.library.type.Dynamic1D;
43
import org.distorted.library.type.Static1D;
44
import org.distorted.library.type.Static3D;
45
import org.distorted.library.type.Static4D;
46

    
47
import java.io.DataInputStream;
48
import java.io.IOException;
49
import java.io.InputStream;
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
public abstract class RubikObject extends DistortedNode
54
  {
55
  private static final Static3D CENTER = new Static3D(0,0,0);
56
  static final int INTERIOR_COLOR = 0xff000000;
57
  public static final int NODE_FBO_SIZE = 600;
58
  private static final int POST_ROTATION_MILLISEC = 500;
59
  private static final int TEXTURE_HEIGHT = 128;
60

    
61
  final Static3D[] ROTATION_AXIS;
62
  final Static4D[] QUATS;
63
  final int NUM_FACES;
64

    
65
  static float OBJECT_SCREEN_RATIO;
66

    
67
  private final int NUM_CUBITS;
68
  private int mRotRowBitmap;
69
  private int mRotAxis;
70
  private Static3D[] mOrigPos;
71
  private Static3D mNodeScale;
72
  private Static4D mQuatAccumulated;
73
  private Cubit[] mCubits;
74
  private int mSize;
75
  private RubikObjectList mList;
76
  private MeshBase mMesh;
77
  private DistortedEffects mEffects;
78
  private VertexEffectRotate mRotateEffect;
79
  private Dynamic1D mRotationAngle;
80
  private Static3D mRotationAxis;
81

    
82
  float mStart, mStep;
83

    
84
  Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
85
  DistortedTexture mTexture;
86

    
87
  MatrixEffectScale mScaleEffect;
88
  MatrixEffectQuaternion mQuatCEffect;
89
  MatrixEffectQuaternion mQuatAEffect;
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

    
93
  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture,
94
              MeshRectangles nodeMesh, DistortedEffects nodeEffects, int[][] moves, RubikObjectList list, Resources res)
95
    {
96
    super(nodeTexture,nodeEffects,nodeMesh);
97

    
98
    resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE);
99

    
100
    mList = list;
101
    mOrigPos = getCubitPositions(size);
102

    
103
    QUATS = getQuats();
104
    NUM_CUBITS  = mOrigPos.length;
105
    ROTATION_AXIS = getRotationAxis();
106
    OBJECT_SCREEN_RATIO = getScreenRatio();
107
    NUM_FACES = getNumFaces();
108

    
109
    mSize = size;
110
    computeStartAndStep(mOrigPos);
111
    mNodeScale= new Static3D(1,1,1);
112
    mQuatAccumulated = quatAcc;
113

    
114
    mRotationAngle= new Dynamic1D();
115
    mRotationAxis = new Static3D(1,0,0);
116
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
117

    
118
    mRotationAngleStatic = new Static1D(0);
119
    mRotationAngleMiddle = new Static1D(0);
120
    mRotationAngleFinal  = new Static1D(0);
121

    
122
    float scale = OBJECT_SCREEN_RATIO*NODE_FBO_SIZE/mSize;
123
    mScaleEffect = new MatrixEffectScale(new Static3D(scale,scale,scale));
124
    mQuatCEffect = new MatrixEffectQuaternion(quatCur, CENTER);
125
    mQuatAEffect = new MatrixEffectQuaternion(quatAcc, CENTER);
126

    
127
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
128
    nodeEffects.apply(nodeScaleEffect);
129

    
130
    mCubits = new Cubit[NUM_CUBITS];
131
    mTexture = new DistortedTexture();
132

    
133
    int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize);
134
    int resourceID= list.getResourceIDs()[sizeIndex];
135

    
136
    InputStream is = res.openRawResource(resourceID);
137
    DataInputStream dos = new DataInputStream(is);
138
    mMesh = new MeshFile(dos);
139

    
140
    try
141
      {
142
      is.close();
143
      }
144
    catch(IOException e)
145
      {
146
      android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
147
      }
148

    
149
    for(int i=0; i<NUM_CUBITS; i++)
150
      {
151
      mCubits[i] = new Cubit(this,mOrigPos[i]);
152
      mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
153
      }
154

    
155
    mEffects = new DistortedEffects();
156

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

    
165
    mEffects.apply(mRotateEffect);
166
    mEffects.apply(mQuatAEffect);
167
    mEffects.apply(mQuatCEffect);
168
    mEffects.apply(mScaleEffect);
169

    
170
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
171

    
172
    setupPosition(moves);
173

    
174
    setProjection(fov, 0.1f);
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178
// Cast centers of all Cubits on the first rotation Axis and compute the leftmost and rightmost
179
// one. From there compute the 'start' (i.e. the leftmost) and 'step' (i.e. distance between two
180
// consecutive).
181
// it is assumed that other rotation axis have the same 'start' and 'step' - this is the case with
182
// the Cube and the Pyraminx.
183
// Start and Step are then needed to compute which rotation row (with respect to a given axis) a
184
// given Cubit belongs to.
185

    
186
  private void computeStartAndStep(Static3D[] pos)
187
    {
188
    float min = Float.MAX_VALUE;
189
    float max = Float.MIN_VALUE;
190
    float axisX = ROTATION_AXIS[0].get0();
191
    float axisY = ROTATION_AXIS[0].get1();
192
    float axisZ = ROTATION_AXIS[0].get2();
193
    float tmp;
194

    
195
    for(int i=0; i<NUM_CUBITS; i++)
196
      {
197
      tmp = pos[i].get0()*axisX + pos[i].get1()*axisY + pos[i].get2()*axisZ;
198
      if( tmp<min ) min=tmp;
199
      if( tmp>max ) max=tmp;
200
      }
201

    
202
    mStart = min;
203
    mStep  = (max-min+1.0f)/mSize;
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
209
    {
210
    int cubitRow = (int)(mCubits[cubit].mRotationRow[axis]+0.5f);
211
    return ((1<<cubitRow)&rowBitmap)!=0;
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215
// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
216
// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
217
// away from the face of the Pyraminx shouldn't be textured.
218

    
219
  private boolean isOnFace( int cubit, int axis, int row)
220
    {
221
    final float MAX_ERROR = 0.0001f;
222
    float diff = mCubits[cubit].mRotationRow[axis] - row;
223
    return diff*diff < MAX_ERROR;
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
// note the minus in front of the sin() - we rotate counterclockwise
228
// when looking towards the direction where the axis increases in values.
229

    
230
  private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
231
    {
232
    Static3D axis = ROTATION_AXIS[axisIndex];
233

    
234
    while( angleInDegrees<0 ) angleInDegrees += 360;
235
    angleInDegrees %= 360;
236
    
237
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
238
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
239

    
240
    return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA);
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  private void setupPosition(int[][] moves)
246
    {
247
    if( moves!=null )
248
      {
249
      Static4D quat;
250
      int index, axis, rowBitmap, angle;
251
      int corr = (360/getBasicAngle());
252

    
253
      for(int[] move: moves)
254
        {
255
        axis     = move[0];
256
        rowBitmap= move[1];
257
        angle    = move[2]*corr;
258
        quat     = makeQuaternion(axis,angle);
259

    
260
        for(int j=0; j<NUM_CUBITS; j++)
261
          if( belongsToRotation(j,axis,rowBitmap) )
262
            {
263
            index = mCubits[j].removeRotationNow(quat);
264
            mMesh.setEffectAssociation(j,mCubits[j].computeAssociation(),index);
265
            }
266
        }
267
      }
268
    }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
  int getCubitFaceColorIndex(int cubit, int face)
273
    {
274
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
275
    return (int)(texMap.get0() / texMap.get2());
276
    }
277

    
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
280

    
281
  void clampPos(Static3D pos)
282
    {
283
    float currError, minError = Float.MAX_VALUE;
284
    int minErrorIndex= -1;
285
    float x = pos.get0();
286
    float y = pos.get1();
287
    float z = pos.get2();
288
    float xo,yo,zo;
289

    
290
    for(int i=0; i<NUM_CUBITS; i++)
291
      {
292
      xo = mOrigPos[i].get0();
293
      yo = mOrigPos[i].get1();
294
      zo = mOrigPos[i].get2();
295

    
296
      currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
297

    
298
      if( currError<minError )
299
        {
300
        minError = currError;
301
        minErrorIndex = i;
302
        }
303
      }
304

    
305
    pos.set( mOrigPos[minErrorIndex] );
306
    }
307

    
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309
// the getFaceColors + final black in a horizontal strip.
310

    
311
  public void createTexture()
312
    {
313
    Bitmap bitmap;
314

    
315
    Paint paint = new Paint();
316
    bitmap = Bitmap.createBitmap( (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
317
    Canvas canvas = new Canvas(bitmap);
318

    
319
    paint.setAntiAlias(true);
320
    paint.setTextAlign(Paint.Align.CENTER);
321
    paint.setStyle(Paint.Style.FILL);
322

    
323
    paint.setColor(INTERIOR_COLOR);
324
    canvas.drawRect(0, 0, (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
325

    
326
    for(int i=0; i<NUM_FACES; i++)
327
      {
328
      createFaceTexture(canvas, paint, i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
329
      }
330

    
331
    mTexture.setTexture(bitmap);
332
    }
333

    
334
///////////////////////////////////////////////////////////////////////////////////////////////////
335

    
336
  public int getSize()
337
    {
338
    return mSize;
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342

    
343
  public void continueRotation(float angleInDegrees)
344
    {
345
    mRotationAngleStatic.set0(angleInDegrees);
346
    }
347

    
348
///////////////////////////////////////////////////////////////////////////////////////////////////
349

    
350
  public Static4D getRotationQuat()
351
      {
352
      return mQuatAccumulated;
353
      }
354

    
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

    
357
  public void recomputeScaleFactor(int scrWidth, int scrHeight)
358
    {
359
    float factor = Math.min(scrWidth,scrHeight);
360
    mNodeScale.set(factor,factor,factor);
361
    }
362

    
363
///////////////////////////////////////////////////////////////////////////////////////////////////
364

    
365
  public void savePreferences(SharedPreferences.Editor editor)
366
    {
367
    for(int i=0; i<NUM_CUBITS; i++) mCubits[i].savePreferences(editor);
368
    }
369

    
370
///////////////////////////////////////////////////////////////////////////////////////////////////
371

    
372
  public void restorePreferences(SharedPreferences preferences)
373
    {
374
    for(int i=0; i<NUM_CUBITS; i++)
375
      {
376
      int index = mCubits[i].restorePreferences(preferences);
377
      mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
378
      }
379
    }
380

    
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382

    
383
  public void releaseResources()
384
    {
385
    mTexture.markForDeletion();
386
    }
387

    
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389

    
390
  public void apply(Effect effect, int position)
391
    {
392
    mEffects.apply(effect, position);
393
    }
394

    
395
///////////////////////////////////////////////////////////////////////////////////////////////////
396

    
397
  public void remove(long effectID)
398
    {
399
    mEffects.abortById(effectID);
400
    }
401

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

    
404
  public void solve()
405
    {
406
    for(int i=0; i<NUM_CUBITS; i++)
407
      {
408
      mCubits[i].solve();
409
      mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
410
      }
411
    }
412

    
413
///////////////////////////////////////////////////////////////////////////////////////////////////
414

    
415
  public boolean isSolved()
416
    {
417
    int index = mCubits[0].mQuatIndex;
418

    
419
    for(int i=1; i<NUM_CUBITS; i++)
420
      {
421
      if( !mCubits[i].thereIsNoVisibleDifference(index) ) return false;
422
      }
423

    
424
    return true;
425
    }
426

    
427
///////////////////////////////////////////////////////////////////////////////////////////////////
428

    
429
  public void resetAllTextureMaps()
430
    {
431
    boolean belongs;
432
    final float ratio = 1.0f/(NUM_FACES+1);
433

    
434
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
435
      {
436
      final Static4D[] maps = new Static4D[NUM_FACES];
437

    
438
      if( 2*ROTATION_AXIS.length == NUM_FACES )  // i.e. there are faces on both ends of the axis (cube)
439
        {
440
        for(int i=0; i<NUM_FACES; i++)
441
          {
442
          belongs = isOnFace(cubit, i/2, i%2==0 ? mSize-1:0 );
443
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
444
          }
445
        }
446
      else if( ROTATION_AXIS.length == NUM_FACES )  // just a single face on the right end of an axis (pyraminx)
447
        {
448
        for(int i=0; i<NUM_FACES; i++)
449
          {
450
          belongs = isOnFace(cubit, i, 0 );
451
          maps[i] = new Static4D( (belongs?i:NUM_FACES)*ratio, 0.0f, ratio, 1.0f);
452
          }
453
        }
454

    
455
      mMesh.setTextureMap(maps,NUM_FACES*cubit);
456
      }
457
    }
458

    
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460

    
461
  public void setTextureMap(int cubit, int face, int newColor)
462
    {
463
    final float ratio = 1.0f/(NUM_FACES+1);
464
    final Static4D[] maps = new Static4D[NUM_FACES];
465

    
466
    try
467
      {
468
      maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f);
469
      mMesh.setTextureMap(maps,NUM_FACES*cubit);
470
      }
471
    catch(ArrayIndexOutOfBoundsException ignored)
472
      {
473
      // the object must have changed in between of us touching the screen and getting here
474
      // (which happens after the next render, i.e. about 30 miliseconds later)
475
      // ignore.
476
      }
477
    }
478

    
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480

    
481
  public void beginNewRotation(int axis, int row )
482
    {
483
    if( axis<0 || axis>=ROTATION_AXIS.length )
484
      {
485
      android.util.Log.e("object", "invalid rotation axis: "+axis);
486
      return;
487
      }
488
    if( row<0 || row>=mSize )
489
      {
490
      android.util.Log.e("object", "invalid rotation row: "+row);
491
      return;
492
      }
493

    
494
    mRotAxis     = axis;
495
    mRotRowBitmap= (1<<row);
496
    mRotationAngleStatic.set0(0.0f);
497
    mRotationAxis.set( ROTATION_AXIS[axis] );
498
    mRotationAngle.add(mRotationAngleStatic);
499
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
500
    }
501

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

    
504
  public long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
505
    {
506
    mRotAxis     = axis;
507
    mRotRowBitmap= rowBitmap;
508

    
509
    mRotationAngleStatic.set0(0.0f);
510
    mRotationAxis.set( ROTATION_AXIS[axis] );
511
    mRotationAngle.setDuration(durationMillis);
512
    mRotationAngle.resetToBeginning();
513
    mRotationAngle.add(new Static1D(0));
514
    mRotationAngle.add(new Static1D(angle));
515
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
516
    mRotateEffect.notifyWhenFinished(listener);
517

    
518
    return mRotateEffect.getID();
519
    }
520

    
521
///////////////////////////////////////////////////////////////////////////////////////////////////
522

    
523
  public long finishRotationNow(EffectListener listener)
524
    {
525
    float angle = getAngle();
526
    int nearestAngleInDegrees = computeNearestAngle(angle);
527
    mRotationAngleStatic.set0(angle);
528
    mRotationAngleFinal.set0(nearestAngleInDegrees);
529
    mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
530

    
531
    mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
532
    mRotationAngle.resetToBeginning();
533
    mRotationAngle.removeAll();
534
    mRotationAngle.add(mRotationAngleStatic);
535
    mRotationAngle.add(mRotationAngleMiddle);
536
    mRotationAngle.add(mRotationAngleFinal);
537
    mRotateEffect.notifyWhenFinished(listener);
538

    
539
    return mRotateEffect.getID();
540
    }
541

    
542

    
543
///////////////////////////////////////////////////////////////////////////////////////////////////
544

    
545
  private float getAngle()
546
    {
547
    int pointNum = mRotationAngle.getNumPoints();
548

    
549
    if( pointNum>=1 )
550
      {
551
      return mRotationAngle.getPoint(pointNum-1).get0();
552
      }
553
    else
554
      {
555
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
556
      crashlytics.log("points in RotationAngle: "+pointNum);
557
      return 0;
558
      }
559
    }
560

    
561
///////////////////////////////////////////////////////////////////////////////////////////////////
562

    
563
  public void removeRotationNow()
564
     {
565
     float angle = getAngle();
566
     int nearestAngleInDegrees = computeNearestAngle(angle);
567
     double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180;
568
     float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
569
     float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
570
     float axisX = ROTATION_AXIS[mRotAxis].get0();
571
     float axisY = ROTATION_AXIS[mRotAxis].get1();
572
     float axisZ = ROTATION_AXIS[mRotAxis].get2();
573
     Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
574

    
575
     mRotationAngle.removeAll();
576
     mRotationAngleStatic.set0(0);
577

    
578
     for(int i=0; i<NUM_CUBITS; i++)
579
       if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
580
         {
581
         int index = mCubits[i].removeRotationNow(quat);
582
         mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
583
         }
584
     }
585

    
586
///////////////////////////////////////////////////////////////////////////////////////////////////
587

    
588
  public void initializeObject(int[][] moves)
589
    {
590
    solve();
591
    setupPosition(moves);
592
    }
593

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

    
596
  public int getCubit(float[] point3D)
597
    {
598
    float dist, minDist = Float. MAX_VALUE;
599
    int currentBest=-1;
600
    float multiplier = returnMultiplier();
601

    
602
    point3D[0] *= multiplier;
603
    point3D[1] *= multiplier;
604
    point3D[2] *= multiplier;
605

    
606
    for(int i=0; i<NUM_CUBITS; i++)
607
      {
608
      dist = mCubits[i].getDistSquared(point3D);
609
      if( dist<minDist )
610
        {
611
        minDist = dist;
612
        currentBest = i;
613
        }
614
      }
615

    
616
    return currentBest;
617
    }
618

    
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620

    
621
  public int computeNearestAngle(float angle)
622
    {
623
    final int NEAREST = 360/getBasicAngle();
624

    
625
    int tmp = (int)((angle+NEAREST/2)/NEAREST);
626
    if( angle< -(NEAREST*0.5) ) tmp-=1;
627

    
628
    return NEAREST*tmp;
629
    }
630

    
631
///////////////////////////////////////////////////////////////////////////////////////////////////
632

    
633
  public RubikObjectList getObjectList()
634
    {
635
    return mList;
636
    }
637

    
638
///////////////////////////////////////////////////////////////////////////////////////////////////
639

    
640
  abstract float getScreenRatio();
641
  abstract Static3D[] getCubitPositions(int size);
642
  abstract Static4D[] getQuats();
643
  abstract int getNumFaces();
644
  abstract MeshBase createCubitMesh(int cubit);
645
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
646
  public abstract Static3D[] getRotationAxis();
647
  public abstract int getBasicAngle();
648
  public abstract float returnMultiplier();
649
  public abstract float returnRotationFactor(float offset);
650
  public abstract String retObjectString();
651
  public abstract float[] getRowChances();
652
  }
(4-4/8)