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 |
749ef882
|
Leszek Koltunski
|
import org.distorted.helpers.FactoryCubit;
|
27 |
|
|
import org.distorted.helpers.FactorySticker;
|
28 |
8f53e513
|
Leszek Koltunski
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.main.DistortedEffects;
|
30 |
|
|
import org.distorted.library.main.DistortedTexture;
|
31 |
|
|
import org.distorted.library.mesh.MeshBase;
|
32 |
efa8aa48
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshSquare;
|
33 |
418aa554
|
Leszek Koltunski
|
import org.distorted.library.type.Static3D;
|
34 |
|
|
import org.distorted.library.type.Static4D;
|
35 |
|
|
|
36 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
9c2f0c91
|
Leszek Koltunski
|
public abstract class TwistyDino extends TwistyObject
|
39 |
418aa554
|
Leszek Koltunski
|
{
|
40 |
|
|
// the four rotation axis of a RubikDino. Must be normalized.
|
41 |
ad38d800
|
Leszek Koltunski
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
42 |
418aa554
|
Leszek Koltunski
|
{
|
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 |
|
|
new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
|
47 |
|
|
};
|
48 |
|
|
|
49 |
925ed78f
|
Leszek Koltunski
|
private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
50 |
|
|
|
51 |
418aa554
|
Leszek Koltunski
|
private static final int[] FACE_COLORS = new int[]
|
52 |
|
|
{
|
53 |
ece1b58d
|
Leszek Koltunski
|
COLOR_YELLOW, COLOR_WHITE,
|
54 |
|
|
COLOR_BLUE , COLOR_GREEN,
|
55 |
323b217c
|
Leszek Koltunski
|
COLOR_RED , COLOR_ORANGE
|
56 |
418aa554
|
Leszek Koltunski
|
};
|
57 |
|
|
|
58 |
|
|
// All legal rotation quats of a RubikDino
|
59 |
eaee1ddc
|
Leszek Koltunski
|
static final Static4D[] QUATS = new Static4D[]
|
60 |
418aa554
|
Leszek Koltunski
|
{
|
61 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
62 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
63 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
64 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
65 |
418aa554
|
Leszek Koltunski
|
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 |
8f53e513
|
Leszek Koltunski
|
new Static4D( 0.5f, -0.5f, -0.5f, 0.5f ),
|
69 |
380162cb
|
Leszek Koltunski
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
70 |
|
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
71 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
72 |
|
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
73 |
8f53e513
|
Leszek Koltunski
|
};
|
74 |
|
|
|
75 |
|
|
// centers of the 12 edges. Must be in the same order like QUATs above.
|
76 |
121e4a39
|
Leszek Koltunski
|
static final float[][] CENTERS = new float[][]
|
77 |
8f53e513
|
Leszek Koltunski
|
{
|
78 |
e6cf7283
|
Leszek Koltunski
|
{ 0.0f, 1.5f, 1.5f },
|
79 |
|
|
{ 1.5f, 0.0f, 1.5f },
|
80 |
|
|
{ 0.0f,-1.5f, 1.5f },
|
81 |
|
|
{-1.5f, 0.0f, 1.5f },
|
82 |
|
|
{ 1.5f, 1.5f, 0.0f },
|
83 |
|
|
{ 1.5f,-1.5f, 0.0f },
|
84 |
|
|
{-1.5f,-1.5f, 0.0f },
|
85 |
|
|
{-1.5f, 1.5f, 0.0f },
|
86 |
|
|
{ 0.0f, 1.5f,-1.5f },
|
87 |
|
|
{ 1.5f, 0.0f,-1.5f },
|
88 |
|
|
{ 0.0f,-1.5f,-1.5f },
|
89 |
|
|
{-1.5f, 0.0f,-1.5f }
|
90 |
418aa554
|
Leszek Koltunski
|
};
|
91 |
|
|
|
92 |
596d62a4
|
Leszek Koltunski
|
private static final double[][] VERTICES = new double[][]
|
93 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
94 |
596d62a4
|
Leszek Koltunski
|
{-1.5, 0.0, 0.0},
|
95 |
|
|
{ 1.5, 0.0, 0.0},
|
96 |
|
|
{ 0.0,-1.5, 0.0},
|
97 |
|
|
{ 0.0, 0.0,-1.5}
|
98 |
b1f2ccf5
|
Leszek Koltunski
|
};
|
99 |
|
|
|
100 |
596d62a4
|
Leszek Koltunski
|
private static final int[][] VERT_INDEXES = new int[][]
|
101 |
b1f2ccf5
|
Leszek Koltunski
|
{
|
102 |
|
|
{2,1,0}, // counterclockwise!
|
103 |
596d62a4
|
Leszek Koltunski
|
{3,0,1},
|
104 |
b1f2ccf5
|
Leszek Koltunski
|
{2,3,1},
|
105 |
|
|
{3,2,0},
|
106 |
|
|
};
|
107 |
|
|
|
108 |
596d62a4
|
Leszek Koltunski
|
private static final float[][] STICKERS = new float[][]
|
109 |
|
|
{
|
110 |
|
|
{ 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
|
111 |
|
|
};
|
112 |
|
|
|
113 |
|
|
private static MeshBase[] mMeshes;
|
114 |
418aa554
|
Leszek Koltunski
|
|
115 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
116 |
|
|
|
117 |
9c2f0c91
|
Leszek Koltunski
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
118 |
|
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
119 |
418aa554
|
Leszek Koltunski
|
{
|
120 |
db875721
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
121 |
418aa554
|
Leszek Koltunski
|
}
|
122 |
|
|
|
123 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124 |
|
|
|
125 |
|
|
float getScreenRatio()
|
126 |
|
|
{
|
127 |
c7e79b69
|
Leszek Koltunski
|
return 0.5f;
|
128 |
418aa554
|
Leszek Koltunski
|
}
|
129 |
|
|
|
130 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
131 |
|
|
|
132 |
|
|
Static4D[] getQuats()
|
133 |
|
|
{
|
134 |
|
|
return QUATS;
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
|
139 |
|
|
int getNumFaces()
|
140 |
|
|
{
|
141 |
|
|
return FACE_COLORS.length;
|
142 |
|
|
}
|
143 |
|
|
|
144 |
7403cdfa
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
145 |
|
|
|
146 |
e6734aa9
|
Leszek Koltunski
|
float[][] getCuts(int size)
|
147 |
7403cdfa
|
Leszek Koltunski
|
{
|
148 |
e6734aa9
|
Leszek Koltunski
|
float[] cut = new float[] { -SQ3/3, +SQ3/3 };
|
149 |
|
|
return new float[][] { cut,cut,cut,cut };
|
150 |
7403cdfa
|
Leszek Koltunski
|
}
|
151 |
|
|
|
152 |
eab9d8f8
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153 |
|
|
|
154 |
a64e07d0
|
Leszek Koltunski
|
int getNumStickerTypes(int numLayers)
|
155 |
eab9d8f8
|
Leszek Koltunski
|
{
|
156 |
596d62a4
|
Leszek Koltunski
|
return STICKERS.length;
|
157 |
eab9d8f8
|
Leszek Koltunski
|
}
|
158 |
|
|
|
159 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160 |
|
|
|
161 |
8f53e513
|
Leszek Koltunski
|
int getNumCubitFaces()
|
162 |
418aa554
|
Leszek Koltunski
|
{
|
163 |
8f53e513
|
Leszek Koltunski
|
return 4;
|
164 |
|
|
}
|
165 |
|
|
|
166 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
167 |
418aa554
|
Leszek Koltunski
|
|
168 |
e6cf7283
|
Leszek Koltunski
|
float[][] getCubitPositions(int size)
|
169 |
8f53e513
|
Leszek Koltunski
|
{
|
170 |
|
|
return CENTERS;
|
171 |
418aa554
|
Leszek Koltunski
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
a64e07d0
|
Leszek Koltunski
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
176 |
418aa554
|
Leszek Koltunski
|
{
|
177 |
596d62a4
|
Leszek Koltunski
|
if( mMeshes==null )
|
178 |
|
|
{
|
179 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
180 |
|
|
factory.clear();
|
181 |
|
|
mMeshes = new MeshBase[1];
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
if( mMeshes[0]==null )
|
185 |
|
|
{
|
186 |
|
|
float[][] bands= new float[][]
|
187 |
|
|
{
|
188 |
|
|
{0.035f,30,0.16f,0.8f,7,2,5},
|
189 |
|
|
{0.020f,45,0.16f,0.2f,3,1,2}
|
190 |
|
|
};
|
191 |
|
|
int[] bandIndexes = new int[] { 0,0,1,1 };
|
192 |
|
|
float[][] corners = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
|
193 |
|
|
int[] cornerIndexes = new int[] { 0,0,1,1 };
|
194 |
b3c9061a
|
Leszek Koltunski
|
float[][] centers = new float[][] { {0.0f, -0.75f, -0.75f} };
|
195 |
|
|
int[] centerIndexes = new int[] { 0,0,0,0 };
|
196 |
596d62a4
|
Leszek Koltunski
|
|
197 |
|
|
FactoryCubit factory = FactoryCubit.getInstance();
|
198 |
|
|
|
199 |
|
|
factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
|
200 |
|
|
mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
|
201 |
|
|
bands, bandIndexes,
|
202 |
|
|
corners, cornerIndexes,
|
203 |
b3c9061a
|
Leszek Koltunski
|
centers, centerIndexes,
|
204 |
596d62a4
|
Leszek Koltunski
|
getNumCubitFaces() );
|
205 |
|
|
}
|
206 |
8f53e513
|
Leszek Koltunski
|
|
207 |
596d62a4
|
Leszek Koltunski
|
MeshBase mesh = mMeshes[0].copy(true);
|
208 |
8f53e513
|
Leszek Koltunski
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
|
209 |
|
|
mesh.apply(quat,0xffffffff,0);
|
210 |
418aa554
|
Leszek Koltunski
|
|
211 |
8f53e513
|
Leszek Koltunski
|
return mesh;
|
212 |
418aa554
|
Leszek Koltunski
|
}
|
213 |
|
|
|
214 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215 |
|
|
|
216 |
ae755eda
|
Leszek Koltunski
|
void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
|
217 |
418aa554
|
Leszek Koltunski
|
{
|
218 |
2fcfce81
|
Leszek Koltunski
|
float R = 0.025f;
|
219 |
76c2bd07
|
Leszek Koltunski
|
float S = 0.05f;
|
220 |
|
|
|
221 |
b89898c5
|
Leszek Koltunski
|
FactorySticker factory = FactorySticker.getInstance();
|
222 |
596d62a4
|
Leszek Koltunski
|
factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
|
223 |
418aa554
|
Leszek Koltunski
|
}
|
224 |
|
|
|
225 |
fb377dae
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
226 |
|
|
|
227 |
|
|
float returnMultiplier()
|
228 |
|
|
{
|
229 |
|
|
return 2.0f;
|
230 |
|
|
}
|
231 |
|
|
|
232 |
418aa554
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
233 |
|
|
// PUBLIC API
|
234 |
|
|
|
235 |
|
|
public Static3D[] getRotationAxis()
|
236 |
|
|
{
|
237 |
ad38d800
|
Leszek Koltunski
|
return ROT_AXIS;
|
238 |
418aa554
|
Leszek Koltunski
|
}
|
239 |
|
|
|
240 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
241 |
|
|
|
242 |
925ed78f
|
Leszek Koltunski
|
public int[] getBasicAngle()
|
243 |
418aa554
|
Leszek Koltunski
|
{
|
244 |
925ed78f
|
Leszek Koltunski
|
return BASIC_ANGLE;
|
245 |
418aa554
|
Leszek Koltunski
|
}
|
246 |
|
|
|
247 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
248 |
ee35e63c
|
Leszek Koltunski
|
// only needed for solvers - there are no Dino solvers ATM)
|
249 |
418aa554
|
Leszek Koltunski
|
|
250 |
|
|
public String retObjectString()
|
251 |
|
|
{
|
252 |
|
|
return "";
|
253 |
|
|
}
|
254 |
6fd4a72c
|
Leszek Koltunski
|
|
255 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
256 |
|
|
|
257 |
|
|
public int getComplexity(int numLayers)
|
258 |
|
|
{
|
259 |
|
|
return 2;
|
260 |
|
|
}
|
261 |
418aa554
|
Leszek Koltunski
|
}
|