1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.VertexEffectDeform;
|
27
|
import org.distorted.library.effect.VertexEffectMove;
|
28
|
import org.distorted.library.effect.VertexEffectRotate;
|
29
|
import org.distorted.library.effect.VertexEffectScale;
|
30
|
import org.distorted.library.effect.VertexEffectSink;
|
31
|
import org.distorted.library.main.DistortedEffects;
|
32
|
import org.distorted.library.main.DistortedTexture;
|
33
|
import org.distorted.library.mesh.MeshBase;
|
34
|
import org.distorted.library.mesh.MeshJoined;
|
35
|
import org.distorted.library.mesh.MeshRectangles;
|
36
|
import org.distorted.library.mesh.MeshTriangles;
|
37
|
import org.distorted.library.type.Static1D;
|
38
|
import org.distorted.library.type.Static3D;
|
39
|
import org.distorted.library.type.Static4D;
|
40
|
import org.distorted.main.RubikSurfaceView;
|
41
|
|
42
|
import java.util.Random;
|
43
|
|
44
|
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
|
45
|
|
46
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
47
|
|
48
|
public class RubikPyraminx extends RubikObject
|
49
|
{
|
50
|
private static final float SQ2 = (float)Math.sqrt(2);
|
51
|
private static final float SQ3 = (float)Math.sqrt(3);
|
52
|
private static final float SQ6 = (float)Math.sqrt(6);
|
53
|
|
54
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
55
|
{
|
56
|
new Static3D( 0, 1, 0 ),
|
57
|
new Static3D( 0, -1.0f/3, 2*SQ2/3 ),
|
58
|
new Static3D(-SQ2*SQ3/3, -1.0f/3, -SQ2/3 ),
|
59
|
new Static3D( SQ2*SQ3/3, -1.0f/3, -SQ2/3 )
|
60
|
};
|
61
|
|
62
|
static final Static3D[] FACE_AXIS = new Static3D[]
|
63
|
{
|
64
|
new Static3D( 0, -1, 0 ),
|
65
|
new Static3D( 0, 1.0f/3,-2*SQ2/3 ),
|
66
|
new Static3D( SQ2*SQ3/3, 1.0f/3, SQ2/3 ),
|
67
|
new Static3D(-SQ2*SQ3/3, 1.0f/3, SQ2/3 )
|
68
|
};
|
69
|
|
70
|
private static final int[] FACE_COLORS = new int[]
|
71
|
{
|
72
|
0xff00ff00, 0xffffff00, // FACE_AXIS[0] (GREEN ) FACE_AXIS[1] (YELLOW )
|
73
|
0xff0000ff, 0xffff0000 // FACE_AXIS[2] (BLUE ) FACE_AXIS[3] (RED )
|
74
|
};
|
75
|
|
76
|
// computed with res/raw/compute_quats.c
|
77
|
private static final Static4D[] QUATS = new Static4D[]
|
78
|
{
|
79
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f),
|
80
|
new Static4D( 0.0f, SQ3/2, 0.0f, 0.5f),
|
81
|
new Static4D( SQ2/2, -SQ3/6, -SQ6/6, 0.5f),
|
82
|
new Static4D(-SQ2/2, -SQ3/6, -SQ6/6, 0.5f),
|
83
|
new Static4D( 0.0f, -SQ3/6, SQ6/3, 0.5f),
|
84
|
new Static4D( 0.0f, SQ3/2, 0.0f, -0.5f),
|
85
|
new Static4D( SQ2/2, -SQ3/6, -SQ6/6, -0.5f),
|
86
|
new Static4D(-SQ2/2, -SQ3/6, -SQ6/6, -0.5f),
|
87
|
new Static4D( 0.0f, -SQ3/6, SQ6/3, -0.5f),
|
88
|
new Static4D( SQ2/2, -SQ3/3, SQ6/6, 0.0f),
|
89
|
new Static4D( 0.0f, -SQ3/3, -SQ6/3, 0.0f),
|
90
|
new Static4D(-SQ2/2, -SQ3/3, SQ6/6, 0.0f)
|
91
|
};
|
92
|
|
93
|
private int[] mRotArray;
|
94
|
private static VertexEffectRotate[] ROTATION;
|
95
|
|
96
|
private static MeshBase mMesh =null;
|
97
|
private static MeshBase[] mMeshRotated = new MeshBase[ROT_AXIS.length];
|
98
|
|
99
|
static
|
100
|
{
|
101
|
Static3D center = new Static3D(0,0,0);
|
102
|
Static1D angle = new Static1D(180.0f);
|
103
|
|
104
|
ROTATION = new VertexEffectRotate[ROT_AXIS.length];
|
105
|
|
106
|
for(int i = 0; i< ROT_AXIS.length; i++)
|
107
|
{
|
108
|
ROTATION[i] = new VertexEffectRotate( angle, ROT_AXIS[i], center);
|
109
|
mMeshRotated[i] = null;
|
110
|
}
|
111
|
}
|
112
|
|
113
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
114
|
|
115
|
RubikPyraminx(int size, Static4D quat, DistortedTexture texture,
|
116
|
MeshRectangles mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
117
|
{
|
118
|
super(size, 30, quat, texture, mesh, effects, moves, RubikObjectList.PYRA, res, scrWidth);
|
119
|
}
|
120
|
|
121
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
122
|
|
123
|
private void emitRow(float x, float y, float z, float dx, float dy, float dz, int n, int rot, Static3D[] array, int index)
|
124
|
{
|
125
|
for(int i=0; i<n; i++)
|
126
|
{
|
127
|
mRotArray[i+index] = rot;
|
128
|
array[i+index] = new Static3D(x+0.5f,y+SQ2*SQ3/12,z+SQ3/6);
|
129
|
x += dx;
|
130
|
y += dy;
|
131
|
z += dz;
|
132
|
}
|
133
|
}
|
134
|
|
135
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
136
|
|
137
|
private int emitLowermost(float x, float y, float z, int n, Static3D[] array)
|
138
|
{
|
139
|
int added = 0;
|
140
|
|
141
|
emitRow( x +0.5f, y+SQ3*SQ2/9, z+ SQ3/18, 1.0f, 0, 0, n-1, 1, array, added);
|
142
|
added += (n-1);
|
143
|
emitRow( x +1.0f/3, y+SQ3*SQ2/9, z+2*SQ3/9, 0.5f, 0, SQ3/2, n-1, 3, array, added);
|
144
|
added += (n-1);
|
145
|
emitRow( x+n-1-1.0f/3, y+SQ3*SQ2/9, z+2*SQ3/9, -0.5f, 0, SQ3/2, n-1, 2, array, added);
|
146
|
added += (n-1);
|
147
|
|
148
|
for(int i=n; i>=1; i--)
|
149
|
{
|
150
|
emitRow(x , y, z , 1,0,0, i , -1, array, added);
|
151
|
added += i;
|
152
|
emitRow(x+0.5f, y, z+SQ3/6, 1,0,0, i-1, 0, array, added);
|
153
|
added += (i-1);
|
154
|
x += 0.5f;
|
155
|
y += 0.0f;
|
156
|
z += SQ3/2;
|
157
|
}
|
158
|
|
159
|
return added;
|
160
|
}
|
161
|
|
162
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163
|
|
164
|
private int emitUpper(float x, float y, float z, int n, Static3D[] array, int index)
|
165
|
{
|
166
|
if( n>1 )
|
167
|
{
|
168
|
emitRow( x , y , z , 1.0f, 0, 0, n-1, -1, array, index);
|
169
|
index += (n-1);
|
170
|
emitRow( x+0.5f , y+SQ3*SQ2/9, z+SQ3/18 , 1.0f, 0, 0, n-1, 1, array, index);
|
171
|
index += (n-1);
|
172
|
emitRow( x+0.5f , y , z+SQ3/2 , 0.5f, 0, SQ3/2, n-1, -1, array, index);
|
173
|
index += (n-1);
|
174
|
emitRow( x +1.0f/3, y+SQ3*SQ2/9, z+2*SQ3/9, 0.5f, 0, SQ3/2, n-1, 3, array, index);
|
175
|
index += (n-1);
|
176
|
emitRow( x+n-1 , y , z , -0.5f, 0, SQ3/2, n-1, -1, array, index);
|
177
|
index += (n-1);
|
178
|
emitRow( x+n-1-1.0f/3, y+SQ3*SQ2/9, z+2*SQ3/9, -0.5f, 0, SQ3/2, n-1, 2, array, index);
|
179
|
index += (n-1);
|
180
|
}
|
181
|
else
|
182
|
{
|
183
|
mRotArray[index] = -1;
|
184
|
array[index] = new Static3D(x+0.5f,y+SQ2*SQ3/12,z+SQ3/6);
|
185
|
index++;
|
186
|
}
|
187
|
|
188
|
return index;
|
189
|
}
|
190
|
|
191
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
192
|
// size^2 + 3*(size-1) in the lowermost layer, then 6*(size-2) in the next, 6*(size-3) in the next,
|
193
|
// ... 6 in the forelast, 1 in the last = 4size^2 - 6size +4 (if size>1)
|
194
|
|
195
|
Static3D[] getCubitPositions(int size)
|
196
|
{
|
197
|
int numCubits = size>1 ? 4*size*size - 6*size +4 : 1;
|
198
|
Static3D[] tmp = new Static3D[numCubits];
|
199
|
mRotArray = new int[numCubits];
|
200
|
|
201
|
int currentIndex = emitLowermost( -0.5f*size, -(SQ2*SQ3/12)*size, -(SQ3/6)*size, size, tmp);
|
202
|
|
203
|
for(int i=size-1; i>=1; i--)
|
204
|
{
|
205
|
currentIndex = emitUpper( -0.5f*i, ((SQ2*SQ3)/12)*(3*size-4*i), -(SQ3/6)*i, i, tmp, currentIndex);
|
206
|
}
|
207
|
|
208
|
return tmp;
|
209
|
}
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
Static4D[] getQuats()
|
214
|
{
|
215
|
return QUATS;
|
216
|
}
|
217
|
|
218
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219
|
|
220
|
int getNumFaces()
|
221
|
{
|
222
|
return FACE_COLORS.length;
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
int getNumCubitFaces()
|
228
|
{
|
229
|
return FACE_COLORS.length;
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
float getScreenRatio()
|
235
|
{
|
236
|
return 0.82f;
|
237
|
}
|
238
|
|
239
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
240
|
|
241
|
int getFaceColor(int cubit, int cubitface, int size)
|
242
|
{
|
243
|
boolean belongs = isOnFace(cubit, cubitface, 0 );
|
244
|
return belongs ? cubitface : NUM_FACES;
|
245
|
}
|
246
|
|
247
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248
|
|
249
|
private MeshBase createStaticMesh(int cubit)
|
250
|
{
|
251
|
final float SQ2 = (float)Math.sqrt(2);
|
252
|
final float SQ3 = (float)Math.sqrt(3);
|
253
|
final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
|
254
|
final int MESHES=4;
|
255
|
|
256
|
int association = 1;
|
257
|
MeshBase[] meshes = new MeshTriangles[MESHES];
|
258
|
|
259
|
meshes[0] = new MeshTriangles(9);
|
260
|
meshes[0].setEffectAssociation(0,association,0);
|
261
|
|
262
|
for(int i=1; i<MESHES; i++)
|
263
|
{
|
264
|
association <<= 1;
|
265
|
meshes[i] = meshes[0].copy(true);
|
266
|
meshes[i].setEffectAssociation(0,association,0);
|
267
|
}
|
268
|
|
269
|
MeshBase result = new MeshJoined(meshes);
|
270
|
|
271
|
Static3D a0 = new Static3D( 0, 1, 0 );
|
272
|
Static3D a1 = new Static3D( 0, -1.0f/3, 2*SQ2/3 );
|
273
|
Static3D a2 = new Static3D(-SQ2*SQ3/3, -1.0f/3, -SQ2/3 );
|
274
|
Static3D a3 = new Static3D( SQ2*SQ3/3, -1.0f/3, -SQ2/3 );
|
275
|
|
276
|
float tetraHeight = SQ2*SQ3/3;
|
277
|
float d1 = 0.75f*tetraHeight;
|
278
|
float d2 =-0.10f*tetraHeight;
|
279
|
float d3 = 0.20f*tetraHeight;
|
280
|
|
281
|
Static3D dCen0 = new Static3D( d1*a0.get0(), d1*a0.get1(), d1*a0.get2() );
|
282
|
Static3D dCen1 = new Static3D( d1*a1.get0(), d1*a1.get1(), d1*a1.get2() );
|
283
|
Static3D dCen2 = new Static3D( d1*a2.get0(), d1*a2.get1(), d1*a2.get2() );
|
284
|
Static3D dCen3 = new Static3D( d1*a3.get0(), d1*a3.get1(), d1*a3.get2() );
|
285
|
|
286
|
Static3D dVec0 = new Static3D( d2*a0.get0(), d2*a0.get1(), d2*a0.get2() );
|
287
|
Static3D dVec1 = new Static3D( d2*a1.get0(), d2*a1.get1(), d2*a1.get2() );
|
288
|
Static3D dVec2 = new Static3D( d2*a2.get0(), d2*a2.get1(), d2*a2.get2() );
|
289
|
Static3D dVec3 = new Static3D( d2*a3.get0(), d2*a3.get1(), d2*a3.get2() );
|
290
|
|
291
|
Static4D dReg = new Static4D(0,0,0,d3);
|
292
|
Static1D dRad = new Static1D(1);
|
293
|
|
294
|
Static1D angle = new Static1D(angleFaces);
|
295
|
Static3D axis1 = new Static3D( -1, 0, 0);
|
296
|
Static3D axis2 = new Static3D(0.5f, 0, -SQ3/2);
|
297
|
Static3D axis3 = new Static3D(0.5f, 0, +SQ3/2);
|
298
|
Static3D center1= new Static3D(0,-SQ3*SQ2/12,-SQ3/6);
|
299
|
Static3D center2= new Static3D(0,-SQ3*SQ2/12,+SQ3/3);
|
300
|
|
301
|
Static3D center = new Static3D(0,0,0);
|
302
|
Static4D region = new Static4D(0,0,0,0.6f);
|
303
|
|
304
|
VertexEffectScale effect1 = new VertexEffectScale ( new Static3D(1,SQ3/2,1) );
|
305
|
VertexEffectRotate effect2 = new VertexEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
|
306
|
VertexEffectMove effect3 = new VertexEffectMove ( new Static3D(0,-SQ3*SQ2/12,SQ3/12) );
|
307
|
VertexEffectRotate effect4 = new VertexEffectRotate( new Static1D(180), new Static3D(0,0,1), center1 );
|
308
|
VertexEffectRotate effect5 = new VertexEffectRotate( angle, axis1, center1 );
|
309
|
VertexEffectRotate effect6 = new VertexEffectRotate( angle, axis2, center2 );
|
310
|
VertexEffectRotate effect7 = new VertexEffectRotate( angle, axis3, center2 );
|
311
|
|
312
|
VertexEffectDeform effect8 = new VertexEffectDeform(dVec0, dRad, dCen0, dReg);
|
313
|
VertexEffectDeform effect9 = new VertexEffectDeform(dVec1, dRad, dCen1, dReg);
|
314
|
VertexEffectDeform effect10= new VertexEffectDeform(dVec2, dRad, dCen2, dReg);
|
315
|
VertexEffectDeform effect11= new VertexEffectDeform(dVec3, dRad, dCen3, dReg);
|
316
|
|
317
|
VertexEffectSink effect12= new VertexEffectSink( new Static1D(1.3f), center, region );
|
318
|
|
319
|
effect4.setMeshAssociation(14,-1); // apply to mesh[1], [2] and [3]
|
320
|
effect5.setMeshAssociation( 2,-1); // apply only to mesh[1]
|
321
|
effect6.setMeshAssociation( 4,-1); // apply only to mesh[2]
|
322
|
effect7.setMeshAssociation( 8,-1); // apply only to mesh[3]
|
323
|
|
324
|
result.apply(effect1);
|
325
|
result.apply(effect2);
|
326
|
result.apply(effect3);
|
327
|
result.apply(effect4);
|
328
|
result.apply(effect5);
|
329
|
result.apply(effect6);
|
330
|
result.apply(effect7);
|
331
|
result.apply(effect8);
|
332
|
result.apply(effect9);
|
333
|
result.apply(effect10);
|
334
|
result.apply(effect11);
|
335
|
result.apply(effect12);
|
336
|
|
337
|
if( mRotArray[cubit]>=0 )
|
338
|
{
|
339
|
result.apply( ROTATION[mRotArray[cubit]] );
|
340
|
}
|
341
|
|
342
|
result.mergeEffComponents();
|
343
|
|
344
|
return result;
|
345
|
}
|
346
|
|
347
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
348
|
|
349
|
MeshBase createCubitMesh(int cubit)
|
350
|
{
|
351
|
int kind = mRotArray[cubit];
|
352
|
|
353
|
if( kind>=0 )
|
354
|
{
|
355
|
if( mMeshRotated[kind]==null ) mMeshRotated[kind] = createStaticMesh(cubit);
|
356
|
return mMeshRotated[kind].copy(true);
|
357
|
}
|
358
|
else
|
359
|
{
|
360
|
if( mMesh==null ) mMesh = createStaticMesh(cubit);
|
361
|
return mMesh.copy(true);
|
362
|
}
|
363
|
}
|
364
|
|
365
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
366
|
|
367
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
|
368
|
{
|
369
|
float STROKE = 0.06f*side;
|
370
|
float OFF = STROKE/2 -1;
|
371
|
float OFF2 = 0.5f*side + OFF;
|
372
|
float HEIGHT = side - OFF;
|
373
|
float RADIUS = side/12.0f;
|
374
|
float ARC1_H = 0.2f*side;
|
375
|
float ARC1_W = side*0.5f;
|
376
|
float ARC2_W = 0.153f*side;
|
377
|
float ARC2_H = 0.905f*side;
|
378
|
float ARC3_W = side-ARC2_W;
|
379
|
|
380
|
paint.setAntiAlias(true);
|
381
|
paint.setStrokeWidth(STROKE);
|
382
|
paint.setColor(FACE_COLORS[face]);
|
383
|
paint.setStyle(Paint.Style.FILL);
|
384
|
|
385
|
canvas.drawRect(left,top,left+side,top+side,paint);
|
386
|
|
387
|
paint.setColor(INTERIOR_COLOR);
|
388
|
paint.setStyle(Paint.Style.STROKE);
|
389
|
|
390
|
canvas.drawLine( left, HEIGHT, side +left, HEIGHT, paint);
|
391
|
canvas.drawLine( OFF +left, side , OFF2 +left, 0, paint);
|
392
|
canvas.drawLine((side-OFF)+left, side , (side-OFF2) +left, 0, paint);
|
393
|
|
394
|
canvas.drawArc( ARC1_W-RADIUS+left, ARC1_H-RADIUS, ARC1_W+RADIUS+left, ARC1_H+RADIUS, 225, 90, false, paint);
|
395
|
canvas.drawArc( ARC2_W-RADIUS+left, ARC2_H-RADIUS, ARC2_W+RADIUS+left, ARC2_H+RADIUS, 105, 90, false, paint);
|
396
|
canvas.drawArc( ARC3_W-RADIUS+left, ARC2_H-RADIUS, ARC3_W+RADIUS+left, ARC2_H+RADIUS, 345, 90, false, paint);
|
397
|
}
|
398
|
|
399
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
400
|
// I don't quite understand it, but 0.82 works better than the theoretically correct SQ3/2 ( 0.866 )
|
401
|
|
402
|
float returnMultiplier()
|
403
|
{
|
404
|
return getSize()/0.82f;//(SQ3/2);
|
405
|
}
|
406
|
|
407
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
408
|
|
409
|
float[] getRowChances()
|
410
|
{
|
411
|
int size = getSize();
|
412
|
int total = size*(size+1)/2;
|
413
|
float running=0.0f;
|
414
|
float[] chances = new float[size];
|
415
|
|
416
|
for(int i=0; i<size; i++)
|
417
|
{
|
418
|
running += (size-i);
|
419
|
chances[i] = running / total;
|
420
|
}
|
421
|
|
422
|
return chances;
|
423
|
}
|
424
|
|
425
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
426
|
// PUBLIC API
|
427
|
|
428
|
public Static3D[] getRotationAxis()
|
429
|
{
|
430
|
return ROT_AXIS;
|
431
|
}
|
432
|
|
433
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
434
|
|
435
|
public int getBasicAngle()
|
436
|
{
|
437
|
return 3;
|
438
|
}
|
439
|
|
440
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
441
|
// 0.82?? see returnMultiplier()
|
442
|
|
443
|
public int computeRowFromOffset(float offset)
|
444
|
{
|
445
|
return (int)(getSize()*offset/0.82f);
|
446
|
}
|
447
|
|
448
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
449
|
|
450
|
public float returnRotationFactor(float offset)
|
451
|
{
|
452
|
int size = getSize();
|
453
|
int row = (int)(size*offset/(SQ3/2));
|
454
|
|
455
|
return ((float)size)/(size-row);
|
456
|
}
|
457
|
|
458
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
459
|
|
460
|
public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
|
461
|
{
|
462
|
int numAxis = ROTATION_AXIS.length;
|
463
|
|
464
|
if( oldRotAxis == START_AXIS )
|
465
|
{
|
466
|
return rnd.nextInt(numAxis);
|
467
|
}
|
468
|
else
|
469
|
{
|
470
|
int newVector = rnd.nextInt(numAxis-1);
|
471
|
return (newVector>=oldRotAxis ? newVector+1 : newVector);
|
472
|
}
|
473
|
}
|
474
|
|
475
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476
|
|
477
|
public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
|
478
|
{
|
479
|
float rowFloat = rnd.nextFloat();
|
480
|
|
481
|
for(int row=0; row<mRowChances.length; row++)
|
482
|
{
|
483
|
if( rowFloat<=mRowChances[row] ) return row;
|
484
|
}
|
485
|
|
486
|
return 0;
|
487
|
}
|
488
|
|
489
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490
|
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
|
491
|
// then if it were rotated by quaternion 'quat'.
|
492
|
// No it is not so simple as the quats need to be the same - imagine a 4x4x4 cube where the two
|
493
|
// middle squares get interchanged. No visible difference!
|
494
|
//
|
495
|
// So: this is true iff the cubit
|
496
|
// a) is a corner or edge and the quaternions are the same
|
497
|
// b) is inside one of the faces and after rotations by both quats it ends up on the same face.
|
498
|
|
499
|
boolean thereIsNoVisibleDifference(Cubit cubit, int quatIndex)
|
500
|
{
|
501
|
if ( cubit.mQuatIndex == quatIndex ) return true;
|
502
|
|
503
|
int belongsToHowManyFaces = 0;
|
504
|
int size = getSize()-1;
|
505
|
float row;
|
506
|
final float MAX_ERROR = 0.01f;
|
507
|
|
508
|
for(int i=0; i<NUM_AXIS; i++)
|
509
|
{
|
510
|
row = cubit.mRotationRow[i];
|
511
|
if( (row <MAX_ERROR && row >-MAX_ERROR) ||
|
512
|
(row-size<MAX_ERROR && row-size>-MAX_ERROR) ) belongsToHowManyFaces++;
|
513
|
}
|
514
|
|
515
|
switch(belongsToHowManyFaces)
|
516
|
{
|
517
|
case 0 : return true ; // 'inside' cubit that does not lie on any face
|
518
|
case 1 : // cubit that lies inside one of the faces
|
519
|
Static3D orig = cubit.getOrigPosition();
|
520
|
Static4D quat1 = QUATS[quatIndex];
|
521
|
Static4D quat2 = QUATS[cubit.mQuatIndex];
|
522
|
|
523
|
Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0);
|
524
|
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 );
|
525
|
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 );
|
526
|
|
527
|
float row1, row2, row3, row4;
|
528
|
float ax,ay,az;
|
529
|
Static3D axis;
|
530
|
float x1 = rotated1.get0();
|
531
|
float y1 = rotated1.get1();
|
532
|
float z1 = rotated1.get2();
|
533
|
float x2 = rotated2.get0();
|
534
|
float y2 = rotated2.get1();
|
535
|
float z2 = rotated2.get2();
|
536
|
|
537
|
for(int i=0; i<NUM_AXIS; i++)
|
538
|
{
|
539
|
axis = ROTATION_AXIS[i];
|
540
|
ax = axis.get0();
|
541
|
ay = axis.get1();
|
542
|
az = axis.get2();
|
543
|
|
544
|
row1 = ((x1*ax + y1*ay + z1*az) - mStart) / mStep;
|
545
|
row2 = ((x2*ax + y2*ay + z2*az) - mStart) / mStep;
|
546
|
row3 = row1 - size;
|
547
|
row4 = row2 - size;
|
548
|
|
549
|
if( (row1<MAX_ERROR && row1>-MAX_ERROR && row2<MAX_ERROR && row2>-MAX_ERROR) ||
|
550
|
(row3<MAX_ERROR && row3>-MAX_ERROR && row4<MAX_ERROR && row4>-MAX_ERROR) )
|
551
|
{
|
552
|
return true;
|
553
|
}
|
554
|
}
|
555
|
return false;
|
556
|
|
557
|
default: return false; // edge or corner
|
558
|
}
|
559
|
}
|
560
|
|
561
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
562
|
// TODO (only needed for solvers - there are no Pyraminx solvers ATM)
|
563
|
|
564
|
public String retObjectString()
|
565
|
{
|
566
|
return "";
|
567
|
}
|
568
|
}
|