Project

General

Profile

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

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

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

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32

    
33
import java.util.Random;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public abstract class TwistyDino extends TwistyObject
38
{
39
  // the four rotation axis of a RubikDino. Must be normalized.
40
  static final Static3D[] ROT_AXIS = new Static3D[]
41
         {
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
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
49

    
50
  private static final int[] FACE_COLORS = new int[]
51
         {
52
           COLOR_YELLOW, COLOR_WHITE,
53
           COLOR_BLUE  , COLOR_GREEN,
54
           COLOR_RED   , COLOR_ORANGE
55
         };
56

    
57
  // All legal rotation quats of a RubikDino
58
  static final Static4D[] QUATS = new Static4D[]
59
         {
60
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
61
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
62
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
63
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
64
           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
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
68
           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
         };
73

    
74
  // centers of the 12 edges. Must be in the same order like QUATs above.
75
  static final float[][] CENTERS = new float[][]
76
         {
77
             { 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
         };
90

    
91
  private static final double[][] VERTICES = new double[][]
92
          {
93
             {-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
          };
98

    
99
  private static final int[][] VERT_INDEXES = new int[][]
100
          {
101
             {2,1,0},   // counterclockwise!
102
             {3,0,1},
103
             {2,3,1},
104
             {3,2,0},
105
          };
106

    
107
  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
  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

    
123
  private int mCurrState;
124
  private int mIndexExcluded;
125
  ScrambleState[] mStates;
126
  private int[][] mScrambleTable;
127
  private int[] mNumOccurences;
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
132
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
133
    {
134
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
135
    }
136

    
137
///////////////////////////////////////////////////////////////////////////////////////////////////
138

    
139
  float getScreenRatio()
140
    {
141
    return 0.5f;
142
    }
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
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  float[][] getCuts(int size)
161
    {
162
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
163
    return new float[][] { cut,cut,cut,cut };
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

    
168
  int getNumStickerTypes(int numLayers)
169
    {
170
    return STICKERS.length;
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  int getNumCubitFaces()
176
    {
177
    return 4;
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  float[][] getCubitPositions(int size)
183
    {
184
    return CENTERS;
185
    }
186

    
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188

    
189
  ObjectShape getObjectShape(int cubit, int numLayers)
190
    {
191
    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
    }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
  Static4D getQuat(int cubit, int numLayers)
203
    {
204
    return QUATS[cubit];
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  int getNumCubitVariants(int numLayers)
210
    {
211
    return 1;
212
    }
213

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  int getCubitVariant(int cubit, int numLayers)
217
    {
218
    return 0;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  int getColor(int face)
224
    {
225
    return FACE_COLORS[face];
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229

    
230
  ObjectSticker retSticker(int face)
231
    {
232
    return mStickers[face/NUM_FACES];
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  float returnMultiplier()
238
    {
239
    return 2.0f;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
270
// PUBLIC API
271

    
272
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
273
    {
274
    if( curr==0 )
275
      {
276
      mCurrState     = 0;
277
      mIndexExcluded =-1;
278
      initializeScrambling();
279
      }
280

    
281
    int[] info= mStates[mCurrState].getRandom(rnd, mIndexExcluded, mScrambleTable, mNumOccurences);
282

    
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
  public Static3D[] getRotationAxis()
294
    {
295
    return ROT_AXIS;
296
    }
297

    
298
///////////////////////////////////////////////////////////////////////////////////////////////////
299

    
300
  public int[] getBasicAngle()
301
    {
302
    return BASIC_ANGLE;
303
    }
304

    
305
///////////////////////////////////////////////////////////////////////////////////////////////////
306

    
307
  public int getComplexity(int numLayers)
308
    {
309
    return 2;
310
    }
311
}
(24-24/41)