74 |
74 |
private int mMeshState, mIconMode;
|
75 |
75 |
private boolean mRotateOnCreation;
|
76 |
76 |
private final Static4D mQuat,mTemp;
|
|
77 |
private boolean mRotAxisIsNormal;
|
|
78 |
private final float[] mNormalTouchPoint;
|
|
79 |
private float mNormalRotAngle;
|
77 |
80 |
|
78 |
81 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79 |
82 |
|
... | ... | |
254 |
257 |
|
255 |
258 |
private void continueRotation(float x, float y)
|
256 |
259 |
{
|
257 |
|
float dx = x-mStartRotX;
|
258 |
|
float dy = y-mStartRotY;
|
259 |
|
float alpha = dx*mAxis[0] + dy*mAxis[1];
|
260 |
|
float x2 = dx - alpha*mAxis[0];
|
261 |
|
float y2 = dy - alpha*mAxis[1];
|
|
260 |
if( !mRotAxisIsNormal )
|
|
261 |
{
|
|
262 |
float dx = x-mStartRotX;
|
|
263 |
float dy = y-mStartRotY;
|
|
264 |
float alpha = dx*mAxis[0] + dy*mAxis[1];
|
|
265 |
float x2 = dx - alpha*mAxis[0];
|
|
266 |
float y2 = dy - alpha*mAxis[1];
|
262 |
267 |
|
263 |
|
float len = (float)Math.sqrt(x2*x2 + y2*y2);
|
|
268 |
float len = (float)Math.sqrt(x2*x2 + y2*y2);
|
264 |
269 |
|
265 |
|
// we have the length of 1D vector 'angle', now the direction:
|
266 |
|
float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
|
|
270 |
// we have the length of 1D vector 'angle', now the direction:
|
|
271 |
float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
|
267 |
272 |
|
268 |
|
float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
|
269 |
|
mCurrentAngle = SWIPING_SENSITIVITY*angle;
|
270 |
|
mPreRender.getObject().continueRotation(mCurrentAngle);
|
|
273 |
float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
|
|
274 |
mCurrentAngle = SWIPING_SENSITIVITY*angle;
|
|
275 |
mPreRender.getObject().continueRotation(mCurrentAngle);
|
271 |
276 |
|
272 |
|
addSpeedProbe(x2,y2);
|
|
277 |
addSpeedProbe(x2,y2);
|
|
278 |
}
|
|
279 |
else
|
|
280 |
{
|
|
281 |
float rotAngle = computeNormalRotAngle(mNormalTouchPoint[0]-x,mNormalTouchPoint[1]-y);
|
|
282 |
mCurrentAngle = rotAngle - mNormalRotAngle;
|
|
283 |
mPreRender.getObject().continueRotation(mCurrentAngle);
|
|
284 |
}
|
|
285 |
}
|
|
286 |
|
|
287 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
288 |
|
|
289 |
private void correctRotationAxis()
|
|
290 |
{
|
|
291 |
if( mAxis[0]==0 && mAxis[1]==0 )
|
|
292 |
{
|
|
293 |
mRotAxisIsNormal = true;
|
|
294 |
|
|
295 |
// 0. get face center in object space
|
|
296 |
// 1. multiply it by mQuat
|
|
297 |
// 2. multiply if by mObjectRatio. Let the result be (x,y,z)
|
|
298 |
// 3. let D be CAMERA_POINT.Z
|
|
299 |
// 4. then compute the point on the screen (X,Y) the face center maps to:
|
|
300 |
// (X,Y) = (Ax,Ay) where A = D/(D-z)
|
|
301 |
|
|
302 |
float[] faceCenter = mTouchControl.getTouchedPuzzleCenter();
|
|
303 |
float D = CAMERA_POINT.get2();
|
|
304 |
float[] rotated = new float[4];
|
|
305 |
QuatHelper.rotateVectorByQuat(rotated, faceCenter[0],faceCenter[1],faceCenter[2],faceCenter[3],mQuat);
|
|
306 |
TwistyObject object = getObject();
|
|
307 |
float ratio = object.getObjectRatio();
|
|
308 |
|
|
309 |
float x = rotated[0] * ratio;
|
|
310 |
float y = rotated[1] * ratio;
|
|
311 |
float z = rotated[2] * ratio;
|
|
312 |
|
|
313 |
float A = D / (D-z);
|
|
314 |
mNormalTouchPoint[0] = A*x;
|
|
315 |
mNormalTouchPoint[1] = A*y;
|
|
316 |
}
|
|
317 |
else
|
|
318 |
{
|
|
319 |
mRotAxisIsNormal = false;
|
|
320 |
}
|
|
321 |
}
|
|
322 |
|
|
323 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
324 |
// in degrees
|
|
325 |
|
|
326 |
private float computeNormalRotAngle(float vx, float vy)
|
|
327 |
{
|
|
328 |
return 0; // TODO
|
273 |
329 |
}
|
274 |
330 |
|
275 |
331 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
290 |
346 |
mCurrentRow = mBuffer[1];
|
291 |
347 |
|
292 |
348 |
mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
|
|
349 |
correctRotationAxis();
|
293 |
350 |
mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
|
|
351 |
if( mRotAxisIsNormal ) mNormalRotAngle = computeNormalRotAngle(mNormalTouchPoint[0]-x,mNormalTouchPoint[1]-y);
|
294 |
352 |
|
295 |
353 |
if( object.beginNewRotation( mCurrentAxis, mCurrentRow ) )
|
296 |
354 |
{
|
... | ... | |
515 |
573 |
mLastMode = -1;
|
516 |
574 |
mRotateOnCreation = false;
|
517 |
575 |
|
|
576 |
mNormalTouchPoint = new float[2];
|
|
577 |
|
518 |
578 |
mLastX = new float[NUM_SPEED_PROBES];
|
519 |
579 |
mLastY = new float[NUM_SPEED_PROBES];
|
520 |
580 |
mLastT = new long[NUM_SPEED_PROBES];
|
Progress with support for touch-control of pieces which we rotate along an axs which is normal to the currently touched face (think Coin Tetrahedron!)