Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 7ee89540

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[][][] ENABLED = new int[][][]
49
      {
50
          {{0,1},{3,1},{2,3},{0,2}},
51
          {{2,3},{3,1},{0,1},{0,2}},
52
          {{1,2},{0,1},{0,3},{2,3}},
53
          {{1,2},{2,3},{0,3},{0,1}},
54
          {{0,3},{0,2},{1,2},{1,3}},
55
          {{1,2},{0,2},{0,3},{1,3}},
56
      };
57

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

    
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

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

    
75
///////////////////////////////////////////////////////////////////////////////////////////////////
76

    
77
  private void initializeQuats()
78
    {
79
    mQuats = new Static4D[]
80
         {
81
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
82
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
83
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
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.5f, -0.5f,  0.5f, -0.5f ),
88
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
89
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
90
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
91
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
92
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
93
         };
94
    }
95

    
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97

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

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

    
114
    return mCuts;
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

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

    
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131

    
132
  int getNumStickerTypes(int numLayers)
133
    {
134
    return 1;
135
    }
136

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

    
139
  int getNumCubitFaces()
140
    {
141
    return 4;
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  float[][] getCubitPositions(int size)
147
    {
148
    if( mCenters ==null )
149
      {
150
      mCenters = new float[][]
151
         {
152
             { 0.0f, 1.5f, 1.5f },
153
             { 1.5f, 0.0f, 1.5f },
154
             { 0.0f,-1.5f, 1.5f },
155
             {-1.5f, 0.0f, 1.5f },
156
             { 1.5f, 1.5f, 0.0f },
157
             { 1.5f,-1.5f, 0.0f },
158
             {-1.5f,-1.5f, 0.0f },
159
             {-1.5f, 1.5f, 0.0f },
160
             { 0.0f, 1.5f,-1.5f },
161
             { 1.5f, 0.0f,-1.5f },
162
             { 0.0f,-1.5f,-1.5f },
163
             {-1.5f, 0.0f,-1.5f }
164
         };
165
      }
166

    
167
    return mCenters;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

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

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

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

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  int getNumCubitVariants(int numLayers)
196
    {
197
    return 1;
198
    }
199

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

    
202
  int getCubitVariant(int cubit, int numLayers)
203
    {
204
    return 0;
205
    }
206

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

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

    
221
    return mStickers[face/NUM_FACE_COLORS];
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225
// PUBLIC API
226

    
227
  public Static3D[] getRotationAxis()
228
    {
229
    return ROT_AXIS;
230
    }
231

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

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

    
246
///////////////////////////////////////////////////////////////////////////////////////////////////
247

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

    
254
///////////////////////////////////////////////////////////////////////////////////////////////////
255

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