Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 588ace55

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

    
24
import android.content.res.Resources;
25

    
26
import org.distorted.objectlib.ObjectShape;
27
import org.distorted.objectlib.ObjectSticker;
28
import org.distorted.objectlib.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
import org.distorted.objectlib.Movement;
35
import org.distorted.objectlib.Movement6;
36
import org.distorted.objectlib.ObjectList;
37
import org.distorted.objectlib.Twisty6;
38

    
39
///////////////////////////////////////////////////////////////////////////////////////////////////
40

    
41
abstract class TwistyDino extends Twisty6
42
{
43
  // the four rotation axis of a RubikDino. Must be normalized.
44
  static final Static3D[] ROT_AXIS = new Static3D[]
45
         {
46
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
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
         };
51

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

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

    
71
///////////////////////////////////////////////////////////////////////////////////////////////////
72

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

    
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

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

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

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

    
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109

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

    
118
    return mCuts;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

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

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

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

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

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

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

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

    
171
    return mCenters;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

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

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

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

    
197
///////////////////////////////////////////////////////////////////////////////////////////////////
198

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

    
204
///////////////////////////////////////////////////////////////////////////////////////////////////
205

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

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

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

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

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
// PUBLIC API
230

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

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

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

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

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

    
258
///////////////////////////////////////////////////////////////////////////////////////////////////
259

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