Project

General

Profile

« Previous | Next » 

Revision c7b00dfb

Added by Leszek Koltunski almost 4 years ago

Introduce two-fingered object resize.

View differences:

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

  
53 53
public abstract class RubikObject extends DistortedNode
54 54
  {
55
  private static final float NODE_RATIO = 1.32f;
56
  private static final float MAX_SIZE_CHANGE = 1.3f;
57
  private static final float MIN_SIZE_CHANGE = 0.8f;
58

  
55 59
  private static final Static3D CENTER = new Static3D(0,0,0);
56 60
  static final int INTERIOR_COLOR = 0xff000000;
57 61
  private static final int POST_ROTATION_MILLISEC = 500;
......
61 65
  final Static4D[] QUATS;
62 66
  final int NUM_FACES;
63 67

  
64
  static float OBJECT_SCREEN_RATIO;
68
  private static float mInitScreenRatio,mObjectScreenRatio;
65 69

  
66 70
  private final int NUM_CUBITS;
67 71
  private final int mNodeSize;
......
78 82
  private VertexEffectRotate mRotateEffect;
79 83
  private Dynamic1D mRotationAngle;
80 84
  private Static3D mRotationAxis;
85
  private Static3D mObjectScale;
81 86

  
82 87
  float mStart, mStep;
83 88

  
......
96 101

  
97 102
    mNodeSize = screenWidth;
98 103

  
99
    resizeFBO(mNodeSize, mNodeSize);
104
    resizeFBO(mNodeSize, (int)(NODE_RATIO*mNodeSize));
100 105

  
101 106
    mList = list;
102 107
    mOrigPos = getCubitPositions(size);
......
104 109
    QUATS = getQuats();
105 110
    NUM_CUBITS  = mOrigPos.length;
106 111
    ROTATION_AXIS = getRotationAxis();
107
    OBJECT_SCREEN_RATIO = getScreenRatio();
112
    mObjectScreenRatio = getScreenRatio();
113
    mInitScreenRatio = mObjectScreenRatio;
108 114
    NUM_FACES = getNumFaces();
109 115

  
110 116
    mSize = size;
111 117
    computeStartAndStep(mOrigPos);
112
    mNodeScale= new Static3D(1,1,1);
118
    mNodeScale= new Static3D(1,NODE_RATIO,1);
113 119
    mQuat = quat;
114 120

  
115 121
    mRotationAngle= new Dynamic1D();
......
120 126
    mRotationAngleMiddle = new Static1D(0);
121 127
    mRotationAngleFinal  = new Static1D(0);
122 128

  
123
    float scale = OBJECT_SCREEN_RATIO*mNodeSize/mSize;
124
    mScaleEffect = new MatrixEffectScale(new Static3D(scale,scale,scale));
129
    float scale = mObjectScreenRatio*mNodeSize/mSize;
130
    mObjectScale= new Static3D(scale,scale,scale);
131
    mScaleEffect = new MatrixEffectScale(mObjectScale);
125 132
    mQuatEffect  = new MatrixEffectQuaternion(quat, CENTER);
126 133

  
127 134
    MatrixEffectScale nodeScaleEffect = new MatrixEffectScale(mNodeScale);
......
173 180
    setProjection(fov, 0.1f);
174 181
    }
175 182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
  public void setObjectRatio(float sizeChange)
186
    {
187
    mObjectScreenRatio *= (1.0f+sizeChange)/2;
188

  
189
    if( mObjectScreenRatio > MAX_SIZE_CHANGE*mInitScreenRatio)
190
      {
191
      mObjectScreenRatio = MAX_SIZE_CHANGE*mInitScreenRatio;
192
      }
193
    if( mObjectScreenRatio < MIN_SIZE_CHANGE*mInitScreenRatio)
194
      {
195
      mObjectScreenRatio = MIN_SIZE_CHANGE*mInitScreenRatio;
196
      }
197

  
198
    float scale = mObjectScreenRatio*mNodeSize/mSize;
199
    mObjectScale.set(scale,scale,scale);
200
    }
201

  
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

  
204
  static float getObjectRatio()
205
    {
206
    return mObjectScreenRatio;
207
    }
208

  
176 209
///////////////////////////////////////////////////////////////////////////////////////////////////
177 210
// Cast centers of all Cubits on the first rotation Axis and compute the leftmost and rightmost
178 211
// one. From there compute the 'start' (i.e. the leftmost) and 'step' (i.e. distance between two
......
356 389
  public void recomputeScaleFactor(int scrWidth, int scrHeight)
357 390
    {
358 391
    float factor = Math.min(scrWidth,scrHeight);
359
    mNodeScale.set(factor,factor,factor);
392
    mNodeScale.set(factor,NODE_RATIO*factor,factor);
360 393
    }
361 394

  
362 395
///////////////////////////////////////////////////////////////////////////////////////////////////
......
615 648

  
616 649
    if( tmp!=0 ) return NEAREST*tmp;
617 650

  
618
    return speed> 1.3f ? NEAREST*(angle>0 ? 1:-1) : 0;
651
    return speed> 1.2f ? NEAREST*(angle>0 ? 1:-1) : 0;
619 652
    }
620 653

  
621 654
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff