1 |
fdec60a3
|
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 |
4f9f99a2
|
Leszek Koltunski
|
package org.distorted.object;
|
21 |
fdec60a3
|
Leszek Koltunski
|
|
22 |
27a70eae
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
23 |
411c6285
|
Leszek Koltunski
|
import android.graphics.Bitmap;
|
24 |
|
|
import android.graphics.Canvas;
|
25 |
|
|
import android.graphics.Paint;
|
26 |
27a70eae
|
Leszek Koltunski
|
|
27 |
|
|
import org.distorted.library.effect.Effect;
|
28 |
|
|
import org.distorted.library.effect.MatrixEffectQuaternion;
|
29 |
|
|
import org.distorted.library.effect.MatrixEffectScale;
|
30 |
|
|
import org.distorted.library.effect.VertexEffectSink;
|
31 |
|
|
import org.distorted.library.main.DistortedEffects;
|
32 |
|
|
import org.distorted.library.main.DistortedNode;
|
33 |
|
|
import org.distorted.library.main.DistortedTexture;
|
34 |
b32444ee
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshBase;
|
35 |
97c012ae
|
Leszek Koltunski
|
import org.distorted.library.mesh.MeshRectangles;
|
36 |
27a70eae
|
Leszek Koltunski
|
import org.distorted.library.message.EffectListener;
|
37 |
f16ff19d
|
Leszek Koltunski
|
import org.distorted.library.type.Dynamic1D;
|
38 |
27a70eae
|
Leszek Koltunski
|
import org.distorted.library.type.Static1D;
|
39 |
|
|
import org.distorted.library.type.Static3D;
|
40 |
|
|
import org.distorted.library.type.Static4D;
|
41 |
4f9f99a2
|
Leszek Koltunski
|
|
42 |
ba740a0c
|
Leszek Koltunski
|
import static org.distorted.magic.RubikRenderer.NODE_FBO_SIZE;
|
43 |
d41742f7
|
Leszek Koltunski
|
|
44 |
0333d81e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
45 |
|
|
|
46 |
27a70eae
|
Leszek Koltunski
|
public abstract class RubikObject extends DistortedNode
|
47 |
fdec60a3
|
Leszek Koltunski
|
{
|
48 |
411c6285
|
Leszek Koltunski
|
static final int TEXTURE_HEIGHT = 128;
|
49 |
27a70eae
|
Leszek Koltunski
|
static final float OBJECT_SCREEN_RATIO = 0.5f;
|
50 |
a10ada2a
|
Leszek Koltunski
|
final float[] LEGAL_QUATS;
|
51 |
efef689c
|
Leszek Koltunski
|
final Static3D[] ROTATION_AXIS;
|
52 |
27a70eae
|
Leszek Koltunski
|
|
53 |
f16ff19d
|
Leszek Koltunski
|
private static final int POST_ROTATION_MILLISEC = 500;
|
54 |
a10ada2a
|
Leszek Koltunski
|
private final int NUM_CUBITS;
|
55 |
3c4a326c
|
Leszek Koltunski
|
private int mRotRow;
|
56 |
efef689c
|
Leszek Koltunski
|
private int mRotAxis;
|
57 |
5ba13c05
|
Leszek Koltunski
|
private Static3D mScale, mNodeScale;
|
58 |
27a70eae
|
Leszek Koltunski
|
private Static4D mQuatAccumulated;
|
59 |
b32444ee
|
Leszek Koltunski
|
private Cubit[] mCubits;
|
60 |
27a70eae
|
Leszek Koltunski
|
|
61 |
e844c116
|
Leszek Koltunski
|
float mStart, mStep;
|
62 |
a10ada2a
|
Leszek Koltunski
|
int mSize;
|
63 |
fdec60a3
|
Leszek Koltunski
|
|
64 |
27a70eae
|
Leszek Koltunski
|
Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
|
65 |
|
|
DistortedTexture mTexture;
|
66 |
|
|
|
67 |
|
|
VertexEffectSink mSinkEffect;
|
68 |
|
|
MatrixEffectScale mScaleEffect;
|
69 |
|
|
MatrixEffectQuaternion mQuatCEffect;
|
70 |
|
|
MatrixEffectQuaternion mQuatAEffect;
|
71 |
|
|
|
72 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
73 |
fdec60a3
|
Leszek Koltunski
|
|
74 |
411c6285
|
Leszek Koltunski
|
RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects)
|
75 |
fdec60a3
|
Leszek Koltunski
|
{
|
76 |
411c6285
|
Leszek Koltunski
|
super(nodeTexture,nodeEffects,nodeMesh);
|
77 |
fdec60a3
|
Leszek Koltunski
|
|
78 |
ba740a0c
|
Leszek Koltunski
|
resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE);
|
79 |
d41742f7
|
Leszek Koltunski
|
|
80 |
10a2e360
|
Leszek Koltunski
|
Static3D[] positions = getCubitPositions(size);
|
81 |
|
|
|
82 |
f16ff19d
|
Leszek Koltunski
|
LEGAL_QUATS = getLegalQuats();
|
83 |
10a2e360
|
Leszek Koltunski
|
NUM_CUBITS = positions.length;
|
84 |
efef689c
|
Leszek Koltunski
|
ROTATION_AXIS = getRotationAxis();
|
85 |
a10ada2a
|
Leszek Koltunski
|
|
86 |
27a70eae
|
Leszek Koltunski
|
mSize = size;
|
87 |
|
|
|
88 |
e844c116
|
Leszek Koltunski
|
computeStartAndStep(positions);
|
89 |
|
|
|
90 |
27a70eae
|
Leszek Koltunski
|
mRotationAngleStatic = new Static1D(0);
|
91 |
|
|
mRotationAngleMiddle = new Static1D(0);
|
92 |
|
|
mRotationAngleFinal = new Static1D(0);
|
93 |
|
|
|
94 |
|
|
mScale = new Static3D(1,1,1);
|
95 |
|
|
mNodeScale= new Static3D(1,1,1);
|
96 |
|
|
|
97 |
|
|
mQuatAccumulated = quatAcc;
|
98 |
|
|
|
99 |
5ba13c05
|
Leszek Koltunski
|
Static3D center = new Static3D(0,0,0);
|
100 |
5974d2ae
|
Leszek Koltunski
|
Static4D region = new Static4D(0,0,0,0.72f);
|
101 |
27a70eae
|
Leszek Koltunski
|
|
102 |
5ba13c05
|
Leszek Koltunski
|
mSinkEffect = new VertexEffectSink( new Static1D(getSinkStrength()), center, region );
|
103 |
27a70eae
|
Leszek Koltunski
|
mScaleEffect = new MatrixEffectScale(mScale);
|
104 |
5ba13c05
|
Leszek Koltunski
|
mQuatCEffect = new MatrixEffectQuaternion(quatCur, center);
|
105 |
|
|
mQuatAEffect = new MatrixEffectQuaternion(quatAcc, center);
|
106 |
27a70eae
|
Leszek Koltunski
|
|
107 |
|
|
MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
|
108 |
411c6285
|
Leszek Koltunski
|
nodeEffects.apply(nodeScaleEffect);
|
109 |
a10ada2a
|
Leszek Koltunski
|
|
110 |
|
|
mCubits = new Cubit[NUM_CUBITS];
|
111 |
5974d2ae
|
Leszek Koltunski
|
mTexture = new DistortedTexture();
|
112 |
a10ada2a
|
Leszek Koltunski
|
|
113 |
|
|
int vertices = (int)(24.0f/mSize + 2.0f);
|
114 |
|
|
|
115 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
116 |
|
|
{
|
117 |
efef689c
|
Leszek Koltunski
|
MeshBase cubitMesh = createCubitMesh(vertices);
|
118 |
10a2e360
|
Leszek Koltunski
|
mCubits[i] = new Cubit(this,cubitMesh,positions[i]);
|
119 |
efef689c
|
Leszek Koltunski
|
textureCubitMesh(cubitMesh,i);
|
120 |
a10ada2a
|
Leszek Koltunski
|
|
121 |
|
|
attach(mCubits[i].mNode);
|
122 |
|
|
}
|
123 |
27a70eae
|
Leszek Koltunski
|
}
|
124 |
|
|
|
125 |
efef689c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126 |
|
|
|
127 |
|
|
private void textureCubitMesh(MeshBase mesh, int cubit)
|
128 |
|
|
{
|
129 |
|
|
boolean belongs;
|
130 |
|
|
final int numFaces = getNumFaces();
|
131 |
|
|
final Static4D[] maps = new Static4D[numFaces];
|
132 |
|
|
final float ratio = 1.0f/(numFaces+1);
|
133 |
|
|
|
134 |
|
|
if( 2*ROTATION_AXIS.length == numFaces )
|
135 |
|
|
{
|
136 |
|
|
for(int i=0; i<numFaces; i++)
|
137 |
|
|
{
|
138 |
|
|
belongs = belongsToRotation(cubit, i/2, i%2==0 ? mSize-1:0 );
|
139 |
|
|
maps[i] = new Static4D( (belongs?i:6)*ratio, 0.0f, ratio, 1.0f);
|
140 |
|
|
}
|
141 |
|
|
}
|
142 |
|
|
else if( ROTATION_AXIS.length == numFaces )
|
143 |
|
|
{
|
144 |
|
|
for(int i=0; i<numFaces; i++)
|
145 |
|
|
{
|
146 |
|
|
belongs = belongsToRotation(cubit, i, mSize-1 );
|
147 |
|
|
maps[i] = new Static4D( (belongs?i:6)*ratio, 0.0f, ratio, 1.0f);
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
|
151 |
|
|
mesh.setTextureMap(maps);
|
152 |
|
|
}
|
153 |
|
|
|
154 |
e844c116
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
155 |
|
|
|
156 |
|
|
private void computeStartAndStep(Static3D[] pos)
|
157 |
|
|
{
|
158 |
|
|
float min = Float.MAX_VALUE;
|
159 |
|
|
float max = Float.MIN_VALUE;
|
160 |
|
|
float axisX = ROTATION_AXIS[0].get0();
|
161 |
|
|
float axisY = ROTATION_AXIS[0].get1();
|
162 |
|
|
float axisZ = ROTATION_AXIS[0].get2();
|
163 |
|
|
float tmp;
|
164 |
|
|
|
165 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
166 |
|
|
{
|
167 |
|
|
tmp = pos[i].get0()*axisX + pos[i].get1()*axisY + pos[i].get2()*axisZ;
|
168 |
|
|
if( tmp<min ) min=tmp;
|
169 |
|
|
if( tmp>max ) max=tmp;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
mStart = min;
|
173 |
|
|
mStep = (max-min+1.0f)/mSize;
|
174 |
|
|
}
|
175 |
|
|
|
176 |
efef689c
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
177 |
|
|
|
178 |
|
|
private boolean belongsToRotation( int cubit, int axis, int row)
|
179 |
|
|
{
|
180 |
10a2e360
|
Leszek Koltunski
|
return mCubits[cubit].mRotationRow[axis]==row;
|
181 |
efef689c
|
Leszek Koltunski
|
}
|
182 |
|
|
|
183 |
f16ff19d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
184 |
|
|
|
185 |
a10ada2a
|
Leszek Koltunski
|
private void resetRotationAngle(Dynamic1D rotationAngle)
|
186 |
f16ff19d
|
Leszek Koltunski
|
{
|
187 |
|
|
rotationAngle.setDuration(POST_ROTATION_MILLISEC);
|
188 |
|
|
rotationAngle.resetToBeginning();
|
189 |
|
|
rotationAngle.removeAll();
|
190 |
|
|
rotationAngle.add(mRotationAngleStatic);
|
191 |
|
|
rotationAngle.add(mRotationAngleMiddle);
|
192 |
|
|
rotationAngle.add(mRotationAngleFinal);
|
193 |
|
|
}
|
194 |
|
|
|
195 |
fdec60a3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
196 |
|
|
|
197 |
27a70eae
|
Leszek Koltunski
|
private float getSinkStrength()
|
198 |
dd73fdab
|
Leszek Koltunski
|
{
|
199 |
27a70eae
|
Leszek Koltunski
|
switch(mSize)
|
200 |
|
|
{
|
201 |
|
|
case 1 : return 1.1f;
|
202 |
|
|
case 2 : return 1.5f;
|
203 |
|
|
case 3 : return 1.8f;
|
204 |
|
|
case 4 : return 2.0f;
|
205 |
|
|
default: return 3.0f - 4.0f/mSize;
|
206 |
|
|
}
|
207 |
dd73fdab
|
Leszek Koltunski
|
}
|
208 |
|
|
|
209 |
411c6285
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
210 |
|
|
// the getFaceColors + final black in a horizontal strip.
|
211 |
|
|
|
212 |
|
|
public void createTexture()
|
213 |
|
|
{
|
214 |
|
|
Bitmap bitmap;
|
215 |
|
|
|
216 |
|
|
final int numColors = getNumFaces();
|
217 |
|
|
|
218 |
|
|
Paint paint = new Paint();
|
219 |
|
|
bitmap = Bitmap.createBitmap( (numColors+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, Bitmap.Config.ARGB_8888);
|
220 |
|
|
Canvas canvas = new Canvas(bitmap);
|
221 |
|
|
|
222 |
|
|
paint.setAntiAlias(true);
|
223 |
|
|
paint.setTextAlign(Paint.Align.CENTER);
|
224 |
|
|
paint.setStyle(Paint.Style.FILL);
|
225 |
|
|
|
226 |
|
|
paint.setColor(0xff000000);
|
227 |
|
|
canvas.drawRect(0, 0, (numColors+1)*TEXTURE_HEIGHT, TEXTURE_HEIGHT, paint);
|
228 |
|
|
|
229 |
|
|
for(int i=0; i<numColors; i++)
|
230 |
|
|
{
|
231 |
|
|
createFaceTexture(canvas,paint,i);
|
232 |
|
|
}
|
233 |
|
|
|
234 |
|
|
mTexture.setTexture(bitmap);
|
235 |
|
|
}
|
236 |
|
|
|
237 |
dd73fdab
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
238 |
|
|
|
239 |
27a70eae
|
Leszek Koltunski
|
public int getSize()
|
240 |
fdec60a3
|
Leszek Koltunski
|
{
|
241 |
27a70eae
|
Leszek Koltunski
|
return mSize;
|
242 |
fdec60a3
|
Leszek Koltunski
|
}
|
243 |
|
|
|
244 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
245 |
|
|
|
246 |
27a70eae
|
Leszek Koltunski
|
public void continueRotation(float angleInDegrees)
|
247 |
fdec60a3
|
Leszek Koltunski
|
{
|
248 |
27a70eae
|
Leszek Koltunski
|
mRotationAngleStatic.set0(angleInDegrees);
|
249 |
fdec60a3
|
Leszek Koltunski
|
}
|
250 |
|
|
|
251 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
252 |
|
|
|
253 |
27a70eae
|
Leszek Koltunski
|
public Static4D getRotationQuat()
|
254 |
|
|
{
|
255 |
|
|
return mQuatAccumulated;
|
256 |
|
|
}
|
257 |
|
|
|
258 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
259 |
|
|
|
260 |
5ba13c05
|
Leszek Koltunski
|
public void recomputeScaleFactor(int scrWidth, int scrHeight)
|
261 |
fdec60a3
|
Leszek Koltunski
|
{
|
262 |
ba740a0c
|
Leszek Koltunski
|
float factor = scrWidth>scrHeight ? scrHeight : scrWidth;
|
263 |
|
|
float scaleFactor = OBJECT_SCREEN_RATIO*NODE_FBO_SIZE/mSize;
|
264 |
27a70eae
|
Leszek Koltunski
|
|
265 |
5ba13c05
|
Leszek Koltunski
|
mNodeScale.set(factor,factor,factor);
|
266 |
27a70eae
|
Leszek Koltunski
|
mScale.set(scaleFactor,scaleFactor,scaleFactor);
|
267 |
fdec60a3
|
Leszek Koltunski
|
}
|
268 |
27a70eae
|
Leszek Koltunski
|
|
269 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
270 |
|
|
|
271 |
a10ada2a
|
Leszek Koltunski
|
public void savePreferences(SharedPreferences.Editor editor)
|
272 |
|
|
{
|
273 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].savePreferences(editor);
|
274 |
|
|
}
|
275 |
f16ff19d
|
Leszek Koltunski
|
|
276 |
a10ada2a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277 |
27a70eae
|
Leszek Koltunski
|
|
278 |
a10ada2a
|
Leszek Koltunski
|
public void restorePreferences(SharedPreferences preferences)
|
279 |
|
|
{
|
280 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].restorePreferences(preferences);
|
281 |
|
|
}
|
282 |
27a70eae
|
Leszek Koltunski
|
|
283 |
a10ada2a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
284 |
74686c71
|
Leszek Koltunski
|
|
285 |
a10ada2a
|
Leszek Koltunski
|
public long finishRotationNow(EffectListener listener)
|
286 |
|
|
{
|
287 |
|
|
boolean first = true;
|
288 |
|
|
long effectID=0;
|
289 |
|
|
|
290 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
291 |
|
|
{
|
292 |
efef689c
|
Leszek Koltunski
|
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
293 |
a10ada2a
|
Leszek Koltunski
|
{
|
294 |
|
|
if( first )
|
295 |
|
|
{
|
296 |
|
|
first=false;
|
297 |
|
|
effectID = mCubits[i].finishRotationNow(listener);
|
298 |
|
|
}
|
299 |
|
|
resetRotationAngle(mCubits[i].mRotationAngle);
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
return effectID;
|
304 |
|
|
}
|
305 |
|
|
|
306 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
307 |
|
|
|
308 |
|
|
public void releaseResources()
|
309 |
|
|
{
|
310 |
|
|
mTexture.markForDeletion();
|
311 |
|
|
|
312 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].releaseResources();
|
313 |
|
|
}
|
314 |
|
|
|
315 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
316 |
|
|
|
317 |
|
|
public void apply(Effect effect, int position)
|
318 |
|
|
{
|
319 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].mEffect.apply(effect, position);
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
323 |
|
|
|
324 |
|
|
public void remove(long effectID)
|
325 |
|
|
{
|
326 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].mEffect.abortById(effectID);
|
327 |
|
|
}
|
328 |
74686c71
|
Leszek Koltunski
|
|
329 |
a10ada2a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330 |
|
|
|
331 |
|
|
public void solve()
|
332 |
|
|
{
|
333 |
|
|
for(int i=0; i<NUM_CUBITS; i++) mCubits[i].solve();
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
337 |
|
|
|
338 |
|
|
public boolean isSolved()
|
339 |
|
|
{
|
340 |
|
|
Static4D q = mCubits[0].mQuatScramble;
|
341 |
|
|
|
342 |
|
|
float x = q.get0();
|
343 |
|
|
float y = q.get1();
|
344 |
|
|
float z = q.get2();
|
345 |
|
|
float w = q.get3();
|
346 |
|
|
|
347 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
348 |
|
|
{
|
349 |
|
|
q = mCubits[i].mQuatScramble;
|
350 |
|
|
|
351 |
|
|
if( q.get0()!=x || q.get1()!=y || q.get2()!=z || q.get3()!=w ) return false;
|
352 |
|
|
}
|
353 |
|
|
|
354 |
|
|
return true;
|
355 |
|
|
}
|
356 |
|
|
|
357 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
358 |
|
|
|
359 |
efef689c
|
Leszek Koltunski
|
public void beginNewRotation(int axis, int row )
|
360 |
a10ada2a
|
Leszek Koltunski
|
{
|
361 |
3c4a326c
|
Leszek Koltunski
|
mRotAxis = axis;
|
362 |
a10ada2a
|
Leszek Koltunski
|
mRotRow = row;
|
363 |
|
|
|
364 |
|
|
mRotationAngleStatic.set0(0.0f);
|
365 |
|
|
|
366 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
367 |
efef689c
|
Leszek Koltunski
|
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
368 |
a10ada2a
|
Leszek Koltunski
|
{
|
369 |
|
|
mCubits[i].beginNewRotation(axis);
|
370 |
|
|
}
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
374 |
|
|
|
375 |
efef689c
|
Leszek Koltunski
|
public long addNewRotation( int axis, int row, int angle, long durationMillis, EffectListener listener )
|
376 |
a10ada2a
|
Leszek Koltunski
|
{
|
377 |
|
|
long effectID=0;
|
378 |
|
|
boolean first = true;
|
379 |
|
|
|
380 |
3c4a326c
|
Leszek Koltunski
|
mRotAxis = axis;
|
381 |
a10ada2a
|
Leszek Koltunski
|
mRotRow = row;
|
382 |
|
|
|
383 |
|
|
mRotationAngleStatic.set0(0.0f);
|
384 |
|
|
|
385 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
386 |
efef689c
|
Leszek Koltunski
|
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
387 |
a10ada2a
|
Leszek Koltunski
|
{
|
388 |
|
|
mCubits[i].addNewRotation(axis,durationMillis,angle);
|
389 |
|
|
|
390 |
|
|
if( first )
|
391 |
|
|
{
|
392 |
|
|
first = false;
|
393 |
|
|
effectID = mCubits[i].setUpCallback(listener);
|
394 |
|
|
}
|
395 |
|
|
}
|
396 |
|
|
|
397 |
|
|
return effectID;
|
398 |
|
|
}
|
399 |
|
|
|
400 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
401 |
|
|
|
402 |
|
|
public void removeRotationNow()
|
403 |
|
|
{
|
404 |
|
|
boolean first = true;
|
405 |
|
|
Static4D quat = null;
|
406 |
|
|
|
407 |
|
|
for(int i=0; i<NUM_CUBITS; i++)
|
408 |
efef689c
|
Leszek Koltunski
|
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
409 |
a10ada2a
|
Leszek Koltunski
|
{
|
410 |
|
|
if( first )
|
411 |
|
|
{
|
412 |
|
|
first = false;
|
413 |
3c4a326c
|
Leszek Koltunski
|
quat = mCubits[i].returnRotationQuat(mRotAxis);
|
414 |
a10ada2a
|
Leszek Koltunski
|
}
|
415 |
|
|
|
416 |
|
|
mCubits[i].removeRotationNow(quat);
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
mRotationAngleStatic.set0(0);
|
420 |
|
|
}
|
421 |
|
|
|
422 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
423 |
|
|
|
424 |
e844c116
|
Leszek Koltunski
|
public int getNumAxis()
|
425 |
10a2e360
|
Leszek Koltunski
|
{
|
426 |
|
|
return ROTATION_AXIS.length;
|
427 |
|
|
}
|
428 |
|
|
|
429 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
430 |
|
|
|
431 |
|
|
abstract Static3D[] getCubitPositions(int size);
|
432 |
a10ada2a
|
Leszek Koltunski
|
abstract float[] getLegalQuats();
|
433 |
411c6285
|
Leszek Koltunski
|
abstract int getNumFaces();
|
434 |
|
|
abstract void createFaceTexture(Canvas canvas, Paint paint, int face);
|
435 |
|
|
abstract MeshBase createCubitMesh(int vertices);
|
436 |
efef689c
|
Leszek Koltunski
|
abstract Static3D[] getRotationAxis();
|
437 |
e844c116
|
Leszek Koltunski
|
public abstract int getBasicAngle();
|
438 |
fdec60a3
|
Leszek Koltunski
|
}
|