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 |
|
|
// the four rotation axis of a RubikDino. Must be normalized.
|
44 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
45 |
418aa554
|
Leszek Koltunski
|
{
|
46 |
|
|
new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
|
47 |
|
|
new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
|
48 |
|
|
new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
|
49 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
private static final int[] FACE_COLORS = new int[]
|
53 |
|
|
{
|
54 |
ece1b58d
|
Leszek Koltunski
|
COLOR_YELLOW, COLOR_WHITE,
|
55 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
56 |
323b217c
|
Leszek Koltunski
|
COLOR_RED , COLOR_ORANGE
|
57 |
418aa554
|
Leszek Koltunski
|
};
|
58 |
|
|
|
59 |
|
|
// All legal rotation quats of a RubikDino
|
60 |
eaee1ddc
|
Leszek Koltunski
|
static final Static4D[] QUATS = new Static4D[]
|
61 |
418aa554
|
Leszek Koltunski
|
{
|
62 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
63 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
64 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
65 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
66 |
418aa554
|
Leszek Koltunski
|
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.5f, -0.5f, 0.5f, -0.5f ),
|
69 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
70 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
71 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
72 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
73 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
74 |
8f53e513
|
Leszek Koltunski
|
};
|
75 |
|
|
|
76 |
|
|
// centers of the 12 edges. Must be in the same order like QUATs above.
|
77 |
|
|
private static final Static3D[] CENTERS = new Static3D[]
|
78 |
|
|
{
|
79 |
c7e79b69
|
Leszek Koltunski
|
new Static3D( 0.0f, 1.5f, 1.5f ),
|
80 |
|
|
new Static3D( 1.5f, 0.0f, 1.5f ),
|
81 |
|
|
new Static3D( 0.0f,-1.5f, 1.5f ),
|
82 |
|
|
new Static3D(-1.5f, 0.0f, 1.5f ),
|
83 |
|
|
new Static3D( 1.5f, 1.5f, 0.0f ),
|
84 |
|
|
new Static3D( 1.5f,-1.5f, 0.0f ),
|
85 |
|
|
new Static3D(-1.5f,-1.5f, 0.0f ),
|
86 |
|
|
new Static3D(-1.5f, 1.5f, 0.0f ),
|
87 |
|
|
new Static3D( 0.0f, 1.5f,-1.5f ),
|
88 |
|
|
new Static3D( 1.5f, 0.0f,-1.5f ),
|
89 |
|
|
new Static3D( 0.0f,-1.5f,-1.5f ),
|
90 |
|
|
new Static3D(-1.5f, 0.0f,-1.5f )
|
91 |
418aa554
|
Leszek Koltunski
|
};
|
92 |
|
|
|
93 |
8f53e513
|
Leszek Koltunski
|
private static MeshBase mMesh;
|
94 |
418aa554
|
Leszek Koltunski
|
|
95 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96 |
|
|
|
97 |
9c2f0c91
|
Leszek Koltunski
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
98 |
|
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
99 |
418aa554
|
Leszek Koltunski
|
{
|
100 |
d99f3a48
|
Leszek Koltunski
|
super(size, size, 60, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
101 |
418aa554
|
Leszek Koltunski
|
}
|
102 |
|
|
|
103 |
ece1b58d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
104 |
|
|
|
105 |
|
|
int mulQuat(int q1, int q2)
|
106 |
|
|
{
|
107 |
|
|
Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
|
108 |
|
|
|
109 |
|
|
float rX = result.get0();
|
110 |
|
|
float rY = result.get1();
|
111 |
|
|
float rZ = result.get2();
|
112 |
|
|
float rW = result.get3();
|
113 |
|
|
|
114 |
|
|
final float MAX_ERROR = 0.1f;
|
115 |
|
|
float dX,dY,dZ,dW;
|
116 |
|
|
|
117 |
|
|
for(int i=0; i<QUATS.length; i++)
|
118 |
|
|
{
|
119 |
|
|
dX = QUATS[i].get0() - rX;
|
120 |
|
|
dY = QUATS[i].get1() - rY;
|
121 |
|
|
dZ = QUATS[i].get2() - rZ;
|
122 |
|
|
dW = QUATS[i].get3() - rW;
|
123 |
|
|
|
124 |
|
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
125 |
|
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
126 |
|
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
127 |
|
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
128 |
|
|
|
129 |
|
|
dX = QUATS[i].get0() + rX;
|
130 |
|
|
dY = QUATS[i].get1() + rY;
|
131 |
|
|
dZ = QUATS[i].get2() + rZ;
|
132 |
|
|
dW = QUATS[i].get3() + rW;
|
133 |
|
|
|
134 |
|
|
if( dX<MAX_ERROR && dX>-MAX_ERROR &&
|
135 |
|
|
dY<MAX_ERROR && dY>-MAX_ERROR &&
|
136 |
|
|
dZ<MAX_ERROR && dZ>-MAX_ERROR &&
|
137 |
|
|
dW<MAX_ERROR && dW>-MAX_ERROR ) return i;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
return -1;
|
141 |
|
|
}
|
142 |
|
|
|
143 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144 |
|
|
|
145 |
|
|
float getScreenRatio()
|
146 |
|
|
{
|
147 |
c7e79b69
|
Leszek Koltunski
|
return 0.5f;
|
148 |
418aa554
|
Leszek Koltunski
|
}
|
149 |
|
|
|
150 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
151 |
|
|
|
152 |
|
|
Static4D[] getQuats()
|
153 |
|
|
{
|
154 |
|
|
return QUATS;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
158 |
|
|
|
159 |
|
|
int getNumFaces()
|
160 |
|
|
{
|
161 |
|
|
return FACE_COLORS.length;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
165 |
|
|
|
166 |
a97e02b7
|
Leszek Koltunski
|
float[] getCuts(int size)
|
167 |
7403cdfa
|
Leszek Koltunski
|
{
|
168 |
80ec6abf
|
Leszek Koltunski
|
return new float[] { -SQ3/3, +SQ3/3 };
|
169 |
7403cdfa
|
Leszek Koltunski
|
}
|
170 |
|
|
|
171 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
172 |
|
|
|
173 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
174 |
eab9d8f8
|
Leszek Koltunski
|
{
|
175 |
|
|
return 1;
|
176 |
|
|
}
|
177 |
|
|
|
178 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
179 |
|
|
|
180 |
8f53e513
|
Leszek Koltunski
|
int getNumCubitFaces()
|
181 |
418aa554
|
Leszek Koltunski
|
{
|
182 |
8f53e513
|
Leszek Koltunski
|
return 4;
|
183 |
|
|
}
|
184 |
|
|
|
185 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
186 |
418aa554
|
Leszek Koltunski
|
|
187 |
8f53e513
|
Leszek Koltunski
|
Static3D[] getCubitPositions(int size)
|
188 |
|
|
{
|
189 |
|
|
return CENTERS;
|
190 |
418aa554
|
Leszek Koltunski
|
}
|
191 |
|
|
|
192 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
193 |
|
|
|
194 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
195 |
418aa554
|
Leszek Koltunski
|
{
|
196 |
b89898c5
|
Leszek Koltunski
|
if( mMesh==null ) mMesh = FactoryCubit.getInstance().createDinoMesh();
|
197 |
8f53e513
|
Leszek Koltunski
|
|
198 |
|
|
MeshBase mesh = mMesh.copy(true);
|
199 |
|
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
|
200 |
|
|
mesh.apply(quat,0xffffffff,0);
|
201 |
418aa554
|
Leszek Koltunski
|
|
202 |
8f53e513
|
Leszek Koltunski
|
return mesh;
|
203 |
418aa554
|
Leszek Koltunski
|
}
|
204 |
|
|
|
205 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206 |
|
|
|
207 |
ae755eda
|
Leszek Koltunski
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
208 |
418aa554
|
Leszek Koltunski
|
{
|
209 |
76c2bd07
|
Leszek Koltunski
|
float F = 0.5f;
|
210 |
2fcfce81
|
Leszek Koltunski
|
float R = 0.025f;
|
211 |
76c2bd07
|
Leszek Koltunski
|
float S = 0.05f;
|
212 |
|
|
float[] vertices = { -F,F/3, 0,-2*F/3, +F,F/3 };
|
213 |
|
|
|
214 |
b89898c5
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
215 |
ae755eda
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
|
216 |
418aa554
|
Leszek Koltunski
|
}
|
217 |
|
|
|
218 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
219 |
|
|
|
220 |
|
|
float returnMultiplier()
|
221 |
|
|
{
|
222 |
|
|
return 2.0f;
|
223 |
|
|
}
|
224 |
|
|
|
225 |
7c969a6d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226 |
|
|
|
227 |
a64e07d0
|
Leszek Koltunski
|
float[] getRowChances(int numLayers)
|
228 |
7c969a6d
|
Leszek Koltunski
|
{
|
229 |
|
|
float[] chances = new float[3];
|
230 |
|
|
|
231 |
|
|
chances[0] = 0.5f;
|
232 |
|
|
chances[1] = 0.5f;
|
233 |
|
|
chances[2] = 1.0f;
|
234 |
|
|
|
235 |
|
|
return chances;
|
236 |
|
|
}
|
237 |
|
|
|
238 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239 |
|
|
// PUBLIC API
|
240 |
|
|
|
241 |
|
|
public Static3D[] getRotationAxis()
|
242 |
|
|
{
|
243 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
244 |
418aa554
|
Leszek Koltunski
|
}
|
245 |
|
|
|
246 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
247 |
|
|
|
248 |
|
|
public int getBasicAngle()
|
249 |
|
|
{
|
250 |
|
|
return 3;
|
251 |
|
|
}
|
252 |
|
|
|
253 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
254 |
|
|
|
255 |
7c969a6d
|
Leszek Koltunski
|
public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
|
256 |
418aa554
|
Leszek Koltunski
|
{
|
257 |
7c969a6d
|
Leszek Koltunski
|
int numAxis = ROTATION_AXIS.length;
|
258 |
418aa554
|
Leszek Koltunski
|
|
259 |
7c969a6d
|
Leszek Koltunski
|
if( oldRotAxis == START_AXIS )
|
260 |
|
|
{
|
261 |
|
|
return rnd.nextInt(numAxis);
|
262 |
|
|
}
|
263 |
|
|
else
|
264 |
|
|
{
|
265 |
|
|
int newVector = rnd.nextInt(numAxis-1);
|
266 |
|
|
return (newVector>=oldRotAxis ? newVector+1 : newVector);
|
267 |
|
|
}
|
268 |
|
|
}
|
269 |
418aa554
|
Leszek Koltunski
|
|
270 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
271 |
ee35e63c
|
Leszek Koltunski
|
// only needed for solvers - there are no Dino solvers ATM)
|
272 |
418aa554
|
Leszek Koltunski
|
|
273 |
|
|
public String retObjectString()
|
274 |
|
|
{
|
275 |
|
|
return "";
|
276 |
|
|
}
|
277 |
6fd4a72c
|
Leszek Koltunski
|
|
278 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
279 |
|
|
|
280 |
|
|
public int getComplexity(int numLayers)
|
281 |
|
|
{
|
282 |
|
|
return 2;
|
283 |
|
|
}
|
284 |
418aa554
|
Leszek Koltunski
|
}
|