Project

General

Profile

« Previous | Next » 

Revision ffd48105

Added by Leszek Koltunski about 5 years ago

RubikCube: make finishingRotation more flexible (can now finish any rotation which did finish interpolating (nearly) to the end - and not only the single-static 'manual' rotation)

View differences:

src/main/java/org/distorted/magic/RubikCube.java
301 301

  
302 302
///////////////////////////////////////////////////////////////////////////////////////////////////
303 303

  
304
    void addNewRotation(int vector, float offset )
304
    void addNewRotation(int vector, int row )
305 305
      {
306 306
      Static3D axis = VectX;
307 307

  
......
313 313
        }
314 314

  
315 315
      mRotAxis = vector;
316
      mRotRow  = (int)(mSize*offset);
316
      mRotRow  = row;
317 317

  
318 318
      mRotationAngleStatic.set1(0.0f);
319 319

  
......
354 354
    long finishRotationNow(EffectListener listener)
355 355
      {
356 356
      boolean first = true;
357
      float startingAngle = mRotationAngleStatic.get1();
358
      int nearestAngleInDegrees = computeNearestAngle(startingAngle);
359 357
      long effectID=0;
360 358

  
361
      mRotationAngleFinal.set1(nearestAngleInDegrees);
362
      mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
363

  
364 359
      for(int x=0; x<mSize; x++)
365 360
        for(int y=0; y<mSize; y++)
366 361
          for(int z=0; z<mSize; z++)
......
368 363
              {
369 364
              if( belongsToRotation(x,y,z,mRotAxis,mRotRow) )
370 365
                {
371
                mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
372
                mRotationAngle[x][y][z].resetToBeginning();
373
                mRotationAngle[x][y][z].add(mRotationAngleMiddle);
374
                mRotationAngle[x][y][z].add(mRotationAngleFinal);
375

  
376 366
                if( first )
377 367
                  {
378 368
                  first = false;
379 369
                  mRotateEffect[x][y][z].notifyWhenFinished(listener);
380 370
                  effectID = mRotateEffect[x][y][z].getID();
371
                  int pointNum = mRotationAngle[x][y][z].getNumPoints();
372

  
373
                  if( pointNum>=1 )
374
                    {
375
                    float startingAngle = mRotationAngle[x][y][z].getPoint(pointNum-1).get1();
376
                    int nearestAngleInDegrees = computeNearestAngle(startingAngle);
377
                    mRotationAngleStatic.set1(startingAngle);
378
                    mRotationAngleFinal.set1(nearestAngleInDegrees);
379
                    mRotationAngleMiddle.set1( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
380
                    }
381
                  else
382
                    {
383
                    android.util.Log.e("cube", "ERROR finishing rotation!");
384
                    return 0;
385
                    }
381 386
                  }
387

  
388
                mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
389
                mRotationAngle[x][y][z].resetToBeginning();
390
                mRotationAngle[x][y][z].removeAll();
391
                mRotationAngle[x][y][z].add(mRotationAngleStatic);
392
                mRotationAngle[x][y][z].add(mRotationAngleMiddle);
393
                mRotationAngle[x][y][z].add(mRotationAngleFinal);
382 394
                }
383 395
              }
384 396

  
src/main/java/org/distorted/magic/RubikSurfaceView.java
234 234
      mTouchPoint[1] = mPoint[1];
235 235
      mTouchPoint[2] = mPoint[2];
236 236

  
237
      mRenderer.getCube().addNewRotation(mRotationVect,offset);
237
      RubikCube cube = mRenderer.getCube();
238
      cube.addNewRotation(mRotationVect, (int)(cube.getSize()*offset) );
238 239
      }
239 240

  
240 241
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff