Project

General

Profile

« Previous | Next » 

Revision 775e675d

Added by Leszek Koltunski over 4 years ago

Further simplifications for object movement - remove from it a reference to the Object altogether.

View differences:

src/main/java/org/distorted/magic/RubikSurfaceView.java
34 34
import android.widget.ImageButton;
35 35
import android.widget.LinearLayout;
36 36

  
37
import org.distorted.library.type.Static2D;
37 38
import org.distorted.library.type.Static4D;
39
import org.distorted.object.RubikCube;
38 40
import org.distorted.object.RubikCubeMovement;
39 41

  
40 42
///////////////////////////////////////////////////////////////////////////////////////////////////
41 43

  
42 44
public class RubikSurfaceView extends GLSurfaceView
43 45
{
46
    // Moving the finger from the middle of the vertical screen to the right edge will rotate a
47
    // given face by SWIPING_SENSITIVITY/2 degrees.
48
    private final static int SWIPING_SENSITIVITY  = 240;
49

  
44 50
    // Moving the finger by 1/12 the distance of min(scrWidth,scrHeight) will start a Rotation.
45 51
    private final static int ROTATION_SENSITIVITY =  12;
46 52

  
......
307 313
        axisY /= axisL;
308 314
        axisZ /= axisL;
309 315

  
310
        float ratio = axisL/mScreenMin;
316
        float ratio = axisL;
311 317
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
312 318

  
313 319
        float cosA = (float)Math.cos(Math.PI*ratio);
......
319 325
      return new Static4D(0f, 0f, 0f, 1f);
320 326
      }
321 327

  
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

  
324
    void setMovement(RubikCubeMovement movement)
325
      {
326
      mMovement = movement;
327
      }
328

  
329 328
///////////////////////////////////////////////////////////////////////////////////////////////////
330 329
// PUBLIC API
331 330
///////////////////////////////////////////////////////////////////////////////////////////////////
......
338 337
        {
339 338
        mInScrambleMode = false;
340 339
        mRenderer = new RubikRenderer(this);
340
        mMovement = new RubikCubeMovement();
341 341

  
342 342
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
343 343
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
......
352 352
    public boolean onTouchEvent(MotionEvent event)
353 353
      {
354 354
      int action = event.getAction();
355
      float x = event.getX() - mScreenWidth*0.5f;
356
      float y = mScreenHeight*0.5f -event.getY();
355
      float x = (event.getX() - mScreenWidth*0.5f)/mScreenMin;
356
      float y = (mScreenHeight*0.5f -event.getY())/mScreenMin;
357 357

  
358 358
      switch(action)
359 359
         {
360 360
         case MotionEvent.ACTION_DOWN: mX = x;
361 361
                                       mY = y;
362
                                       mLastTouchedFace = mMovement.faceTouched(mQuatAccumulated,mCameraDistance, x, y);
362
                                       mLastTouchedFace = mMovement.faceTouched(mQuatAccumulated,mCameraDistance/mScreenMin, x, y);
363 363

  
364 364
                                       if( mLastTouchedFace != RubikCubeMovement.NONE )
365 365
                                         {
......
379 379
                                         mTempCurrent.set(quatFromDrag(mX-x,y-mY));
380 380
                                         mRenderer.setQuatCurrentOnNextRender();
381 381

  
382
                                         int minimumDist = (mScreenMin*mScreenMin)/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY);
383

  
384
                                         if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > minimumDist )
382
                                         if( (mX-x)*(mX-x) + (mY-y)*(mY-y) > 1.0f/(DIRECTION_SENSITIVITY*DIRECTION_SENSITIVITY) )
385 383
                                           {
386 384
                                           mX = x;
387 385
                                           mY = y;
......
393 391
                                         }
394 392
                                       if( mBeginningRotation )
395 393
                                         {
396
                                         int minimumDistToStartRotating = (mScreenMin*mScreenMin)/(ROTATION_SENSITIVITY*ROTATION_SENSITIVITY);
397

  
398
                                         if( (mX-x)*(mX-x)+(mY-y)*(mY-y) > minimumDistToStartRotating )
394
                                         if( (mX-x)*(mX-x)+(mY-y)*(mY-y) > 1.0f/(ROTATION_SENSITIVITY*ROTATION_SENSITIVITY) )
399 395
                                           {
400
                                           mMovement.addNewRotation(mQuatAccumulated,mLastTouchedFace, x, y);
396
                                           Static2D rot = mMovement.newRotation(mQuatAccumulated,mLastTouchedFace, x, y);
397
                                           RubikCube cube = mRenderer.getCube();
398

  
399
                                           cube.addNewRotation( (int)rot.get1(), (int)(cube.getSize()*rot.get2()) );
400

  
401 401
                                           mBeginningRotation = false;
402 402
                                           mContinuingRotation= true;
403 403
                                           }
404 404
                                         }
405 405
                                       else if( mContinuingRotation )
406 406
                                         {
407
                                         mMovement.continueRotation(mQuatAccumulated,mLastTouchedFace, x, y, mScreenMin);
407
                                         float angle = mMovement.continueRotation(mQuatAccumulated,mLastTouchedFace, x, y);
408

  
409
                                         mRenderer.getCube().continueRotation(SWIPING_SENSITIVITY*angle);
408 410
                                         }
409 411
                                       break;
410 412
         case MotionEvent.ACTION_UP  : if( mDragging )

Also available in: Unified diff