Project

General

Profile

« Previous | Next » 

Revision ab31cf6f

Added by Leszek Koltunski over 2 years ago

Cuboids: movement.

View differences:

src/main/java/org/distorted/objectlib/main/Movement.java
41 41
  private final float[] mPoint, mCamera, mTouch;
42 42
  private final float[] mPoint2D, mMove2D;
43 43
  private final int[] mEnabledRotAxis;
44
  private final float mDistanceCenterFace3D;
44
  private final float[] mDistanceCenterFace3D;
45 45
  private final Static3D[] mFaceAxis;
46 46

  
47 47
  private int mLastTouchedFace;
......
61 61
///////////////////////////////////////////////////////////////////////////////////////////////////
62 62

  
63 63
  Movement(Static3D[] rotAxis, Static3D[] faceAxis, float[][] cuts, boolean[][] rotatable,
64
           float distance3D, float size, int type, int[][][] enabled)
64
           float[] distance3D, float size, int type, int[][][] enabled)
65 65
    {
66 66
    mPoint = new float[3];
67 67
    mCamera= new float[3];
......
82 82

  
83 83
    computeCastedAxis(rotAxis);
84 84
    computeBorders(cuts,rotatable,size);
85
    computeLinear(distance3D,rotAxis,faceAxis);
85
    computeLinear(rotAxis,faceAxis);
86 86
    }
87 87

  
88 88
///////////////////////////////////////////////////////////////////////////////////////////////////
......
180 180
    {
181 181
    Static3D faceAxis = mFaceAxis[index];
182 182
    float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2();
183
    return castCameraOnAxis > mDistanceCenterFace3D;
183
    return castCameraOnAxis > mDistanceCenterFace3D[index];
184 184
    }
185 185

  
186 186
///////////////////////////////////////////////////////////////////////////////////////////////////
......
207 207
    if( denom != 0.0f )
208 208
      {
209 209
      float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2];
210
      float alpha = (mDistanceCenterFace3D-axisCam)/denom;
210
      float alpha = (mDistanceCenterFace3D[index]-axisCam)/denom;
211 211

  
212 212
      output[0] = mCamera[0] + d0*alpha;
213 213
      output[1] = mCamera[1] + d1*alpha;
......
356 356
// the 3D 'cuts' to translate it from 3D (i.e. with respect to the rotAxis) to 2D in-face (i.e. with
357 357
// respect to the 2D rotAxis cast into a particular face)
358 358

  
359
  private void computeLinear(float distance3D, Static3D[] rotAxis, Static3D[] faceAxis)
359
  private void computeLinear(Static3D[] rotAxis, Static3D[] faceAxis)
360 360
    {
361 361
    int numFaces = faceAxis.length;
362 362
    int numRot   = rotAxis.length;
......
373 373
          {
374 374
          float coeff = (float)Math.sqrt(1/(mA[i][j]*mA[i][j]) -1);
375 375
          int sign = computeSign(faceAxis[i],rotAxis[j]);
376
          mB[i][j] = sign*distance3D*coeff;
376
          mB[i][j] = sign*coeff*mDistanceCenterFace3D[i];
377 377
          }
378 378
        else mB[i][j] = 0.0f;
379 379
        }
src/main/java/org/distorted/objectlib/main/Movement12.java
35 35

  
36 36
  public  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
37 37
  private static final float DIST2D = (SIN54/COS54)/2;
38
  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
39
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
38 40

  
39 41
  public static final Static3D[] FACE_AXIS = new Static3D[]
40 42
         {
......
56 58

  
57 59
  public Movement12(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
58 60
    {
59
    super(rotAxis, FACE_AXIS, cuts,rotatable,DIST3D, size, type, enabled);
61
    super(rotAxis, FACE_AXIS, cuts,rotatable,D3D, size, type, enabled);
60 62
    }
61 63

  
62 64
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/Movement4.java
29 29
  private static final float DIST3D = SQ6/12;
30 30
  private static final float DIST2D = SQ3/6;
31 31

  
32
  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D };
33

  
32 34
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 35
         {
34 36
           new Static3D(     0,+SQ3/3,+SQ6/3),
......
41 43

  
42 44
  public Movement4(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
43 45
    {
44
    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
46
    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
45 47
    }
46 48

  
47 49
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/Movement6.java
29 29
  private static final float DIST3D = 0.5f;
30 30
  private static final float DIST2D = 0.5f;
31 31

  
32
  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
33

  
32 34
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 35
         {
34 36
           new Static3D(1,0,0), new Static3D(-1,0,0),
......
40 42

  
41 43
  public Movement6(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
42 44
    {
43
    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
45
    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
44 46
    }
45 47

  
46 48
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/Movement8.java
29 29
  private static final float DIST3D = SQ6/6;
30 30
  private static final float DIST2D = SQ3/6;
31 31

  
32
  private static final float[] D3D  = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
33

  
32 34
  public static final Static3D[] FACE_AXIS = new Static3D[]
33 35
         {
34 36
           new Static3D(+SQ6/3,+SQ3/3,     0), new Static3D(-SQ6/3,-SQ3/3,     0),
......
41 43

  
42 44
  public Movement8(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
43 45
    {
44
    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
46
    super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
45 47
    }
46 48

  
47 49
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objectlib/main/MovementC.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.objectlib.main;
21

  
22
import org.distorted.library.type.Static3D;
23

  
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
// Cuboids
26

  
27
public class MovementC extends Movement
28
{
29
  private final float[] mDist3D;
30

  
31
  public static final Static3D[] FACE_AXIS = new Static3D[]
32
         {
33
           new Static3D(1,0,0), new Static3D(-1,0,0),
34
           new Static3D(0,1,0), new Static3D(0,-1,0),
35
           new Static3D(0,0,1), new Static3D(0,0,-1)
36
         };
37

  
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

  
40
  public MovementC(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type,
41
                   int[][][] enabled, float[] dist3D)
42
    {
43
    super(rotAxis, FACE_AXIS, cuts, rotatable, dist3D, size, type, enabled);
44

  
45
    mDist3D = dist3D;
46
    }
47

  
48
///////////////////////////////////////////////////////////////////////////////////////////////////
49

  
50
  int returnPart(int type, int face, float[] touchPoint)
51
    {
52
    return 0;
53
    }
54

  
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

  
57
  public float returnRotationFactor(int[] numLayers, int row)
58
    {
59
    return 1.0f;
60
    }
61

  
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

  
64
  boolean isInsideFace(int face, float[] p)
65
    {
66
    switch(face/2)
67
      {
68
      case 0: return ( p[0]<=mDist3D[4] && p[0]>=-mDist3D[4] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] );
69
      case 1: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[4] && p[1]>=-mDist3D[4] );
70
      case 2: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] );
71
      }
72
    return false;
73
    }
74
}
src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java
31 31

  
32 32
import org.distorted.objectlib.R;
33 33
import org.distorted.objectlib.main.Movement;
34
import org.distorted.objectlib.main.Movement6;
34
import org.distorted.objectlib.main.MovementC;
35 35
import org.distorted.objectlib.main.ObjectControl;
36 36
import org.distorted.objectlib.main.ObjectType;
37 37
import org.distorted.objectlib.helpers.ObjectShape;
......
244 244
    {
245 245
    if( mQuats ==null ) initializeQuats();
246 246
    int status = retCubitSolvedStatus(cubit,numLayers);
247
    return status<0 ? null : buildSolvedQuats(Movement6.FACE_AXIS[status], mQuats);
247
    return status<0 ? null : buildSolvedQuats(MovementC.FACE_AXIS[status], mQuats);
248 248
    }
249 249

  
250 250
///////////////////////////////////////////////////////////////////////////////////////////////////
......
608 608
    }
609 609

  
610 610
///////////////////////////////////////////////////////////////////////////////////////////////////
611
// TODO
612 611

  
613 612
  public Movement getMovement()
614 613
    {
......
618 617
      if( mCuts==null ) getCuts(numLayers);
619 618
      getLayerRotatable(numLayers);
620 619
      float avg = (numLayers[0]+numLayers[1]+numLayers[2])/3.0f;
621
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,avg,TYPE_NOT_SPLIT,ENABLED);
620

  
621
      float[] dist3D =
622
        {
623
        0.5f*numLayers[0]/avg,
624
        0.5f*numLayers[0]/avg,
625
        0.5f*numLayers[1]/avg,
626
        0.5f*numLayers[1]/avg,
627
        0.5f*numLayers[2]/avg,
628
        0.5f*numLayers[2]/avg,
629
        };
630

  
631
      mMovement = new MovementC(ROT_AXIS,mCuts,mLayerRotatable,avg,TYPE_NOT_SPLIT,ENABLED,dist3D);
622 632
      }
623 633
    return mMovement;
624 634
    }

Also available in: Unified diff