Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 20898e6f

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.ScrambleStateGraph;
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
  ScrambleStateGraph[] mStates;
126

    
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

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

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  float getScreenRatio()
138
    {
139
    return 0.5f;
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  Static4D[] getQuats()
145
    {
146
    return QUATS;
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  int getNumFaces()
152
    {
153
    return FACE_COLORS.length;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

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

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

    
166
  int getNumStickerTypes(int numLayers)
167
    {
168
    return STICKERS.length;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  int getNumCubitFaces()
174
    {
175
    return 4;
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

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

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

    
187
  ObjectShape getObjectShape(int cubit, int numLayers)
188
    {
189
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
190
    int[] bandIndices   = new int[] { 0,0,1,1 };
191
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
192
    int[] cornerIndices = new int[] { 0,0,1,1 };
193
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
194
    int[] centerIndices = new int[] { 0,0,0,0 };
195
    return new ObjectShape(VERTICES,VERT_INDEXES,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

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

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  int getNumCubitVariants(int numLayers)
208
    {
209
    return 1;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  int getCubitVariant(int cubit, int numLayers)
215
    {
216
    return 0;
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  int getColor(int face)
222
    {
223
    return FACE_COLORS[face];
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

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

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234

    
235
  float returnMultiplier()
236
    {
237
    return 2.0f;
238
    }
239

    
240
///////////////////////////////////////////////////////////////////////////////////////////////////
241
// PUBLIC API
242

    
243
  public void randomizeNewScramble(int[][] scramble, Random rnd, int curr, int totalScrambles)
244
    {
245
    if( curr==0 )
246
      {
247
      mCurrState     = 0;
248
      mIndexExcluded =-1;
249
      }
250

    
251
    int total = mStates[mCurrState].getTotal(mIndexExcluded);
252
    int random= rnd.nextInt(total);
253
    int[] info= mStates[mCurrState].getInfo(random,mIndexExcluded);
254

    
255
    scramble[curr][0] = info[0];
256
    scramble[curr][1] = info[1];
257
    scramble[curr][2] = info[2];
258

    
259
    mCurrState     = info[3];
260
    mIndexExcluded = info[0];
261
    }
262

    
263
///////////////////////////////////////////////////////////////////////////////////////////////////
264

    
265
  public Static3D[] getRotationAxis()
266
    {
267
    return ROT_AXIS;
268
    }
269

    
270
///////////////////////////////////////////////////////////////////////////////////////////////////
271

    
272
  public int[] getBasicAngle()
273
    {
274
    return BASIC_ANGLE;
275
    }
276

    
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

    
279
  public int getComplexity(int numLayers)
280
    {
281
    return 2;
282
    }
283
}
(24-24/41)