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