1 |
29b82486
|
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.objectlib.objects;
|
21 |
|
|
|
22 |
|
|
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
|
23 |
|
|
|
24 |
|
|
import android.content.res.Resources;
|
25 |
|
|
|
26 |
|
|
import org.distorted.library.main.DistortedEffects;
|
27 |
|
|
import org.distorted.library.main.DistortedTexture;
|
28 |
|
|
import org.distorted.library.mesh.MeshSquare;
|
29 |
|
|
import org.distorted.library.type.Static3D;
|
30 |
|
|
import org.distorted.library.type.Static4D;
|
31 |
|
|
|
32 |
4e1dc313
|
Leszek Koltunski
|
import org.distorted.objectlib.R;
|
33 |
29b82486
|
Leszek Koltunski
|
import org.distorted.objectlib.main.Movement;
|
34 |
|
|
import org.distorted.objectlib.main.Movement6;
|
35 |
198c5bf0
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.ObjectShape;
|
36 |
|
|
import org.distorted.objectlib.helpers.ObjectSticker;
|
37 |
|
|
import org.distorted.objectlib.helpers.ScrambleState;
|
38 |
29b82486
|
Leszek Koltunski
|
import org.distorted.objectlib.main.Twisty6;
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
|
42 |
|
|
abstract class TwistyDino extends Twisty6
|
43 |
|
|
{
|
44 |
|
|
// the four rotation axis of a RubikDino. Must be normalized.
|
45 |
|
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
46 |
|
|
{
|
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 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
51 |
|
|
};
|
52 |
|
|
|
53 |
|
|
private static final int[][][] ENABLED = new int[][][]
|
54 |
|
|
{
|
55 |
|
|
{{0,1},{3,1},{2,3},{0,2}},
|
56 |
|
|
{{2,3},{3,1},{0,1},{0,2}},
|
57 |
|
|
{{1,2},{0,1},{0,3},{2,3}},
|
58 |
|
|
{{1,2},{2,3},{0,3},{0,1}},
|
59 |
|
|
{{0,3},{0,2},{1,2},{1,3}},
|
60 |
|
|
{{1,2},{0,2},{0,3},{1,3}},
|
61 |
|
|
};
|
62 |
|
|
|
63 |
|
|
private int[] mBasicAngle;
|
64 |
|
|
private Static4D[] mQuats;
|
65 |
|
|
private float[][] mCuts;
|
66 |
|
|
private boolean[][] mLayerRotatable;
|
67 |
|
|
private ObjectSticker[] mStickers;
|
68 |
|
|
private float[][] mCenters;
|
69 |
|
|
private Movement mMovement;
|
70 |
|
|
ScrambleState[] mStates;
|
71 |
|
|
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
|
|
|
74 |
ecf3d6e3
|
Leszek Koltunski
|
TwistyDino(int size, Static4D quat, Static3D move, DistortedTexture texture,
|
75 |
|
|
MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
|
76 |
29b82486
|
Leszek Koltunski
|
{
|
77 |
ecf3d6e3
|
Leszek Koltunski
|
super(size, size, quat, move, texture, mesh, effects, res, scrWidth);
|
78 |
29b82486
|
Leszek Koltunski
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
|
82 |
|
|
private void initializeQuats()
|
83 |
|
|
{
|
84 |
|
|
mQuats = new Static4D[]
|
85 |
|
|
{
|
86 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
87 |
|
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
88 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
89 |
|
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
90 |
|
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
91 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, -0.5f ),
|
92 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, -0.5f ),
|
93 |
|
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
94 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
95 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
96 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
97 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
98 |
|
|
};
|
99 |
|
|
}
|
100 |
|
|
|
101 |
4e1dc313
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
102 |
|
|
|
103 |
|
|
protected int getResource(int numLayers)
|
104 |
|
|
{
|
105 |
|
|
return R.raw.dino;
|
106 |
|
|
}
|
107 |
|
|
|
108 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
109 |
|
|
|
110 |
|
|
protected Static4D[] getQuats()
|
111 |
|
|
{
|
112 |
|
|
if( mQuats==null ) initializeQuats();
|
113 |
|
|
return mQuats;
|
114 |
|
|
}
|
115 |
|
|
|
116 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
117 |
|
|
|
118 |
|
|
protected float[][] getCuts(int size)
|
119 |
|
|
{
|
120 |
|
|
if( mCuts==null )
|
121 |
|
|
{
|
122 |
|
|
float[] cut = new float[] { -SQ3/3, +SQ3/3 };
|
123 |
|
|
mCuts = new float[][] { cut,cut,cut,cut };
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
return mCuts;
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
|
|
|
131 |
|
|
private void getLayerRotatable(int numLayers)
|
132 |
|
|
{
|
133 |
|
|
if( mLayerRotatable==null )
|
134 |
|
|
{
|
135 |
|
|
int numAxis = ROT_AXIS.length;
|
136 |
|
|
boolean[] tmp = new boolean[] {true,false,true};
|
137 |
|
|
mLayerRotatable = new boolean[numAxis][];
|
138 |
|
|
for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
|
139 |
|
|
}
|
140 |
|
|
}
|
141 |
|
|
|
142 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
143 |
|
|
|
144 |
|
|
protected int getNumStickerTypes(int numLayers)
|
145 |
|
|
{
|
146 |
|
|
return 1;
|
147 |
|
|
}
|
148 |
|
|
|
149 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150 |
|
|
|
151 |
|
|
protected int getNumCubitFaces()
|
152 |
|
|
{
|
153 |
|
|
return 4;
|
154 |
|
|
}
|
155 |
|
|
|
156 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
157 |
|
|
|
158 |
|
|
protected float[][] getCubitPositions(int size)
|
159 |
|
|
{
|
160 |
|
|
if( mCenters ==null )
|
161 |
|
|
{
|
162 |
|
|
mCenters = new float[][]
|
163 |
|
|
{
|
164 |
|
|
{ 0.0f, 1.5f, 1.5f },
|
165 |
|
|
{ 1.5f, 0.0f, 1.5f },
|
166 |
|
|
{ 0.0f,-1.5f, 1.5f },
|
167 |
|
|
{-1.5f, 0.0f, 1.5f },
|
168 |
|
|
{ 1.5f, 1.5f, 0.0f },
|
169 |
|
|
{ 1.5f,-1.5f, 0.0f },
|
170 |
|
|
{-1.5f,-1.5f, 0.0f },
|
171 |
|
|
{-1.5f, 1.5f, 0.0f },
|
172 |
|
|
{ 0.0f, 1.5f,-1.5f },
|
173 |
|
|
{ 1.5f, 0.0f,-1.5f },
|
174 |
|
|
{ 0.0f,-1.5f,-1.5f },
|
175 |
|
|
{-1.5f, 0.0f,-1.5f }
|
176 |
|
|
};
|
177 |
|
|
}
|
178 |
|
|
|
179 |
|
|
return mCenters;
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
183 |
|
|
|
184 |
|
|
protected ObjectShape getObjectShape(int cubit, int numLayers)
|
185 |
|
|
{
|
186 |
|
|
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} };
|
187 |
|
|
int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
|
188 |
|
|
float[][] bands = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
|
189 |
|
|
int[] bandIndices = new int[] { 0,0,1,1 };
|
190 |
|
|
float[][] corners = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
|
191 |
|
|
int[] cornerIndices = new int[] { 0,0,1,1 };
|
192 |
|
|
float[][] centers = new float[][] { {0.0f, -0.75f, -0.75f} };
|
193 |
|
|
int[] centerIndices = new int[] { 0,0,0,0 };
|
194 |
|
|
return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
|
199 |
|
|
protected Static4D getQuat(int cubit, int numLayers)
|
200 |
|
|
{
|
201 |
|
|
if( mQuats==null ) initializeQuats();
|
202 |
|
|
return mQuats[cubit];
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
206 |
|
|
|
207 |
|
|
protected int getNumCubitVariants(int numLayers)
|
208 |
|
|
{
|
209 |
|
|
return 1;
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
|
214 |
|
|
protected int getCubitVariant(int cubit, int numLayers)
|
215 |
|
|
{
|
216 |
|
|
return 0;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
220 |
|
|
|
221 |
|
|
protected ObjectSticker retSticker(int face)
|
222 |
|
|
{
|
223 |
|
|
if( mStickers==null )
|
224 |
|
|
{
|
225 |
|
|
float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
|
226 |
|
|
float radius = 0.025f;
|
227 |
|
|
float stroke = 0.050f;
|
228 |
|
|
float[] radii = new float[] {radius,radius,radius};
|
229 |
|
|
mStickers = new ObjectSticker[STICKERS.length];
|
230 |
|
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
return mStickers[face/NUM_FACE_COLORS];
|
234 |
|
|
}
|
235 |
|
|
|
236 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
237 |
|
|
// PUBLIC API
|
238 |
|
|
|
239 |
|
|
public Static3D[] getRotationAxis()
|
240 |
|
|
{
|
241 |
|
|
return ROT_AXIS;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
|
246 |
|
|
public Movement getMovement()
|
247 |
|
|
{
|
248 |
|
|
if( mMovement==null )
|
249 |
|
|
{
|
250 |
|
|
int numLayers = getNumLayers();
|
251 |
|
|
if( mCuts==null ) getCuts(numLayers);
|
252 |
|
|
getLayerRotatable(numLayers);
|
253 |
|
|
mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,ENABLED);
|
254 |
|
|
}
|
255 |
|
|
return mMovement;
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259 |
|
|
|
260 |
|
|
public int[] getBasicAngle()
|
261 |
|
|
{
|
262 |
|
|
if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
|
263 |
|
|
return mBasicAngle;
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
267 |
|
|
|
268 |
|
|
public int getComplexity(int numLayers)
|
269 |
|
|
{
|
270 |
|
|
return 2;
|
271 |
|
|
}
|
272 |
|
|
}
|