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 |
|
|
|
24 |
f10a88a8
|
Leszek Koltunski
|
import org.distorted.helpers.ObjectShape;
|
25 |
9c06394a
|
Leszek Koltunski
|
import org.distorted.helpers.ObjectSticker;
|
26 |
6cf89a3e
|
Leszek Koltunski
|
import org.distorted.helpers.ScrambleState;
|
27 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
28 |
|
|
import org.distorted.library.main.DistortedTexture;
|
29 |
efa8aa48
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshSquare;
|
30 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
31 |
|
|
import org.distorted.library.type.Static4D;
|
32 |
|
|
|
33 |
20898e6f
|
Leszek Koltunski
|
import java.util.Random;
|
34 |
|
|
|
35 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
9c2f0c91
|
Leszek Koltunski
|
public abstract class TwistyDino extends TwistyObject
|
38 |
418aa554
|
Leszek Koltunski
|
{
|
39 |
|
|
// the four rotation axis of a RubikDino. Must be normalized.
|
40 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
41 |
418aa554
|
Leszek Koltunski
|
{
|
42 |
|
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
43 |
|
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
44 |
|
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
45 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
46 |
|
|
};
|
47 |
|
|
|
48 |
|
|
private static final int[] FACE_COLORS = new int[]
|
49 |
|
|
{
|
50 |
ece1b58d
|
Leszek Koltunski
|
COLOR_YELLOW, COLOR_WHITE,
|
51 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
52 |
323b217c
|
Leszek Koltunski
|
COLOR_RED , COLOR_ORANGE
|
53 |
418aa554
|
Leszek Koltunski
|
};
|
54 |
|
|
|
55 |
20898e6f
|
Leszek Koltunski
|
private int mCurrState;
|
56 |
|
|
private int mIndexExcluded;
|
57 |
6cf89a3e
|
Leszek Koltunski
|
private int[][] mScrambleTable;
|
58 |
|
|
private int[] mNumOccurences;
|
59 |
d464f54f
|
Leszek Koltunski
|
private int[] mBasicAngle;
|
60 |
|
|
private Static4D[] mQuats;
|
61 |
|
|
private ObjectSticker[] mStickers;
|
62 |
85449b44
|
Leszek Koltunski
|
private float[][] mCenters;
|
63 |
d464f54f
|
Leszek Koltunski
|
ScrambleState[] mStates;
|
64 |
20898e6f
|
Leszek Koltunski
|
|
65 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
9c2f0c91
|
Leszek Koltunski
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
68 |
|
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
69 |
418aa554
|
Leszek Koltunski
|
{
|
70 |
db875721
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
71 |
418aa554
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
d464f54f
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
|
|
private void initializeQuats()
|
76 |
|
|
{
|
77 |
|
|
mQuats = new Static4D[]
|
78 |
|
|
{
|
79 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
80 |
|
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
81 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
82 |
|
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
83 |
|
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
84 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
85 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ),
|
86 |
|
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
87 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
88 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
89 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
90 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
91 |
|
|
};
|
92 |
|
|
}
|
93 |
|
|
|
94 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
95 |
|
|
|
96 |
|
|
float getScreenRatio()
|
97 |
|
|
{
|
98 |
c7e79b69
|
Leszek Koltunski
|
return 0.5f;
|
99 |
418aa554
|
Leszek Koltunski
|
}
|
100 |
|
|
|
101 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
Static4D[] getQuats()
|
104 |
|
|
{
|
105 |
d464f54f
|
Leszek Koltunski
|
if( mQuats==null ) initializeQuats();
|
106 |
|
|
return mQuats;
|
107 |
418aa554
|
Leszek Koltunski
|
}
|
108 |
|
|
|
109 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110 |
|
|
|
111 |
|
|
int getNumFaces()
|
112 |
|
|
{
|
113 |
|
|
return FACE_COLORS.length;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int size)
|
119 |
7403cdfa
|
Leszek Koltunski
|
{
|
120 |
e6734aa9
|
Leszek Koltunski
|
float[] cut = new float[] { -SQ3/3, +SQ3/3 };
|
121 |
|
|
return new float[][] { cut,cut,cut,cut };
|
122 |
7403cdfa
|
Leszek Koltunski
|
}
|
123 |
|
|
|
124 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
125 |
|
|
|
126 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
127 |
eab9d8f8
|
Leszek Koltunski
|
{
|
128 |
d464f54f
|
Leszek Koltunski
|
return 1;
|
129 |
eab9d8f8
|
Leszek Koltunski
|
}
|
130 |
|
|
|
131 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132 |
|
|
|
133 |
8f53e513
|
Leszek Koltunski
|
int getNumCubitFaces()
|
134 |
418aa554
|
Leszek Koltunski
|
{
|
135 |
8f53e513
|
Leszek Koltunski
|
return 4;
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139 |
418aa554
|
Leszek Koltunski
|
|
140 |
e6cf7283
|
Leszek Koltunski
|
float[][] getCubitPositions(int size)
|
141 |
8f53e513
|
Leszek Koltunski
|
{
|
142 |
d464f54f
|
Leszek Koltunski
|
if( mCenters ==null )
|
143 |
|
|
{
|
144 |
|
|
mCenters = new float[][]
|
145 |
|
|
{
|
146 |
|
|
{ 0.0f, 1.5f, 1.5f },
|
147 |
|
|
{ 1.5f, 0.0f, 1.5f },
|
148 |
|
|
{ 0.0f,-1.5f, 1.5f },
|
149 |
|
|
{-1.5f, 0.0f, 1.5f },
|
150 |
|
|
{ 1.5f, 1.5f, 0.0f },
|
151 |
|
|
{ 1.5f,-1.5f, 0.0f },
|
152 |
|
|
{-1.5f,-1.5f, 0.0f },
|
153 |
|
|
{-1.5f, 1.5f, 0.0f },
|
154 |
|
|
{ 0.0f, 1.5f,-1.5f },
|
155 |
|
|
{ 1.5f, 0.0f,-1.5f },
|
156 |
|
|
{ 0.0f,-1.5f,-1.5f },
|
157 |
|
|
{-1.5f, 0.0f,-1.5f }
|
158 |
|
|
};
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
return mCenters;
|
162 |
418aa554
|
Leszek Koltunski
|
}
|
163 |
|
|
|
164 |
f10a88a8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
3e605536
|
Leszek Koltunski
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
167 |
f10a88a8
|
Leszek Koltunski
|
{
|
168 |
d464f54f
|
Leszek Koltunski
|
double[][] vertices = new double[][] { {-1.5, 0.0, 0.0},{ 1.5, 0.0, 0.0},{ 0.0,-1.5, 0.0},{ 0.0, 0.0,-1.5} };
|
169 |
|
|
int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
|
170 |
3e605536
|
Leszek Koltunski
|
float[][] bands = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
|
171 |
|
|
int[] bandIndices = new int[] { 0,0,1,1 };
|
172 |
|
|
float[][] corners = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
|
173 |
|
|
int[] cornerIndices = new int[] { 0,0,1,1 };
|
174 |
|
|
float[][] centers = new float[][] { {0.0f, -0.75f, -0.75f} };
|
175 |
|
|
int[] centerIndices = new int[] { 0,0,0,0 };
|
176 |
d464f54f
|
Leszek Koltunski
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
177 |
f10a88a8
|
Leszek Koltunski
|
}
|
178 |
|
|
|
179 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
180 |
|
|
|
181 |
3e605536
|
Leszek Koltunski
|
Static4D getQuat(int cubit, int numLayers)
|
182 |
f10a88a8
|
Leszek Koltunski
|
{
|
183 |
d464f54f
|
Leszek Koltunski
|
if( mQuats==null ) initializeQuats();
|
184 |
|
|
return mQuats[cubit];
|
185 |
f10a88a8
|
Leszek Koltunski
|
}
|
186 |
|
|
|
187 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188 |
|
|
|
189 |
3e605536
|
Leszek Koltunski
|
int getNumCubitVariants(int numLayers)
|
190 |
f10a88a8
|
Leszek Koltunski
|
{
|
191 |
3e605536
|
Leszek Koltunski
|
return 1;
|
192 |
f10a88a8
|
Leszek Koltunski
|
}
|
193 |
|
|
|
194 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195 |
|
|
|
196 |
3e605536
|
Leszek Koltunski
|
int getCubitVariant(int cubit, int numLayers)
|
197 |
418aa554
|
Leszek Koltunski
|
{
|
198 |
3e605536
|
Leszek Koltunski
|
return 0;
|
199 |
418aa554
|
Leszek Koltunski
|
}
|
200 |
|
|
|
201 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
202 |
|
|
|
203 |
9c06394a
|
Leszek Koltunski
|
int getColor(int face)
|
204 |
418aa554
|
Leszek Koltunski
|
{
|
205 |
9c06394a
|
Leszek Koltunski
|
return FACE_COLORS[face];
|
206 |
|
|
}
|
207 |
76c2bd07
|
Leszek Koltunski
|
|
208 |
9c06394a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
209 |
|
|
|
210 |
|
|
ObjectSticker retSticker(int face)
|
211 |
|
|
{
|
212 |
d464f54f
|
Leszek Koltunski
|
if( mStickers==null )
|
213 |
|
|
{
|
214 |
|
|
float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
|
215 |
|
|
float radius = 0.025f;
|
216 |
|
|
float stroke = 0.050f;
|
217 |
|
|
float[] radii = new float[] {radius,radius,radius};
|
218 |
|
|
mStickers = new ObjectSticker[STICKERS.length];
|
219 |
|
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
220 |
|
|
}
|
221 |
|
|
|
222 |
9c06394a
|
Leszek Koltunski
|
return mStickers[face/NUM_FACES];
|
223 |
418aa554
|
Leszek Koltunski
|
}
|
224 |
|
|
|
225 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226 |
|
|
|
227 |
|
|
float returnMultiplier()
|
228 |
|
|
{
|
229 |
|
|
return 2.0f;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
6cf89a3e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233 |
|
|
|
234 |
|
|
private void initializeScrambling()
|
235 |
|
|
{
|
236 |
|
|
int numLayers = getNumLayers();
|
237 |
|
|
|
238 |
|
|
if( mScrambleTable ==null )
|
239 |
|
|
{
|
240 |
|
|
mScrambleTable = new int[NUM_AXIS][numLayers];
|
241 |
|
|
}
|
242 |
|
|
if( mNumOccurences ==null )
|
243 |
|
|
{
|
244 |
|
|
int max=0;
|
245 |
|
|
|
246 |
|
|
for (ScrambleState mState : mStates)
|
247 |
|
|
{
|
248 |
|
|
int tmp = mState.getTotal(-1);
|
249 |
|
|
if (max < tmp) max = tmp;
|
250 |
|
|
}
|
251 |
|
|
|
252 |
|
|
mNumOccurences = new int[max];
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
for(int i=0; i<NUM_AXIS; i++)
|
256 |
|
|
for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
|
257 |
|
|
}
|
258 |
|
|
|
259 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
260 |
|
|
// PUBLIC API
|
261 |
|
|
|
262 |
20898e6f
|
Leszek Koltunski
|
public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
|
263 |
|
|
{
|
264 |
|
|
if( curr==0 )
|
265 |
|
|
{
|
266 |
|
|
mCurrState = 0;
|
267 |
|
|
mIndexExcluded =-1;
|
268 |
6cf89a3e
|
Leszek Koltunski
|
initializeScrambling();
|
269 |
20898e6f
|
Leszek Koltunski
|
}
|
270 |
|
|
|
271 |
6cf89a3e
|
Leszek Koltunski
|
int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
|
272 |
20898e6f
|
Leszek Koltunski
|
|
273 |
|
|
scramble[curr][0] = info[0];
|
274 |
|
|
scramble[curr][1] = info[1];
|
275 |
|
|
scramble[curr][2] = info[2];
|
276 |
|
|
|
277 |
|
|
mCurrState = info[3];
|
278 |
|
|
mIndexExcluded = info[0];
|
279 |
|
|
}
|
280 |
|
|
|
281 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
282 |
|
|
|
283 |
418aa554
|
Leszek Koltunski
|
public Static3D[] getRotationAxis()
|
284 |
|
|
{
|
285 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
286 |
418aa554
|
Leszek Koltunski
|
}
|
287 |
|
|
|
288 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
289 |
|
|
|
290 |
925ed78f
|
Leszek Koltunski
|
public int[] getBasicAngle()
|
291 |
418aa554
|
Leszek Koltunski
|
{
|
292 |
d464f54f
|
Leszek Koltunski
|
if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
293 |
|
|
return mBasicAngle;
|
294 |
418aa554
|
Leszek Koltunski
|
}
|
295 |
|
|
|
296 |
6fd4a72c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
297 |
|
|
|
298 |
|
|
public int getComplexity(int numLayers)
|
299 |
|
|
{
|
300 |
|
|
return 2;
|
301 |
|
|
}
|
302 |
418aa554
|
Leszek Koltunski
|
}
|