Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 967c1d17

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[] NUM_ENABLED = {2,2,2,2,2,2};
49
50
  private static final int[][][] ENABLED = new int[][][]
51
      {
52
          {{0,1},{3,1},{2,3},{0,2}},
53
          {{2,3},{3,1},{0,1},{0,2}},
54
          {{1,2},{0,1},{0,3},{2,3}},
55
          {{1,2},{2,3},{0,3},{0,1}},
56
          {{0,3},{0,2},{1,2},{1,3}},
57
          {{1,2},{0,2},{0,3},{1,3}},
58
      };
59
60 d464f54f Leszek Koltunski
  private int[] mBasicAngle;
61
  private Static4D[] mQuats;
62 ef018c1b Leszek Koltunski
  private float[][] mCuts;
63
  private boolean[][] mLayerRotatable;
64 d464f54f Leszek Koltunski
  private ObjectSticker[] mStickers;
65 85449b44 Leszek Koltunski
  private float[][] mCenters;
66 e9a87113 Leszek Koltunski
  private Movement mMovement;
67 d464f54f Leszek Koltunski
  ScrambleState[] mStates;
68 20898e6f Leszek Koltunski
69 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
70
71 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
72
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
73 418aa554 Leszek Koltunski
    {
74 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
75 418aa554 Leszek Koltunski
    }
76
77 d464f54f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79
  private void initializeQuats()
80
    {
81
    mQuats = new Static4D[]
82
         {
83
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
84
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
85
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
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.5f, -0.5f,  0.5f, -0.5f ),
90
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
91
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
92
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
93
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
94
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
95
         };
96
    }
97
98 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
99
100
  Static4D[] getQuats()
101
    {
102 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
103
    return mQuats;
104 418aa554 Leszek Koltunski
    }
105
106 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
107
108 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
109 7403cdfa Leszek Koltunski
    {
110 ef018c1b Leszek Koltunski
    if( mCuts==null )
111
      {
112
      float[] cut = new float[] { -SQ3/3, +SQ3/3 };
113
      mCuts = new float[][] { cut,cut,cut,cut };
114
      }
115
116
    return mCuts;
117
    }
118
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120
121
  private void getLayerRotatable(int numLayers)
122
    {
123
    if( mLayerRotatable==null )
124
      {
125
      int numAxis = ROT_AXIS.length;
126
      boolean[] tmp = new boolean[] {true,false,true};
127
      mLayerRotatable = new boolean[numAxis][];
128
      for(int i=0; i<numAxis; i++) mLayerRotatable[i] = tmp;
129
      }
130 7403cdfa Leszek Koltunski
    }
131
132 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
133
134 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
135 eab9d8f8 Leszek Koltunski
    {
136 d464f54f Leszek Koltunski
    return 1;
137 eab9d8f8 Leszek Koltunski
    }
138
139 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
140
141 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
142 418aa554 Leszek Koltunski
    {
143 8f53e513 Leszek Koltunski
    return 4;
144
    }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147 418aa554 Leszek Koltunski
148 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
149 8f53e513 Leszek Koltunski
    {
150 d464f54f Leszek Koltunski
    if( mCenters ==null )
151
      {
152
      mCenters = new float[][]
153
         {
154
             { 0.0f, 1.5f, 1.5f },
155
             { 1.5f, 0.0f, 1.5f },
156
             { 0.0f,-1.5f, 1.5f },
157
             {-1.5f, 0.0f, 1.5f },
158
             { 1.5f, 1.5f, 0.0f },
159
             { 1.5f,-1.5f, 0.0f },
160
             {-1.5f,-1.5f, 0.0f },
161
             {-1.5f, 1.5f, 0.0f },
162
             { 0.0f, 1.5f,-1.5f },
163
             { 1.5f, 0.0f,-1.5f },
164
             { 0.0f,-1.5f,-1.5f },
165
             {-1.5f, 0.0f,-1.5f }
166
         };
167
      }
168
169
    return mCenters;
170 418aa554 Leszek Koltunski
    }
171
172 f10a88a8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174 3e605536 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
175 f10a88a8 Leszek Koltunski
    {
176 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} };
177
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
178 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} };
179
    int[] bandIndices   = new int[] { 0,0,1,1 };
180
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
181
    int[] cornerIndices = new int[] { 0,0,1,1 };
182
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
183
    int[] centerIndices = new int[] { 0,0,0,0 };
184 d464f54f Leszek Koltunski
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
185 f10a88a8 Leszek Koltunski
    }
186
187
///////////////////////////////////////////////////////////////////////////////////////////////////
188
189 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
190 f10a88a8 Leszek Koltunski
    {
191 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
192
    return mQuats[cubit];
193 f10a88a8 Leszek Koltunski
    }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
197 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
198 f10a88a8 Leszek Koltunski
    {
199 3e605536 Leszek Koltunski
    return 1;
200 f10a88a8 Leszek Koltunski
    }
201
202 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
203
204 3e605536 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
205 418aa554 Leszek Koltunski
    {
206 3e605536 Leszek Koltunski
    return 0;
207 418aa554 Leszek Koltunski
    }
208
209 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
210
211
  ObjectSticker retSticker(int face)
212
    {
213 d464f54f Leszek Koltunski
    if( mStickers==null )
214
      {
215
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
216
      float radius = 0.025f;
217
      float stroke = 0.050f;
218
      float[] radii = new float[] {radius,radius,radius};
219
      mStickers     = new ObjectSticker[STICKERS.length];
220
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
221
      }
222
223 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
224 418aa554 Leszek Koltunski
    }
225
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227
// PUBLIC API
228
229
  public Static3D[] getRotationAxis()
230
    {
231 ad38d800 Leszek Koltunski
    return ROT_AXIS;
232 418aa554 Leszek Koltunski
    }
233
234 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
235
236
  public Movement getMovement()
237
    {
238 ef018c1b Leszek Koltunski
    if( mMovement==null )
239
      {
240
      int numLayers = getNumLayers();
241
      if( mCuts==null ) getCuts(numLayers);
242
      getLayerRotatable(numLayers);
243 967c1d17 Leszek Koltunski
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_SPLIT_CORNER,NUM_ENABLED,ENABLED);
244 ef018c1b Leszek Koltunski
      }
245 e9a87113 Leszek Koltunski
    return mMovement;
246
    }
247
248 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
249
250 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
251 418aa554 Leszek Koltunski
    {
252 d464f54f Leszek Koltunski
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
253
    return mBasicAngle;
254 418aa554 Leszek Koltunski
    }
255
256 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
257
258
  public int getComplexity(int numLayers)
259
    {
260
    return 2;
261
    }
262 418aa554 Leszek Koltunski
}