Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ ef018c1b

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