Project

General

Profile

« Previous | Next » 

Revision fa806818

Added by Leszek Koltunski over 3 years ago

Rename 'Minx' to 'Kilominx' - there would be a separate 'Kilominx' and 'Megaminx' series.

View differences:

src/main/java/org/distorted/objects/MovementKilominx.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.objects;
21

  
22
import org.distorted.library.type.Static3D;
23
import static org.distorted.objects.TwistyKilominx.C1;
24
import static org.distorted.objects.TwistyKilominx.C2;
25
import static org.distorted.objects.TwistyKilominx.LEN;
26
import static org.distorted.objects.FactoryCubit.SIN54;
27
import static org.distorted.objects.FactoryCubit.COS54;
28
import static org.distorted.objects.TwistyObject.SQ5;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
class MovementKilominx extends Movement
33
{
34
  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5)/3;
35
  static final float DIST2D = (0.5f*SIN54/COS54)/3;
36

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

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

  
55
  MovementKilominx()
56
    {
57
    super(TwistyKilominx.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  int computeRowFromOffset(int face, int size, float offset)
63
    {
64
    return offset<DIST2D ? 0:2;
65
    }
66

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

  
69
  public float returnRotationFactor(int size, 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
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
159

  
160
  boolean isInsideFace(int face, float[] p)
161
    {
162
    return returnPartOfThePentagon(p,face) > 0;
163
    }
164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
168
    {
169
    int part = returnPartOfThePentagon(touchPoint,face);
170

  
171
    if( part>0 )
172
      {
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;
301
      }
302
    }
303
}
src/main/java/org/distorted/objects/MovementMinx.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.objects;
21

  
22
import org.distorted.library.type.Static3D;
23
import static org.distorted.objects.TwistyMinx.C1;
24
import static org.distorted.objects.TwistyMinx.C2;
25
import static org.distorted.objects.TwistyMinx.LEN;
26
import static org.distorted.objects.FactoryCubit.SIN54;
27
import static org.distorted.objects.FactoryCubit.COS54;
28
import static org.distorted.objects.TwistyObject.SQ5;
29

  
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

  
32
class MovementMinx extends Movement
33
{
34
  static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5)/3;
35
  static final float DIST2D = (0.5f*SIN54/COS54)/3;
36

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

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

  
55
  MovementMinx()
56
    {
57
    super(TwistyMinx.ROT_AXIS, FACE_AXIS, DIST3D, DIST2D);
58
    }
59

  
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

  
62
  int computeRowFromOffset(int face, int size, float offset)
63
    {
64
    return offset<DIST2D ? 0:2;
65
    }
66

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

  
69
  public float returnRotationFactor(int size, 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
// 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
///////////////////////////////////////////////////////////////////////////////////////////////////
159

  
160
  boolean isInsideFace(int face, float[] p)
161
    {
162
    return returnPartOfThePentagon(p,face) > 0;
163
    }
164

  
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

  
167
  void computeEnabledAxis(int face, float[] touchPoint, int[] enabled)
168
    {
169
    int part = returnPartOfThePentagon(touchPoint,face);
170

  
171
    if( part>0 )
172
      {
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;
301
      }
302
    }
303
}
src/main/java/org/distorted/objects/ObjectList.java
132 132

  
133 133
  KILO (
134 134
         new int[][] {
135
                       {3 , 18, R.raw.minx3, R.drawable.ui_small_minx3, R.drawable.ui_medium_minx3, R.drawable.ui_big_minx3, R.drawable.ui_huge_minx3} ,
135
                       {3 , 18, R.raw.kilo3, R.drawable.ui_small_kilo3, R.drawable.ui_medium_kilo3, R.drawable.ui_big_kilo3, R.drawable.ui_huge_kilo3} ,
136 136
                     },
137
         TwistyMinx.class,
138
         new MovementMinx(),
137
         TwistyKilominx.class,
138
         new MovementKilominx(),
139 139
         4
140 140
       ),
141 141
  ;
......
520 520
      case  7: return new TwistySkewb     (size, quat, texture, mesh, effects, moves, res, scrWidth);
521 521
      case  8: return new TwistyIvy       (size, quat, texture, mesh, effects, moves, res, scrWidth);
522 522
      case  9: return new TwistyRex       (size, quat, texture, mesh, effects, moves, res, scrWidth);
523
      case 10: return new TwistyMinx      (size, quat, texture, mesh, effects, moves, res, scrWidth);
523
      case 10: return new TwistyKilominx  (size, quat, texture, mesh, effects, moves, res, scrWidth);
524 524
      }
525 525

  
526 526
    return null;
src/main/java/org/distorted/objects/TwistyKilominx.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.objects;
21

  
22
import android.content.res.Resources;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.R;
34

  
35
import java.util.Random;
36

  
37
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
public class TwistyKilominx extends TwistyObject
42
{
43
  private static final int FACES_PER_CUBIT =6;
44

  
45
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
46
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
47
  static final float C2 = (SQ5+3)/4;
48
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
49

  
50
  // the six rotation axis of a Kilominx. Must be normalized.
51
  static final Static3D[] ROT_AXIS = new Static3D[]
52
         {
53
           new Static3D( C2/LEN, C1/LEN, 0      ),
54
           new Static3D(-C2/LEN, C1/LEN, 0      ),
55
           new Static3D( 0     , C2/LEN, C1/LEN ),
56
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
57
           new Static3D( C1/LEN, 0     , C2/LEN ),
58
           new Static3D( C1/LEN, 0     ,-C2/LEN )
59
         };
60

  
61
  private static final int MINX_LGREEN = 0xff53aa00;
62
  private static final int MINX_PINK   = 0xfffd7ab7;
63
  private static final int MINX_SANDY  = 0xffefd48b;
64
  private static final int MINX_LBLUE  = 0xff00a2d7;
65
  private static final int MINX_ORANGE = 0xffff6200;
66
  private static final int MINX_VIOLET = 0xff7d59a4;
67
  private static final int MINX_DGREEN = 0xff007a47;
68
  private static final int MINX_DRED   = 0xffbd0000;
69
  private static final int MINX_DBLUE  = 0xff1a29b2;
70
  private static final int MINX_DYELLOW= 0xffffc400;
71
  private static final int MINX_WHITE  = 0xffffffff;
72
  private static final int MINX_GREY   = 0xff727c7b;
73

  
74
  private static final int[] FACE_COLORS = new int[]
75
         {
76
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
77
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
78
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
79
         };
80

  
81
  // All 60 legal rotation quats of a Kilominx
82
  private static final Static4D[] QUATS = new Static4D[]
83
         {
84
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
85
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
86
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
87
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
88

  
89
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
90
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
91
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
92
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
93
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
94
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
95
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
96
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
97

  
98
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
99
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
100
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
101
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
102
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
103
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
104
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
105
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
106
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
107
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
108
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
109
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
110

  
111
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
112
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
113
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
114
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
115
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
116
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
117
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
118
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
119
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
120
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
121
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
122
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
123

  
124
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
125
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
126
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
127
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
128
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
129
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
130
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
131
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
132
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
133
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
134
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
135
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
136

  
137
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
138
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
139
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
140
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
141
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
142
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
143
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
144
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
145
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
146
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
147
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
148
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
149
         };
150

  
151
  private static final int[][] mFaceMap =
152
         {
153
           {  0, 1, 8, 12,12,12 },
154
           {  6, 5,10, 12,12,12 },
155
           {  1, 0,11, 12,12,12 },
156
           {  5, 6, 3, 12,12,12 },
157
           {  0, 9, 4, 12,12,12 },
158
           {  5, 4, 9, 12,12,12 },
159
           {  7, 1, 2, 12,12,12 },
160
           {  2, 6, 7, 12,12,12 },
161
           { 10, 9, 8, 12,12,12 },
162
           {  4, 3,11, 12,12,12 },
163
           {  7,10, 8, 12,12,12 },
164
           {  3, 2,11, 12,12,12 },
165
           {  0, 8, 9, 12,12,12 },
166
           {  9,10, 5, 12,12,12 },
167
           {  0, 4,11, 12,12,12 },
168
           {  4, 5, 3, 12,12,12 },
169
           {  1, 7, 8, 12,12,12 },
170
           {  7, 6,10, 12,12,12 },
171
           {  2, 1,11, 12,12,12 },
172
           {  6, 2, 3, 12,12,12 },
173
         };
174

  
175
  private static MeshBase mMesh;
176

  
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

  
179
  TwistyKilominx(int size, Static4D quat, DistortedTexture texture,
180
                 MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
181
    {
182
    super(size, size, 30, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
183
    }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  float getScreenRatio()
188
    {
189
    return 0.9f;
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  Static4D[] getQuats()
195
    {
196
    return QUATS;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  int getNumFaces()
202
    {
203
    return FACE_COLORS.length;
204
    }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
  boolean shouldResetTextureMaps()
209
    {
210
    return false;
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  int getNumStickerTypes()
216
    {
217
    return 1;
218
    }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

  
222
  float[] getCuts(int numLayers)
223
    {
224
    return new float[] { -0.5f , 0.5f };
225
    }
226

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

  
229
  int getNumCubitFaces()
230
    {
231
    return FACES_PER_CUBIT;
232
    }
233

  
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

  
236
  Static3D[] getCubitPositions(int numLayers)
237
    {
238
    final Static3D[] CENTERS = new Static3D[20];
239

  
240
    CENTERS[ 0] = new Static3D( 0.0f, 0.5f,   C2);
241
    CENTERS[ 1] = new Static3D( 0.0f, 0.5f,  -C2);
242
    CENTERS[ 2] = new Static3D( 0.0f,-0.5f,   C2);
243
    CENTERS[ 3] = new Static3D( 0.0f,-0.5f,  -C2);
244
    CENTERS[ 4] = new Static3D(   C2, 0.0f, 0.5f);
245
    CENTERS[ 5] = new Static3D(   C2, 0.0f,-0.5f);
246
    CENTERS[ 6] = new Static3D(  -C2, 0.0f, 0.5f);
247
    CENTERS[ 7] = new Static3D(  -C2, 0.0f,-0.5f);
248
    CENTERS[ 8] = new Static3D( 0.5f,   C2, 0.0f);
249
    CENTERS[ 9] = new Static3D( 0.5f,  -C2, 0.0f);
250
    CENTERS[10] = new Static3D(-0.5f,   C2, 0.0f);
251
    CENTERS[11] = new Static3D(-0.5f,  -C2, 0.0f);
252
    CENTERS[12] = new Static3D(   C1,   C1,   C1);
253
    CENTERS[13] = new Static3D(   C1,   C1,  -C1);
254
    CENTERS[14] = new Static3D(   C1,  -C1,   C1);
255
    CENTERS[15] = new Static3D(   C1,  -C1,  -C1);
256
    CENTERS[16] = new Static3D(  -C1,   C1,   C1);
257
    CENTERS[17] = new Static3D(  -C1,   C1,  -C1);
258
    CENTERS[18] = new Static3D(  -C1,  -C1,   C1);
259
    CENTERS[19] = new Static3D(  -C1,  -C1,  -C1);
260

  
261
    return CENTERS;
262
    }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
  private int getQuat(int cubit)
267
    {
268
    switch(cubit)
269
      {
270
      case  0: return 0;
271
      case  1: return 2;
272
      case  2: return 3;
273
      case  3: return 1;
274
      case  4: return 40;
275
      case  5: return 31;
276
      case  6: return 41;
277
      case  7: return 30;
278
      case  8: return 39;
279
      case  9: return 35;
280
      case 10: return 36;
281
      case 11: return 34;
282
      case 12: return 56;
283
      case 13: return 32;
284
      case 14: return 43;
285
      case 15: return 21;
286
      case 16: return 48;
287
      case 17: return 28;
288
      case 18: return 42;
289
      case 19: return 23;
290
      }
291

  
292
    return 0;
293
    }
294

  
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

  
297
  MeshBase createCubitMesh(int cubit)
298
    {
299
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createMinxCornerMesh();
300
    MeshBase mesh = mMesh.copy(true);
301

  
302
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
303
    mesh.apply(quat,0xffffffff,0);
304

  
305
    return mesh;
306
    }
307

  
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

  
310
  int getFaceColor(int cubit, int cubitface, int numLayers)
311
    {
312
    return mFaceMap[cubit][cubitface];
313
    }
314

  
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

  
317
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
318
    {
319
    float S = 0.07f;
320
    float R = 0.09f;
321

  
322
    float A = 0.86f;
323
    float X1= (SQ5+1)/8;
324
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
325
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
326

  
327
    float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
328

  
329
    FactorySticker factory = FactorySticker.getInstance();
330
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
331

  
332
    float MID = TEXTURE_HEIGHT*0.5f;
333
    float WID = TEXTURE_HEIGHT*0.1f;
334
    float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
335
    canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
336
    }
337

  
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

  
340
  float returnMultiplier()
341
    {
342
    return 2.0f;
343
    }
344

  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

  
347
  float[] getRowChances()
348
    {
349
    return new float[] { 0.5f, 0.5f, 1.0f };
350
    }
351

  
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
// PUBLIC API
354

  
355
  public Static3D[] getRotationAxis()
356
    {
357
    return ROT_AXIS;
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  public int getBasicAngle()
363
    {
364
    return 5;
365
    }
366

  
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

  
369
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
370
    {
371
    int numAxis = ROTATION_AXIS.length;
372

  
373
    if( oldRotAxis == START_AXIS )
374
      {
375
      return rnd.nextInt(numAxis);
376
      }
377
    else
378
      {
379
      int newVector = rnd.nextInt(numAxis-1);
380
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
381
      }
382
    }
383

  
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

  
386
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
387
    {
388
    float rowFloat = rnd.nextFloat();
389

  
390
    for(int row=0; row<mRowChances.length; row++)
391
      {
392
      if( rowFloat<=mRowChances[row] ) return row;
393
      }
394

  
395
    return 0;
396
    }
397

  
398
///////////////////////////////////////////////////////////////////////////////////////////////////
399
// The Kilominx is solved if and only if:
400
//
401
// all cubits are rotated with the same quat.
402

  
403
  public boolean isSolved()
404
    {
405
    int q = CUBITS[0].mQuatIndex;
406

  
407
    for(int i=0; i<NUM_CUBITS; i++)
408
      {
409
      if( CUBITS[i].mQuatIndex != q ) return false;
410
      }
411

  
412
    return true;
413
    }
414

  
415
///////////////////////////////////////////////////////////////////////////////////////////////////
416
// only needed for solvers - there are no Kilominx solvers ATM)
417

  
418
  public String retObjectString()
419
    {
420
    return "";
421
    }
422

  
423
///////////////////////////////////////////////////////////////////////////////////////////////////
424

  
425
  public int getObjectName(int numLayers)
426
    {
427
    return R.string.minx2;
428
    }
429

  
430
///////////////////////////////////////////////////////////////////////////////////////////////////
431

  
432
  public int getInventor(int numLayers)
433
    {
434
    return R.string.minx2_inventor;
435
    }
436

  
437
///////////////////////////////////////////////////////////////////////////////////////////////////
438

  
439
  public int getComplexity(int numLayers)
440
    {
441
    return 3;
442
    }
443
}
src/main/java/org/distorted/objects/TwistyMinx.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.objects;
21

  
22
import android.content.res.Resources;
23
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

  
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.R;
34

  
35
import java.util.Random;
36

  
37
import static org.distorted.effects.scramble.ScrambleEffect.START_AXIS;
38

  
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

  
41
public class TwistyMinx extends TwistyObject
42
{
43
  private static final int FACES_PER_CUBIT =6;
44

  
45
  static final float C0 = (SQ5-1)/4;                       // cos(72 deg)
46
  static final float C1 = (SQ5+1)/4;                       // cos(36 deg)
47
  static final float C2 = (SQ5+3)/4;
48
  static final float LEN= (float)(Math.sqrt(1.25f+0.5f*SQ5));
49

  
50
  // the six rotation axis of a Kilominx. Must be normalized.
51
  static final Static3D[] ROT_AXIS = new Static3D[]
52
         {
53
           new Static3D( C2/LEN, C1/LEN, 0      ),
54
           new Static3D(-C2/LEN, C1/LEN, 0      ),
55
           new Static3D( 0     , C2/LEN, C1/LEN ),
56
           new Static3D( 0     ,-C2/LEN, C1/LEN ),
57
           new Static3D( C1/LEN, 0     , C2/LEN ),
58
           new Static3D( C1/LEN, 0     ,-C2/LEN )
59
         };
60

  
61
  private static final int MINX_LGREEN = 0xff53aa00;
62
  private static final int MINX_PINK   = 0xfffd7ab7;
63
  private static final int MINX_SANDY  = 0xffefd48b;
64
  private static final int MINX_LBLUE  = 0xff00a2d7;
65
  private static final int MINX_ORANGE = 0xffff6200;
66
  private static final int MINX_VIOLET = 0xff7d59a4;
67
  private static final int MINX_DGREEN = 0xff007a47;
68
  private static final int MINX_DRED   = 0xffbd0000;
69
  private static final int MINX_DBLUE  = 0xff1a29b2;
70
  private static final int MINX_DYELLOW= 0xffffc400;
71
  private static final int MINX_WHITE  = 0xffffffff;
72
  private static final int MINX_GREY   = 0xff727c7b;
73

  
74
  private static final int[] FACE_COLORS = new int[]
75
         {
76
           MINX_LGREEN, MINX_PINK   , MINX_SANDY , MINX_LBLUE,
77
           MINX_ORANGE, MINX_VIOLET , MINX_DGREEN, MINX_DRED ,
78
           MINX_DBLUE , MINX_DYELLOW, MINX_WHITE , MINX_GREY
79
         };
80

  
81
  // All 60 legal rotation quats of a Kilominx
82
  private static final Static4D[] QUATS = new Static4D[]
83
         {
84
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
85
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
86
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
87
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
88

  
89
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
90
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f ),
91
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
92
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
93
           new Static4D( -0.5f,  0.5f,  0.5f,  0.5f ),
94
           new Static4D( -0.5f,  0.5f, -0.5f,  0.5f ),
95
           new Static4D( -0.5f, -0.5f,  0.5f,  0.5f ),
96
           new Static4D( -0.5f, -0.5f, -0.5f,  0.5f ),
97

  
98
           new Static4D(  0.5f,    C1,    C0,  0.0f ),
99
           new Static4D(  0.5f,    C1,   -C0,  0.0f ),
100
           new Static4D(  0.5f,   -C1,    C0,  0.0f ),
101
           new Static4D(  0.5f,   -C1,   -C0,  0.0f ),
102
           new Static4D(    C0,  0.5f,    C1,  0.0f ),
103
           new Static4D(    C0,  0.5f,   -C1,  0.0f ),
104
           new Static4D(   -C0,  0.5f,    C1,  0.0f ),
105
           new Static4D(   -C0,  0.5f,   -C1,  0.0f ),
106
           new Static4D(    C1,    C0,  0.5f,  0.0f ),
107
           new Static4D(    C1,   -C0,  0.5f,  0.0f ),
108
           new Static4D(   -C1,    C0,  0.5f,  0.0f ),
109
           new Static4D(   -C1,   -C0,  0.5f,  0.0f ),
110

  
111
           new Static4D(  0.0f,    C0,    C1,  0.5f ),
112
           new Static4D(  0.0f,    C0,   -C1,  0.5f ),
113
           new Static4D(  0.0f,   -C0,    C1,  0.5f ),
114
           new Static4D(  0.0f,   -C0,   -C1,  0.5f ),
115
           new Static4D(    C0,    C1,  0.0f,  0.5f ),
116
           new Static4D(    C0,   -C1,  0.0f,  0.5f ),
117
           new Static4D(   -C0,    C1,  0.0f,  0.5f ),
118
           new Static4D(   -C0,   -C1,  0.0f,  0.5f ),
119
           new Static4D(    C1,  0.0f,    C0,  0.5f ),
120
           new Static4D(    C1,  0.0f,   -C0,  0.5f ),
121
           new Static4D(   -C1,  0.0f,    C0,  0.5f ),
122
           new Static4D(   -C1,  0.0f,   -C0,  0.5f ),
123

  
124
           new Static4D(  0.0f,    C1,  0.5f,    C0 ),
125
           new Static4D(  0.0f,    C1, -0.5f,    C0 ),
126
           new Static4D(  0.0f,   -C1,  0.5f,    C0 ),
127
           new Static4D(  0.0f,   -C1, -0.5f,    C0 ),
128
           new Static4D(  0.5f,  0.0f,    C1,    C0 ),
129
           new Static4D(  0.5f,  0.0f,   -C1,    C0 ),
130
           new Static4D( -0.5f,  0.0f,    C1,    C0 ),
131
           new Static4D( -0.5f,  0.0f,   -C1,    C0 ),
132
           new Static4D(    C1,  0.5f,  0.0f,    C0 ),
133
           new Static4D(    C1, -0.5f,  0.0f,    C0 ),
134
           new Static4D(   -C1,  0.5f,  0.0f,    C0 ),
135
           new Static4D(   -C1, -0.5f,  0.0f,    C0 ),
136

  
137
           new Static4D(  0.0f,  0.5f,    C0,    C1 ),
138
           new Static4D(  0.0f,  0.5f,   -C0,    C1 ),
139
           new Static4D(  0.0f, -0.5f,    C0,    C1 ),
140
           new Static4D(  0.0f, -0.5f,   -C0,    C1 ),
141
           new Static4D(  0.5f,    C0,  0.0f,    C1 ),
142
           new Static4D(  0.5f,   -C0,  0.0f,    C1 ),
143
           new Static4D( -0.5f,    C0,  0.0f,    C1 ),
144
           new Static4D( -0.5f,   -C0,  0.0f,    C1 ),
145
           new Static4D(    C0,  0.0f,  0.5f,    C1 ),
146
           new Static4D(    C0,  0.0f, -0.5f,    C1 ),
147
           new Static4D(   -C0,  0.0f,  0.5f,    C1 ),
148
           new Static4D(   -C0,  0.0f, -0.5f,    C1 ),
149
         };
150

  
151
  private static final int[][] mFaceMap =
152
         {
153
           {  0, 1, 8, 12,12,12 },
154
           {  6, 5,10, 12,12,12 },
155
           {  1, 0,11, 12,12,12 },
156
           {  5, 6, 3, 12,12,12 },
157
           {  0, 9, 4, 12,12,12 },
158
           {  5, 4, 9, 12,12,12 },
159
           {  7, 1, 2, 12,12,12 },
160
           {  2, 6, 7, 12,12,12 },
161
           { 10, 9, 8, 12,12,12 },
162
           {  4, 3,11, 12,12,12 },
163
           {  7,10, 8, 12,12,12 },
164
           {  3, 2,11, 12,12,12 },
165
           {  0, 8, 9, 12,12,12 },
166
           {  9,10, 5, 12,12,12 },
167
           {  0, 4,11, 12,12,12 },
168
           {  4, 5, 3, 12,12,12 },
169
           {  1, 7, 8, 12,12,12 },
170
           {  7, 6,10, 12,12,12 },
171
           {  2, 1,11, 12,12,12 },
172
           {  6, 2, 3, 12,12,12 },
173
         };
174

  
175
  private static MeshBase mMesh;
176

  
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

  
179
  TwistyMinx(int size, Static4D quat, DistortedTexture texture,
180
             MeshSquare mesh, DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
181
    {
182
    super(size, size, 30, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
183
    }
184

  
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

  
187
  float getScreenRatio()
188
    {
189
    return 0.9f;
190
    }
191

  
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

  
194
  Static4D[] getQuats()
195
    {
196
    return QUATS;
197
    }
198

  
199
///////////////////////////////////////////////////////////////////////////////////////////////////
200

  
201
  int getNumFaces()
202
    {
203
    return FACE_COLORS.length;
204
    }
205

  
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

  
208
  boolean shouldResetTextureMaps()
209
    {
210
    return false;
211
    }
212

  
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

  
215
  int getNumStickerTypes()
216
    {
217
    return 1;
218
    }
219

  
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

  
222
  float[] getCuts(int numLayers)
223
    {
224
    return new float[] { -0.5f , 0.5f };
225
    }
226

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
228

  
229
  int getNumCubitFaces()
230
    {
231
    return FACES_PER_CUBIT;
232
    }
233

  
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235

  
236
  Static3D[] getCubitPositions(int numLayers)
237
    {
238
    final Static3D[] CENTERS = new Static3D[20];
239

  
240
    CENTERS[ 0] = new Static3D( 0.0f, 0.5f,   C2);
241
    CENTERS[ 1] = new Static3D( 0.0f, 0.5f,  -C2);
242
    CENTERS[ 2] = new Static3D( 0.0f,-0.5f,   C2);
243
    CENTERS[ 3] = new Static3D( 0.0f,-0.5f,  -C2);
244
    CENTERS[ 4] = new Static3D(   C2, 0.0f, 0.5f);
245
    CENTERS[ 5] = new Static3D(   C2, 0.0f,-0.5f);
246
    CENTERS[ 6] = new Static3D(  -C2, 0.0f, 0.5f);
247
    CENTERS[ 7] = new Static3D(  -C2, 0.0f,-0.5f);
248
    CENTERS[ 8] = new Static3D( 0.5f,   C2, 0.0f);
249
    CENTERS[ 9] = new Static3D( 0.5f,  -C2, 0.0f);
250
    CENTERS[10] = new Static3D(-0.5f,   C2, 0.0f);
251
    CENTERS[11] = new Static3D(-0.5f,  -C2, 0.0f);
252
    CENTERS[12] = new Static3D(   C1,   C1,   C1);
253
    CENTERS[13] = new Static3D(   C1,   C1,  -C1);
254
    CENTERS[14] = new Static3D(   C1,  -C1,   C1);
255
    CENTERS[15] = new Static3D(   C1,  -C1,  -C1);
256
    CENTERS[16] = new Static3D(  -C1,   C1,   C1);
257
    CENTERS[17] = new Static3D(  -C1,   C1,  -C1);
258
    CENTERS[18] = new Static3D(  -C1,  -C1,   C1);
259
    CENTERS[19] = new Static3D(  -C1,  -C1,  -C1);
260

  
261
    return CENTERS;
262
    }
263

  
264
///////////////////////////////////////////////////////////////////////////////////////////////////
265

  
266
  private int getQuat(int cubit)
267
    {
268
    switch(cubit)
269
      {
270
      case  0: return 0;
271
      case  1: return 2;
272
      case  2: return 3;
273
      case  3: return 1;
274
      case  4: return 40;
275
      case  5: return 31;
276
      case  6: return 41;
277
      case  7: return 30;
278
      case  8: return 39;
279
      case  9: return 35;
280
      case 10: return 36;
281
      case 11: return 34;
282
      case 12: return 56;
283
      case 13: return 32;
284
      case 14: return 43;
285
      case 15: return 21;
286
      case 16: return 48;
287
      case 17: return 28;
288
      case 18: return 42;
289
      case 19: return 23;
290
      }
291

  
292
    return 0;
293
    }
294

  
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296

  
297
  MeshBase createCubitMesh(int cubit)
298
    {
299
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createMinxCornerMesh();
300
    MeshBase mesh = mMesh.copy(true);
301

  
302
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
303
    mesh.apply(quat,0xffffffff,0);
304

  
305
    return mesh;
306
    }
307

  
308
///////////////////////////////////////////////////////////////////////////////////////////////////
309

  
310
  int getFaceColor(int cubit, int cubitface, int numLayers)
311
    {
312
    return mFaceMap[cubit][cubitface];
313
    }
314

  
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

  
317
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
318
    {
319
    float S = 0.07f;
320
    float R = 0.09f;
321

  
322
    float A = 0.86f;
323
    float X1= (SQ5+1)/8;
324
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
325
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
326

  
327
    float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
328

  
329
    FactorySticker factory = FactorySticker.getInstance();
330
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
331

  
332
    float MID = TEXTURE_HEIGHT*0.5f;
333
    float WID = TEXTURE_HEIGHT*0.1f;
334
    float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
335
    canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
336
    }
337

  
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339

  
340
  float returnMultiplier()
341
    {
342
    return 2.0f;
343
    }
344

  
345
///////////////////////////////////////////////////////////////////////////////////////////////////
346

  
347
  float[] getRowChances()
348
    {
349
    return new float[] { 0.5f, 0.5f, 1.0f };
350
    }
351

  
352
///////////////////////////////////////////////////////////////////////////////////////////////////
353
// PUBLIC API
354

  
355
  public Static3D[] getRotationAxis()
356
    {
357
    return ROT_AXIS;
358
    }
359

  
360
///////////////////////////////////////////////////////////////////////////////////////////////////
361

  
362
  public int getBasicAngle()
363
    {
364
    return 5;
365
    }
366

  
367
///////////////////////////////////////////////////////////////////////////////////////////////////
368

  
369
  public int randomizeNewRotAxis(Random rnd, int oldRotAxis)
370
    {
371
    int numAxis = ROTATION_AXIS.length;
372

  
373
    if( oldRotAxis == START_AXIS )
374
      {
375
      return rnd.nextInt(numAxis);
376
      }
377
    else
378
      {
379
      int newVector = rnd.nextInt(numAxis-1);
380
      return (newVector>=oldRotAxis ? newVector+1 : newVector);
381
      }
382
    }
383

  
384
///////////////////////////////////////////////////////////////////////////////////////////////////
385

  
386
  public int randomizeNewRow(Random rnd, int oldRotAxis, int oldRow, int newRotAxis)
387
    {
388
    float rowFloat = rnd.nextFloat();
389

  
390
    for(int row=0; row<mRowChances.length; row++)
391
      {
392
      if( rowFloat<=mRowChances[row] ) return row;
393
      }
394

  
395
    return 0;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff