Project

General

Profile

Download (10.2 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 6cf89a3e

1 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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
24 f10a88a8 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 6cf89a3e Leszek Koltunski
import org.distorted.helpers.ScrambleState;
27 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
30 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
33 20898e6f Leszek Koltunski
import java.util.Random;
34
35 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 9c2f0c91 Leszek Koltunski
public abstract class TwistyDino extends TwistyObject
38 418aa554 Leszek Koltunski
{
39
  // the four rotation axis of a RubikDino. Must be normalized.
40 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
41 418aa554 Leszek Koltunski
         {
42
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
44
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
45
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
46
         };
47
48 925ed78f Leszek Koltunski
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
49
50 418aa554 Leszek Koltunski
  private static final int[] FACE_COLORS = new int[]
51
         {
52 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
53
           COLOR_BLUE  , COLOR_GREEN,
54 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
55 418aa554 Leszek Koltunski
         };
56
57
  // All legal rotation quats of a RubikDino
58 eaee1ddc Leszek Koltunski
  static final Static4D[] QUATS = new Static4D[]
59 418aa554 Leszek Koltunski
         {
60
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
61 380162cb Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
62 8f53e513 Leszek Koltunski
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
63 380162cb Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
64 418aa554 Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
65
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
66
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
67 8f53e513 Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
68 380162cb Leszek Koltunski
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
69
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
70
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
71
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
72 8f53e513 Leszek Koltunski
         };
73
74
  // centers of the 12 edges. Must be in the same order like QUATs above.
75 121e4a39 Leszek Koltunski
  static final float[][] CENTERS = new float[][]
76 8f53e513 Leszek Koltunski
         {
77 e6cf7283 Leszek Koltunski
             { 0.0f, 1.5f, 1.5f },
78
             { 1.5f, 0.0f, 1.5f },
79
             { 0.0f,-1.5f, 1.5f },
80
             {-1.5f, 0.0f, 1.5f },
81
             { 1.5f, 1.5f, 0.0f },
82
             { 1.5f,-1.5f, 0.0f },
83
             {-1.5f,-1.5f, 0.0f },
84
             {-1.5f, 1.5f, 0.0f },
85
             { 0.0f, 1.5f,-1.5f },
86
             { 1.5f, 0.0f,-1.5f },
87
             { 0.0f,-1.5f,-1.5f },
88
             {-1.5f, 0.0f,-1.5f }
89 418aa554 Leszek Koltunski
         };
90
91 596d62a4 Leszek Koltunski
  private static final double[][] VERTICES = new double[][]
92 b1f2ccf5 Leszek Koltunski
          {
93 596d62a4 Leszek Koltunski
             {-1.5, 0.0, 0.0},
94
             { 1.5, 0.0, 0.0},
95
             { 0.0,-1.5, 0.0},
96
             { 0.0, 0.0,-1.5}
97 b1f2ccf5 Leszek Koltunski
          };
98
99 596d62a4 Leszek Koltunski
  private static final int[][] VERT_INDEXES = new int[][]
100 b1f2ccf5 Leszek Koltunski
          {
101
             {2,1,0},   // counterclockwise!
102 596d62a4 Leszek Koltunski
             {3,0,1},
103 b1f2ccf5 Leszek Koltunski
             {2,3,1},
104
             {3,2,0},
105
          };
106
107 596d62a4 Leszek Koltunski
  private static final float[][] STICKERS = new float[][]
108
          {
109
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
110
          };
111
112 9c06394a Leszek Koltunski
  private static final ObjectSticker[] mStickers;
113
114
  static
115
    {
116
    float radius = 0.025f;
117
    float stroke = 0.050f;
118
    float[] radii = new float[] {radius,radius,radius};
119
    mStickers = new ObjectSticker[STICKERS.length];
120
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
121
    }
122 418aa554 Leszek Koltunski
123 20898e6f Leszek Koltunski
  private int mCurrState;
124
  private int mIndexExcluded;
125 6cf89a3e Leszek Koltunski
  ScrambleState[] mStates;
126
  private int[][] mScrambleTable;
127
  private int[] mNumOccurences;
128 20898e6f Leszek Koltunski
129 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
130
131 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
132
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
133 418aa554 Leszek Koltunski
    {
134 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
135 418aa554 Leszek Koltunski
    }
136
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139
  float getScreenRatio()
140
    {
141 c7e79b69 Leszek Koltunski
    return 0.5f;
142 418aa554 Leszek Koltunski
    }
143
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145
146
  Static4D[] getQuats()
147
    {
148
    return QUATS;
149
    }
150
151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
153
  int getNumFaces()
154
    {
155
    return FACE_COLORS.length;
156
    }
157
158 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
161 7403cdfa Leszek Koltunski
    {
162 e6734aa9 Leszek Koltunski
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
163
    return new float[][] { cut,cut,cut,cut };
164 7403cdfa Leszek Koltunski
    }
165
166 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
169 eab9d8f8 Leszek Koltunski
    {
170 596d62a4 Leszek Koltunski
    return STICKERS.length;
171 eab9d8f8 Leszek Koltunski
    }
172
173 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
176 418aa554 Leszek Koltunski
    {
177 8f53e513 Leszek Koltunski
    return 4;
178
    }
179
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181 418aa554 Leszek Koltunski
182 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
183 8f53e513 Leszek Koltunski
    {
184
    return CENTERS;
185 418aa554 Leszek Koltunski
    }
186
187 f10a88a8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
188
189 3e605536 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
190 f10a88a8 Leszek Koltunski
    {
191 3e605536 Leszek Koltunski
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
192
    int[] bandIndices   = new int[] { 0,0,1,1 };
193
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
194
    int[] cornerIndices = new int[] { 0,0,1,1 };
195
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
196
    int[] centerIndices = new int[] { 0,0,0,0 };
197
    return new ObjectShape(VERTICES,VERT_INDEXES,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
198 f10a88a8 Leszek Koltunski
    }
199
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
203 f10a88a8 Leszek Koltunski
    {
204 3e605536 Leszek Koltunski
    return QUATS[cubit];
205 f10a88a8 Leszek Koltunski
    }
206
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
209 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
210 f10a88a8 Leszek Koltunski
    {
211 3e605536 Leszek Koltunski
    return 1;
212 f10a88a8 Leszek Koltunski
    }
213
214 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
215
216 3e605536 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
217 418aa554 Leszek Koltunski
    {
218 3e605536 Leszek Koltunski
    return 0;
219 418aa554 Leszek Koltunski
    }
220
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222
223 9c06394a Leszek Koltunski
  int getColor(int face)
224 418aa554 Leszek Koltunski
    {
225 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
226
    }
227 76c2bd07 Leszek Koltunski
228 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230
  ObjectSticker retSticker(int face)
231
    {
232
    return mStickers[face/NUM_FACES];
233 418aa554 Leszek Koltunski
    }
234
235 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237
  float returnMultiplier()
238
    {
239
    return 2.0f;
240
    }
241
242 6cf89a3e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  private void initializeScrambling()
245
    {
246
    int numLayers = getNumLayers();
247
248
    if( mScrambleTable ==null )
249
      {
250
      mScrambleTable = new int[NUM_AXIS][numLayers];
251
      }
252
    if( mNumOccurences ==null )
253
      {
254
      int max=0;
255
256
      for (ScrambleState mState : mStates)
257
        {
258
        int tmp = mState.getTotal(-1);
259
        if (max < tmp) max = tmp;
260
        }
261
262
      mNumOccurences = new int[max];
263
      }
264
265
    for(int i=0; i<NUM_AXIS; i++)
266
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
267
    }
268
269 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
270
// PUBLIC API
271
272 20898e6f Leszek Koltunski
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
273
    {
274
    if( curr==0 )
275
      {
276
      mCurrState     = 0;
277
      mIndexExcluded =-1;
278 6cf89a3e Leszek Koltunski
      initializeScrambling();
279 20898e6f Leszek Koltunski
      }
280
281 6cf89a3e Leszek Koltunski
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
282 20898e6f Leszek Koltunski
283
    scramble[curr][0] = info[0];
284
    scramble[curr][1] = info[1];
285
    scramble[curr][2] = info[2];
286
287
    mCurrState     = info[3];
288
    mIndexExcluded = info[0];
289
    }
290
291
///////////////////////////////////////////////////////////////////////////////////////////////////
292
293 418aa554 Leszek Koltunski
  public Static3D[] getRotationAxis()
294
    {
295 ad38d800 Leszek Koltunski
    return ROT_AXIS;
296 418aa554 Leszek Koltunski
    }
297
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299
300 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
301 418aa554 Leszek Koltunski
    {
302 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
303 418aa554 Leszek Koltunski
    }
304
305 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
306
307
  public int getComplexity(int numLayers)
308
    {
309
    return 2;
310
    }
311 418aa554 Leszek Koltunski
}