Project

General

Profile

« Previous | Next » 

Revision f6bf4e77

Added by Leszek Koltunski about 2 years ago

Bandaged Creator: add support for two-fingered rescaling.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
61 61
{
62 62
   public static final float BRIGHTNESS = 0.333f;
63 63
   private static final int RESET_DURATION = 1000;
64
   static final float SCREEN_RATIO = 0.5f;
64
   private static final float MAX_SIZE_CHANGE = 1.70f;
65
   private static final float MIN_SIZE_CHANGE = 0.50f;
66
   private static final float INIT_RATIO = 0.5f;
65 67

  
66 68
   private final BandagedCreatorView mView;
67 69
   private final DistortedScreen mScreen;
......
72 74
   private BandagedCubit[] mCubits;
73 75
   private boolean mInitialPhase;
74 76
   private long mStartTime;
75
   private float mScaleValue;
76 77
   private float mQuatX, mQuatY, mQuatZ, mQuatW;
77 78
   private int mX, mY, mZ, mNumCubits;
78
   private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits, mCreatingCubits;
79
   private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits, mCreatingCubits, mRescaling;
79 80
   private int mIndex1, mIndex2;
80 81
   private int mSaveIcon;
81 82
   private DistortedFramebuffer mFramebuffer;
82 83
   private String mPath;
83 84
   private boolean mCubitsCreated;
84 85
   private int mWidth, mHeight;
86
   private float mScaleValue, mObjectScreenRatio;
85 87

  
86 88
///////////////////////////////////////////////////////////////////////////////////////////////////
87 89

  
......
98 100
     mConnectingCubits = false;
99 101
     mCubitsCreated    = false;
100 102
     mCreatingCubits   = false;
103
     mRescaling        = false;
101 104

  
105
     mObjectScreenRatio= INIT_RATIO;
102 106
     mSaveIcon = -1;
103 107
     mObjSize  = new int[3];
104 108

  
......
260 264
           }
261 265
         }
262 266
       }
267

  
268
     if( mRescaling )
269
       {
270
       mRescaling = false;
271
       rescaleObject();
272
       for(int i=0; i<mNumCubits; i++) mCubits[i].scaleMove(mScaleValue);
273
       BandagedCreatorTouchControl control = mView.getTouchControl();
274
       control.setObjectRatio(mObjectScreenRatio);
275
       }
263 276
     }
264 277

  
265 278
///////////////////////////////////////////////////////////////////////////////////////////////////
......
538 551
     mSaveIcon = -1;
539 552
     }
540 553

  
554
///////////////////////////////////////////////////////////////////////////////////////////////////
555

  
556
   void mulObjectRatio(float ratio)
557
     {
558
     mObjectScreenRatio *= ratio;
559

  
560
     if( mObjectScreenRatio>MAX_SIZE_CHANGE*INIT_RATIO) mObjectScreenRatio = MAX_SIZE_CHANGE*INIT_RATIO;
561
     if( mObjectScreenRatio<MIN_SIZE_CHANGE*INIT_RATIO) mObjectScreenRatio = MIN_SIZE_CHANGE*INIT_RATIO;
562

  
563
     mRescaling = true;
564
     }
565

  
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

  
568
   float getObjectRatio()
569
     {
570
     return mObjectScreenRatio;
571
     }
572

  
541 573
///////////////////////////////////////////////////////////////////////////////////////////////////
542 574

  
543 575
   private void rescaleObject()
544 576
     {
545
     //final int min = mX<mY ? Math.min(mX, mZ) : Math.min(mY, mZ);
546
     //final int size= (mX+mY+mZ-min)/2;
547 577
     final int size = mX>mY ? Math.max(mX, mZ) : Math.max(mY, mZ);
548
     final float Q = SCREEN_RATIO/size;
578
     final float Q = mObjectScreenRatio/size;
549 579
     mScaleValue = mWidth<mHeight ? Q*mWidth : Q*mHeight;
550 580
     mScale.set( mScaleValue,mScaleValue,mScaleValue );
551 581
     }

Also available in: Unified diff