Project

General

Profile

Download (9.9 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyDino.java @ 7ba38dd4

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.objectlib.objects;
21

    
22
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
24

    
25
import android.content.res.Resources;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
import org.distorted.objectlib.R;
31
import org.distorted.objectlib.helpers.ObjectShape;
32
import org.distorted.objectlib.helpers.ObjectSticker;
33
import org.distorted.objectlib.helpers.ScrambleState;
34
import org.distorted.objectlib.main.ObjectControl;
35
import org.distorted.objectlib.main.Twisty6;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
abstract class TwistyDino extends Twisty6
40
{
41
  // the four rotation axis of a RubikDino. Must be normalized.
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
44
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
45
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
46
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
47
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
48
         };
49

    
50
  private int[] mBasicAngle;
51
  private Static4D[] mQuats;
52
  private float[][] mCuts;
53
  private ObjectSticker[] mStickers;
54
  private float[][] mCenters;
55
  ScrambleState[] mStates;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  TwistyDino(int[] numL, Static4D quat, Static3D move, Resources res)
60
    {
61
    super(numL, numL[0], quat, move, res);
62
    }
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

    
66
  private void initializeQuats()
67
    {
68
    mQuats = new Static4D[]
69
         {
70
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
71
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
72
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
73
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
74
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
75
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
76
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
77
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
78
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
79
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
80
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
81
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
82
         };
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  protected int getResource(int[] numLayers)
88
    {
89
    return R.raw.dino_3;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public Static4D[] getQuats()
95
    {
96
    if( mQuats==null ) initializeQuats();
97
    return mQuats;
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  public float[][] getCuts(int[] numLayers)
103
    {
104
    if( mCuts==null )
105
      {
106
      float[] cut = new float[] { -SQ3/3, +SQ3/3 };
107
      mCuts = new float[][] { cut,cut,cut,cut };
108
      }
109

    
110
    return mCuts;
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public boolean[][] getLayerRotatable(int[] numLayers)
116
    {
117
    int numAxis = ROT_AXIS.length;
118
    boolean[] tmp = new boolean[] {true,false,true};
119
    boolean[][] layerRotatable = new boolean[numAxis][];
120
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
121

    
122
    return layerRotatable;
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  public int getMovementType()
128
    {
129
    return MOVEMENT_HEXAHEDRON;
130
    }
131

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

    
134
  public int getMovementSplit()
135
    {
136
    return TYPE_SPLIT_CORNER;
137
    }
138

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

    
141
  public int[][][] getEnabled()
142
    {
143
    return new int[][][]
144
      {
145
          {{0,1},{3,1},{2,3},{0,2}},
146
          {{2,3},{3,1},{0,1},{0,2}},
147
          {{1,2},{0,1},{0,3},{2,3}},
148
          {{1,2},{2,3},{0,3},{0,1}},
149
          {{0,3},{0,2},{1,2},{1,3}},
150
          {{1,2},{0,2},{0,3},{1,3}},
151
      };
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  public float[] getDist3D(int[] numLayers)
157
    {
158
    return null;
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public int getNumStickerTypes(int[] numLayers)
164
    {
165
    return 1;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169

    
170
  public int getNumCubitFaces()
171
    {
172
    return 4;
173
    }
174

    
175
///////////////////////////////////////////////////////////////////////////////////////////////////
176

    
177
  public float[][] getCubitPositions(int[] numLayers)
178
    {
179
    if( mCenters ==null )
180
      {
181
      mCenters = new float[][]
182
         {
183
             { 0.0f, 1.5f, 1.5f },
184
             { 1.5f, 0.0f, 1.5f },
185
             { 0.0f,-1.5f, 1.5f },
186
             {-1.5f, 0.0f, 1.5f },
187
             { 1.5f, 1.5f, 0.0f },
188
             { 1.5f,-1.5f, 0.0f },
189
             {-1.5f,-1.5f, 0.0f },
190
             {-1.5f, 1.5f, 0.0f },
191
             { 0.0f, 1.5f,-1.5f },
192
             { 1.5f, 0.0f,-1.5f },
193
             { 0.0f,-1.5f,-1.5f },
194
             {-1.5f, 0.0f,-1.5f }
195
         };
196
      }
197

    
198
    return mCenters;
199
    }
200

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

    
203
  public ObjectShape getObjectShape(int variant)
204
    {
205
    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} };
206
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
207
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
208
    int[] bandIndices   = new int[] { 0,0,1,1 };
209
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
210
    int[] cornerIndices = new int[] { 0,0,1,1 };
211
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
212
    int[] centerIndices = new int[] { 0,0,0,0 };
213
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  public Static4D getQuat(int cubit, int[] numLayers)
219
    {
220
    if( mQuats==null ) initializeQuats();
221
    return mQuats[cubit];
222
    }
223

    
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225

    
226
  public int getNumCubitVariants(int[] numLayers)
227
    {
228
    return 1;
229
    }
230

    
231
///////////////////////////////////////////////////////////////////////////////////////////////////
232

    
233
  public int getCubitVariant(int cubit, int[] numLayers)
234
    {
235
    return 0;
236
    }
237

    
238
///////////////////////////////////////////////////////////////////////////////////////////////////
239

    
240
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
241
    {
242
    return 0;
243
    }
244

    
245
///////////////////////////////////////////////////////////////////////////////////////////////////
246

    
247
  public ObjectSticker retSticker(int sticker)
248
    {
249
    if( mStickers==null )
250
      {
251
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
252
      float radius = 0.025f;
253
      float stroke = 0.050f;
254
      float[] radii = new float[] {radius,radius,radius};
255

    
256
      if( ObjectControl.isInIconMode() )
257
        {
258
        stroke*=1.5f;
259
        }
260

    
261
      mStickers     = new ObjectSticker[STICKERS.length];
262
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
263
      }
264

    
265
    return mStickers[sticker];
266
    }
267

    
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
// PUBLIC API
270

    
271
  public Static3D[] getRotationAxis()
272
    {
273
    return ROT_AXIS;
274
    }
275

    
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277

    
278
  public int[] getBasicAngle()
279
    {
280
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
281
    return mBasicAngle;
282
    }
283

    
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

    
286
  public int getComplexity(int[] numLayers)
287
    {
288
    return 2;
289
    }
290
}
(8-8/25)