Project

General

Profile

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

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

1 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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.res.Resources;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
26 8f53e513 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectMove;
27
import org.distorted.library.effect.MatrixEffectQuaternion;
28
import org.distorted.library.effect.MatrixEffectRotate;
29
import org.distorted.library.effect.MatrixEffectScale;
30
import org.distorted.library.effect.VertexEffectDeform;
31
import org.distorted.library.effect.VertexEffectMove;
32
import org.distorted.library.effect.VertexEffectRotate;
33
import org.distorted.library.effect.VertexEffectScale;
34
import org.distorted.library.effect.VertexEffectSink;
35 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
36
import org.distorted.library.main.DistortedTexture;
37
import org.distorted.library.mesh.MeshBase;
38 8f53e513 Leszek Koltunski
import org.distorted.library.mesh.MeshJoined;
39 418aa554 Leszek Koltunski
import org.distorted.library.mesh.MeshRectangles;
40 8f53e513 Leszek Koltunski
import org.distorted.library.mesh.MeshTriangles;
41
import org.distorted.library.type.Static1D;
42 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
43
import org.distorted.library.type.Static4D;
44 6b6504fe Leszek Koltunski
import org.distorted.main.RubikSurfaceView;
45 418aa554 Leszek Koltunski
46 7c969a6d Leszek Koltunski
import java.util.Random;
47
48
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
49
50 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
51
52
public class RubikDino extends RubikObject
53
{
54 8f53e513 Leszek Koltunski
  private static final float SQ2 = (float)Math.sqrt(2);
55
  private static final float SQ3 = (float)Math.sqrt(3);
56
  private static final float ANGLE_FACES = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
57 418aa554 Leszek Koltunski
58
  // the four rotation axis of a RubikDino. Must be normalized.
59 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
60 418aa554 Leszek Koltunski
         {
61
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
62
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
63
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
64
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
65
         };
66
67 ad38d800 Leszek Koltunski
  // the six axis that determine the faces
68
  static final Static3D[] FACE_AXIS = new Static3D[]
69
         {
70
           new Static3D(1,0,0), new Static3D(-1,0,0),
71
           new Static3D(0,1,0), new Static3D(0,-1,0),
72
           new Static3D(0,0,1), new Static3D(0,0,-1)
73
         };
74
75 418aa554 Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
76
         {
77 ad38d800 Leszek Koltunski
           0xffffff00, 0xffffffff,   // FACE_AXIS[0] (right-YELLOW) FACE_AXIS[1] (left  -WHITE)
78
           0xff0000ff, 0xff00ff00,   // FACE_AXIS[2] (top  -BLUE  ) FACE_AXIS[3] (bottom-GREEN)
79
           0xffff0000, 0xffb5651d    // FACE_AXIS[4] (front-RED   ) FACE_AXIS[5] (back  -BROWN)
80 418aa554 Leszek Koltunski
         };
81
82
  // All legal rotation quats of a RubikDino
83
  private static final Static4D[] QUATS = new Static4D[]
84
         {
85
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
86 380162cb Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
87 8f53e513 Leszek Koltunski
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
88 380162cb Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
89 418aa554 Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
90
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
91
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
92 8f53e513 Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
93 380162cb Leszek Koltunski
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
94
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
95
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
96
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
97 8f53e513 Leszek Koltunski
         };
98
99
  // centers of the 12 edges. Must be in the same order like QUATs above.
100
  private static final Static3D[] CENTERS = new Static3D[]
101
         {
102 c7e79b69 Leszek Koltunski
           new Static3D( 0.0f, 1.5f, 1.5f ),
103
           new Static3D( 1.5f, 0.0f, 1.5f ),
104
           new Static3D( 0.0f,-1.5f, 1.5f ),
105
           new Static3D(-1.5f, 0.0f, 1.5f ),
106
           new Static3D( 1.5f, 1.5f, 0.0f ),
107
           new Static3D( 1.5f,-1.5f, 0.0f ),
108
           new Static3D(-1.5f,-1.5f, 0.0f ),
109
           new Static3D(-1.5f, 1.5f, 0.0f ),
110
           new Static3D( 0.0f, 1.5f,-1.5f ),
111
           new Static3D( 1.5f, 0.0f,-1.5f ),
112
           new Static3D( 0.0f,-1.5f,-1.5f ),
113
           new Static3D(-1.5f, 0.0f,-1.5f )
114 418aa554 Leszek Koltunski
         };
115
116 f6d06256 Leszek Koltunski
  private static final int[] mFaceMap = {2,4, 4,0, 3,4, 4,1,
117
                                         0,2, 0,3, 1,3, 1,2,
118
                                         2,5, 5,0, 3,5, 5,1 };
119
120 8f53e513 Leszek Koltunski
  private static MeshBase mMesh;
121 418aa554 Leszek Koltunski
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123
124
  RubikDino(int size, Static4D quat, DistortedTexture texture,
125
            MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
126
    {
127
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
128
    }
129
130 8f53e513 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132
  private MeshBase createTetrahedronMesh()
133
    {
134
    final float SQ2 = (float)Math.sqrt(2);
135
    final float SQ3 = (float)Math.sqrt(3);
136
    final int MESHES=4;
137
138
    int association = 1;
139
    MeshBase[] meshes = new MeshTriangles[MESHES];
140
141 380162cb Leszek Koltunski
    meshes[0] = new MeshTriangles(11);
142 8f53e513 Leszek Koltunski
    meshes[0].setEffectAssociation(0,association,0);
143
144
    for(int i=1; i<MESHES; i++)
145
      {
146
      association <<= 1;
147
      meshes[i] = meshes[0].copy(true);
148
      meshes[i].setEffectAssociation(0,association,0);
149
      }
150
151
    MeshBase result = new MeshJoined(meshes);
152
153
    Static3D a0 = new Static3D(         0,        1,       0 );
154
    Static3D a1 = new Static3D(         0,  -1.0f/3, 2*SQ2/3 );
155
    Static3D a2 = new Static3D(-SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
156
    Static3D a3 = new Static3D( SQ2*SQ3/3,  -1.0f/3,  -SQ2/3 );
157
158
    float tetraHeight = SQ2*SQ3/3;
159
    float d1 = 0.75f*tetraHeight;
160
    float d2 =-0.10f*tetraHeight;
161 380162cb Leszek Koltunski
    float d3 =-0.05f*tetraHeight;
162
    float d4 = 0.15f*tetraHeight;
163 8f53e513 Leszek Koltunski
164
    Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
165
    Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
166
    Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
167
    Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
168
169 380162cb Leszek Koltunski
    Static3D dVec0 = new Static3D( d3*a0.get0(), d3*a0.get1(), d3*a0.get2() );
170
    Static3D dVec1 = new Static3D( d3*a1.get0(), d3*a1.get1(), d3*a1.get2() );
171 8f53e513 Leszek Koltunski
    Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
172
    Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
173
174 380162cb Leszek Koltunski
    Static4D dReg  = new Static4D(0,0,0,d4);
175 8f53e513 Leszek Koltunski
    Static1D dRad  = new Static1D(1);
176
177
    Static1D angle  = new Static1D(ANGLE_FACES);
178
    Static3D axis1  = new Static3D(  -1, 0,      0);
179
    Static3D axis2  = new Static3D(0.5f, 0, -SQ3/2);
180
    Static3D axis3  = new Static3D(0.5f, 0, +SQ3/2);
181
    Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
182
    Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
183
184
    Static3D center = new Static3D(0,0,0);
185
    Static4D region = new Static4D(0,0,0,0.6f);
186
187
    VertexEffectScale   effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
188
    VertexEffectRotate  effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
189
    VertexEffectMove    effect3 = new VertexEffectMove  ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
190
    VertexEffectRotate  effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
191
    VertexEffectRotate  effect5 = new VertexEffectRotate( angle, axis1, center1 );
192
    VertexEffectRotate  effect6 = new VertexEffectRotate( angle, axis2, center2 );
193
    VertexEffectRotate  effect7 = new VertexEffectRotate( angle, axis3, center2 );
194
195
    VertexEffectDeform  effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
196
    VertexEffectDeform  effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
197
    VertexEffectDeform  effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
198
    VertexEffectDeform  effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
199
200 ee64e15a Leszek Koltunski
    VertexEffectSink effect12= new VertexEffectSink( new Static1D(1.25f), center, region );
201 8f53e513 Leszek Koltunski
202
    effect4.setMeshAssociation(14,-1);  // apply to mesh[1], [2] and [3]
203
    effect5.setMeshAssociation( 2,-1);  // apply only to mesh[1]
204
    effect6.setMeshAssociation( 4,-1);  // apply only to mesh[2]
205
    effect7.setMeshAssociation( 8,-1);  // apply only to mesh[3]
206
207
    result.apply(effect1);
208
    result.apply(effect2);
209
    result.apply(effect3);
210
    result.apply(effect4);
211
    result.apply(effect5);
212
    result.apply(effect6);
213
    result.apply(effect7);
214
    result.apply(effect8);
215
    result.apply(effect9);
216
    result.apply(effect10);
217
    result.apply(effect11);
218
    result.apply(effect12);
219
220
    result.mergeEffComponents();
221
222
    return result;
223
    }
224
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226
227
  private void createBasicMesh()
228
    {
229
    mMesh = createTetrahedronMesh();
230
231
    Static3D axis = new Static3D(1,0,0);
232
    Static3D cent = new Static3D(0,0,0);
233
234
    MatrixEffectMove   moveEffect = new MatrixEffectMove  ( new Static3D(0.0f,SQ3*SQ2/12,SQ3/6) );
235
    MatrixEffectRotate rot1Effect = new MatrixEffectRotate( new Static1D(180+ANGLE_FACES/2), axis, cent);
236 c7e79b69 Leszek Koltunski
    MatrixEffectScale  scalEffect = new MatrixEffectScale ( new Static3D(3.0f, 3*SQ2/2, 1.5f) );
237 8f53e513 Leszek Koltunski
    MatrixEffectRotate rot2Effect = new MatrixEffectRotate( new Static1D(-45), axis, cent);
238
239 380162cb Leszek Koltunski
    mMesh.apply(moveEffect, 0xffffffff, 0);
240
    mMesh.apply(rot1Effect, 0xffffffff, 0);
241
    mMesh.apply(scalEffect, 0xffffffff, 0);
242
    mMesh.apply(rot2Effect, 0xffffffff, 0);
243 8f53e513 Leszek Koltunski
    }
244
245 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
246
247
  float getScreenRatio()
248
    {
249 c7e79b69 Leszek Koltunski
    return 0.5f;
250 418aa554 Leszek Koltunski
    }
251
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253
254
  Static4D[] getQuats()
255
    {
256
    return QUATS;
257
    }
258
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
261
  int getNumFaces()
262
    {
263
    return FACE_COLORS.length;
264
    }
265
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267
268 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
269 418aa554 Leszek Koltunski
    {
270 8f53e513 Leszek Koltunski
    return 4;
271
    }
272
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274 418aa554 Leszek Koltunski
275 8f53e513 Leszek Koltunski
  Static3D[] getCubitPositions(int size)
276
    {
277
    return CENTERS;
278 418aa554 Leszek Koltunski
    }
279
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281
282
  MeshBase createCubitMesh(int cubit)
283
    {
284 8f53e513 Leszek Koltunski
    if( mMesh==null ) createBasicMesh();
285
286
    MeshBase mesh = mMesh.copy(true);
287
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
288
    mesh.apply(quat,0xffffffff,0);
289 418aa554 Leszek Koltunski
290 8f53e513 Leszek Koltunski
    return mesh;
291 418aa554 Leszek Koltunski
    }
292
293 f6d06256 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
294
295
  int getFaceColor(int cubit, int cubitface, int size)
296
    {
297
    switch(cubitface)
298
      {
299
      case 0 : return mFaceMap[2*cubit];
300
      case 1 : return mFaceMap[2*cubit+1];
301
      default: return NUM_FACES;
302
      }
303
    }
304
305 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
306
307
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
308
    {
309
    float STROKE = 0.06f*side;
310
    float OFF = STROKE/2 -1;
311
    float OFF2 = 0.5f*side + OFF;
312
    float HEIGHT = side - OFF;
313
    float RADIUS = side/12.0f;
314
    float ARC1_H = 0.2f*side;
315
    float ARC1_W = side*0.5f;
316
    float ARC2_W = 0.153f*side;
317
    float ARC2_H = 0.905f*side;
318
    float ARC3_W = side-ARC2_W;
319
320
    paint.setAntiAlias(true);
321
    paint.setStrokeWidth(STROKE);
322
    paint.setColor(FACE_COLORS[face]);
323
    paint.setStyle(Paint.Style.FILL);
324
325
    canvas.drawRect(left,top,left+side,top+side,paint);
326
327
    paint.setColor(INTERIOR_COLOR);
328
    paint.setStyle(Paint.Style.STROKE);
329
330
    canvas.drawLine(           left, HEIGHT,  side       +left, HEIGHT, paint);
331
    canvas.drawLine(      OFF +left, side  ,       OFF2  +left,      0, paint);
332
    canvas.drawLine((side-OFF)+left, side  , (side-OFF2) +left,      0, paint);
333
334
    canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint);
335
    canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint);
336
    canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint);
337
    }
338
339 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
340
341
  float returnMultiplier()
342
    {
343
    return 2.0f;
344
    }
345
346 7c969a6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
347
348
  float[] getRowChances()
349
    {
350
    float[] chances = new float[3];
351
352
    chances[0] = 0.5f;
353
    chances[1] = 0.5f;
354
    chances[2] = 1.0f;
355
356
    return chances;
357
    }
358
359 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
360
// PUBLIC API
361
362
  public Static3D[] getRotationAxis()
363
    {
364 ad38d800 Leszek Koltunski
    return ROT_AXIS;
365 418aa554 Leszek Koltunski
    }
366
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368
369
  public int getBasicAngle()
370
    {
371
    return 3;
372
    }
373
374
///////////////////////////////////////////////////////////////////////////////////////////////////
375
376 fb377dae Leszek Koltunski
  public int computeRowFromOffset(float offset)
377 418aa554 Leszek Koltunski
    {
378 fb377dae Leszek Koltunski
    return offset<0.5f ? 0:2;
379 418aa554 Leszek Koltunski
    }
380
381
///////////////////////////////////////////////////////////////////////////////////////////////////
382
383
  public float returnRotationFactor(float offset)
384
    {
385
    return 1.0f;
386
    }
387
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390 7c969a6d Leszek Koltunski
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
391 418aa554 Leszek Koltunski
    {
392 7c969a6d Leszek Koltunski
    int numAxis = ROTATION_AXIS.length;
393 418aa554 Leszek Koltunski
394 7c969a6d Leszek Koltunski
    if( oldRotAxis == START_AXIS )
395
      {
396
      return rnd.nextInt(numAxis);
397
      }
398
    else
399
      {
400
      int newVector = rnd.nextInt(numAxis-1);
401
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
402
      }
403
    }
404 418aa554 Leszek Koltunski
405 7c969a6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
406
407
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
408
    {
409
    float rowFloat = rnd.nextFloat();
410
411
    switch(oldRotAxis)
412
      {
413
      case 0 : switch(newRotAxis)
414
                 {
415
                 case 1:
416
                 case 2: return oldRow;
417
                 case 3: return 2-oldRow;
418
                 default: android.util.Log.e("dino", "error: oldRotAxis="+oldRotAxis+" newRotAxis:"+newRotAxis);
419
                 }
420
      case 1 : switch(newRotAxis)
421
                 {
422
                 case 0:
423
                 case 3: return oldRow;
424
                 case 2: return 2-oldRow;
425
                 default: android.util.Log.e("dino", "error: oldRotAxis="+oldRotAxis+" newRotAxis:"+newRotAxis);
426
                 }
427
      case 2 : switch(newRotAxis)
428
                 {
429
                 case 0:
430
                 case 3: return oldRow;
431
                 case 1: return 2-oldRow;
432
                 default: android.util.Log.e("dino", "error: oldRotAxis="+oldRotAxis+" newRotAxis:"+newRotAxis);
433
                 }
434
      case 3 : switch(newRotAxis)
435
                 {
436
                 case 1:
437
                 case 2: return oldRow;
438
                 case 0: return 2-oldRow;
439
                 default: android.util.Log.e("dino", "error: oldRotAxis="+oldRotAxis+" newRotAxis:"+newRotAxis);
440
                 }
441
      default: return rowFloat<=0.5f ? 0:2;
442
      }
443 418aa554 Leszek Koltunski
    }
444
445 1ebc4767 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
446 6b6504fe Leszek Koltunski
// remember about the double cover or unit quaternions!
447 1ebc4767 Leszek Koltunski
448 6b6504fe Leszek Koltunski
  private int mulQuat(int q1, int q2)
449 1ebc4767 Leszek Koltunski
    {
450 6b6504fe Leszek Koltunski
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
451
452
    float rX = result.get0();
453
    float rY = result.get1();
454
    float rZ = result.get2();
455
    float rW = result.get3();
456
457
    final float MAX_ERROR = 0.1f;
458
    float dX,dY,dZ,dW;
459
460
    for(int i=0; i<QUATS.length; i++)
461
      {
462
      dX = QUATS[i].get0() - rX;
463
      dY = QUATS[i].get1() - rY;
464
      dZ = QUATS[i].get2() - rZ;
465
      dW = QUATS[i].get3() - rW;
466
467
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
468
          dY<MAX_ERROR && dY>-MAX_ERROR &&
469
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
470
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
471
472
      dX = QUATS[i].get0() + rX;
473
      dY = QUATS[i].get1() + rY;
474
      dZ = QUATS[i].get2() + rZ;
475
      dW = QUATS[i].get3() + rW;
476
477
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
478
          dY<MAX_ERROR && dY>-MAX_ERROR &&
479
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
480
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
481
      }
482
483
    return -1;
484
    }
485
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487
// Dino is solved if and only if:
488
//
489
// All four 'X' cubits (i.e. those whose longest edge goes along the X axis) are rotated
490
// by the same quaternion qX, similarly all four 'Y' cubits by the same qY and all four 'Z'
491
// by the same qZ, and then either:
492
//
493
// a) qX = qY = qZ
494
// b) qY = qX*Q2 and qZ = qX*Q8  (i.e. swap of WHITE and YELLOW faces)
495
// c) qX = qY*Q2 and qZ = qY*Q10 (i.e. swap of BLUE and GREEN faces)
496
// d) qX = qZ*Q8 and qY = qZ*Q10 (i.e. swap of RED and BROWN faces)
497
//
498
// BUT: cases b), c) and d) are really the same - it's all just a mirror image of the original.
499
//
500
// X cubits: 0, 2, 8, 10
501
// Y cubits: 1, 3, 9, 11
502
// Z cubits: 4, 5, 6, 7
503
504
  public boolean isSolved()
505
    {
506
    int qX = CUBITS[0].mQuatIndex;
507
    int qY = CUBITS[1].mQuatIndex;
508
    int qZ = CUBITS[4].mQuatIndex;
509
510
    if( CUBITS[2].mQuatIndex != qX || CUBITS[8].mQuatIndex != qX || CUBITS[10].mQuatIndex != qX ||
511
        CUBITS[3].mQuatIndex != qY || CUBITS[9].mQuatIndex != qY || CUBITS[11].mQuatIndex != qY ||
512
        CUBITS[5].mQuatIndex != qZ || CUBITS[6].mQuatIndex != qZ || CUBITS[ 7].mQuatIndex != qZ  )
513
      {
514
      return false;
515
      }
516
517
    return ( qX==qY && qX==qZ ) || ( qY==mulQuat(qX,2) && qZ==mulQuat(qX,8) );
518 1ebc4767 Leszek Koltunski
    }
519
520 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
521
// TODO  (only needed for solvers - there are no Dino solvers ATM)
522
523
  public String retObjectString()
524
    {
525
    return "";
526
    }
527
528
}