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 |
|
|
import android.graphics.Canvas;
|
24 |
|
|
import android.graphics.Paint;
|
25 |
|
|
|
26 |
8f53e513
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
27 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
28 |
|
|
import org.distorted.library.main.DistortedTexture;
|
29 |
|
|
import org.distorted.library.mesh.MeshBase;
|
30 |
efa8aa48
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshSquare;
|
31 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
32 |
|
|
import org.distorted.library.type.Static4D;
|
33 |
ece1b58d
|
Leszek Koltunski
|
import org.distorted.main.RubikSurfaceView;
|
34 |
418aa554
|
Leszek Koltunski
|
|
35 |
7c969a6d
|
Leszek Koltunski
|
import java.util.Random;
|
36 |
|
|
|
37 |
|
|
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
|
38 |
|
|
|
39 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40 |
|
|
|
41 |
9c2f0c91
|
Leszek Koltunski
|
public abstract class TwistyDino extends TwistyObject
|
42 |
418aa554
|
Leszek Koltunski
|
{
|
43 |
8f53e513
|
Leszek Koltunski
|
private static final float SQ3 = (float)Math.sqrt(3);
|
44 |
418aa554
|
Leszek Koltunski
|
|
45 |
|
|
// the four rotation axis of a RubikDino. Must be normalized.
|
46 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
47 |
418aa554
|
Leszek Koltunski
|
{
|
48 |
|
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
49 |
|
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
50 |
|
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
51 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
52 |
|
|
};
|
53 |
|
|
|
54 |
|
|
private static final int[] FACE_COLORS = new int[]
|
55 |
|
|
{
|
56 |
ece1b58d
|
Leszek Koltunski
|
COLOR_YELLOW, COLOR_WHITE,
|
57 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
58 |
|
|
COLOR_RED , COLOR_BROWN
|
59 |
418aa554
|
Leszek Koltunski
|
};
|
60 |
|
|
|
61 |
|
|
// All legal rotation quats of a RubikDino
|
62 |
eaee1ddc
|
Leszek Koltunski
|
static final Static4D[] QUATS = new Static4D[]
|
63 |
418aa554
|
Leszek Koltunski
|
{
|
64 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
65 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
66 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
67 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
68 |
418aa554
|
Leszek Koltunski
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
69 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
70 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ),
|
71 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
72 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
73 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
74 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
75 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
76 |
8f53e513
|
Leszek Koltunski
|
};
|
77 |
|
|
|
78 |
|
|
// centers of the 12 edges. Must be in the same order like QUATs above.
|
79 |
|
|
private static final Static3D[] CENTERS = new Static3D[]
|
80 |
|
|
{
|
81 |
c7e79b69
|
Leszek Koltunski
|
new Static3D( 0.0f, 1.5f, 1.5f ),
|
82 |
|
|
new Static3D( 1.5f, 0.0f, 1.5f ),
|
83 |
|
|
new Static3D( 0.0f,-1.5f, 1.5f ),
|
84 |
|
|
new Static3D(-1.5f, 0.0f, 1.5f ),
|
85 |
|
|
new Static3D( 1.5f, 1.5f, 0.0f ),
|
86 |
|
|
new Static3D( 1.5f,-1.5f, 0.0f ),
|
87 |
|
|
new Static3D(-1.5f,-1.5f, 0.0f ),
|
88 |
|
|
new Static3D(-1.5f, 1.5f, 0.0f ),
|
89 |
|
|
new Static3D( 0.0f, 1.5f,-1.5f ),
|
90 |
|
|
new Static3D( 1.5f, 0.0f,-1.5f ),
|
91 |
|
|
new Static3D( 0.0f,-1.5f,-1.5f ),
|
92 |
|
|
new Static3D(-1.5f, 0.0f,-1.5f )
|
93 |
418aa554
|
Leszek Koltunski
|
};
|
94 |
|
|
|
95 |
8f53e513
|
Leszek Koltunski
|
private static MeshBase mMesh;
|
96 |
418aa554
|
Leszek Koltunski
|
|
97 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98 |
|
|
|
99 |
9c2f0c91
|
Leszek Koltunski
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
100 |
|
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
101 |
418aa554
|
Leszek Koltunski
|
{
|
102 |
eaee1ddc
|
Leszek Koltunski
|
super(size, 60, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
103 |
418aa554
|
Leszek Koltunski
|
}
|
104 |
|
|
|
105 |
ece1b58d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
106 |
|
|
|
107 |
|
|
int mulQuat(int q1, int q2)
|
108 |
|
|
{
|
109 |
|
|
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
|
110 |
|
|
|
111 |
|
|
float rX = result.get0();
|
112 |
|
|
float rY = result.get1();
|
113 |
|
|
float rZ = result.get2();
|
114 |
|
|
float rW = result.get3();
|
115 |
|
|
|
116 |
|
|
final float MAX_ERROR = 0.1f;
|
117 |
|
|
float dX,dY,dZ,dW;
|
118 |
|
|
|
119 |
|
|
for(int i=0; i<QUATS.length; i++)
|
120 |
|
|
{
|
121 |
|
|
dX = QUATS[i].get0() - rX;
|
122 |
|
|
dY = QUATS[i].get1() - rY;
|
123 |
|
|
dZ = QUATS[i].get2() - rZ;
|
124 |
|
|
dW = QUATS[i].get3() - rW;
|
125 |
|
|
|
126 |
|
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
127 |
|
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
128 |
|
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
129 |
|
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
130 |
|
|
|
131 |
|
|
dX = QUATS[i].get0() + rX;
|
132 |
|
|
dY = QUATS[i].get1() + rY;
|
133 |
|
|
dZ = QUATS[i].get2() + rZ;
|
134 |
|
|
dW = QUATS[i].get3() + rW;
|
135 |
|
|
|
136 |
|
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
137 |
|
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
138 |
|
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
139 |
|
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
return -1;
|
143 |
|
|
}
|
144 |
|
|
|
145 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146 |
|
|
|
147 |
|
|
float getScreenRatio()
|
148 |
|
|
{
|
149 |
c7e79b69
|
Leszek Koltunski
|
return 0.5f;
|
150 |
418aa554
|
Leszek Koltunski
|
}
|
151 |
|
|
|
152 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153 |
|
|
|
154 |
|
|
Static4D[] getQuats()
|
155 |
|
|
{
|
156 |
|
|
return QUATS;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160 |
|
|
|
161 |
|
|
int getNumFaces()
|
162 |
|
|
{
|
163 |
|
|
return FACE_COLORS.length;
|
164 |
|
|
}
|
165 |
|
|
|
166 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
|
|
|
168 |
|
|
float getBasicStep()
|
169 |
|
|
{
|
170 |
|
|
return SQ3;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
|
|
int getNumStickerTypes()
|
176 |
|
|
{
|
177 |
|
|
return 1;
|
178 |
|
|
}
|
179 |
|
|
|
180 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
181 |
|
|
|
182 |
8f53e513
|
Leszek Koltunski
|
int getNumCubitFaces()
|
183 |
418aa554
|
Leszek Koltunski
|
{
|
184 |
8f53e513
|
Leszek Koltunski
|
return 4;
|
185 |
|
|
}
|
186 |
|
|
|
187 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
188 |
418aa554
|
Leszek Koltunski
|
|
189 |
8f53e513
|
Leszek Koltunski
|
Static3D[] getCubitPositions(int size)
|
190 |
|
|
{
|
191 |
|
|
return CENTERS;
|
192 |
418aa554
|
Leszek Koltunski
|
}
|
193 |
|
|
|
194 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
195 |
|
|
|
196 |
|
|
MeshBase createCubitMesh(int cubit)
|
197 |
|
|
{
|
198 |
ac940e24
|
Leszek Koltunski
|
if( mMesh==null ) mMesh = CubitFactory.getInstance().createDinoMesh();
|
199 |
8f53e513
|
Leszek Koltunski
|
|
200 |
|
|
MeshBase mesh = mMesh.copy(true);
|
201 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
|
202 |
|
|
mesh.apply(quat,0xffffffff,0);
|
203 |
418aa554
|
Leszek Koltunski
|
|
204 |
8f53e513
|
Leszek Koltunski
|
return mesh;
|
205 |
418aa554
|
Leszek Koltunski
|
}
|
206 |
|
|
|
207 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
208 |
|
|
|
209 |
|
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top, int side)
|
210 |
|
|
{
|
211 |
fcc0e034
|
Leszek Koltunski
|
float STROKE = 0.04f*side;
|
212 |
|
|
float L= left;
|
213 |
|
|
float H= 0.333f*side;
|
214 |
|
|
float LEN = 0.5f*side;
|
215 |
418aa554
|
Leszek Koltunski
|
|
216 |
|
|
paint.setAntiAlias(true);
|
217 |
|
|
paint.setStrokeWidth(STROKE);
|
218 |
|
|
paint.setColor(FACE_COLORS[face]);
|
219 |
|
|
paint.setStyle(Paint.Style.FILL);
|
220 |
|
|
|
221 |
|
|
canvas.drawRect(left,top,left+side,top+side,paint);
|
222 |
|
|
|
223 |
|
|
paint.setColor(INTERIOR_COLOR);
|
224 |
|
|
paint.setStyle(Paint.Style.STROKE);
|
225 |
|
|
|
226 |
fcc0e034
|
Leszek Koltunski
|
canvas.drawLine( L , H, L+2*LEN, H , paint);
|
227 |
|
|
canvas.drawLine( L , H, L+ LEN, H+LEN, paint);
|
228 |
|
|
canvas.drawLine( L+2*LEN, H, L+ LEN, H+LEN, paint);
|
229 |
|
|
|
230 |
|
|
float S1 = 0.150f*side;
|
231 |
|
|
float S2 = 0.090f*side;
|
232 |
|
|
float X = 0.7f*S2;
|
233 |
|
|
float Y = 0.2f*S1;
|
234 |
|
|
|
235 |
|
|
float LA = left+0.500f*side;
|
236 |
|
|
float RA = left;
|
237 |
|
|
float TA = 0.333f*side;
|
238 |
|
|
float BA = 0.833f*side;
|
239 |
418aa554
|
Leszek Koltunski
|
|
240 |
fcc0e034
|
Leszek Koltunski
|
canvas.drawArc( RA+X , TA , RA+X+S2 , TA+S2, 135,135, false, paint);
|
241 |
|
|
canvas.drawArc( RA+side-S2-X, TA , RA+side-X, TA+S2, 270,135, false, paint);
|
242 |
|
|
canvas.drawArc( LA-S1/2 , BA-S1-Y, LA+S1/2 , BA-Y , 45, 90, false, paint);
|
243 |
418aa554
|
Leszek Koltunski
|
}
|
244 |
|
|
|
245 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
246 |
|
|
|
247 |
|
|
float returnMultiplier()
|
248 |
|
|
{
|
249 |
|
|
return 2.0f;
|
250 |
|
|
}
|
251 |
|
|
|
252 |
7c969a6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
253 |
|
|
|
254 |
|
|
float[] getRowChances()
|
255 |
|
|
{
|
256 |
|
|
float[] chances = new float[3];
|
257 |
|
|
|
258 |
|
|
chances[0] = 0.5f;
|
259 |
|
|
chances[1] = 0.5f;
|
260 |
|
|
chances[2] = 1.0f;
|
261 |
|
|
|
262 |
|
|
return chances;
|
263 |
|
|
}
|
264 |
|
|
|
265 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266 |
|
|
// PUBLIC API
|
267 |
|
|
|
268 |
|
|
public Static3D[] getRotationAxis()
|
269 |
|
|
{
|
270 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
271 |
418aa554
|
Leszek Koltunski
|
}
|
272 |
|
|
|
273 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274 |
|
|
|
275 |
|
|
public int getBasicAngle()
|
276 |
|
|
{
|
277 |
|
|
return 3;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281 |
|
|
|
282 |
7c969a6d
|
Leszek Koltunski
|
public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
|
283 |
418aa554
|
Leszek Koltunski
|
{
|
284 |
7c969a6d
|
Leszek Koltunski
|
int numAxis = ROTATION_AXIS.length;
|
285 |
418aa554
|
Leszek Koltunski
|
|
286 |
7c969a6d
|
Leszek Koltunski
|
if( oldRotAxis == START_AXIS )
|
287 |
|
|
{
|
288 |
|
|
return rnd.nextInt(numAxis);
|
289 |
|
|
}
|
290 |
|
|
else
|
291 |
|
|
{
|
292 |
|
|
int newVector = rnd.nextInt(numAxis-1);
|
293 |
|
|
return (newVector>=oldRotAxis ? newVector+1 : newVector);
|
294 |
|
|
}
|
295 |
|
|
}
|
296 |
418aa554
|
Leszek Koltunski
|
|
297 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
298 |
ee35e63c
|
Leszek Koltunski
|
// only needed for solvers - there are no Dino solvers ATM)
|
299 |
418aa554
|
Leszek Koltunski
|
|
300 |
|
|
public String retObjectString()
|
301 |
|
|
{
|
302 |
|
|
return "";
|
303 |
|
|
}
|
304 |
|
|
|
305 |
|
|
}
|