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 TwistyDiamond extends TwistyObject
|
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
|
TwistyDiamond(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, ObjectList.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
|
}
|