Project

General

Profile

« Previous | Next » 

Revision 216c5526

Added by Leszek Koltunski over 4 years ago

RubikCube: fix dragging.

View differences:

src/main/java/org/distorted/magic/RubikSurfaceView.java
354 354

  
355 355
    private Static4D quatFromDrag(float dragX, float dragY)
356 356
      {
357
      float axisX = dragY;  // inverted X and Y - rotation axis is
358
      float axisY = dragX;  // perpendicular to (dragX,dragY)   Why not (-dragY, dragX) ? because Y axis is also inverted!
357
      float axisX = dragY;  // inverted X and Y - rotation axis is perpendicular to (dragX,dragY)
358
      float axisY = dragX;  // Why not (-dragY, dragX) ? because Y axis is also inverted!
359 359
      float axisZ = 0;
360 360
      float axisL = (float)Math.sqrt(axisX*axisX + axisY*axisY + axisZ*axisZ);
361 361

  
......
365 365
        axisY /= axisL;
366 366
        axisZ /= axisL;
367 367

  
368
        float cosA = (float)Math.cos(axisL*Math.PI/mScreenMin);
368
        float ratio = axisL/mScreenMin;
369
        ratio = ratio - (int)ratio;     // the cos() is only valid in (0,Pi)
370

  
371
        float cosA = (float)Math.cos(Math.PI*ratio);
369 372
        float sinA = (float)Math.sqrt(1-cosA*cosA);
370 373

  
371 374
        return new Static4D(axisX*sinA, axisY*sinA, axisZ*sinA, cosA);

Also available in: Unified diff