Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 967c1d17

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 static org.distorted.objects.Movement.TYPE_SPLIT_CORNER;
23

    
24
import android.content.res.Resources;
25

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

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

    
37
public abstract class TwistyDino extends Twisty6
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[] NUM_ENABLED = {2,2,2,2,2,2};
49

    
50
  private static final int[][][] ENABLED = new int[][][]
51
      {
52
          {{0,1},{3,1},{2,3},{0,2}},
53
          {{2,3},{3,1},{0,1},{0,2}},
54
          {{1,2},{0,1},{0,3},{2,3}},
55
          {{1,2},{2,3},{0,3},{0,1}},
56
          {{0,3},{0,2},{1,2},{1,3}},
57
          {{1,2},{0,2},{0,3},{1,3}},
58
      };
59

    
60
  private int[] mBasicAngle;
61
  private Static4D[] mQuats;
62
  private float[][] mCuts;
63
  private boolean[][] mLayerRotatable;
64
  private ObjectSticker[] mStickers;
65
  private float[][] mCenters;
66
  private Movement mMovement;
67
  ScrambleState[] mStates;
68

    
69
///////////////////////////////////////////////////////////////////////////////////////////////////
70

    
71
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
72
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
73
    {
74
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78

    
79
  private void initializeQuats()
80
    {
81
    mQuats = new Static4D[]
82
         {
83
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
84
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
85
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
86
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
87
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
88
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
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.0f,  1.0f,  0.0f,  0.0f ),
92
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
93
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
94
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
95
         };
96
    }
97

    
98
///////////////////////////////////////////////////////////////////////////////////////////////////
99

    
100
  Static4D[] getQuats()
101
    {
102
    if( mQuats==null ) initializeQuats();
103
    return mQuats;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  float[][] getCuts(int size)
109
    {
110
    if( mCuts==null )
111
      {
112
      float[] cut = new float[] { -SQ3/3, +SQ3/3 };
113
      mCuts = new float[][] { cut,cut,cut,cut };
114
      }
115

    
116
    return mCuts;
117
    }
118

    
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

    
121
  private void getLayerRotatable(int numLayers)
122
    {
123
    if( mLayerRotatable==null )
124
      {
125
      int numAxis = ROT_AXIS.length;
126
      boolean[] tmp = new boolean[] {true,false,true};
127
      mLayerRotatable = new boolean[numAxis][];
128
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
129
      }
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  int getNumStickerTypes(int numLayers)
135
    {
136
    return 1;
137
    }
138

    
139
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  int getNumCubitFaces()
142
    {
143
    return 4;
144
    }
145

    
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

    
148
  float[][] getCubitPositions(int size)
149
    {
150
    if( mCenters ==null )
151
      {
152
      mCenters = new float[][]
153
         {
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
             { 1.5f, 1.5f, 0.0f },
159
             { 1.5f,-1.5f, 0.0f },
160
             {-1.5f,-1.5f, 0.0f },
161
             {-1.5f, 1.5f, 0.0f },
162
             { 0.0f, 1.5f,-1.5f },
163
             { 1.5f, 0.0f,-1.5f },
164
             { 0.0f,-1.5f,-1.5f },
165
             {-1.5f, 0.0f,-1.5f }
166
         };
167
      }
168

    
169
    return mCenters;
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  ObjectShape getObjectShape(int cubit, int numLayers)
175
    {
176
    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} };
177
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
178
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
179
    int[] bandIndices   = new int[] { 0,0,1,1 };
180
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
181
    int[] cornerIndices = new int[] { 0,0,1,1 };
182
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
183
    int[] centerIndices = new int[] { 0,0,0,0 };
184
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
185
    }
186

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

    
189
  Static4D getQuat(int cubit, int numLayers)
190
    {
191
    if( mQuats==null ) initializeQuats();
192
    return mQuats[cubit];
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  int getNumCubitVariants(int numLayers)
198
    {
199
    return 1;
200
    }
201

    
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203

    
204
  int getCubitVariant(int cubit, int numLayers)
205
    {
206
    return 0;
207
    }
208

    
209
///////////////////////////////////////////////////////////////////////////////////////////////////
210

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

    
223
    return mStickers[face/NUM_FACE_COLORS];
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
// PUBLIC API
228

    
229
  public Static3D[] getRotationAxis()
230
    {
231
    return ROT_AXIS;
232
    }
233

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

    
236
  public Movement getMovement()
237
    {
238
    if( mMovement==null )
239
      {
240
      int numLayers = getNumLayers();
241
      if( mCuts==null ) getCuts(numLayers);
242
      getLayerRotatable(numLayers);
243
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,NUM_ENABLED,ENABLED);
244
      }
245
    return mMovement;
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public int[] getBasicAngle()
251
    {
252
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
253
    return mBasicAngle;
254
    }
255

    
256
///////////////////////////////////////////////////////////////////////////////////////////////////
257

    
258
  public int getComplexity(int numLayers)
259
    {
260
    return 2;
261
    }
262
}
(19-19/38)