1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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
|
import org.distorted.helpers.FactoryCubit;
|
25
|
import org.distorted.helpers.ObjectShape;
|
26
|
import org.distorted.helpers.ObjectSticker;
|
27
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
28
|
import org.distorted.library.main.DistortedEffects;
|
29
|
import org.distorted.library.main.DistortedTexture;
|
30
|
import org.distorted.library.mesh.MeshBase;
|
31
|
import org.distorted.library.mesh.MeshSquare;
|
32
|
import org.distorted.library.type.Static3D;
|
33
|
import org.distorted.library.type.Static4D;
|
34
|
|
35
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36
|
|
37
|
public abstract class TwistyDino extends TwistyObject
|
38
|
{
|
39
|
// the four rotation axis of a RubikDino. Must be normalized.
|
40
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
41
|
{
|
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[] BASIC_ANGLE = new int[] { 3,3,3,3 };
|
49
|
|
50
|
private static final int[] FACE_COLORS = new int[]
|
51
|
{
|
52
|
COLOR_YELLOW, COLOR_WHITE,
|
53
|
COLOR_BLUE , COLOR_GREEN,
|
54
|
COLOR_RED , COLOR_ORANGE
|
55
|
};
|
56
|
|
57
|
// All legal rotation quats of a RubikDino
|
58
|
static final Static4D[] QUATS = new Static4D[]
|
59
|
{
|
60
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
61
|
new Static4D( 0.5f, 0.5f, 0.5f, -0.5f ),
|
62
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
63
|
new Static4D( 0.5f, -0.5f, -0.5f, -0.5f ),
|
64
|
new Static4D( 0.5f, 0.5f, 0.5f, 0.5f ),
|
65
|
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
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
69
|
new Static4D( 0.5f, -0.5f, 0.5f, 0.5f ),
|
70
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
71
|
new Static4D( 0.5f, 0.5f, -0.5f, 0.5f )
|
72
|
};
|
73
|
|
74
|
// centers of the 12 edges. Must be in the same order like QUATs above.
|
75
|
static final float[][] CENTERS = new float[][]
|
76
|
{
|
77
|
{ 0.0f, 1.5f, 1.5f },
|
78
|
{ 1.5f, 0.0f, 1.5f },
|
79
|
{ 0.0f,-1.5f, 1.5f },
|
80
|
{-1.5f, 0.0f, 1.5f },
|
81
|
{ 1.5f, 1.5f, 0.0f },
|
82
|
{ 1.5f,-1.5f, 0.0f },
|
83
|
{-1.5f,-1.5f, 0.0f },
|
84
|
{-1.5f, 1.5f, 0.0f },
|
85
|
{ 0.0f, 1.5f,-1.5f },
|
86
|
{ 1.5f, 0.0f,-1.5f },
|
87
|
{ 0.0f,-1.5f,-1.5f },
|
88
|
{-1.5f, 0.0f,-1.5f }
|
89
|
};
|
90
|
|
91
|
private static final double[][] VERTICES = new double[][]
|
92
|
{
|
93
|
{-1.5, 0.0, 0.0},
|
94
|
{ 1.5, 0.0, 0.0},
|
95
|
{ 0.0,-1.5, 0.0},
|
96
|
{ 0.0, 0.0,-1.5}
|
97
|
};
|
98
|
|
99
|
private static final int[][] VERT_INDEXES = new int[][]
|
100
|
{
|
101
|
{2,1,0}, // counterclockwise!
|
102
|
{3,0,1},
|
103
|
{2,3,1},
|
104
|
{3,2,0},
|
105
|
};
|
106
|
|
107
|
private static final float[][] STICKERS = new float[][]
|
108
|
{
|
109
|
{ 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
|
110
|
};
|
111
|
|
112
|
private static final ObjectSticker[] mStickers;
|
113
|
|
114
|
static
|
115
|
{
|
116
|
float radius = 0.025f;
|
117
|
float stroke = 0.050f;
|
118
|
float[] radii = new float[] {radius,radius,radius};
|
119
|
mStickers = new ObjectSticker[STICKERS.length];
|
120
|
mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
|
121
|
}
|
122
|
|
123
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
124
|
|
125
|
TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
126
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
127
|
{
|
128
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
129
|
}
|
130
|
|
131
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
132
|
|
133
|
float getScreenRatio()
|
134
|
{
|
135
|
return 0.5f;
|
136
|
}
|
137
|
|
138
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
139
|
|
140
|
Static4D[] getQuats()
|
141
|
{
|
142
|
return QUATS;
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
int getNumFaces()
|
148
|
{
|
149
|
return FACE_COLORS.length;
|
150
|
}
|
151
|
|
152
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
153
|
|
154
|
float[][] getCuts(int size)
|
155
|
{
|
156
|
float[] cut = new float[] { -SQ3/3, +SQ3/3 };
|
157
|
return new float[][] { cut,cut,cut,cut };
|
158
|
}
|
159
|
|
160
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
161
|
|
162
|
int getNumStickerTypes(int numLayers)
|
163
|
{
|
164
|
return STICKERS.length;
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
int getNumCubitFaces()
|
170
|
{
|
171
|
return 4;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
float[][] getCubitPositions(int size)
|
177
|
{
|
178
|
return CENTERS;
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
private Static4D getQuat(int cubit, int numLayers)
|
184
|
{
|
185
|
return QUATS[cubit];
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
private int getNumCubitVariants(int numLayers)
|
191
|
{
|
192
|
return 1;
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
|
197
|
int getCubitVariant(int cubit, int numLayers)
|
198
|
{
|
199
|
return 0;
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
ObjectShape getObjectShape(int cubit, int numLayers)
|
205
|
{
|
206
|
float[][] bands= new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
|
207
|
int[] bandIndices = new int[] { 0,0,1,1 };
|
208
|
float[][] corners = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
|
209
|
int[] cornerIndices = new int[] { 0,0,1,1 };
|
210
|
float[][] centers = new float[][] { {0.0f, -0.75f, -0.75f} };
|
211
|
int[] centerIndices = new int[] { 0,0,0,0 };
|
212
|
|
213
|
return new ObjectShape(VERTICES,VERT_INDEXES,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
|
214
|
}
|
215
|
|
216
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217
|
|
218
|
MeshBase createCubitMesh(int cubit, int numLayers)
|
219
|
{
|
220
|
int variant = getCubitVariant(cubit,numLayers);
|
221
|
|
222
|
if( mMeshes==null )
|
223
|
{
|
224
|
FactoryCubit factory = FactoryCubit.getInstance();
|
225
|
factory.clear();
|
226
|
mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
|
227
|
}
|
228
|
|
229
|
if( mMeshes[variant]==null )
|
230
|
{
|
231
|
ObjectShape shape = getObjectShape(cubit,numLayers);
|
232
|
FactoryCubit factory = FactoryCubit.getInstance();
|
233
|
factory.createNewFaceTransform(shape);
|
234
|
mMeshes[variant] = factory.createRoundedSolid(shape);
|
235
|
}
|
236
|
|
237
|
MeshBase mesh = mMeshes[variant].copy(true);
|
238
|
MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
|
239
|
mesh.apply(quat,0xffffffff,0);
|
240
|
|
241
|
return mesh;
|
242
|
}
|
243
|
|
244
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245
|
|
246
|
int getColor(int face)
|
247
|
{
|
248
|
return FACE_COLORS[face];
|
249
|
}
|
250
|
|
251
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252
|
|
253
|
ObjectSticker retSticker(int face)
|
254
|
{
|
255
|
return mStickers[face/NUM_FACES];
|
256
|
}
|
257
|
|
258
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259
|
|
260
|
float returnMultiplier()
|
261
|
{
|
262
|
return 2.0f;
|
263
|
}
|
264
|
|
265
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
266
|
// PUBLIC API
|
267
|
|
268
|
public Static3D[] getRotationAxis()
|
269
|
{
|
270
|
return ROT_AXIS;
|
271
|
}
|
272
|
|
273
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
274
|
|
275
|
public int[] getBasicAngle()
|
276
|
{
|
277
|
return BASIC_ANGLE;
|
278
|
}
|
279
|
|
280
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
281
|
|
282
|
public int getComplexity(int numLayers)
|
283
|
{
|
284
|
return 2;
|
285
|
}
|
286
|
}
|