Project

General

Profile

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

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

1 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 967c1d17 Leszek Koltunski
import static org.distorted.objects.Movement.TYPE_SPLIT_CORNER;
23
24 418aa554 Leszek Koltunski
import android.content.res.Resources;
25
26 f10a88a8 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
27 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
28 6cf89a3e Leszek Koltunski
import org.distorted.helpers.ScrambleState;
29 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
32 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37 efa81f0c Leszek Koltunski
public abstract class TwistyDino extends Twisty6
38 418aa554 Leszek Koltunski
{
39
  // the four rotation axis of a RubikDino. Must be normalized.
40 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
41 418aa554 Leszek Koltunski
         {
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 967c1d17 Leszek Koltunski
  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 d464f54f Leszek Koltunski
  private int[] mBasicAngle;
59
  private Static4D[] mQuats;
60 ef018c1b Leszek Koltunski
  private float[][] mCuts;
61
  private boolean[][] mLayerRotatable;
62 d464f54f Leszek Koltunski
  private ObjectSticker[] mStickers;
63 85449b44 Leszek Koltunski
  private float[][] mCenters;
64 e9a87113 Leszek Koltunski
  private Movement mMovement;
65 d464f54f Leszek Koltunski
  ScrambleState[] mStates;
66 20898e6f Leszek Koltunski
67 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
70
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
71 418aa554 Leszek Koltunski
    {
72 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
73 418aa554 Leszek Koltunski
    }
74
75 d464f54f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
  Static4D[] getQuats()
99
    {
100 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
101
    return mQuats;
102 418aa554 Leszek Koltunski
    }
103
104 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
105
106 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
107 7403cdfa Leszek Koltunski
    {
108 ef018c1b Leszek Koltunski
    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 7403cdfa Leszek Koltunski
    }
129
130 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
133 eab9d8f8 Leszek Koltunski
    {
134 d464f54f Leszek Koltunski
    return 1;
135 eab9d8f8 Leszek Koltunski
    }
136
137 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
138
139 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
140 418aa554 Leszek Koltunski
    {
141 8f53e513 Leszek Koltunski
    return 4;
142
    }
143
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145 418aa554 Leszek Koltunski
146 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
147 8f53e513 Leszek Koltunski
    {
148 d464f54f Leszek Koltunski
    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 418aa554 Leszek Koltunski
    }
169
170 f10a88a8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172 3e605536 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
173 f10a88a8 Leszek Koltunski
    {
174 d464f54f Leszek Koltunski
    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 3e605536 Leszek Koltunski
    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 d464f54f Leszek Koltunski
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
183 f10a88a8 Leszek Koltunski
    }
184
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186
187 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
188 f10a88a8 Leszek Koltunski
    {
189 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
190
    return mQuats[cubit];
191 f10a88a8 Leszek Koltunski
    }
192
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
195 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
196 f10a88a8 Leszek Koltunski
    {
197 3e605536 Leszek Koltunski
    return 1;
198 f10a88a8 Leszek Koltunski
    }
199
200 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
201
202 3e605536 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
203 418aa554 Leszek Koltunski
    {
204 3e605536 Leszek Koltunski
    return 0;
205 418aa554 Leszek Koltunski
    }
206
207 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
208
209
  ObjectSticker retSticker(int face)
210
    {
211 d464f54f Leszek Koltunski
    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 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
222 418aa554 Leszek Koltunski
    }
223
224
///////////////////////////////////////////////////////////////////////////////////////////////////
225
// PUBLIC API
226
227
  public Static3D[] getRotationAxis()
228
    {
229 ad38d800 Leszek Koltunski
    return ROT_AXIS;
230 418aa554 Leszek Koltunski
    }
231
232 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234
  public Movement getMovement()
235
    {
236 ef018c1b Leszek Koltunski
    if( mMovement==null )
237
      {
238
      int numLayers = getNumLayers();
239
      if( mCuts==null ) getCuts(numLayers);
240
      getLayerRotatable(numLayers);
241 7ee89540 Leszek Koltunski
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,ENABLED);
242 ef018c1b Leszek Koltunski
      }
243 e9a87113 Leszek Koltunski
    return mMovement;
244
    }
245
246 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
247
248 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
249 418aa554 Leszek Koltunski
    {
250 d464f54f Leszek Koltunski
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
251
    return mBasicAngle;
252 418aa554 Leszek Koltunski
    }
253
254 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
255
256
  public int getComplexity(int numLayers)
257
    {
258
    return 2;
259
    }
260 418aa554 Leszek Koltunski
}