Revision c7b00dfb
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/main/RubikSurfaceView.java | ||
---|---|---|
72 | 72 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
73 | 73 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
74 | 74 |
|
75 |
private float mRotAngle; |
|
75 |
private float mRotAngle, mInitDistance;
|
|
76 | 76 |
private int mPtrID1, mPtrID2; |
77 | 77 |
private float mX, mY; |
78 | 78 |
private float mStartRotX, mStartRotY; |
... | ... | |
374 | 374 |
mTemp.set(dragQuat); |
375 | 375 |
|
376 | 376 |
mRotAngle = angleNow; |
377 |
|
|
378 |
float distNow = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) ); |
|
379 |
float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance; |
|
380 |
mInitDistance = distNow; |
|
381 |
|
|
382 |
RubikObject object = mPreRender.getObject(); |
|
383 |
object.setObjectRatio(distQuot); |
|
377 | 384 |
} |
378 | 385 |
else |
379 | 386 |
{ |
... | ... | |
575 | 582 |
float y2 = event.getY(pointer); |
576 | 583 |
|
577 | 584 |
mRotAngle = getAngle(x,-y,x2,-y2); |
585 |
mInitDistance = -1; |
|
578 | 586 |
} |
579 | 587 |
|
580 | 588 |
mX = (x - mScreenWidth*0.5f)/mScreenMin; |
... | ... | |
595 | 603 |
float y2 = event.getY(pointer); |
596 | 604 |
|
597 | 605 |
mRotAngle = getAngle(x,-y,x2,-y2); |
606 |
mInitDistance = -1; |
|
598 | 607 |
} |
599 | 608 |
|
600 | 609 |
if( mBeginningRotation || mContinuingRotation ) |
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 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objects/RubikObjectMovement.java | ||
---|---|---|
247 | 247 |
|
248 | 248 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera) |
249 | 249 |
{ |
250 |
mPoint[0] = rotatedTouchPoint.get0()/RubikObject.OBJECT_SCREEN_RATIO; |
|
251 |
mPoint[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO; |
|
252 |
mPoint[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO; |
|
250 |
float objectRatio = RubikObject.getObjectRatio(); |
|
253 | 251 |
|
254 |
mCamera[0] = rotatedCamera.get0()/RubikObject.OBJECT_SCREEN_RATIO; |
|
255 |
mCamera[1] = rotatedCamera.get1()/RubikObject.OBJECT_SCREEN_RATIO; |
|
256 |
mCamera[2] = rotatedCamera.get2()/RubikObject.OBJECT_SCREEN_RATIO; |
|
252 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
253 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
254 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
255 |
|
|
256 |
mCamera[0] = rotatedCamera.get0()/objectRatio; |
|
257 |
mCamera[1] = rotatedCamera.get1()/objectRatio; |
|
258 |
mCamera[2] = rotatedCamera.get2()/objectRatio; |
|
257 | 259 |
|
258 | 260 |
for( mLastTouchedAxis=0; mLastTouchedAxis<mNumAxis; mLastTouchedAxis++) |
259 | 261 |
{ |
... | ... | |
276 | 278 |
|
277 | 279 |
public Static2D newRotation(Static4D rotatedTouchPoint) |
278 | 280 |
{ |
279 |
mPoint[0] = rotatedTouchPoint.get0()/RubikObject.OBJECT_SCREEN_RATIO; |
|
280 |
mPoint[1] = rotatedTouchPoint.get1()/RubikObject.OBJECT_SCREEN_RATIO; |
|
281 |
mPoint[2] = rotatedTouchPoint.get2()/RubikObject.OBJECT_SCREEN_RATIO; |
|
281 |
float objectRatio = RubikObject.getObjectRatio(); |
|
282 |
|
|
283 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
284 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
285 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
282 | 286 |
|
283 | 287 |
castTouchPointOntoFace(mAxis[mLastTouchedAxis], mLastTouchedLR, mTouch); |
284 | 288 |
convertTo2Dcoords(mTouch, mAxis[mLastTouchedAxis], mLastTouchedLR, mMove2D); |
Also available in: Unified diff
Introduce two-fingered object resize.