Project

General

Profile

« Previous | Next » 

Revision 451c6c36

Added by Leszek Koltunski almost 4 years ago

Progress with the Kilominx movement (appears to be working now)

View differences:

src/main/java/org/distorted/objects/MovementMinx.java
72 72
    }
73 73

  
74 74
///////////////////////////////////////////////////////////////////////////////////////////////////
75
// TODO; approximation
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
// Return 1,2,3,4,5 - the vertex of the pentagon to which point 'point' is the closest, if the
121
// 'point' is inside the pentagon - or 0 otherwise.
122
// The 'first' vertex is the one we meet the first when we rotate clockwise starting from 12:00.
123
// This vertex makes angle 'returnAngle()' with the line coming out upwards from the center of the
124
// pentagon.
125
// Distance from the center to a vertex of the pentagon = 1/(6*COS54)
126

  
127
  private int returnPartOfThePentagon(float[] point, int face)
128
    {
129
    float angle = returnAngle(face);
130
    float A = (float)(Math.PI/5);
131

  
132
    for(int i=0; i<5; i++)
133
      {
134
      if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return 0;
135
      }
136

  
137
    if( isOnTheLeft(point, 0, 2.5f*A-angle) )
138
      {
139
      if( isOnTheLeft(point, 0, 3.5f*A-angle) )
140
        {
141
        return isOnTheLeft(point, 0, 5.5f*A-angle) ? 4 : 5;
142
        }
143
      else return 1;
144
      }
145
    else
146
      {
147
      if( isOnTheLeft(point, 0, 4.5f*A-angle) )
148
        {
149
        return 3;
150
        }
151
      else
152
        {
153
        return isOnTheLeft(point, 0, 6.5f*A-angle) ? 2 : 1;
154
        }
155
      }
156
    }
157

  
158
///////////////////////////////////////////////////////////////////////////////////////////////////
76 159

  
77 160
  boolean isInsideFace(int face, float[] p)
78 161
    {
79
    return ( p[0]*p[0] + p[1]*p[1] <= 1/(4*COS54*COS54) );
162
    return returnPartOfThePentagon(p,face) > 0;
80 163
    }
81 164

  
82 165
///////////////////////////////////////////////////////////////////////////////////////////////////
83 166

  
84 167
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
85 168
    {
86
    enabled[0] = 5;
169
    int part = returnPartOfThePentagon(touchPoint,face);
87 170

  
88
    switch(face)
171
    if( part>0 )
89 172
      {
90
      case  0:
91
      case  3:  enabled[1]=1; enabled[2]=2; enabled[3]=3; enabled[4]=4; enabled[5]=5; break;
92
      case  1:
93
      case  2:  enabled[1]=0; enabled[2]=2; enabled[3]=3; enabled[4]=4; enabled[5]=5; break;
94
      case  4:
95
      case  7:  enabled[1]=0; enabled[2]=1; enabled[3]=3; enabled[4]=4; enabled[5]=5; break;
96
      case  5:
97
      case  6:  enabled[1]=0; enabled[2]=1; enabled[3]=2; enabled[4]=4; enabled[5]=5; break;
98
      case  8:
99
      case 11:  enabled[1]=0; enabled[2]=1; enabled[3]=2; enabled[4]=3; enabled[5]=5; break;
100
      case  9:
101
      case 10:  enabled[1]=0; enabled[2]=1; enabled[3]=2; enabled[4]=3; enabled[5]=4; break;
173
      enabled[0] = 2;
174

  
175
      switch(face)
176
        {
177
        case  0:  switch(part)
178
                    {
179
                    case 1: enabled[1]=2; enabled[2]=3; break;
180
                    case 2: enabled[1]=3; enabled[2]=5; break;
181
                    case 3: enabled[1]=5; enabled[2]=1; break;
182
                    case 4: enabled[1]=1; enabled[2]=4; break;
183
                    case 5: enabled[1]=4; enabled[2]=2; break;
184
                    }
185
                  break;
186

  
187
        case  1:  switch(part)
188
                    {
189
                    case 1: enabled[1]=0; enabled[2]=5; break;
190
                    case 2: enabled[1]=5; enabled[2]=2; break;
191
                    case 3: enabled[1]=2; enabled[2]=3; break;
192
                    case 4: enabled[1]=3; enabled[2]=4; break;
193
                    case 5: enabled[1]=4; enabled[2]=0; break;
194
                    }
195
                  break;
196

  
197
        case  2:  switch(part)
198
                    {
199
                    case 1: enabled[1]=3; enabled[2]=2; break;
200
                    case 2: enabled[1]=2; enabled[2]=5; break;
201
                    case 3: enabled[1]=5; enabled[2]=0; break;
202
                    case 4: enabled[1]=0; enabled[2]=4; break;
203
                    case 5: enabled[1]=4; enabled[2]=3; break;
204
                    }
205
                  break;
206

  
207
        case  3:  switch(part)
208
                    {
209
                    case 1: enabled[1]=1; enabled[2]=5; break;
210
                    case 2: enabled[1]=5; enabled[2]=3; break;
211
                    case 3: enabled[1]=3; enabled[2]=2; break;
212
                    case 4: enabled[1]=2; enabled[2]=4; break;
213
                    case 5: enabled[1]=4; enabled[2]=1; break;
214
                    }
215
                  break;
216

  
217
        case  4:  switch(part)
218
                    {
219
                    case 1: enabled[1]=3; enabled[2]=0; break;
220
                    case 2: enabled[1]=0; enabled[2]=4; break;
221
                    case 3: enabled[1]=4; enabled[2]=5; break;
222
                    case 4: enabled[1]=5; enabled[2]=1; break;
223
                    case 5: enabled[1]=1; enabled[2]=3; break;
224
                    }
225
                  break;
226

  
227
        case  5:  switch(part)
228
                    {
229
                    case 1: enabled[1]=2; enabled[2]=1; break;
230
                    case 2: enabled[1]=1; enabled[2]=4; break;
231
                    case 3: enabled[1]=4; enabled[2]=5; break;
232
                    case 4: enabled[1]=5; enabled[2]=0; break;
233
                    case 5: enabled[1]=0; enabled[2]=2; break;
234
                    }
235
                  break;
236

  
237
        case  6:  switch(part)
238
                    {
239
                    case 1: enabled[1]=5; enabled[2]=4; break;
240
                    case 2: enabled[1]=4; enabled[2]=1; break;
241
                    case 3: enabled[1]=1; enabled[2]=2; break;
242
                    case 4: enabled[1]=2; enabled[2]=0; break;
243
                    case 5: enabled[1]=0; enabled[2]=5; break;
244
                    }
245
                  break;
246

  
247
        case  7:  switch(part)
248
                    {
249
                    case 1: enabled[1]=5; enabled[2]=4; break;
250
                    case 2: enabled[1]=4; enabled[2]=0; break;
251
                    case 3: enabled[1]=0; enabled[2]=3; break;
252
                    case 4: enabled[1]=3; enabled[2]=1; break;
253
                    case 5: enabled[1]=1; enabled[2]=5; break;
254
                    }
255
                  break;
256

  
257
        case  8: switch(part)
258
                    {
259
                    case 1: enabled[1]=2; enabled[2]=0; break;
260
                    case 2: enabled[1]=0; enabled[2]=1; break;
261
                    case 3: enabled[1]=1; enabled[2]=3; break;
262
                    case 4: enabled[1]=3; enabled[2]=5; break;
263
                    case 5: enabled[1]=5; enabled[2]=2; break;
264
                    }
265
                  break;
266

  
267
        case  9:  switch(part)
268
                    {
269
                    case 1: enabled[1]=3; enabled[2]=4; break;
270
                    case 2: enabled[1]=4; enabled[2]=2; break;
271
                    case 3: enabled[1]=2; enabled[2]=1; break;
272
                    case 4: enabled[1]=1; enabled[2]=0; break;
273
                    case 5: enabled[1]=0; enabled[2]=3; break;
274
                    }
275
                  break;
276

  
277
        case 10:  switch(part)
278
                    {
279
                    case 1: enabled[1]=2; enabled[2]=4; break;
280
                    case 2: enabled[1]=4; enabled[2]=3; break;
281
                    case 3: enabled[1]=3; enabled[2]=0; break;
282
                    case 4: enabled[1]=0; enabled[2]=1; break;
283
                    case 5: enabled[1]=1; enabled[2]=2; break;
284
                    }
285
                  break;
286

  
287
        case 11:  switch(part)
288
                    {
289
                    case 1: enabled[1]=3; enabled[2]=1; break;
290
                    case 2: enabled[1]=1; enabled[2]=0; break;
291
                    case 3: enabled[1]=0; enabled[2]=2; break;
292
                    case 4: enabled[1]=2; enabled[2]=5; break;
293
                    case 5: enabled[1]=5; enabled[2]=3; break;
294
                    }
295
                  break;
296
        }
297
      }
298
    else
299
      {
300
      enabled[0] = 0;
102 301
      }
103 302
    }
104 303
}

Also available in: Unified diff