Project

General

Profile

« Previous | Next » 

Revision f6bf4e77

Added by Leszek Koltunski over 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
     }
src/main/java/org/distorted/bandaged/BandagedCreatorView.java
65 65
        BandagedCreatorActivity act = (BandagedCreatorActivity)context;
66 66
        mRenderer = new BandagedCreatorRenderer(this);
67 67
        DistortedScreen screen = mRenderer.getScreen();
68
        mTouchControl = new BandagedCreatorTouchControl(BandagedCreatorRenderer.SCREEN_RATIO, screen.getFOV() );
68
        mTouchControl = new BandagedCreatorTouchControl( mRenderer.getObjectRatio() , screen.getFOV() );
69 69

  
70 70
        final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
71 71

  
......
102 102
      return mTouchedIndex1;
103 103
      }
104 104

  
105
///////////////////////////////////////////////////////////////////////////////////////////////////
106

  
107
    public BandagedCreatorTouchControl getTouchControl()
108
      {
109
      return mTouchControl;
110
      }
111

  
105 112
///////////////////////////////////////////////////////////////////////////////////////////////////
106 113

  
107 114
    public BandagedCreatorRenderer getRenderer()
......
214 221
        mRenderer.resetQuats();
215 222
        mRotAngle = angleNow;
216 223

  
217
/*
218
        float distNow  = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
224
        float distNow  = (float)Math.sqrt( (mX1-mX2)*(mX1-mX2) + (mY1-mY2)*(mY1-mY2) );
219 225
        float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
220 226
        mInitDistance = distNow;
221
        TwistyObject object = mPreRender.getObject();
222
        if( object!=null ) object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
223
 */
227
        mRenderer.mulObjectRatio(distQuot);
224 228
        }
225 229
      else
226 230
        {

Also available in: Unified diff