Project

General

Profile

« Previous | Next » 

Revision ece1b58d

Added by Leszek Koltunski about 4 years ago

1) correction for Dino4's isSolved() [ remember about the mirror! ]
2) beginnings of support for the Skewb Diamond

View differences:

src/main/java/org/distorted/main/RubikSurfaceView.java
31 31
import com.google.firebase.crashlytics.FirebaseCrashlytics;
32 32

  
33 33
import org.distorted.library.type.Static2D;
34
import org.distorted.library.type.Static3D;
35 34
import org.distorted.library.type.Static4D;
36 35
import org.distorted.objects.RubikObject;
37 36
import org.distorted.objects.RubikMovement;
src/main/java/org/distorted/objects/RubikCube.java
65 65

  
66 66
  private static final int[] FACE_COLORS = new int[]
67 67
         {
68
           0xffffff00, 0xffffffff,   // FACE_AXIS[0] (right-YELLOW) FACE_AXIS[1] (left  -WHITE)
69
           0xff0000ff, 0xff00ff00,   // FACE_AXIS[2] (top  -BLUE  ) FACE_AXIS[3] (bottom-GREEN)
70
           0xffff0000, 0xffb5651d    // FACE_AXIS[4] (front-RED   ) FACE_AXIS[5] (back  -BROWN)
68
           COLOR_YELLOW, COLOR_WHITE,
69
           COLOR_BLUE  , COLOR_GREEN,
70
           COLOR_RED   , COLOR_BROWN
71 71
         };
72 72

  
73 73
  // All legal rotation quats of a RubikCube of any size.
src/main/java/org/distorted/objects/RubikDiamond.java
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.res.Resources;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33

  
34
import java.util.Random;
35

  
36
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
public class RubikDiamond extends RubikObject
41
{
42
  private static final float SQ2 = (float)Math.sqrt(2);
43
  private static final float SQ3 = (float)Math.sqrt(3);
44
  private static final float SQ6 = (float)Math.sqrt(6);
45

  
46
  private static final int FACES_PER_CUBIT =8;
47

  
48
  // the four rotation axis of a Diamond. Must be normalized.
49
  static final Static3D[] ROT_AXIS = new Static3D[]
50
         {
51
           new Static3D(+SQ6/3,+SQ3/3,     0),
52
           new Static3D(-SQ6/3,+SQ3/3,     0),
53
           new Static3D(     0,+SQ3/3,+SQ6/3),
54
           new Static3D(     0,+SQ3/3,-SQ6/3)
55
         };
56

  
57
  // the eight axis that determine the faces
58
  static final Static3D[] FACE_AXIS = new Static3D[]
59
         {
60
           new Static3D(+SQ6/3,+SQ3/3,     0), new Static3D(-SQ6/3,-SQ3/3,     0),
61
           new Static3D(-SQ6/3,+SQ3/3,     0), new Static3D(+SQ6/3,-SQ3/3,     0),
62
           new Static3D(     0,+SQ3/3,+SQ6/3), new Static3D(     0,-SQ3/3,-SQ6/3),
63
           new Static3D(     0,+SQ3/3,-SQ6/3), new Static3D(     0,-SQ3/3,+SQ6/3)
64
         };
65

  
66
  private static final int[] FACE_COLORS = new int[]
67
         {
68
           COLOR_YELLOW, COLOR_WHITE,
69
           COLOR_BLUE  , COLOR_GREEN,
70
           COLOR_RED   , COLOR_BROWN,
71
           COLOR_PINK  , COLOR_VIOLET
72
         };
73

  
74
  // All legal rotation quats of a Diamond
75
  private static final Static4D[] QUATS = new Static4D[]
76
         {
77
           new Static4D(  0.0f,  0.0f,   0.0f,  1.0f ),
78
           new Static4D(  0.0f,  1.0f,   0.0f,  0.0f ),
79
           new Static4D(+SQ2/2,  0.5f,   0.0f,  0.5f ),
80
           new Static4D(-SQ2/2,  0.5f,   0.0f,  0.5f ),
81
           new Static4D(  0.0f,  0.5f, +SQ2/2,  0.5f ),
82
           new Static4D(  0.0f,  0.5f, -SQ2/2,  0.5f ),
83
           new Static4D(+SQ2/2,  0.5f,   0.0f, -0.5f ),
84
           new Static4D(-SQ2/2,  0.5f,   0.0f, -0.5f ),
85
           new Static4D(  0.0f,  0.5f, +SQ2/2, -0.5f ),
86
           new Static4D(  0.0f,  0.5f, -SQ2/2, -0.5f ),
87
           new Static4D(+SQ2/2,  0.0f, -SQ2/2,  0.0f ),
88
           new Static4D(-SQ2/2,  0.0f, -SQ2/2,  0.0f )
89
         };
90

  
91
  private static final float DIST = 0.50f;
92

  
93
  // centers of the 6 octahedrons + 8 tetrahedrons ( i.e. of the all 14 cubits)
94
  private static final Static3D[] CENTERS = new Static3D[]
95
         {
96
           new Static3D( DIST,          0, DIST ),
97
           new Static3D( DIST,          0,-DIST ),
98
           new Static3D(-DIST,          0,-DIST ),
99
           new Static3D(-DIST,          0, DIST ),
100
           new Static3D(    0, DIST*SQ2  ,    0 ),
101
           new Static3D(    0,-DIST*SQ2  ,    0 ),
102

  
103
           new Static3D(    0, DIST*SQ2/2, DIST ),
104
           new Static3D( DIST, DIST*SQ2/2,    0 ),
105
           new Static3D(    0, DIST*SQ2/2,-DIST ),
106
           new Static3D(-DIST, DIST*SQ2/2,    0 ),
107
           new Static3D(    0,-DIST*SQ2/2, DIST ),
108
           new Static3D( DIST,-DIST*SQ2/2,    0 ),
109
           new Static3D(    0,-DIST*SQ2/2,-DIST ),
110
           new Static3D(-DIST,-DIST*SQ2/2,    0 )
111
         };
112

  
113
  // Colors of the faces of cubits. Each cubit has 8 faces
114
  private static final int[][] mFaceMap = new int[][]
115
         {
116
           { 6,1,8,8, 2,5,8,8 },
117
           { 8,1,3,8, 8,5,7,8 },
118
           { 8,8,3,4, 8,8,7,0 },
119
           { 6,8,8,4, 2,8,8,0 },
120
           { 6,1,3,4, 8,8,8,8 },
121
           { 8,8,8,8, 2,5,7,0 },
122

  
123
           { 6,8,8,8, 8,8,8,8 },
124
           { 1,8,8,8, 8,8,8,8 },
125
           { 3,8,8,8, 8,8,8,8 },
126
           { 4,8,8,8, 8,8,8,8 },
127
           { 2,8,8,8, 8,8,8,8 },
128
           { 5,8,8,8, 8,8,8,8 },
129
           { 7,8,8,8, 8,8,8,8 },
130
           { 0,8,8,8, 8,8,8,8 }
131
         };
132

  
133
  private static MeshBase mOctaMesh, mTetraMesh;
134

  
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

  
137
  RubikDiamond(int size, Static4D quat, DistortedTexture texture,
138
               MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
139
    {
140
    super(size, 60, quat, texture, mesh, effects, moves, RubikObjectList.DIAM, res, scrWidth);
141
    }
142

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  private void createOctaMesh()
146
    {
147

  
148
    }
149

  
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

  
152
  private void createTetraMesh()
153
    {
154

  
155
    }
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

  
159
  float getScreenRatio()
160
    {
161
    return 1.0f;
162
    }
163

  
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

  
166
  Static4D[] getQuats()
167
    {
168
    return QUATS;
169
    }
170

  
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

  
173
  int getNumFaces()
174
    {
175
    return FACE_COLORS.length;
176
    }
177

  
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

  
180
  boolean shouldResetTextureMaps()
181
    {
182
    return false;
183
    }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  int getNumStickerTypes()
188
    {
189
    return 1;
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  float getBasicStep()
195
    {
196
    return SQ6/6;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  int getNumCubitFaces()
202
    {
203
    return FACES_PER_CUBIT;
204
    }
205

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

  
208
  Static3D[] getCubitPositions(int size)
209
    {
210
    return CENTERS;
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  private Static4D getQuat(int cubit)
216
    {
217
    switch(cubit)
218
      {
219
      case  0:
220
      case  1:
221
      case  2:
222
      case  3:
223
      case  4:
224
      case  5:
225
      case  6: return QUATS[0];                          // unit quat
226
      case  7: return new Static4D( SQ2/2,0,0,SQ2/2);    //  90 along Y
227
      case  8: return QUATS[1];                          // 180 along Y
228
      case  9: return new Static4D(-SQ2/2,0,0,SQ2/2);    //  90 along Y
229
      case 10: return new Static4D(     0,0,1,    0);    // 180 along Z
230
      case 11: return new Static4D(0, SQ2/2,SQ2/2,0);    //
231
      case 12: return new Static4D(     1,0,0,    0);    // 180 along X
232
      case 13: return new Static4D(0,-SQ2/2,SQ2/2,0);    //
233
      }
234

  
235
    return null;
236
    }
237

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

  
240
  MeshBase createCubitMesh(int cubit)
241
    {
242
    MeshBase mesh;
243

  
244
    if( cubit<6 )
245
      {
246
      if( mOctaMesh==null ) createOctaMesh();
247
      mesh = mOctaMesh.copy(true);
248
      }
249
    else
250
      {
251
      if( mTetraMesh==null ) createTetraMesh();
252
      mesh = mTetraMesh.copy(true);
253
      }
254

  
255
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit), new Static3D(0,0,0) );
256
    mesh.apply(quat,0xffffffff,0);
257

  
258
    return mesh;
259
    }
260

  
261
///////////////////////////////////////////////////////////////////////////////////////////////////
262

  
263
  int getFaceColor(int cubit, int cubitface, int size)
264
    {
265
    return mFaceMap[cubit][cubitface];
266
    }
267

  
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269

  
270
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
271
    {
272
    float STROKE = 0.044f*side;
273
    float OFF = STROKE/2 -1;
274
    float OFF2 = 0.5f*side + OFF;
275
    float HEIGHT = side - OFF;
276
    float RADIUS = side/12.0f;
277
    float ARC1_H = 0.2f*side;
278
    float ARC1_W = side*0.5f;
279
    float ARC2_W = 0.153f*side;
280
    float ARC2_H = 0.905f*side;
281
    float ARC3_W = side-ARC2_W;
282

  
283
    float M = SQ3/2;
284
    float D = (M/2 - 0.51f)*side;
285

  
286
    paint.setAntiAlias(true);
287
    paint.setStrokeWidth(STROKE);
288
    paint.setColor(FACE_COLORS[face]);
289
    paint.setStyle(Paint.Style.FILL);
290

  
291
    canvas.drawRect(left,top,left+side,top+side,paint);
292

  
293
    paint.setColor(INTERIOR_COLOR);
294
    paint.setStyle(Paint.Style.STROKE);
295

  
296
    canvas.drawLine(           left, M*HEIGHT+D,  side       +left, M*HEIGHT+D, paint);
297
    canvas.drawLine(      OFF +left, M*side  +D,       OFF2  +left,          D, paint);
298
    canvas.drawLine((side-OFF)+left, M*side  +D, (side-OFF2) +left,          D, paint);
299

  
300
    canvas.drawArc( ARC1_W-RADIUS+left, M*(ARC1_H-RADIUS)+D, ARC1_W+RADIUS+left, M*(ARC1_H+RADIUS)+D, 225, 90, false, paint);
301
    canvas.drawArc( ARC2_W-RADIUS+left, M*(ARC2_H-RADIUS)+D, ARC2_W+RADIUS+left, M*(ARC2_H+RADIUS)+D, 105, 90, false, paint);
302
    canvas.drawArc( ARC3_W-RADIUS+left, M*(ARC2_H-RADIUS)+D, ARC3_W+RADIUS+left, M*(ARC2_H+RADIUS)+D, 345, 90, false, paint);
303
    }
304

  
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

  
307
  float returnMultiplier()
308
    {
309
    return 2.0f;
310
    }
311

  
312
///////////////////////////////////////////////////////////////////////////////////////////////////
313

  
314
  float[] getRowChances()
315
    {
316
    float[] chances = new float[2];
317

  
318
    chances[0] = 0.5f;
319
    chances[1] = 1.0f;
320

  
321
    return chances;
322
    }
323

  
324
///////////////////////////////////////////////////////////////////////////////////////////////////
325
// PUBLIC API
326

  
327
  public Static3D[] getRotationAxis()
328
    {
329
    return ROT_AXIS;
330
    }
331

  
332
///////////////////////////////////////////////////////////////////////////////////////////////////
333

  
334
  public int getBasicAngle()
335
    {
336
    return 3;
337
    }
338

  
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340

  
341
  public int computeRowFromOffset(float offset)
342
    {
343
    return offset<0.25f ? 0:1;
344
    }
345

  
346
///////////////////////////////////////////////////////////////////////////////////////////////////
347

  
348
  public float returnRotationFactor(float offset)
349
    {
350
    return 1.0f;
351
    }
352

  
353
///////////////////////////////////////////////////////////////////////////////////////////////////
354

  
355
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
356
    {
357
    int numAxis = ROTATION_AXIS.length;
358

  
359
    if( oldRotAxis == START_AXIS )
360
      {
361
      return rnd.nextInt(numAxis);
362
      }
363
    else
364
      {
365
      int newVector = rnd.nextInt(numAxis-1);
366
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
367
      }
368
    }
369

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

  
372
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
373
    {
374
    float rowFloat = rnd.nextFloat();
375

  
376
    for(int row=0; row<mRowChances.length; row++)
377
      {
378
      if( rowFloat<=mRowChances[row] ) return row;
379
      }
380

  
381
    return 0;
382
    }
383

  
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385
// The Diamond is solved if and only if:
386
//
387
// ??
388

  
389
  public boolean isSolved()
390
    {
391

  
392

  
393
    return false;
394
    }
395

  
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
// only needed for solvers - there are no Diamond solvers ATM)
398

  
399
  public String retObjectString()
400
    {
401
    return "";
402
    }
403

  
404
}
src/main/java/org/distorted/objects/RubikDino.java
37 37
import org.distorted.library.type.Static1D;
38 38
import org.distorted.library.type.Static3D;
39 39
import org.distorted.library.type.Static4D;
40
import org.distorted.main.RubikSurfaceView;
40 41

  
41 42
import java.util.Random;
42 43

  
......
68 69

  
69 70
  private static final int[] FACE_COLORS = new int[]
70 71
         {
71
           0xffffff00, 0xffffffff,   // FACE_AXIS[0] (right-YELLOW) FACE_AXIS[1] (left  -WHITE)
72
           0xff0000ff, 0xff00ff00,   // FACE_AXIS[2] (top  -BLUE  ) FACE_AXIS[3] (bottom-GREEN)
73
           0xffff0000, 0xffb5651d    // FACE_AXIS[4] (front-RED   ) FACE_AXIS[5] (back  -BROWN)
72
           COLOR_YELLOW, COLOR_WHITE,
73
           COLOR_BLUE  , COLOR_GREEN,
74
           COLOR_RED   , COLOR_BROWN
74 75
         };
75 76

  
76 77
  // All legal rotation quats of a RubikDino
......
245 246
    mMesh.mergeEffComponents();
246 247
    }
247 248

  
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250

  
251
  int mulQuat(int q1, int q2)
252
    {
253
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
254

  
255
    float rX = result.get0();
256
    float rY = result.get1();
257
    float rZ = result.get2();
258
    float rW = result.get3();
259

  
260
    final float MAX_ERROR = 0.1f;
261
    float dX,dY,dZ,dW;
262

  
263
    for(int i=0; i<QUATS.length; i++)
264
      {
265
      dX = QUATS[i].get0() - rX;
266
      dY = QUATS[i].get1() - rY;
267
      dZ = QUATS[i].get2() - rZ;
268
      dW = QUATS[i].get3() - rW;
269

  
270
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
271
          dY<MAX_ERROR && dY>-MAX_ERROR &&
272
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
273
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
274

  
275
      dX = QUATS[i].get0() + rX;
276
      dY = QUATS[i].get1() + rY;
277
      dZ = QUATS[i].get2() + rZ;
278
      dW = QUATS[i].get3() + rW;
279

  
280
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
281
          dY<MAX_ERROR && dY>-MAX_ERROR &&
282
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
283
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
284
      }
285

  
286
    return -1;
287
    }
288

  
248 289
///////////////////////////////////////////////////////////////////////////////////////////////////
249 290

  
250 291
  float getScreenRatio()
src/main/java/org/distorted/objects/RubikDino4.java
73 73
    }
74 74

  
75 75
///////////////////////////////////////////////////////////////////////////////////////////////////
76
// Dino4 is solved if and only if the four groups of three same-colored cubits each are rotate with
77
// the same quaternion (actually we need to check only 3 first groups - if those are correct, the
78
// fourth one also needs to be correct).
76
// Dino4 is solved if and only if the four groups of three same-colored cubits are each 'together'
77
// (actually we need to check only 3 first groups - if those are correct, the fourth one also needs
78
// to be correct).
79 79
//
80
// White group : 6,10,11
81
// Red group   : 0,3,7
82
// Blue group  : 1,2,5
83
// Yellow group: 4,8,9
80
// White group : (X,Y,Z) = 10,11,6
81
// Red group   : (X,Y,Z) = 0,3,7
82
// Blue group  : (X,Y,Z) = 2,1,5
83
// Yellow group: (X,Y,Z) = 8,9,4
84
//
85
// A group of 3 cubits is 'together' if and only if they are all rotated with one quat - but we cannot
86
// forget that the whole Dino can be mirrored! (so then qY = qX*Q2 and qZ = qX*Q8 )
87
//
88
// X cubits: 0, 2, 8, 10
89
// Y cubits: 1, 3, 9, 11
90
// Z cubits: 4, 5, 6, 7
84 91

  
85 92
  public boolean isSolved()
86 93
    {
87
    int qR = CUBITS[0].mQuatIndex;
88
    int qB = CUBITS[1].mQuatIndex;
89
    int qY = CUBITS[4].mQuatIndex;
94
    int redX = CUBITS[0].mQuatIndex;
95
    int bluX = CUBITS[2].mQuatIndex;
96
    int yelX = CUBITS[8].mQuatIndex;
97

  
98
    if (CUBITS[3].mQuatIndex == redX && CUBITS[7].mQuatIndex == redX &&
99
        CUBITS[1].mQuatIndex == bluX && CUBITS[5].mQuatIndex == bluX &&
100
        CUBITS[9].mQuatIndex == yelX && CUBITS[4].mQuatIndex == yelX  ) return true;
90 101

  
91
    return (CUBITS[3].mQuatIndex == qR && CUBITS[7].mQuatIndex == qR &&
92
            CUBITS[2].mQuatIndex == qB && CUBITS[5].mQuatIndex == qB &&
93
            CUBITS[8].mQuatIndex == qY && CUBITS[9].mQuatIndex == qY  );
102
    if (CUBITS[3].mQuatIndex != mulQuat(redX,2)) return false;
103
    if (CUBITS[7].mQuatIndex != mulQuat(redX,8)) return false;
104
    if (CUBITS[1].mQuatIndex != mulQuat(bluX,2)) return false;
105
    if (CUBITS[5].mQuatIndex != mulQuat(bluX,8)) return false;
106
    if (CUBITS[9].mQuatIndex != mulQuat(yelX,2)) return false;
107
    if (CUBITS[4].mQuatIndex != mulQuat(yelX,8)) return false;
108

  
109
    return true;
94 110
    }
95 111
}
src/main/java/org/distorted/objects/RubikDino6.java
47 47
    super(size, quat, texture, mesh, effects, moves, RubikObjectList.DINO, res, scrWidth);
48 48
    }
49 49

  
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

  
52
  private int mulQuat(int q1, int q2)
53
    {
54
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
55

  
56
    float rX = result.get0();
57
    float rY = result.get1();
58
    float rZ = result.get2();
59
    float rW = result.get3();
60

  
61
    final float MAX_ERROR = 0.1f;
62
    float dX,dY,dZ,dW;
63

  
64
    for(int i=0; i<QUATS.length; i++)
65
      {
66
      dX = QUATS[i].get0() - rX;
67
      dY = QUATS[i].get1() - rY;
68
      dZ = QUATS[i].get2() - rZ;
69
      dW = QUATS[i].get3() - rW;
70

  
71
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
72
          dY<MAX_ERROR && dY>-MAX_ERROR &&
73
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
74
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
75

  
76
      dX = QUATS[i].get0() + rX;
77
      dY = QUATS[i].get1() + rY;
78
      dZ = QUATS[i].get2() + rZ;
79
      dW = QUATS[i].get3() + rW;
80

  
81
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
82
          dY<MAX_ERROR && dY>-MAX_ERROR &&
83
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
84
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
85
      }
86

  
87
    return -1;
88
    }
89

  
90 50
///////////////////////////////////////////////////////////////////////////////////////////////////
91 51

  
92 52
  int getFaceColor(int cubit, int cubitface, int size)
src/main/java/org/distorted/objects/RubikHelicopter.java
74 74

  
75 75
  private static final int[] FACE_COLORS = new int[]
76 76
         {
77
           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)
77
           COLOR_YELLOW, COLOR_WHITE,
78
           COLOR_BLUE  , COLOR_GREEN,
79
           COLOR_RED   , COLOR_BROWN
80 80
         };
81 81

  
82 82
  // All legal rotation quats of a HELICOPTER (same as the Cube!)
src/main/java/org/distorted/objects/RubikMovementDiamond.java
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
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24
class RubikMovementDiamond extends RubikMovement
25
{
26
  RubikMovementDiamond()
27
    {
28
    super(RubikDiamond.ROT_AXIS, RubikDiamond.FACE_AXIS, 0.25f, 0.25f);
29
    }
30

  
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32
// _____________
33
// |  \  0  /  |
34
// |   \   /   |
35
// | 3 |   | 1 |
36
// |   /   \   |
37
// |  /  2  \  |
38
// -------------
39

  
40
  private int getQuarter(float[] touchPoint)
41
    {
42
    boolean p0 = touchPoint[1] >= touchPoint[0];
43
    boolean p1 = touchPoint[1] >=-touchPoint[0];
44

  
45
    if( p0 )  return p1 ? 0:3;
46
    else      return p1 ? 1:2;
47
    }
48

  
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

  
51
  boolean isInsideFace(float[] p)
52
    {
53
    return ( p[0]<=0.25f && p[0]>=-0.25f && p[1]<=0.25f && p[1]>=-0.25f );
54
    }
55

  
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

  
58
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
59
    {
60
    enabled[0] = 2;
61

  
62
    int quarter = getQuarter(touchPoint);
63

  
64
    switch(face)
65
      {
66
      case 0: switch(quarter)
67
                {
68
                case 0: enabled[1]=0; enabled[2]=1; break;
69
                case 1: enabled[1]=3; enabled[2]=1; break;
70
                case 2: enabled[1]=2; enabled[2]=3; break;
71
                case 3: enabled[1]=0; enabled[2]=2; break;
72
                }
73
              break;
74
      case 1: switch(quarter)
75
                {
76
                case 0: enabled[1]=2; enabled[2]=3; break;
77
                case 1: enabled[1]=3; enabled[2]=1; break;
78
                case 2: enabled[1]=0; enabled[2]=1; break;
79
                case 3: enabled[1]=0; enabled[2]=2; break;
80
                }
81
              break;
82
      case 2: switch(quarter)
83
                {
84
                case 0: enabled[1]=1; enabled[2]=2; break;
85
                case 1: enabled[1]=0; enabled[2]=1; break;
86
                case 2: enabled[1]=0; enabled[2]=3; break;
87
                case 3: enabled[1]=2; enabled[2]=3; break;
88
                }
89
              break;
90
      case 3: switch(quarter)
91
                {
92
                case 0: enabled[1]=1; enabled[2]=2; break;
93
                case 1: enabled[1]=2; enabled[2]=3; break;
94
                case 2: enabled[1]=0; enabled[2]=3; break;
95
                case 3: enabled[1]=0; enabled[2]=1; break;
96
                }
97
              break;
98
      case 4: switch(quarter)
99
                {
100
                case 0: enabled[1]=0; enabled[2]=3; break;
101
                case 1: enabled[1]=0; enabled[2]=2; break;
102
                case 2: enabled[1]=1; enabled[2]=2; break;
103
                case 3: enabled[1]=1; enabled[2]=3; break;
104
                }
105
              break;
106
      case 5: switch(quarter)
107
                {
108
                case 0: enabled[1]=1; enabled[2]=2; break;
109
                case 1: enabled[1]=0; enabled[2]=2; break;
110
                case 2: enabled[1]=0; enabled[2]=3; break;
111
                case 3: enabled[1]=1; enabled[2]=3; break;
112
                }
113
              break;
114
      }
115
    }
116
}
src/main/java/org/distorted/objects/RubikObject.java
55 55

  
56 56
public abstract class RubikObject extends DistortedNode
57 57
  {
58
  static final int COLOR_YELLOW = 0xffffff00;
59
  static final int COLOR_WHITE  = 0xffffffff;
60
  static final int COLOR_BLUE   = 0xff0000ff;
61
  static final int COLOR_GREEN  = 0xff00ff00;
62
  static final int COLOR_RED    = 0xffff0000;
63
  static final int COLOR_BROWN  = 0xffb5651d;
64
  static final int COLOR_PINK   = 0xffe134eb;
65
  static final int COLOR_VIOLET = 0xffa534eb;
66

  
58 67
  private static final float NODE_RATIO = 1.32f;
59 68
  private static final float MAX_SIZE_CHANGE = 1.3f;
60 69
  private static final float MIN_SIZE_CHANGE = 0.8f;
src/main/java/org/distorted/objects/RubikObjectList.java
57 57
         1
58 58
       ),
59 59

  
60
  DIAM (
61
         new int[][] {
62
                       {2 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
63
                     },
64
         RubikDiamond.class,
65
         new RubikMovementDiamond(),
66
         1
67
       ),
68

  
60 69
  DINO (
61 70
         new int[][] {
62 71
                       {3 , 10, R.raw.dino, R.drawable.ui_small_dino, R.drawable.ui_medium_dino, R.drawable.ui_big_dino, R.drawable.ui_huge_dino} ,
......
466 475
      {
467 476
      case 0: return new RubikCube      (size, quat, texture, mesh, effects, moves, res, scrWidth);
468 477
      case 1: return new RubikPyraminx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
469
      case 2: return new RubikDino6     (size, quat, texture, mesh, effects, moves, res, scrWidth);
470
      case 3: return new RubikDino4     (size, quat, texture, mesh, effects, moves, res, scrWidth);
471
      case 4: return new RubikSkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
472
      case 5: return new RubikHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
478
      case 2: return new RubikDiamond   (size, quat, texture, mesh, effects, moves, res, scrWidth);
479
      case 3: return new RubikDino6     (size, quat, texture, mesh, effects, moves, res, scrWidth);
480
      case 4: return new RubikDino4     (size, quat, texture, mesh, effects, moves, res, scrWidth);
481
      case 5: return new RubikSkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
482
      case 6: return new RubikHelicopter(size, quat, texture, mesh, effects, moves, res, scrWidth);
473 483
      }
474 484

  
475 485
    return null;
src/main/java/org/distorted/objects/RubikPyraminx.java
68 68

  
69 69
  private static final int[] FACE_COLORS = new int[]
70 70
         {
71
           0xff00ff00, 0xffffff00,  // FACE_AXIS[0] (GREEN ) FACE_AXIS[1] (YELLOW )
72
           0xff0000ff, 0xffff0000   // FACE_AXIS[2] (BLUE  ) FACE_AXIS[3] (RED    )
71
           COLOR_GREEN , COLOR_YELLOW,
72
           COLOR_BLUE  , COLOR_RED
73 73
         };
74 74

  
75 75
  // computed with res/raw/compute_quats.c
src/main/java/org/distorted/objects/RubikSkewb.java
72 72

  
73 73
  private static final int[] FACE_COLORS = new int[]
74 74
         {
75
           0xffffff00, 0xffffffff,   // FACE_AXIS[0] (right-YELLOW) FACE_AXIS[1] (left  -WHITE)
76
           0xff0000ff, 0xff00ff00,   // FACE_AXIS[2] (top  -BLUE  ) FACE_AXIS[3] (bottom-GREEN)
77
           0xffff0000, 0xffb5651d    // FACE_AXIS[4] (front-RED   ) FACE_AXIS[5] (back  -BROWN)
75
           COLOR_YELLOW, COLOR_WHITE,
76
           COLOR_BLUE  , COLOR_GREEN,
77
           COLOR_RED   , COLOR_BROWN
78 78
         };
79 79

  
80 80
  // All legal rotation quats of a RubikSkewb
src/main/res/raw/compute_quats.c
2 2
#include <math.h>
3 3
#include <stdlib.h>
4 4

  
5
#define DINO
5
#define DIAM
6 6

  
7 7
#define SQ2 1.41421356237f
8 8
#define SQ3 1.73205080757f
......
38 38
                            {+SQ3/3,-SQ3/3,-SQ3/3} };
39 39
#endif
40 40

  
41
#ifdef DIAM
42
#define NUM_AXIS    4
43
#define BASIC_ANGLE 3
44

  
45
float axis[NUM_AXIS][3] = { {+SQ3*SQ2/3,+SQ3/3,         0} ,
46
                            {-SQ3*SQ2/3,+SQ3/3,         0} ,
47
                            {         0,+SQ3/3,+SQ3*SQ2/3} ,
48
                            {         0,+SQ3/3,-SQ3*SQ2/3} };
49
#endif
50

  
41 51
#ifdef HELI
42 52
#define NUM_AXIS 6
43 53
#define BASIC_ANGLE 2

Also available in: Unified diff