Revision d4374cd3
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/rubik/RubikCube.java | ||
---|---|---|
42 | 42 |
|
43 | 43 |
class RubikCube |
44 | 44 |
{ |
45 |
private static final int POST_ROTATION_MILLISEC = 500; |
|
45 | 46 |
private static final int TEXTURE_SIZE = 100; |
46 | 47 |
|
47 | 48 |
private static final Static3D VectX = new Static3D(1,0,0); |
... | ... | |
54 | 55 |
private Static3D[][][] mRotationAxis; |
55 | 56 |
private Dynamic1D[][][] mRotationAngle; |
56 | 57 |
private Static3D[][][] mCurrentPosition; |
57 |
private Static1D mRotationAngleStatic, mRotationAngleNearest;
|
|
58 |
private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
|
|
58 | 59 |
private DistortedTexture mTexture; |
59 | 60 |
private DistortedEffects mEffectsListeningForNow; |
60 | 61 |
|
... | ... | |
67 | 68 |
{ |
68 | 69 |
mSize = size; |
69 | 70 |
|
70 |
mRotationAngleStatic = new Static1D(0); |
|
71 |
mRotationAngleNearest = new Static1D(0); |
|
71 |
mRotationAngleStatic = new Static1D(0); |
|
72 |
mRotationAngleMiddle = new Static1D(0); |
|
73 |
mRotationAngleFinal = new Static1D(0); |
|
72 | 74 |
|
73 | 75 |
mRotAxis= RubikSurfaceView.VECTX; |
74 | 76 |
mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE); |
... | ... | |
218 | 220 |
void finishRotationCalledOnNextRender(EffectListener listener) |
219 | 221 |
{ |
220 | 222 |
boolean first = true; |
221 |
int nearestAngleInDegrees = computeNearestAngle(mRotationAngleStatic.get1()); |
|
222 |
|
|
223 |
|
|
224 |
android.util.Log.e("cube", "finish: angle="+((int)mRotationAngleStatic.get1())+" ret: "+nearestAngleInDegrees); |
|
223 |
float startingAngle = mRotationAngleStatic.get1(); |
|
224 |
int nearestAngleInDegrees = computeNearestAngle(startingAngle); |
|
225 | 225 |
|
226 |
|
|
227 |
mRotationAngleNearest.set1(nearestAngleInDegrees);
|
|
226 |
mRotationAngleFinal.set1(nearestAngleInDegrees); |
|
227 |
mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
|
|
228 | 228 |
|
229 | 229 |
for(int x=0; x<mSize; x++) |
230 | 230 |
for(int y=0; y<mSize; y++) |
... | ... | |
233 | 233 |
{ |
234 | 234 |
if( belongsToRotation(x,y,z,mRotAxis,mRotRow) ) |
235 | 235 |
{ |
236 |
mRotationAngle[x][y][z].makeRunNowFor(2000); |
|
237 |
mRotationAngle[x][y][z].add(mRotationAngleNearest); |
|
236 |
mRotationAngle[x][y][z].makeRunNowFor(POST_ROTATION_MILLISEC); |
|
237 |
mRotationAngle[x][y][z].add(mRotationAngleMiddle); |
|
238 |
mRotationAngle[x][y][z].add(mRotationAngleFinal); |
|
238 | 239 |
|
239 | 240 |
if( first ) |
240 | 241 |
{ |
... | ... | |
257 | 258 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
258 | 259 |
float cosA = (float)Math.cos(nearestAngleInRadians*0.5); |
259 | 260 |
|
260 |
android.util.Log.e("cube", "remove: angle="+((int)mRotationAngleStatic.get1())+" ret: "+nearestAngleInDegrees); |
|
261 |
|
|
262 | 261 |
mRotationAngleStatic.set1(0); |
263 |
mRotationAngleNearest.set1(0); |
|
264 | 262 |
|
265 | 263 |
float qx=0,qy=0,qz=0; |
266 | 264 |
|
Also available in: Unified diff
RubikCube: make the post-rotation effect 'nice'.