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.helpers.FactoryCubit;
|
27
|
import org.distorted.helpers.FactorySticker;
|
28
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29
|
import org.distorted.library.main.DistortedEffects;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshBase;
|
32
|
import org.distorted.library.mesh.MeshSquare;
|
33
|
import org.distorted.library.type.Static3D;
|
34
|
import org.distorted.library.type.Static4D;
|
35
|
import org.distorted.main.RubikSurfaceView;
|
36
|
|
37
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
38
|
|
39
|
public abstract class TwistyDino extends TwistyObject
|
40
|
{
|
41
|
// the four rotation axis of a RubikDino. Must be normalized.
|
42
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
43
|
{
|
44
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
45
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
46
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
47
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
48
|
};
|
49
|
|
50
|
private static final int[] FACE_COLORS = new int[]
|
51
|
{
|
52
|
COLOR_YELLOW, COLOR_WHITE,
|
53
|
COLOR_BLUE , COLOR_GREEN,
|
54
|
COLOR_RED , COLOR_ORANGE
|
55
|
};
|
56
|
|
57
|
// All legal rotation quats of a RubikDino
|
58
|
static final Static4D[] QUATS = new Static4D[]
|
59
|
{
|
60
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
61
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
62
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
63
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
64
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
65
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
66
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ),
|
67
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
68
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
69
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
70
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
71
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
72
|
};
|
73
|
|
74
|
// centers of the 12 edges. Must be in the same order like QUATs above.
|
75
|
private static final float[][] CENTERS = new float[][]
|
76
|
{
|
77
|
{ 0.0f, 1.5f, 1.5f },
|
78
|
{ 1.5f, 0.0f, 1.5f },
|
79
|
{ 0.0f,-1.5f, 1.5f },
|
80
|
{-1.5f, 0.0f, 1.5f },
|
81
|
{ 1.5f, 1.5f, 0.0f },
|
82
|
{ 1.5f,-1.5f, 0.0f },
|
83
|
{-1.5f,-1.5f, 0.0f },
|
84
|
{-1.5f, 1.5f, 0.0f },
|
85
|
{ 0.0f, 1.5f,-1.5f },
|
86
|
{ 1.5f, 0.0f,-1.5f },
|
87
|
{ 0.0f,-1.5f,-1.5f },
|
88
|
{-1.5f, 0.0f,-1.5f }
|
89
|
};
|
90
|
|
91
|
private static final double[][] VERTICES = new double[][]
|
92
|
{
|
93
|
{-1.5, 0.0, 0.0},
|
94
|
{ 1.5, 0.0, 0.0},
|
95
|
{ 0.0,-1.5, 0.0},
|
96
|
{ 0.0, 0.0,-1.5}
|
97
|
};
|
98
|
|
99
|
private static final int[][] VERT_INDEXES = new int[][]
|
100
|
{
|
101
|
{2,1,0}, // counterclockwise!
|
102
|
{3,0,1},
|
103
|
{2,3,1},
|
104
|
{3,2,0},
|
105
|
};
|
106
|
|
107
|
private static final float[][] STICKERS = new float[][]
|
108
|
{
|
109
|
{ 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
|
110
|
};
|
111
|
|
112
|
private static MeshBase[] mMeshes;
|
113
|
|
114
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115
|
|
116
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
117
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
118
|
{
|
119
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
120
|
}
|
121
|
|
122
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123
|
|
124
|
double[][] getVertices(int cubitType)
|
125
|
{
|
126
|
return VERTICES;
|
127
|
}
|
128
|
|
129
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130
|
|
131
|
int[][] getVertIndexes(int cubitType)
|
132
|
{
|
133
|
return VERT_INDEXES;
|
134
|
}
|
135
|
|
136
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
137
|
|
138
|
int getNumCubitTypes(int numLayers)
|
139
|
{
|
140
|
return 1;
|
141
|
}
|
142
|
|
143
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144
|
|
145
|
int mulQuat(int q1, int q2)
|
146
|
{
|
147
|
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
|
148
|
|
149
|
float rX = result.get0();
|
150
|
float rY = result.get1();
|
151
|
float rZ = result.get2();
|
152
|
float rW = result.get3();
|
153
|
|
154
|
final float MAX_ERROR = 0.1f;
|
155
|
float dX,dY,dZ,dW;
|
156
|
|
157
|
for(int i=0; i<QUATS.length; i++)
|
158
|
{
|
159
|
dX = QUATS[i].get0() - rX;
|
160
|
dY = QUATS[i].get1() - rY;
|
161
|
dZ = QUATS[i].get2() - rZ;
|
162
|
dW = QUATS[i].get3() - rW;
|
163
|
|
164
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
165
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
166
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
167
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
168
|
|
169
|
dX = QUATS[i].get0() + rX;
|
170
|
dY = QUATS[i].get1() + rY;
|
171
|
dZ = QUATS[i].get2() + rZ;
|
172
|
dW = QUATS[i].get3() + rW;
|
173
|
|
174
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
175
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
176
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
177
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
178
|
}
|
179
|
|
180
|
return -1;
|
181
|
}
|
182
|
|
183
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184
|
|
185
|
float getScreenRatio()
|
186
|
{
|
187
|
return 0.5f;
|
188
|
}
|
189
|
|
190
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191
|
|
192
|
Static4D[] getQuats()
|
193
|
{
|
194
|
return QUATS;
|
195
|
}
|
196
|
|
197
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198
|
|
199
|
int getNumFaces()
|
200
|
{
|
201
|
return FACE_COLORS.length;
|
202
|
}
|
203
|
|
204
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
205
|
|
206
|
float[] getCuts(int size)
|
207
|
{
|
208
|
return new float[] { -SQ3/3, +SQ3/3 };
|
209
|
}
|
210
|
|
211
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
212
|
|
213
|
int getNumStickerTypes(int numLayers)
|
214
|
{
|
215
|
return STICKERS.length;
|
216
|
}
|
217
|
|
218
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219
|
|
220
|
int getNumCubitFaces()
|
221
|
{
|
222
|
return 4;
|
223
|
}
|
224
|
|
225
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226
|
|
227
|
float[][] getCubitPositions(int size)
|
228
|
{
|
229
|
return CENTERS;
|
230
|
}
|
231
|
|
232
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233
|
|
234
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
235
|
{
|
236
|
if( mMeshes==null )
|
237
|
{
|
238
|
FactoryCubit factory = FactoryCubit.getInstance();
|
239
|
factory.clear();
|
240
|
mMeshes = new MeshBase[1];
|
241
|
}
|
242
|
|
243
|
if( mMeshes[0]==null )
|
244
|
{
|
245
|
float[][] bands= new float[][]
|
246
|
{
|
247
|
{0.035f,30,0.16f,0.8f,7,2,5},
|
248
|
{0.020f,45,0.16f,0.2f,3,1,2}
|
249
|
};
|
250
|
int[] bandIndexes = new int[] { 0,0,1,1 };
|
251
|
float[][] corners = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
|
252
|
int[] cornerIndexes = new int[] { 0,0,1,1 };
|
253
|
float[][] centers = new float[][] { {0.0f, -0.75f, -0.75f} };
|
254
|
int[] centerIndexes = new int[] { 0,0,0,0 };
|
255
|
|
256
|
FactoryCubit factory = FactoryCubit.getInstance();
|
257
|
|
258
|
factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
|
259
|
mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
|
260
|
bands, bandIndexes,
|
261
|
corners, cornerIndexes,
|
262
|
centers, centerIndexes,
|
263
|
getNumCubitFaces() );
|
264
|
}
|
265
|
|
266
|
MeshBase mesh = mMeshes[0].copy(true);
|
267
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
|
268
|
mesh.apply(quat,0xffffffff,0);
|
269
|
|
270
|
return mesh;
|
271
|
}
|
272
|
|
273
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274
|
|
275
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
276
|
{
|
277
|
float R = 0.025f;
|
278
|
float S = 0.05f;
|
279
|
|
280
|
FactorySticker factory = FactorySticker.getInstance();
|
281
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
282
|
}
|
283
|
|
284
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
285
|
|
286
|
float returnMultiplier()
|
287
|
{
|
288
|
return 2.0f;
|
289
|
}
|
290
|
|
291
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
292
|
|
293
|
float[] getRowChances(int numLayers)
|
294
|
{
|
295
|
float[] chances = new float[3];
|
296
|
|
297
|
chances[0] = 0.5f;
|
298
|
chances[1] = 0.5f;
|
299
|
chances[2] = 1.0f;
|
300
|
|
301
|
return chances;
|
302
|
}
|
303
|
|
304
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305
|
// PUBLIC API
|
306
|
|
307
|
public Static3D[] getRotationAxis()
|
308
|
{
|
309
|
return ROT_AXIS;
|
310
|
}
|
311
|
|
312
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
313
|
|
314
|
public int getBasicAngle()
|
315
|
{
|
316
|
return 3;
|
317
|
}
|
318
|
|
319
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320
|
// only needed for solvers - there are no Dino solvers ATM)
|
321
|
|
322
|
public String retObjectString()
|
323
|
{
|
324
|
return "";
|
325
|
}
|
326
|
|
327
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
328
|
|
329
|
public int getComplexity(int numLayers)
|
330
|
{
|
331
|
return 2;
|
332
|
}
|
333
|
}
|