Project

General

Profile

« Previous | Next » 

Revision 30bd2f96

Added by Leszek Koltunski almost 3 years ago

Move the control of object scaling out the objectlib.
Thee xact way the object is scaled needs to be decided in the app, as only the app knows that e.g. in the Rubik main screen, if it is a square, then obejct needs to be a bit smaller than in case of Config screen (if that one happens to be a square)

View differences:

src/main/java/org/distorted/objectlib/main/ObjectControl.java
53 53
    private TouchControl mTouchControl, mTouchControlBackup;
54 54
    private TwistyObjectNode mObjectNode;
55 55
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
56
    private int mScreenWidth, mScreenHeight, mScreenMin;
56
    private int mScreenWidth, mScreenHeight, mScalingSize;
57 57
    private float mMoveX, mMoveY;
58 58
    private int mLastMode;
59 59

  
......
192 192
      {
193 193
      if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
194 194
        {
195
        float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
196
        float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
195
        float x2 = (mX2 - mScreenWidth*0.5f)/ mScalingSize;
196
        float y2 = (mScreenHeight*0.5f - mY2)/ mScalingSize;
197 197

  
198 198
        float angleNow = getAngle(x,y,x2,y2);
199 199
        float angleDiff = angleNow-mRotAngle;
......
211 211
        TwistyObject object = mPreRender.getObject();
212 212
        if( object!=null )
213 213
          {
214
          object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
214
          object.setObjectRatio(distQuot, mScalingSize );
215 215
          float ratio = object.getObjectRatio();
216 216
          if( mLastMode==MODE_REPLACE ) mTouchControl.setObjectRatio(ratio);
217 217
          }
......
389 389
      float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
390 390
      float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
391 391

  
392
      float x = (pX - mScreenWidth*0.5f)/mScreenMin;
393
      float y = (mScreenHeight*0.5f -pY)/mScreenMin;
392
      float x = (pX - mScreenWidth*0.5f)/ mScalingSize;
393
      float y = (mScreenHeight*0.5f -pY)/ mScalingSize;
394 394

  
395 395
      if( mBeginningRotation )
396 396
        {
......
417 417

  
418 418
    private void actionDown(float x, float y)
419 419
      {
420
      mX = (x -  mScreenWidth*0.5f)/mScreenMin;
421
      mY = (mScreenHeight*0.5f - y)/mScreenMin;
420
      mX = (x -  mScreenWidth*0.5f)/ mScalingSize;
421
      mY = (mScreenHeight*0.5f - y)/ mScalingSize;
422 422

  
423 423
      setUpDragOrRotate(true,mX,mY);
424 424
      }
......
442 442
      mRotAngle = getAngle(x1,-y1, x2,-y2);
443 443
      mInitDistance = -1;
444 444

  
445
      mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
446
      mY = (mScreenHeight*0.5f - y1)/mScreenMin;
445
      mX = (x1 - mScreenWidth*0.5f )/ mScalingSize;
446
      mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
447 447

  
448 448
      if( mBeginningRotation )
449 449
        {
......
463 463
      {
464 464
      if( p1isUp )
465 465
        {
466
        mX = (x2 -  mScreenWidth*0.5f)/mScreenMin;
467
        mY = (mScreenHeight*0.5f - y2)/mScreenMin;
466
        mX = (x2 -  mScreenWidth*0.5f)/ mScalingSize;
467
        mY = (mScreenHeight*0.5f - y2)/ mScalingSize;
468 468
        }
469 469
      if( p2isUp )
470 470
        {
471
        mX = (x1 -  mScreenWidth*0.5f)/mScreenMin;
472
        mY = (mScreenHeight*0.5f - y1)/mScreenMin;
471
        mX = (x1 -  mScreenWidth*0.5f)/ mScalingSize;
472
        mY = (mScreenHeight*0.5f - y1)/ mScalingSize;
473 473
        }
474 474
      }
475 475

  
......
532 532
        }
533 533
      }
534 534

  
535
///////////////////////////////////////////////////////////////////////////////////////////////////
536

  
537
    int getScalingSize()
538
      {
539
      return mScalingSize;
540
      }
541

  
535 542
///////////////////////////////////////////////////////////////////////////////////////////////////
536 543

  
537 544
    void setTouchControl(TwistyObject object)
......
621 628

  
622 629
///////////////////////////////////////////////////////////////////////////////////////////////////
623 630

  
624
    public void setScreenSize(int width, int height)
631
    public void setScreenSizeAndScaling(int width, int height, int scaling)
625 632
      {
626 633
      mScreenWidth = width;
627 634
      mScreenHeight= height;
628
      mScreenMin   = Math.min(width,height);
635
      mScalingSize = scaling;
629 636

  
630 637
      if( mObjectNode!=null ) mObjectNode.setSize(width,height);
631 638

  
......
634 641
      if( object!=null )
635 642
        {
636 643
        object.setTexture();
637
        object.setNodeSize(mScreenMin);
644
        object.setNodeSize(mScalingSize);
638 645
        }
639 646
      }
640 647

  
......
686 693

  
687 694
    public void scaleNow(float scale)
688 695
      {
689
      mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getMinSize() );
696
      mPreRender.getObject().setObjectRatioNow(scale,mScalingSize );
690 697
      }
691 698

  
692 699
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/ObjectPreRender.java
134 134
        {
135 135
        mNewObject.setLibInterface(mInterface);
136 136
        mController.setTouchControl(mNewObject);
137
        TwistyObjectNode node = mController.getNode();
138
        if( node!=null ) mNewObject.setObjectRatioNow(mScale, node.getMinSize() );
137
        mNewObject.setObjectRatioNow(mScale, mController.getScalingSize() );
139 138

  
140 139
        if( mPreferences!=null )
141 140
          {
src/main/java/org/distorted/objectlib/main/TwistyObjectNode.java
21 21
public class TwistyObjectNode extends DistortedNode
22 22
  {
23 23
  private final Static3D mScale;
24
  private int mWidth, mHeight, mMin;
24
  private int mWidth, mHeight;
25 25
  private float mCameraDist;
26 26

  
27 27
///////////////////////////////////////////////////////////////////////////////////////////////////
......
42 42

  
43 43
  void setSize(int surfaceW, int surfaceH)
44 44
    {
45
    mWidth      = surfaceW;
46
    mHeight     = surfaceH;
47
    mMin        = Math.min(mWidth,mHeight);
45
    mWidth  = surfaceW;
46
    mHeight = surfaceH;
48 47

  
49 48
    resizeFBO(mWidth,mHeight);
50 49

  
......
77 76
    setProjection( convertedFOVinDeg, 0.1f);
78 77
    }
79 78

  
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

  
82
  public int getMinSize()
83
    {
84
    return mMin;
85
    }
86

  
87 79
///////////////////////////////////////////////////////////////////////////////////////////////////
88 80

  
89 81
  public int getWidth()

Also available in: Unified diff