Project

General

Profile

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

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

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.R;
33
import org.distorted.objectlib.main.Movement;
34
import org.distorted.objectlib.main.Movement6;
35
import org.distorted.objectlib.helpers.ObjectShape;
36
import org.distorted.objectlib.helpers.ObjectSticker;
37
import org.distorted.objectlib.helpers.ScrambleState;
38
import org.distorted.objectlib.main.ObjectControl;
39
import org.distorted.objectlib.main.Twisty6;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

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

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

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

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  TwistyDino(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
76
             MeshSquare mesh, DistortedEffects effects, Resources res, int scrWidth)
77
    {
78
    super(numL, numL[0], quat, move, texture, mesh, effects, res, scrWidth);
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

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

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  protected int getResource(int[] numLayers)
105
    {
106
    return R.raw.dino;
107
    }
108

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

    
111
  protected Static4D[] getQuats()
112
    {
113
    if( mQuats==null ) initializeQuats();
114
    return mQuats;
115
    }
116

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

    
119
  protected float[][] getCuts(int[] numLayers)
120
    {
121
    if( mCuts==null )
122
      {
123
      float[] cut = new float[] { -SQ3/3, +SQ3/3 };
124
      mCuts = new float[][] { cut,cut,cut,cut };
125
      }
126

    
127
    return mCuts;
128
    }
129

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

    
132
  private void getLayerRotatable(int[] numLayers)
133
    {
134
    if( mLayerRotatable==null )
135
      {
136
      int numAxis = ROT_AXIS.length;
137
      boolean[] tmp = new boolean[] {true,false,true};
138
      mLayerRotatable = new boolean[numAxis][];
139
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
140
      }
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  protected int getNumStickerTypes(int[] numLayers)
146
    {
147
    return 1;
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  protected int getNumCubitFaces()
153
    {
154
    return 4;
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  protected float[][] getCubitPositions(int[] numLayers)
160
    {
161
    if( mCenters ==null )
162
      {
163
      mCenters = new float[][]
164
         {
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
             { 1.5f, 1.5f, 0.0f },
170
             { 1.5f,-1.5f, 0.0f },
171
             {-1.5f,-1.5f, 0.0f },
172
             {-1.5f, 1.5f, 0.0f },
173
             { 0.0f, 1.5f,-1.5f },
174
             { 1.5f, 0.0f,-1.5f },
175
             { 0.0f,-1.5f,-1.5f },
176
             {-1.5f, 0.0f,-1.5f }
177
         };
178
      }
179

    
180
    return mCenters;
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
186
    {
187
    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} };
188
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
189
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
190
    int[] bandIndices   = new int[] { 0,0,1,1 };
191
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
192
    int[] cornerIndices = new int[] { 0,0,1,1 };
193
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
194
    int[] centerIndices = new int[] { 0,0,0,0 };
195
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
196
    }
197

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

    
200
  protected Static4D getQuat(int cubit, int[] numLayers)
201
    {
202
    if( mQuats==null ) initializeQuats();
203
    return mQuats[cubit];
204
    }
205

    
206
///////////////////////////////////////////////////////////////////////////////////////////////////
207

    
208
  protected int getNumCubitVariants(int[] numLayers)
209
    {
210
    return 1;
211
    }
212

    
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214

    
215
  protected int getCubitVariant(int cubit, int[] numLayers)
216
    {
217
    return 0;
218
    }
219

    
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221

    
222
  protected ObjectSticker retSticker(int face)
223
    {
224
    if( mStickers==null )
225
      {
226
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
227
      float radius = 0.025f;
228
      float stroke = 0.050f;
229
      float[] radii = new float[] {radius,radius,radius};
230

    
231
      if( ObjectControl.isInIconMode() )
232
        {
233
        stroke*=1.5f;
234
        }
235

    
236
      mStickers     = new ObjectSticker[STICKERS.length];
237
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
238
      }
239

    
240
    return mStickers[face/NUM_FACE_COLORS];
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244
// PUBLIC API
245

    
246
  public Static3D[] getRotationAxis()
247
    {
248
    return ROT_AXIS;
249
    }
250

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

    
253
  public Movement getMovement()
254
    {
255
    if( mMovement==null )
256
      {
257
      int[] numLayers = getNumLayers();
258
      if( mCuts==null ) getCuts(numLayers);
259
      getLayerRotatable(numLayers);
260
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers[0],TYPE_SPLIT_CORNER,ENABLED);
261
      }
262
    return mMovement;
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  public int[] getBasicAngle()
268
    {
269
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
270
    return mBasicAngle;
271
    }
272

    
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274

    
275
  public int getComplexity(int[] numLayers)
276
    {
277
    return 2;
278
    }
279
}
(8-8/25)