Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ d464f54f

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[] FACE_COLORS = new int[]
49
         {
50
           COLOR_YELLOW, COLOR_WHITE,
51
           COLOR_BLUE  , COLOR_GREEN,
52
           COLOR_RED   , COLOR_ORANGE
53
         };
54

    
55
  private int mCurrState;
56
  private int mIndexExcluded;
57
  private int[][] mScrambleTable;
58
  private int[] mNumOccurences;
59
  private int[] mBasicAngle;
60
  private Static4D[] mQuats;
61
  private ObjectSticker[] mStickers;
62
  float[][] mCenters;
63
  ScrambleState[] mStates;
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
68
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
69
    {
70
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  private void initializeQuats()
76
    {
77
    mQuats = new Static4D[]
78
         {
79
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
80
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
81
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
82
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
83
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
84
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
85
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
86
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
87
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
88
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
89
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
90
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
91
         };
92
    }
93

    
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95

    
96
  float getScreenRatio()
97
    {
98
    return 0.5f;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  Static4D[] getQuats()
104
    {
105
    if( mQuats==null ) initializeQuats();
106
    return mQuats;
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  int getNumFaces()
112
    {
113
    return FACE_COLORS.length;
114
    }
115

    
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

    
118
  float[][] getCuts(int size)
119
    {
120
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
121
    return new float[][] { cut,cut,cut,cut };
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  int getNumStickerTypes(int numLayers)
127
    {
128
    return 1;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  int getNumCubitFaces()
134
    {
135
    return 4;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  float[][] getCubitPositions(int size)
141
    {
142
    if( mCenters ==null )
143
      {
144
      mCenters = new float[][]
145
         {
146
             { 0.0f, 1.5f, 1.5f },
147
             { 1.5f, 0.0f, 1.5f },
148
             { 0.0f,-1.5f, 1.5f },
149
             {-1.5f, 0.0f, 1.5f },
150
             { 1.5f, 1.5f, 0.0f },
151
             { 1.5f,-1.5f, 0.0f },
152
             {-1.5f,-1.5f, 0.0f },
153
             {-1.5f, 1.5f, 0.0f },
154
             { 0.0f, 1.5f,-1.5f },
155
             { 1.5f, 0.0f,-1.5f },
156
             { 0.0f,-1.5f,-1.5f },
157
             {-1.5f, 0.0f,-1.5f }
158
         };
159
      }
160

    
161
    return mCenters;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  ObjectShape getObjectShape(int cubit, int numLayers)
167
    {
168
    double[][] vertices = new double[][] { {-1.5, 0.0, 0.0},{ 1.5, 0.0, 0.0},{ 0.0,-1.5, 0.0},{ 0.0, 0.0,-1.5} };
169
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
170
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
171
    int[] bandIndices   = new int[] { 0,0,1,1 };
172
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
173
    int[] cornerIndices = new int[] { 0,0,1,1 };
174
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
175
    int[] centerIndices = new int[] { 0,0,0,0 };
176
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  Static4D getQuat(int cubit, int numLayers)
182
    {
183
    if( mQuats==null ) initializeQuats();
184
    return mQuats[cubit];
185
    }
186

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

    
189
  int getNumCubitVariants(int numLayers)
190
    {
191
    return 1;
192
    }
193

    
194
///////////////////////////////////////////////////////////////////////////////////////////////////
195

    
196
  int getCubitVariant(int cubit, int numLayers)
197
    {
198
    return 0;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  int getColor(int face)
204
    {
205
    return FACE_COLORS[face];
206
    }
207

    
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209

    
210
  ObjectSticker retSticker(int face)
211
    {
212
    if( mStickers==null )
213
      {
214
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
215
      float radius = 0.025f;
216
      float stroke = 0.050f;
217
      float[] radii = new float[] {radius,radius,radius};
218
      mStickers     = new ObjectSticker[STICKERS.length];
219
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
220
      }
221

    
222
    return mStickers[face/NUM_FACES];
223
    }
224

    
225
///////////////////////////////////////////////////////////////////////////////////////////////////
226

    
227
  float returnMultiplier()
228
    {
229
    return 2.0f;
230
    }
231

    
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233

    
234
  private void initializeScrambling()
235
    {
236
    int numLayers = getNumLayers();
237

    
238
    if( mScrambleTable ==null )
239
      {
240
      mScrambleTable = new int[NUM_AXIS][numLayers];
241
      }
242
    if( mNumOccurences ==null )
243
      {
244
      int max=0;
245

    
246
      for (ScrambleState mState : mStates)
247
        {
248
        int tmp = mState.getTotal(-1);
249
        if (max < tmp) max = tmp;
250
        }
251

    
252
      mNumOccurences = new int[max];
253
      }
254

    
255
    for(int i=0; i<NUM_AXIS; i++)
256
      for(int j=0; j<numLayers; j++) mScrambleTable[i][j] = 0;
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260
// PUBLIC API
261

    
262
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
263
    {
264
    if( curr==0 )
265
      {
266
      mCurrState     = 0;
267
      mIndexExcluded =-1;
268
      initializeScrambling();
269
      }
270

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

    
273
    scramble[curr][0] = info[0];
274
    scramble[curr][1] = info[1];
275
    scramble[curr][2] = info[2];
276

    
277
    mCurrState     = info[3];
278
    mIndexExcluded = info[0];
279
    }
280

    
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282

    
283
  public Static3D[] getRotationAxis()
284
    {
285
    return ROT_AXIS;
286
    }
287

    
288
///////////////////////////////////////////////////////////////////////////////////////////////////
289

    
290
  public int[] getBasicAngle()
291
    {
292
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
293
    return mBasicAngle;
294
    }
295

    
296
///////////////////////////////////////////////////////////////////////////////////////////////////
297

    
298
  public int getComplexity(int numLayers)
299
    {
300
    return 2;
301
    }
302
}
(24-24/41)