Project

General

Profile

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

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

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.TYPE_SPLIT_CORNER;
23

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
import org.distorted.objectlib.main.Movement;
33
import org.distorted.objectlib.main.Movement6;
34
import org.distorted.objectlib.main.ObjectList;
35
import org.distorted.objectlib.main.ObjectShape;
36
import org.distorted.objectlib.main.ObjectSticker;
37
import org.distorted.objectlib.main.ScrambleState;
38
import org.distorted.objectlib.main.Twisty6;
39

    
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41

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

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

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

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

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

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

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

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

    
119
    return mCuts;
120
    }
121

    
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

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

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

    
137
  protected int getNumStickerTypes(int numLayers)
138
    {
139
    return 1;
140
    }
141

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

    
144
  protected int getNumCubitFaces()
145
    {
146
    return 4;
147
    }
148

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

    
151
  protected float[][] getCubitPositions(int size)
152
    {
153
    if( mCenters ==null )
154
      {
155
      mCenters = new float[][]
156
         {
157
             { 0.0f, 1.5f, 1.5f },
158
             { 1.5f, 0.0f, 1.5f },
159
             { 0.0f,-1.5f, 1.5f },
160
             {-1.5f, 0.0f, 1.5f },
161
             { 1.5f, 1.5f, 0.0f },
162
             { 1.5f,-1.5f, 0.0f },
163
             {-1.5f,-1.5f, 0.0f },
164
             {-1.5f, 1.5f, 0.0f },
165
             { 0.0f, 1.5f,-1.5f },
166
             { 1.5f, 0.0f,-1.5f },
167
             { 0.0f,-1.5f,-1.5f },
168
             {-1.5f, 0.0f,-1.5f }
169
         };
170
      }
171

    
172
    return mCenters;
173
    }
174

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

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

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  protected Static4D getQuat(int cubit, int numLayers)
193
    {
194
    if( mQuats==null ) initializeQuats();
195
    return mQuats[cubit];
196
    }
197

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

    
200
  protected int getNumCubitVariants(int numLayers)
201
    {
202
    return 1;
203
    }
204

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

    
207
  protected int getCubitVariant(int cubit, int numLayers)
208
    {
209
    return 0;
210
    }
211

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

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

    
226
    return mStickers[face/NUM_FACE_COLORS];
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230
// PUBLIC API
231

    
232
  public Static3D[] getRotationAxis()
233
    {
234
    return ROT_AXIS;
235
    }
236

    
237
///////////////////////////////////////////////////////////////////////////////////////////////////
238

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

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252

    
253
  public int[] getBasicAngle()
254
    {
255
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
256
    return mBasicAngle;
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  public int getComplexity(int numLayers)
262
    {
263
    return 2;
264
    }
265
}
(8-8/25)