Project

General

Profile

« Previous | Next » 

Revision 5b05d357

Added by Leszek Koltunski over 3 years ago

Minor

View differences:

src/main/java/org/distorted/objects/MovementCube.java
43 43

  
44 44
    switch(face)
45 45
      {
46
      case 0:
47
      case 1: enabled[1]=1; enabled[2]=2; break;
48
      case 2:
49
      case 3: enabled[1]=0; enabled[2]=2; break;
50
      case 4:
51
      case 5: enabled[1]=0; enabled[2]=1; break;
46
      case 0: case 1: enabled[1]=1; enabled[2]=2; break;
47
      case 2: case 3: enabled[1]=0; enabled[2]=2; break;
48
      case 4: case 5: enabled[1]=0; enabled[2]=1; break;
52 49
      }
53 50
    }
54 51
}
src/main/java/org/distorted/objects/MovementSquare.java
35 35
    return offset<DIST2D? 0 : 2-axisIndex;
36 36
    }
37 37

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

  
40
  public float returnRotationFactor(int numLayers, int row)
41
    {
42
    return 1.0f;
43
    }
44

  
45
///////////////////////////////////////////////////////////////////////////////////////////////////
46

  
47
  boolean isInsideFace(int face, float[] p)
48
    {
49
    return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D );
50
    }
51

  
52 38
///////////////////////////////////////////////////////////////////////////////////////////////////
53 39

  
54 40
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
src/main/java/org/distorted/objects/MovementUltimate.java
19 19

  
20 20
package org.distorted.objects;
21 21

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

  
24
import static org.distorted.objects.TwistyMinx.C2;
25
import static org.distorted.objects.TwistyMinx.COS54;
26
import static org.distorted.objects.TwistyMinx.LEN;
27
import static org.distorted.objects.TwistyMinx.SIN54;
28
import static org.distorted.objects.TwistyObject.SQ5;
29

  
30 22
///////////////////////////////////////////////////////////////////////////////////////////////////
31 23

  
32
class MovementUltimate extends Movement
24
class MovementUltimate extends Movement12
33 25
{
34
  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5);
35
  static final float DIST2D = (SIN54/COS54)/2;
36

  
37
  static final Static3D[] FACE_AXIS = new Static3D[]
38
         {
39
           new Static3D(    C2/LEN, SIN54/LEN,    0      ),
40
           new Static3D(    C2/LEN,-SIN54/LEN,    0      ),
41
           new Static3D(   -C2/LEN, SIN54/LEN,    0      ),
42
           new Static3D(   -C2/LEN,-SIN54/LEN,    0      ),
43
           new Static3D( 0        ,    C2/LEN, SIN54/LEN ),
44
           new Static3D( 0        ,    C2/LEN,-SIN54/LEN ),
45
           new Static3D( 0        ,   -C2/LEN, SIN54/LEN ),
46
           new Static3D( 0        ,   -C2/LEN,-SIN54/LEN ),
47
           new Static3D( SIN54/LEN,    0     ,    C2/LEN ),
48
           new Static3D( SIN54/LEN,    0     ,   -C2/LEN ),
49
           new Static3D(-SIN54/LEN,    0     ,    C2/LEN ),
50
           new Static3D(-SIN54/LEN,    0     ,   -C2/LEN )
51
         };
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55 26
  MovementUltimate()
56 27
    {
57
    super(TwistyUltimate.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
28
    super(TwistyUltimate.ROT_AXIS);
58 29
    }
59 30

  
60 31
///////////////////////////////////////////////////////////////////////////////////////////////////
......
64 35
    return offset<DIST2D ? 0:1;
65 36
    }
66 37

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
  public float returnRotationFactor(int numLayers, int row)
70
    {
71
    return 1.0f;
72
    }
73

  
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// return angle (in radians) that the line connecting the center C of the pentagonal face and the
76
// first vertex of the pentagon makes with a vertical line coming upwards from the center C.
77

  
78
  private float returnAngle(int face)
79
    {
80
    switch(face)
81
      {
82
      case  0:
83
      case  2:
84
      case  6:
85
      case  7: return 0.0f;
86
      case  1:
87
      case  3:
88
      case  4:
89
      case  5: return (float)(36*Math.PI/180);
90
      case  9:
91
      case 10: return (float)(54*Math.PI/180);
92
      case  8:
93
      case 11: return (float)(18*Math.PI/180);
94
      }
95

  
96
    return 0.0f;
97
    }
98

  
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100
// The pair (distance,angle) defines a point P in R^2 in polar coordinate system. Let V be the vector
101
// from the center of the coordinate system to P.
102
// Let P' be the point defined by polar (distance,angle+PI/2). Let Lh be the half-line starting at
103
// P' and going in the direction of V.
104
// Return true iff point 'point' lies on the left of Lh, i.e. when we rotate (using the center of
105
// the coordinate system as the center of rotation) 'point' and Lh in such a way that Lh points
106
// directly upwards, is 'point' on the left or the right of it?
107

  
108
  private boolean isOnTheLeft(float[] point, float distance, float angle)
109
    {
110
    float sin = (float)Math.sin(angle);
111
    float cos = (float)Math.cos(angle);
112

  
113
    float vx = point[0] + sin*distance;
114
    float vy = point[1] - cos*distance;
115

  
116
    return vx*sin < vy*cos;
117
    }
118

  
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

  
121
  private int returnPartOfThePentagon(float[] point, int face)
122
    {
123
    float angle = returnAngle(face);
124
    float A = (float)(Math.PI/5);
125

  
126
    for(int i=0; i<5; i++)
127
      {
128
      if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return 0;
129
      }
130

  
131
    return 1;
132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  boolean isInsideFace(int face, float[] p)
137
    {
138
    return returnPartOfThePentagon(p,face) > 0;
139
    }
140

  
141 38
///////////////////////////////////////////////////////////////////////////////////////////////////
142 39

  
143 40
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
......
146 43

  
147 44
    switch(face)
148 45
      {
149
      case  0: enabled[1] = 2; enabled[2] = 3; break;
150
      case  1: enabled[1] = 1; enabled[2] = 3; break;
151
      case  2: enabled[1] = 1; enabled[2] = 3; break;
152
      case  3: enabled[1] = 2; enabled[2] = 3; break;
153
      case  4: enabled[1] = 0; enabled[2] = 3; break;
154
      case  5: enabled[1] = 0; enabled[2] = 2; break;
155
      case  6: enabled[1] = 0; enabled[2] = 2; break;
156
      case  7: enabled[1] = 0; enabled[2] = 3; break;
157
      case  8: enabled[1] = 1; enabled[2] = 2; break;
158
      case  9: enabled[1] = 0; enabled[2] = 1; break;
159
      case 10: enabled[1] = 0; enabled[2] = 1; break;
160
      case 11: enabled[1] = 1; enabled[2] = 2; break;
46
      case  0: case 3: enabled[1] = 2; enabled[2] = 3; break;
47
      case  1: case 2: enabled[1] = 1; enabled[2] = 3; break;
48
      case  4: case 7: enabled[1] = 0; enabled[2] = 3; break;
49
      case  5: case 6: enabled[1] = 0; enabled[2] = 2; break;
50
      case  8: case 11:enabled[1] = 1; enabled[2] = 2; break;
51
      case  9: case 10:enabled[1] = 0; enabled[2] = 1; break;
161 52
      }
162 53
    }
163 54
}

Also available in: Unified diff