Project

General

Profile

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

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

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

    
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

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

    
61
  private static boolean mCreateFromDMesh = false;
62

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

    
68
  final Static3D[] ROTATION_AXIS;
69
  final Static4D[] QUATS;
70
  final int NUM_FACES;
71
  final int NUM_CUBIT_FACES;
72

    
73
  private static float mInitScreenRatio,mObjectScreenRatio;
74

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

    
92
  float mStart, mStep;
93

    
94
  Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
95
  DistortedTexture mTexture;
96

    
97
  MatrixEffectScale mScaleEffect;
98
  MatrixEffectQuaternion mQuatEffect;
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

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

    
107
    mNodeSize = screenWidth;
108

    
109
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
110

    
111
    mList = list;
112
    mOrigPos = getCubitPositions(size);
113

    
114
    QUATS = getQuats();
115
    NUM_CUBITS  = mOrigPos.length;
116
    ROTATION_AXIS = getRotationAxis();
117
    mObjectScreenRatio = getScreenRatio();
118
    mInitScreenRatio = mObjectScreenRatio;
119
    NUM_FACES = getNumFaces();
120
    NUM_CUBIT_FACES = getNumCubitFaces();
121

    
122
    mSize = size;
123
    computeStartAndStep(mOrigPos);
124
    mNodeScale= new Static3D(1,NODE_RATIO,1);
125
    mQuat = quat;
126

    
127
    mRotationAngle= new Dynamic1D();
128
    mRotationAxis = new Static3D(1,0,0);
129
    mRotateEffect = new VertexEffectRotate(mRotationAngle, mRotationAxis, CENTER);
130

    
131
    mRotationAngleStatic = new Static1D(0);
132
    mRotationAngleMiddle = new Static1D(0);
133
    mRotationAngleFinal  = new Static1D(0);
134

    
135
    float scale  = mObjectScreenRatio*mNodeSize/mSize;
136
    mObjectScale = new Static3D(scale,scale,scale);
137
    mScaleEffect = new MatrixEffectScale(mObjectScale);
138
    mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
139

    
140
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
141
    nodeEffects.apply(nodeScaleEffect);
142

    
143
    createMeshAndCubits(list,res);
144

    
145
    mTexture = new DistortedTexture();
146
    mEffects = new DistortedEffects();
147

    
148
    int num_quats = QUATS.length;
149
    for(int q=0; q<num_quats; q++)
150
      {
151
      VertexEffectQuaternion vq = new VertexEffectQuaternion(QUATS[q],CENTER);
152
      vq.setMeshAssociation(0,q);
153
      mEffects.apply(vq);
154
      }
155

    
156
    mEffects.apply(mRotateEffect);
157
    mEffects.apply(mQuatEffect);
158
    mEffects.apply(mScaleEffect);
159

    
160
    attach( new DistortedNode(mTexture,mEffects,mMesh) );
161

    
162
    setupPosition(moves);
163

    
164
    setProjection(fov, 0.1f);
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  private void createMeshAndCubits(RubikObjectList list, Resources res)
170
    {
171
    mCubits = new Cubit[NUM_CUBITS];
172

    
173
    if( mCreateFromDMesh )
174
      {
175
      int sizeIndex = RubikObjectList.getSizeIndex(list.ordinal(),mSize);
176
      int resourceID= list.getResourceIDs()[sizeIndex];
177

    
178
      InputStream is = res.openRawResource(resourceID);
179
      DataInputStream dos = new DataInputStream(is);
180
      mMesh = new MeshFile(dos);
181

    
182
      try
183
        {
184
        is.close();
185
        }
186
      catch(IOException e)
187
        {
188
        android.util.Log.e("meshFile", "Error closing InputStream: "+e.toString());
189
        }
190

    
191
      for(int i=0; i<NUM_CUBITS; i++)
192
        {
193
        mCubits[i] = new Cubit(this,mOrigPos[i]);
194
        mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
195
        }
196
      }
197
    else
198
      {
199
      MeshBase[] cubitMesh = new MeshBase[NUM_CUBITS];
200

    
201
      for(int i=0; i<NUM_CUBITS; i++)
202
        {
203
        mCubits[i] = new Cubit(this,mOrigPos[i]);
204
        cubitMesh[i] = createCubitMesh(i);
205
        cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0);
206
        cubitMesh[i].setEffectAssociation(0, mCubits[i].computeAssociation(), 0);
207
        }
208

    
209
      mMesh = new MeshJoined(cubitMesh);
210
      resetAllTextureMaps();
211
      }
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  public void setObjectRatio(float sizeChange)
217
    {
218
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
219

    
220
    if( mObjectScreenRatio > MAX_SIZE_CHANGE*mInitScreenRatio)
221
      {
222
      mObjectScreenRatio = MAX_SIZE_CHANGE*mInitScreenRatio;
223
      }
224
    if( mObjectScreenRatio < MIN_SIZE_CHANGE*mInitScreenRatio)
225
      {
226
      mObjectScreenRatio = MIN_SIZE_CHANGE*mInitScreenRatio;
227
      }
228

    
229
    float scale = mObjectScreenRatio*mNodeSize/mSize;
230
    mObjectScale.set(scale,scale,scale);
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  static float getObjectRatio()
236
    {
237
    return mObjectScreenRatio;
238
    }
239

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

    
249
  private void computeStartAndStep(Static3D[] pos)
250
    {
251
    float min = Float.MAX_VALUE;
252
    float max = Float.MIN_VALUE;
253
    float axisX = ROTATION_AXIS[0].get0();
254
    float axisY = ROTATION_AXIS[0].get1();
255
    float axisZ = ROTATION_AXIS[0].get2();
256
    float tmp;
257

    
258
    for(int i=0; i<NUM_CUBITS; i++)
259
      {
260
      tmp = pos[i].get0()*axisX + pos[i].get1()*axisY + pos[i].get2()*axisZ;
261
      if( tmp<min ) min=tmp;
262
      if( tmp>max ) max=tmp;
263
      }
264

    
265
    mStart = min;
266
    mStep  = (max-min+1.0f)/mSize;
267
    }
268

    
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270

    
271
  private boolean belongsToRotation( int cubit, int axis, int rowBitmap)
272
    {
273
    int cubitRow = (int)(mCubits[cubit].mRotationRow[axis]+0.5f);
274
    return ((1<<cubitRow)&rowBitmap)!=0;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278
// note the minus in front of the sin() - we rotate counterclockwise
279
// when looking towards the direction where the axis increases in values.
280

    
281
  private Static4D makeQuaternion(int axisIndex, int angleInDegrees)
282
    {
283
    Static3D axis = ROTATION_AXIS[axisIndex];
284

    
285
    while( angleInDegrees<0 ) angleInDegrees += 360;
286
    angleInDegrees %= 360;
287
    
288
    float cosA = (float)Math.cos(Math.PI*angleInDegrees/360);
289
    float sinA =-(float)Math.sqrt(1-cosA*cosA);
290

    
291
    return new Static4D(axis.get0()*sinA, axis.get1()*sinA, axis.get2()*sinA, cosA);
292
    }
293

    
294
///////////////////////////////////////////////////////////////////////////////////////////////////
295

    
296
  private synchronized void setupPosition(int[][] moves)
297
    {
298
    if( moves!=null )
299
      {
300
      Static4D quat;
301
      int index, axis, rowBitmap, angle;
302
      int corr = (360/getBasicAngle());
303

    
304
      for(int[] move: moves)
305
        {
306
        axis     = move[0];
307
        rowBitmap= move[1];
308
        angle    = move[2]*corr;
309
        quat     = makeQuaternion(axis,angle);
310

    
311
        for(int j=0; j<NUM_CUBITS; j++)
312
          if( belongsToRotation(j,axis,rowBitmap) )
313
            {
314
            index = mCubits[j].removeRotationNow(quat);
315
            mMesh.setEffectAssociation(j,mCubits[j].computeAssociation(),index);
316
            }
317
        }
318
      }
319
    }
320

    
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
// we cannot use belongsToRotation for deciding if to texture a face. Counterexample: the 'rotated'
323
// tetrahedrons of Pyraminx nearby the edge: they belong to rotation but their face which is rotated
324
// away from the face of the Pyraminx shouldn't be textured.
325

    
326
  boolean isOnFace( int cubit, int axis, int row)
327
    {
328
    final float MAX_ERROR = 0.0001f;
329
    float diff = mCubits[cubit].mRotationRow[axis] - row;
330
    return diff*diff < MAX_ERROR;
331
    }
332

    
333
///////////////////////////////////////////////////////////////////////////////////////////////////
334

    
335
  int getCubitFaceColorIndex(int cubit, int face)
336
    {
337
    Static4D texMap = mMesh.getTextureMap(NUM_FACES*cubit + face);
338
    return (int)(texMap.get0() / texMap.get2());
339
    }
340

    
341
///////////////////////////////////////////////////////////////////////////////////////////////////
342
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
343

    
344
  void clampPos(Static3D pos)
345
    {
346
    float currError, minError = Float.MAX_VALUE;
347
    int minErrorIndex= -1;
348
    float x = pos.get0();
349
    float y = pos.get1();
350
    float z = pos.get2();
351
    float xo,yo,zo;
352

    
353
    for(int i=0; i<NUM_CUBITS; i++)
354
      {
355
      xo = mOrigPos[i].get0();
356
      yo = mOrigPos[i].get1();
357
      zo = mOrigPos[i].get2();
358

    
359
      currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z);
360

    
361
      if( currError<minError )
362
        {
363
        minError = currError;
364
        minErrorIndex = i;
365
        }
366
      }
367

    
368
    pos.set( mOrigPos[minErrorIndex] );
369
    }
370

    
371
///////////////////////////////////////////////////////////////////////////////////////////////////
372
// the getFaceColors + final black in a horizontal strip.
373

    
374
  public void createTexture()
375
    {
376
    Bitmap bitmap;
377

    
378
    Paint paint = new Paint();
379
    bitmap = Bitmap.createBitmap( (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
380
    Canvas canvas = new Canvas(bitmap);
381

    
382
    paint.setAntiAlias(true);
383
    paint.setTextAlign(Paint.Align.CENTER);
384
    paint.setStyle(Paint.Style.FILL);
385

    
386
    paint.setColor(INTERIOR_COLOR);
387
    canvas.drawRect(0, 0, (NUM_FACES+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
388

    
389
    for(int i=0; i<NUM_FACES; i++)
390
      {
391
      createFaceTexture(canvas, paint, i, i*TEXTURE_HEIGHT, 0, TEXTURE_HEIGHT);
392
      }
393

    
394
    mTexture.setTexture(bitmap);
395
    }
396

    
397
///////////////////////////////////////////////////////////////////////////////////////////////////
398

    
399
  public int getSize()
400
    {
401
    return mSize;
402
    }
403

    
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

    
406
  public void continueRotation(float angleInDegrees)
407
    {
408
    mRotationAngleStatic.set0(angleInDegrees);
409
    }
410

    
411
///////////////////////////////////////////////////////////////////////////////////////////////////
412

    
413
  public Static4D getRotationQuat()
414
      {
415
      return mQuat;
416
      }
417

    
418
///////////////////////////////////////////////////////////////////////////////////////////////////
419

    
420
  public void recomputeScaleFactor(int scrWidth, int scrHeight)
421
    {
422
    float factor = Math.min(scrWidth,scrHeight);
423
    mNodeScale.set(factor,NODE_RATIO*factor,factor);
424
    }
425

    
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427

    
428
  public void savePreferences(SharedPreferences.Editor editor)
429
    {
430
    for(int i=0; i<NUM_CUBITS; i++) mCubits[i].savePreferences(editor);
431
    }
432

    
433
///////////////////////////////////////////////////////////////////////////////////////////////////
434

    
435
  public synchronized void restorePreferences(SharedPreferences preferences)
436
    {
437
    for(int i=0; i<NUM_CUBITS; i++)
438
      {
439
      int index = mCubits[i].restorePreferences(preferences);
440
      mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
441
      }
442
    }
443

    
444
///////////////////////////////////////////////////////////////////////////////////////////////////
445

    
446
  public void releaseResources()
447
    {
448
    mTexture.markForDeletion();
449
    }
450

    
451
///////////////////////////////////////////////////////////////////////////////////////////////////
452

    
453
  public void apply(Effect effect, int position)
454
    {
455
    mEffects.apply(effect, position);
456
    }
457

    
458
///////////////////////////////////////////////////////////////////////////////////////////////////
459

    
460
  public void remove(long effectID)
461
    {
462
    mEffects.abortById(effectID);
463
    }
464

    
465
///////////////////////////////////////////////////////////////////////////////////////////////////
466

    
467
  public synchronized void solve()
468
    {
469
    for(int i=0; i<NUM_CUBITS; i++)
470
      {
471
      mCubits[i].solve();
472
      mMesh.setEffectAssociation(i, mCubits[i].computeAssociation(), 0);
473
      }
474
    }
475

    
476
///////////////////////////////////////////////////////////////////////////////////////////////////
477

    
478
  public boolean isSolved()
479
    {
480
    int index = mCubits[0].mQuatIndex;
481

    
482
    for(int i=1; i<NUM_CUBITS; i++)
483
      {
484
      if( !mCubits[i].thereIsNoVisibleDifference(index) ) return false;
485
      }
486

    
487
    return true;
488
    }
489

    
490
///////////////////////////////////////////////////////////////////////////////////////////////////
491

    
492
  public void resetAllTextureMaps()
493
    {
494
    final float ratio = 1.0f/(NUM_FACES+1);
495
    int color;
496

    
497
    for(int cubit=0; cubit<NUM_CUBITS; cubit++)
498
      {
499
      final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
500

    
501
      for(int cubitface=0; cubitface<NUM_CUBIT_FACES; cubitface++)
502
        {
503
        color = getFaceColor(cubit,cubitface,mSize);
504
        maps[cubitface] = new Static4D( color*ratio, 0.0f, ratio, 1.0f);
505
        }
506

    
507
      mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
508
      }
509
    }
510

    
511
///////////////////////////////////////////////////////////////////////////////////////////////////
512

    
513
  public void setTextureMap(int cubit, int face, int newColor)
514
    {
515
    final float ratio = 1.0f/(NUM_FACES+1);
516
    final Static4D[] maps = new Static4D[NUM_CUBIT_FACES];
517

    
518
    maps[face] = new Static4D( newColor*ratio, 0.0f, ratio, 1.0f);
519
    mMesh.setTextureMap(maps,NUM_CUBIT_FACES*cubit);
520
    }
521

    
522
///////////////////////////////////////////////////////////////////////////////////////////////////
523

    
524
  public synchronized void beginNewRotation(int axis, int row )
525
    {
526
    if( axis<0 || axis>=ROTATION_AXIS.length )
527
      {
528
      android.util.Log.e("object", "invalid rotation axis: "+axis);
529
      return;
530
      }
531
    if( row<0 || row>=mSize )
532
      {
533
      android.util.Log.e("object", "invalid rotation row: "+row);
534
      return;
535
      }
536

    
537
    mRotAxis     = axis;
538
    mRotRowBitmap= (1<<row);
539
    mRotationAngleStatic.set0(0.0f);
540
    mRotationAxis.set( ROTATION_AXIS[axis] );
541
    mRotationAngle.add(mRotationAngleStatic);
542
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
543
    }
544

    
545
///////////////////////////////////////////////////////////////////////////////////////////////////
546

    
547
  public synchronized long addNewRotation( int axis, int rowBitmap, int angle, long durationMillis, EffectListener listener )
548
    {
549
    mRotAxis     = axis;
550
    mRotRowBitmap= rowBitmap;
551

    
552
    mRotationAngleStatic.set0(0.0f);
553
    mRotationAxis.set( ROTATION_AXIS[axis] );
554
    mRotationAngle.setDuration(durationMillis);
555
    mRotationAngle.resetToBeginning();
556
    mRotationAngle.add(new Static1D(0));
557
    mRotationAngle.add(new Static1D(angle));
558
    mRotateEffect.setMeshAssociation( mRotRowBitmap<<(axis*RubikObjectList.MAX_OBJECT_SIZE) , -1);
559
    mRotateEffect.notifyWhenFinished(listener);
560

    
561
    return mRotateEffect.getID();
562
    }
563

    
564
///////////////////////////////////////////////////////////////////////////////////////////////////
565

    
566
  public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
567
    {
568
    float angle = getAngle();
569
    mRotationAngleStatic.set0(angle);
570
    mRotationAngleFinal.set0(nearestAngleInDegrees);
571
    mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
572

    
573
    mRotationAngle.setDuration(POST_ROTATION_MILLISEC);
574
    mRotationAngle.resetToBeginning();
575
    mRotationAngle.removeAll();
576
    mRotationAngle.add(mRotationAngleStatic);
577
    mRotationAngle.add(mRotationAngleMiddle);
578
    mRotationAngle.add(mRotationAngleFinal);
579
    mRotateEffect.notifyWhenFinished(listener);
580

    
581
    return mRotateEffect.getID();
582
    }
583

    
584

    
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586

    
587
  private float getAngle()
588
    {
589
    int pointNum = mRotationAngle.getNumPoints();
590

    
591
    if( pointNum>=1 )
592
      {
593
      return mRotationAngle.getPoint(pointNum-1).get0();
594
      }
595
    else
596
      {
597
      FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance();
598
      crashlytics.log("points in RotationAngle: "+pointNum);
599
      return 0;
600
      }
601
    }
602

    
603
///////////////////////////////////////////////////////////////////////////////////////////////////
604

    
605
  public synchronized void removeRotationNow()
606
    {
607
    float angle = getAngle();
608
    double nearestAngleInRadians = angle*Math.PI/180;
609
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
610
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
611
    float axisX = ROTATION_AXIS[mRotAxis].get0();
612
    float axisY = ROTATION_AXIS[mRotAxis].get1();
613
    float axisZ = ROTATION_AXIS[mRotAxis].get2();
614
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
615

    
616
    mRotationAngle.removeAll();
617
    mRotationAngleStatic.set0(0);
618

    
619
    for(int i=0; i<NUM_CUBITS; i++)
620
      if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
621
        {
622
        int index = mCubits[i].removeRotationNow(quat);
623
        mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
624
        }
625
    }
626

    
627
///////////////////////////////////////////////////////////////////////////////////////////////////
628

    
629
  public void initializeObject(int[][] moves)
630
    {
631
    solve();
632
    setupPosition(moves);
633
    }
634

    
635
///////////////////////////////////////////////////////////////////////////////////////////////////
636

    
637
  public int getCubit(float[] point3D)
638
    {
639
    float dist, minDist = Float.MAX_VALUE;
640
    int currentBest=-1;
641
    float multiplier = returnMultiplier();
642

    
643
    point3D[0] *= multiplier;
644
    point3D[1] *= multiplier;
645
    point3D[2] *= multiplier;
646

    
647
    for(int i=0; i<NUM_CUBITS; i++)
648
      {
649
      dist = mCubits[i].getDistSquared(point3D);
650
      if( dist<minDist )
651
        {
652
        minDist = dist;
653
        currentBest = i;
654
        }
655
      }
656

    
657
    return currentBest;
658
    }
659

    
660
///////////////////////////////////////////////////////////////////////////////////////////////////
661

    
662
  public int computeNearestAngle(float angle, float speed)
663
    {
664
    final int NEAREST = 360/getBasicAngle();
665

    
666
    int tmp = (int)((angle+NEAREST/2)/NEAREST);
667
    if( angle< -(NEAREST*0.5) ) tmp-=1;
668

    
669
    if( tmp!=0 ) return NEAREST*tmp;
670

    
671
    return speed> 1.2f ? NEAREST*(angle>0 ? 1:-1) : 0;
672
    }
673

    
674
///////////////////////////////////////////////////////////////////////////////////////////////////
675

    
676
  public int getNodeSize()
677
    {
678
    return mNodeSize;
679
    }
680

    
681
///////////////////////////////////////////////////////////////////////////////////////////////////
682

    
683
  public RubikObjectList getObjectList()
684
    {
685
    return mList;
686
    }
687

    
688
///////////////////////////////////////////////////////////////////////////////////////////////////
689

    
690
  abstract float getScreenRatio();
691
  abstract Static3D[] getCubitPositions(int size);
692
  abstract Static4D[] getQuats();
693
  abstract int getNumFaces();
694
  abstract int getNumCubitFaces();
695
  abstract MeshBase createCubitMesh(int cubit);
696
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side);
697
  abstract int getFaceColor(int cubit, int cubitface, int size);
698
  public abstract Static3D[] getRotationAxis();
699
  public abstract int getBasicAngle();
700
  public abstract float returnMultiplier();
701
  public abstract float returnRotationFactor(float offset);
702
  public abstract String retObjectString();
703
  public abstract float[] getRowChances();
704
  }
(6-6/10)