Project

General

Profile

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

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

1 29b82486 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.objectlib.objects;
21
22 59c20632 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
23 29b82486 Leszek Koltunski
import static org.distorted.objectlib.main.Movement.TYPE_SPLIT_CORNER;
24
25
import android.content.res.Resources;
26
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
33 4e1dc313 Leszek Koltunski
import org.distorted.objectlib.R;
34 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
35
import org.distorted.objectlib.helpers.ObjectSticker;
36
import org.distorted.objectlib.helpers.ScrambleState;
37 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
38 29b82486 Leszek Koltunski
import org.distorted.objectlib.main.Twisty6;
39
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42
abstract class TwistyDino extends Twisty6
43
{
44
  // the four rotation axis of a RubikDino. Must be normalized.
45
  static final Static3D[] ROT_AXIS = new Static3D[]
46
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
51
         };
52
53
  private int[] mBasicAngle;
54
  private Static4D[] mQuats;
55
  private float[][] mCuts;
56
  private ObjectSticker[] mStickers;
57
  private float[][] mCenters;
58
  ScrambleState[] mStates;
59
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61
62 a57e6870 Leszek Koltunski
  TwistyDino(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
63 e7daa161 Leszek Koltunski
             MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
64 29b82486 Leszek Koltunski
    {
65 e7daa161 Leszek Koltunski
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
66 29b82486 Leszek Koltunski
    }
67
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69
70
  private void initializeQuats()
71
    {
72
    mQuats = new Static4D[]
73
         {
74
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
75
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
76
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
77
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
78
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
79
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
80
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
81
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
82
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
83
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
84
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
85
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
86
         };
87
    }
88
89 4e1dc313 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
90
91 a57e6870 Leszek Koltunski
  protected int getResource(int[] numLayers)
92 4e1dc313 Leszek Koltunski
    {
93
    return R.raw.dino;
94
    }
95
96 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
  protected Static4D[] getQuats()
99
    {
100
    if( mQuats==null ) initializeQuats();
101
    return mQuats;
102
    }
103
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
106 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
107 29b82486 Leszek Koltunski
    {
108
    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 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
120 29b82486 Leszek Koltunski
    {
121 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
122
    boolean[] tmp = new boolean[] {true,false,true};
123
    boolean[][] layerRotatable = new boolean[numAxis][];
124
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
125
126
    return layerRotatable;
127
    }
128
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130
131
  public int getMovementType()
132
    {
133
    return MOVEMENT_HEXAHEDRON;
134
    }
135
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137
138
  public int getMovementSplit()
139
    {
140
    return TYPE_SPLIT_CORNER;
141
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
  public int[][][] getEnabled()
146
    {
147
    return new int[][][]
148 29b82486 Leszek Koltunski
      {
149 59c20632 Leszek Koltunski
          {{0,1},{3,1},{2,3},{0,2}},
150
          {{2,3},{3,1},{0,1},{0,2}},
151
          {{1,2},{0,1},{0,3},{2,3}},
152
          {{1,2},{2,3},{0,3},{0,1}},
153
          {{0,3},{0,2},{1,2},{1,3}},
154
          {{1,2},{0,2},{0,3},{1,3}},
155
      };
156
    }
157
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160
  public float[] getDist3D(int[] numLayers)
161
    {
162
    return null;
163 29b82486 Leszek Koltunski
    }
164
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
167 a57e6870 Leszek Koltunski
  protected int getNumStickerTypes(int[] numLayers)
168 29b82486 Leszek Koltunski
    {
169
    return 1;
170
    }
171
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174
  protected int getNumCubitFaces()
175
    {
176
    return 4;
177
    }
178
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180
181 a57e6870 Leszek Koltunski
  protected float[][] getCubitPositions(int[] numLayers)
182 29b82486 Leszek Koltunski
    {
183
    if( mCenters ==null )
184
      {
185
      mCenters = new float[][]
186
         {
187
             { 0.0f, 1.5f, 1.5f },
188
             { 1.5f, 0.0f, 1.5f },
189
             { 0.0f,-1.5f, 1.5f },
190
             {-1.5f, 0.0f, 1.5f },
191
             { 1.5f, 1.5f, 0.0f },
192
             { 1.5f,-1.5f, 0.0f },
193
             {-1.5f,-1.5f, 0.0f },
194
             {-1.5f, 1.5f, 0.0f },
195
             { 0.0f, 1.5f,-1.5f },
196
             { 1.5f, 0.0f,-1.5f },
197
             { 0.0f,-1.5f,-1.5f },
198
             {-1.5f, 0.0f,-1.5f }
199
         };
200
      }
201
202
    return mCenters;
203
    }
204
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206
207 a57e6870 Leszek Koltunski
  protected ObjectShape getObjectShape(int cubit, int[] numLayers)
208 29b82486 Leszek Koltunski
    {
209
    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} };
210
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
211
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
212
    int[] bandIndices   = new int[] { 0,0,1,1 };
213
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
214
    int[] cornerIndices = new int[] { 0,0,1,1 };
215
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
216
    int[] centerIndices = new int[] { 0,0,0,0 };
217
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
218
    }
219
220
///////////////////////////////////////////////////////////////////////////////////////////////////
221
222 a57e6870 Leszek Koltunski
  protected Static4D getQuat(int cubit, int[] numLayers)
223 29b82486 Leszek Koltunski
    {
224
    if( mQuats==null ) initializeQuats();
225
    return mQuats[cubit];
226
    }
227
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
230 a57e6870 Leszek Koltunski
  protected int getNumCubitVariants(int[] numLayers)
231 29b82486 Leszek Koltunski
    {
232
    return 1;
233
    }
234
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236
237 a57e6870 Leszek Koltunski
  protected int getCubitVariant(int cubit, int[] numLayers)
238 29b82486 Leszek Koltunski
    {
239
    return 0;
240
    }
241
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  protected ObjectSticker retSticker(int face)
245
    {
246
    if( mStickers==null )
247
      {
248
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
249
      float radius = 0.025f;
250
      float stroke = 0.050f;
251
      float[] radii = new float[] {radius,radius,radius};
252 8592461c Leszek Koltunski
253
      if( ObjectControl.isInIconMode() )
254
        {
255
        stroke*=1.5f;
256
        }
257
258 29b82486 Leszek Koltunski
      mStickers     = new ObjectSticker[STICKERS.length];
259
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
260
      }
261
262
    return mStickers[face/NUM_FACE_COLORS];
263
    }
264
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266
// PUBLIC API
267
268
  public Static3D[] getRotationAxis()
269
    {
270
    return ROT_AXIS;
271
    }
272
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274
275
  public int[] getBasicAngle()
276
    {
277
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
278
    return mBasicAngle;
279
    }
280
281
///////////////////////////////////////////////////////////////////////////////////////////////////
282
283 a57e6870 Leszek Koltunski
  public int getComplexity(int[] numLayers)
284 29b82486 Leszek Koltunski
    {
285
    return 2;
286
    }
287
}