| 24 |
24 |
import android.content.pm.ConfigurationInfo;
|
| 25 |
25 |
import android.opengl.GLSurfaceView;
|
| 26 |
26 |
import android.util.AttributeSet;
|
|
27 |
import android.util.DisplayMetrics;
|
| 27 |
28 |
import android.view.MotionEvent;
|
| 28 |
29 |
|
| 29 |
30 |
import org.distorted.library.type.Static2D;
|
| ... | ... | |
| 49 |
50 |
// Moving the finger from the middle of the vertical screen to the right edge will rotate a
|
| 50 |
51 |
// given face by SWIPING_SENSITIVITY/2 degrees.
|
| 51 |
52 |
private final static int SWIPING_SENSITIVITY = 240;
|
| 52 |
|
// Moving the finger by 1/15 the distance of min(scrWidth,scrHeight) will start a Rotation.
|
| 53 |
|
private final static int ROTATION_SENSITIVITY = 15;
|
| 54 |
|
// Every 1/12 the distance of min(scrWidth,scrHeight) the direction of cube rotation will reset.
|
| 55 |
|
private final static int DIRECTION_SENSITIVITY= 12;
|
|
53 |
// Moving the finger by 0.33 of an inch will start a Rotation.
|
|
54 |
private final static float ROTATION_SENSITIVITY = 0.33f;
|
|
55 |
// Every 0.33 of an inch the direction of cube drag will reset.
|
|
56 |
private final static float DIRECTION_SENSITIVITY= 0.33f;
|
| 56 |
57 |
|
| 57 |
58 |
// Where did we get this sqrt(3)/2 ? From the (default, i.e. 60 degrees - see InternalOutputSurface!)
|
| 58 |
59 |
// FOV of the projection matrix of the Node onto the Screen.
|
| ... | ... | |
| 81 |
82 |
private float[] mLastAngles;
|
| 82 |
83 |
private long[] mLastTimestamps;
|
| 83 |
84 |
private int mFirstIndex, mLastIndex;
|
|
85 |
private int mDensity;
|
| 84 |
86 |
|
| 85 |
87 |
private static Static4D mQuatCurrent = new Static4D(0,0,0,1);
|
| 86 |
88 |
private static Static4D mQuatAccumulated= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
|
| ... | ... | |
| 312 |
314 |
|
| 313 |
315 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 314 |
316 |
|
| 315 |
|
private boolean canBeginRotate(float x, float y)
|
|
317 |
private float retFingerDragDistanceInInches(float xFrom, float yFrom, float xTo, float yTo)
|
| 316 |
318 |
{
|
| 317 |
|
return (mX-x)*(mX-x) + (mY-y)*(mY-y) > 1.0f/(ROTATION_SENSITIVITY*ROTATION_SENSITIVITY);
|
| 318 |
|
}
|
| 319 |
|
|
| 320 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
319 |
float xDist = mScreenWidth*(xFrom-xTo);
|
|
320 |
float yDist = mScreenHeight*(yFrom-yTo);
|
|
321 |
float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
|
| 321 |
322 |
|
| 322 |
|
private boolean shouldChangeDirection(float x, float y)
|
| 323 |
|
{
|
| 324 |
|
return (mX-x)*(mX-x) + (mY-y)*(mY-y) > 1.0f/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY);
|
|
323 |
return distInPixels/mDensity;
|
| 325 |
324 |
}
|
| 326 |
325 |
|
| 327 |
326 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| ... | ... | |
| 392 |
391 |
{
|
| 393 |
392 |
if( mBeginningRotation )
|
| 394 |
393 |
{
|
| 395 |
|
if( canBeginRotate(x,y) )
|
|
394 |
if( retFingerDragDistanceInInches(mX,mY,x,y) > ROTATION_SENSITIVITY )
|
| 396 |
395 |
{
|
| 397 |
396 |
mStartRotX = x;
|
| 398 |
397 |
mStartRotY = y;
|
| ... | ... | |
| 447 |
446 |
mTempCurrent.set(quatFromDrag(mX-x,y-mY));
|
| 448 |
447 |
mPreRender.setQuatCurrentOnNextRender();
|
| 449 |
448 |
|
| 450 |
|
if( shouldChangeDirection(x,y) )
|
|
449 |
if( retFingerDragDistanceInInches(mX,mY,x,y) > DIRECTION_SENSITIVITY )
|
| 451 |
450 |
{
|
| 452 |
451 |
mX = x;
|
| 453 |
452 |
mY = y;
|
| ... | ... | |
| 515 |
514 |
mRenderer = new RubikRenderer(this);
|
| 516 |
515 |
mPreRender = new RubikPreRender(this);
|
| 517 |
516 |
|
| 518 |
|
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
| 519 |
|
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
| 520 |
|
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
|
| 521 |
|
setRenderer(mRenderer);
|
|
517 |
RubikActivity act = (RubikActivity)context;
|
|
518 |
DisplayMetrics dm = new DisplayMetrics();
|
|
519 |
act.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
|
520 |
|
|
521 |
mDensity = dm.densityDpi;
|
|
522 |
|
|
523 |
final ActivityManager activityManager= (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
524 |
|
|
525 |
if( activityManager!=null )
|
|
526 |
{
|
|
527 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
|
528 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 );
|
|
529 |
setRenderer(mRenderer);
|
|
530 |
}
|
| 522 |
531 |
}
|
| 523 |
532 |
}
|
| 524 |
533 |
|
Make the rotations and drag be independent of physical screen dimensions - take into account pixel density.