Project

General

Profile

« Previous | Next » 

Revision 168b6b56

Added by Leszek Koltunski almost 4 years ago

Improvements for the way we rotate layers of Objects. (take the speed into account - so even if we rotated a layer of a Cube to less than 45 degrees, but we did it fast, do a 90 degree rotation!)

View differences:

src/main/java/org/distorted/objects/RubikObject.java
520 520

  
521 521
///////////////////////////////////////////////////////////////////////////////////////////////////
522 522

  
523
  public long finishRotationNow(EffectListener listener)
523
  public long finishRotationNow(EffectListener listener, int nearestAngleInDegrees)
524 524
    {
525 525
    float angle = getAngle();
526
    int nearestAngleInDegrees = computeNearestAngle(angle);
527 526
    mRotationAngleStatic.set0(angle);
528 527
    mRotationAngleFinal.set0(nearestAngleInDegrees);
529 528
    mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-angle)*0.2f );
......
561 560
///////////////////////////////////////////////////////////////////////////////////////////////////
562 561

  
563 562
  public void removeRotationNow()
564
     {
565
     float angle = getAngle();
566
     int nearestAngleInDegrees = computeNearestAngle(angle);
567
     double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180;
568
     float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
569
     float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
570
     float axisX = ROTATION_AXIS[mRotAxis].get0();
571
     float axisY = ROTATION_AXIS[mRotAxis].get1();
572
     float axisZ = ROTATION_AXIS[mRotAxis].get2();
573
     Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
574

  
575
     mRotationAngle.removeAll();
576
     mRotationAngleStatic.set0(0);
577

  
578
     for(int i=0; i<NUM_CUBITS; i++)
579
       if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
580
         {
581
         int index = mCubits[i].removeRotationNow(quat);
582
         mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
583
         }
584
     }
563
    {
564
    float angle = getAngle();
565
    double nearestAngleInRadians = angle*Math.PI/180;
566
    float sinA =-(float)Math.sin(nearestAngleInRadians*0.5);
567
    float cosA = (float)Math.cos(nearestAngleInRadians*0.5);
568
    float axisX = ROTATION_AXIS[mRotAxis].get0();
569
    float axisY = ROTATION_AXIS[mRotAxis].get1();
570
    float axisZ = ROTATION_AXIS[mRotAxis].get2();
571
    Static4D quat = new Static4D( axisX*sinA, axisY*sinA, axisZ*sinA, cosA);
572

  
573
    mRotationAngle.removeAll();
574
    mRotationAngleStatic.set0(0);
575

  
576
    for(int i=0; i<NUM_CUBITS; i++)
577
      if( belongsToRotation(i,mRotAxis,mRotRowBitmap) )
578
        {
579
        int index = mCubits[i].removeRotationNow(quat);
580
        mMesh.setEffectAssociation(i,mCubits[i].computeAssociation(),index);
581
        }
582
    }
585 583

  
586 584
///////////////////////////////////////////////////////////////////////////////////////////////////
587 585

  
......
618 616

  
619 617
///////////////////////////////////////////////////////////////////////////////////////////////////
620 618

  
621
  public int computeNearestAngle(float angle)
619
  public int computeNearestAngle(float angle, float speed)
622 620
    {
623 621
    final int NEAREST = 360/getBasicAngle();
624 622

  
625
    int tmp = (int)((angle+NEAREST/2)/NEAREST);
626
    if( angle< -(NEAREST*0.5) ) tmp-=1;
623
    float angleAndSpeed = angle + 100*speed;
624

  
625
    int tmp1 = (int)((angle+NEAREST/2)/NEAREST);
626
    if( angle< -(NEAREST*0.5) ) tmp1-=1;
627

  
628
    int tmp2 = (int)((angleAndSpeed+NEAREST/2)/NEAREST);
629
    if( angleAndSpeed< -(NEAREST*0.5) ) tmp2-=1;
627 630

  
628
    return NEAREST*tmp;
631
    return NEAREST*(tmp1==0 ? tmp2 : tmp1);
629 632
    }
630 633

  
631 634
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff