1 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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.objectlib.objects;
|
21 |
|
|
|
22 |
|
|
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
|
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 |
|
|
import org.distorted.objectlib.main.Movement;
|
32 |
|
|
import org.distorted.objectlib.main.Movement6;
|
33 |
|
|
import org.distorted.objectlib.main.Twisty6;
|
34 |
|
|
|
35 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
36 |
|
|
|
37 |
|
|
abstract class TwistySquare extends Twisty6
|
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 |
|
|
// The third, artificial axis is for the generic scrambling algorithm.
|
44 |
|
|
// Otherwise it wouldn't be possible to rotate the LO and UP layers
|
45 |
|
|
// consecutively.
|
46 |
|
|
|
47 |
|
|
static final Static3D[] ROT_AXIS = new Static3D[]
|
48 |
|
|
{
|
49 |
|
|
new Static3D(0,+1,0),
|
50 |
|
|
new Static3D(COS15,0,SIN15),
|
51 |
|
|
new Static3D(0,-1,0),
|
52 |
|
|
};
|
53 |
|
|
|
54 |
|
|
private static final int[][][] ENABLED = new int[][][]
|
55 |
|
|
{
|
56 |
|
|
{{0}},{{0}},{{1}},{{1}},{{0,1}},{{0,1}}
|
57 |
|
|
};
|
58 |
|
|
|
59 |
|
|
private int[] mBasicAngle;
|
60 |
|
|
private float[][] mCuts;
|
61 |
|
|
private boolean[][] mLayerRotatable;
|
62 |
|
|
private Movement mMovement;
|
63 |
|
|
Static4D[] mQuats;
|
64 |
|
|
|
65 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
66 |
|
|
|
67 |
|
|
TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
|
68 |
61aa85e4
|
Leszek Koltunski
|
DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
|
69 |
29b82486
|
Leszek Koltunski
|
{
|
70 |
61aa85e4
|
Leszek Koltunski
|
super(size, size, quat, texture, mesh, effects, moves, res, scrWidth);
|
71 |
29b82486
|
Leszek Koltunski
|
}
|
72 |
|
|
|
73 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
74 |
|
|
|
75 |
|
|
void initializeQuats()
|
76 |
|
|
{
|
77 |
|
|
mQuats = new Static4D[]
|
78 |
|
|
{
|
79 |
|
|
new Static4D( 0.0f, 0.0f, 0.0f, 1.0f ),
|
80 |
|
|
new Static4D( 0.0f, SIN15, 0.0f, COS15 ),
|
81 |
|
|
new Static4D( 0.0f, 0.5f, 0.0f, SQ3/2 ),
|
82 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f, SQ2/2 ),
|
83 |
|
|
new Static4D( 0.0f, SQ3/2, 0.0f, 0.5f ),
|
84 |
|
|
new Static4D( 0.0f, COS15, 0.0f, SIN15 ),
|
85 |
|
|
new Static4D( 0.0f, 1.0f, 0.0f, 0.0f ),
|
86 |
|
|
new Static4D( 0.0f, COS15, 0.0f,-SIN15 ),
|
87 |
|
|
new Static4D( 0.0f, SQ3/2, 0.0f, -0.5f ),
|
88 |
|
|
new Static4D( 0.0f, SQ2/2, 0.0f,-SQ2/2 ),
|
89 |
|
|
new Static4D( 0.0f, 0.5f, 0.0f,-SQ3/2 ),
|
90 |
|
|
new Static4D( 0.0f, SIN15, 0.0f,-COS15 ),
|
91 |
|
|
|
92 |
|
|
new Static4D( 1.0f, 0.0f, 0.0f, 0.0f ),
|
93 |
|
|
new Static4D( COS15, 0.0f, SIN15, 0.0f ),
|
94 |
|
|
new Static4D( SQ3/2, 0.0f, 0.5f, 0.0f ),
|
95 |
|
|
new Static4D( SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
96 |
|
|
new Static4D( 0.5f, 0.0f, SQ3/2, 0.0f ),
|
97 |
|
|
new Static4D( SIN15, 0.0f, COS15, 0.0f ),
|
98 |
|
|
new Static4D( 0.0f, 0.0f, 1.0f, 0.0f ),
|
99 |
|
|
new Static4D(-SIN15, 0.0f, COS15, 0.0f ),
|
100 |
|
|
new Static4D( -0.5f, 0.0f, SQ3/2, 0.0f ),
|
101 |
|
|
new Static4D(-SQ2/2, 0.0f, SQ2/2, 0.0f ),
|
102 |
|
|
new Static4D(-SQ3/2, 0.0f, 0.5f, 0.0f ),
|
103 |
|
|
new Static4D(-COS15, 0.0f, SIN15, 0.0f )
|
104 |
|
|
};
|
105 |
|
|
}
|
106 |
|
|
|
107 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
108 |
|
|
|
109 |
|
|
void initializeBasicAngle()
|
110 |
|
|
{
|
111 |
|
|
mBasicAngle = new int[] {12,2,12};
|
112 |
|
|
}
|
113 |
|
|
|
114 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
115 |
|
|
|
116 |
|
|
protected Static4D[] getQuats()
|
117 |
|
|
{
|
118 |
|
|
if( mQuats==null ) initializeQuats();
|
119 |
|
|
return mQuats;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
|
124 |
|
|
protected int getNumCubitFaces()
|
125 |
|
|
{
|
126 |
|
|
return 6;
|
127 |
|
|
}
|
128 |
|
|
|
129 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
|
|
|
131 |
|
|
protected float[][] getCuts(int numLayers)
|
132 |
|
|
{
|
133 |
|
|
if( mCuts==null )
|
134 |
|
|
{
|
135 |
|
|
mCuts = new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
return mCuts;
|
139 |
|
|
}
|
140 |
|
|
|
141 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
|
|
|
143 |
|
|
private void getLayerRotatable(int numLayers)
|
144 |
|
|
{
|
145 |
|
|
if( mLayerRotatable==null )
|
146 |
|
|
{
|
147 |
|
|
mLayerRotatable = new boolean[][] { {true,false,true}, {true,true}, {true,false,true} };
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152 |
|
|
// PUBLIC API
|
153 |
|
|
|
154 |
|
|
public Static3D[] getRotationAxis()
|
155 |
|
|
{
|
156 |
|
|
return ROT_AXIS;
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160 |
|
|
|
161 |
|
|
public Movement getMovement()
|
162 |
|
|
{
|
163 |
|
|
if( mMovement==null )
|
164 |
|
|
{
|
165 |
|
|
int numLayers = getNumLayers();
|
166 |
|
|
if( mCuts==null ) getCuts(numLayers);
|
167 |
|
|
getLayerRotatable(numLayers);
|
168 |
|
|
mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
|
169 |
|
|
}
|
170 |
|
|
return mMovement;
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
174 |
|
|
|
175 |
|
|
public int[] getBasicAngle()
|
176 |
|
|
{
|
177 |
|
|
if( mBasicAngle ==null ) initializeBasicAngle();
|
178 |
|
|
return mBasicAngle;
|
179 |
|
|
}
|
180 |
|
|
}
|