1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2021 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.library.main.DistortedEffects;
|
25
|
import org.distorted.library.main.DistortedTexture;
|
26
|
import org.distorted.library.mesh.MeshSquare;
|
27
|
import org.distorted.library.type.Static3D;
|
28
|
import org.distorted.library.type.Static4D;
|
29
|
|
30
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
31
|
|
32
|
abstract class TwistySquare extends TwistyObject
|
33
|
{
|
34
|
static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
|
35
|
static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
|
36
|
static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
|
37
|
static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
|
38
|
|
39
|
static final float COS15 = (SQ6+SQ2)/4;
|
40
|
static final float SIN15 = (SQ6-SQ2)/4;
|
41
|
static final float X = 3*(2-SQ3)/2;
|
42
|
|
43
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
44
|
{
|
45
|
new Static3D(0,1,0),
|
46
|
new Static3D(COS15,0,SIN15)
|
47
|
};
|
48
|
|
49
|
static final int[] BASIC_ANGLE = new int[] { 12,2 };
|
50
|
|
51
|
static final int[] FACE_COLORS = new int[]
|
52
|
{
|
53
|
COLOR_YELLOW, COLOR_WHITE,
|
54
|
COLOR_BLUE , COLOR_GREEN,
|
55
|
COLOR_RED , COLOR_ORANGE
|
56
|
};
|
57
|
|
58
|
static final Static4D[] QUATS = new Static4D[]
|
59
|
{
|
60
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
61
|
new Static4D( 0.0f, SIN15, 0.0f, COS15 ),
|
62
|
new Static4D( 0.0f, 0.5f, 0.0f, SQ3/2 ),
|
63
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2 ),
|
64
|
new Static4D( 0.0f, SQ3/2, 0.0f, 0.5f ),
|
65
|
new Static4D( 0.0f, COS15, 0.0f, SIN15 ),
|
66
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
67
|
new Static4D( 0.0f, COS15, 0.0f,-SIN15 ),
|
68
|
new Static4D( 0.0f, SQ3/2, 0.0f, -0.5f ),
|
69
|
new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2 ),
|
70
|
new Static4D( 0.0f, 0.5f, 0.0f,-SQ3/2 ),
|
71
|
new Static4D( 0.0f, SIN15, 0.0f,-COS15 ),
|
72
|
|
73
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
74
|
new Static4D( COS15, 0.0f, SIN15, 0.0f ),
|
75
|
new Static4D( SQ3/2, 0.0f, 0.5f, 0.0f ),
|
76
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
77
|
new Static4D( 0.5f, 0.0f, SQ3/2, 0.0f ),
|
78
|
new Static4D( SIN15, 0.0f, COS15, 0.0f ),
|
79
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
80
|
new Static4D(-SIN15, 0.0f, COS15, 0.0f ),
|
81
|
new Static4D( -0.5f, 0.0f, SQ3/2, 0.0f ),
|
82
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
83
|
new Static4D(-SQ3/2, 0.0f, 0.5f, 0.0f ),
|
84
|
new Static4D(-COS15, 0.0f, SIN15, 0.0f )
|
85
|
};
|
86
|
|
87
|
static final double[][] VERTICES_MIDDLE = new double[][]
|
88
|
{
|
89
|
{ -1.5-X, 0.5, 1.5 },
|
90
|
{ 0.0, 0.5, 1.5 },
|
91
|
{ 0.0, 0.5,-1.5 },
|
92
|
{ -1.5+X, 0.5,-1.5 },
|
93
|
{ -1.5-X,-0.5, 1.5 },
|
94
|
{ 0.0,-0.5, 1.5 },
|
95
|
{ 0.0,-0.5,-1.5 },
|
96
|
{ -1.5+X,-0.5,-1.5 }
|
97
|
};
|
98
|
|
99
|
static final int[][] VERT_INDEXES_MIDDLE = new int[][]
|
100
|
{
|
101
|
{0,1,2,3}, // counterclockwise!
|
102
|
{4,5,6,7},
|
103
|
{4,5,1,0},
|
104
|
{5,6,2,1},
|
105
|
{6,7,3,2},
|
106
|
{7,4,0,3}
|
107
|
};
|
108
|
|
109
|
static final double[][] VERTICES_EDGE = new double[][]
|
110
|
{
|
111
|
{ -X, 0.5, 0.0 },
|
112
|
{ +X, 0.5, 0.0 },
|
113
|
{0.0, 0.5,-1.5 },
|
114
|
{ -X,-0.5, 0.0 },
|
115
|
{ +X,-0.5, 0.0 },
|
116
|
{0.0,-0.5,-1.5 },
|
117
|
};
|
118
|
|
119
|
static final int[][] VERT_INDEXES_EDGE = new int[][]
|
120
|
{
|
121
|
{0,1,2}, // counterclockwise!
|
122
|
{3,4,5},
|
123
|
{3,4,1,0},
|
124
|
{4,5,2,1},
|
125
|
{5,3,0,2}
|
126
|
};
|
127
|
|
128
|
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
|
129
|
static final int[][] QUAT_MULT = new int[][]
|
130
|
{
|
131
|
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
|
132
|
{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
|
133
|
{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
|
134
|
{ 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
|
135
|
{ 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
|
136
|
{ 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
|
137
|
{ 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
|
138
|
{ 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
|
139
|
{ 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
|
140
|
{ 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
|
141
|
{ 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
|
142
|
{ 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
|
143
|
{ 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1,},
|
144
|
{ 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2,},
|
145
|
{ 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4, 3,},
|
146
|
{ 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5, 4,},
|
147
|
{ 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6, 5,},
|
148
|
{ 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7, 6,},
|
149
|
{ 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8, 7,},
|
150
|
{ 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9, 8,},
|
151
|
{ 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10, 9,},
|
152
|
{ 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11, 10,},
|
153
|
{ 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 11,},
|
154
|
{ 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,}
|
155
|
};
|
156
|
|
157
|
int mLastRot;
|
158
|
|
159
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160
|
|
161
|
TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
162
|
DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
|
163
|
{
|
164
|
super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
|
165
|
}
|
166
|
|
167
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
168
|
|
169
|
Static4D[] getQuats()
|
170
|
{
|
171
|
return QUATS;
|
172
|
}
|
173
|
|
174
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
175
|
|
176
|
boolean shouldResetTextureMaps()
|
177
|
{
|
178
|
return false;
|
179
|
}
|
180
|
|
181
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182
|
|
183
|
int getNumFaces()
|
184
|
{
|
185
|
return FACE_COLORS.length;
|
186
|
}
|
187
|
|
188
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189
|
|
190
|
int getNumCubitFaces()
|
191
|
{
|
192
|
return 6;
|
193
|
}
|
194
|
|
195
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196
|
|
197
|
float getScreenRatio()
|
198
|
{
|
199
|
return 0.5f;
|
200
|
}
|
201
|
|
202
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
203
|
|
204
|
float returnMultiplier()
|
205
|
{
|
206
|
return 1.0f;
|
207
|
}
|
208
|
|
209
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210
|
|
211
|
float[][] getCuts(int numLayers)
|
212
|
{
|
213
|
return new float[][] { {-0.5f,+0.5f}, {0.0f} };
|
214
|
}
|
215
|
|
216
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
217
|
|
218
|
int getColor(int face)
|
219
|
{
|
220
|
return FACE_COLORS[face];
|
221
|
}
|
222
|
|
223
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
224
|
// PUBLIC API
|
225
|
|
226
|
public Static3D[] getRotationAxis()
|
227
|
{
|
228
|
return ROT_AXIS;
|
229
|
}
|
230
|
|
231
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
232
|
|
233
|
public int[] getBasicAngle()
|
234
|
{
|
235
|
return BASIC_ANGLE;
|
236
|
}
|
237
|
}
|