Project

General

Profile

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

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

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.objects;
21

    
22
import android.content.res.Resources;
23

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.helpers.ScrambleState;
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
///////////////////////////////////////////////////////////////////////////////////////////////////
34

    
35
public abstract class TwistyDino extends Twisty6
36
{
37
  // the four rotation axis of a RubikDino. Must be normalized.
38
  static final Static3D[] ROT_AXIS = new Static3D[]
39
         {
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
  private int[] mBasicAngle;
47
  private Static4D[] mQuats;
48
  private float[][] mCuts;
49
  private boolean[][] mLayerRotatable;
50
  private ObjectSticker[] mStickers;
51
  private float[][] mCenters;
52
  private Movement mMovement;
53
  ScrambleState[] mStates;
54

    
55
///////////////////////////////////////////////////////////////////////////////////////////////////
56

    
57
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
58
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
59
    {
60
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
85

    
86
  Static4D[] getQuats()
87
    {
88
    if( mQuats==null ) initializeQuats();
89
    return mQuats;
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  float[][] getCuts(int size)
95
    {
96
    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
    }
117

    
118
///////////////////////////////////////////////////////////////////////////////////////////////////
119

    
120
  int getNumStickerTypes(int numLayers)
121
    {
122
    return 1;
123
    }
124

    
125
///////////////////////////////////////////////////////////////////////////////////////////////////
126

    
127
  int getNumCubitFaces()
128
    {
129
    return 4;
130
    }
131

    
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133

    
134
  float[][] getCubitPositions(int size)
135
    {
136
    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
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  ObjectShape getObjectShape(int cubit, int numLayers)
161
    {
162
    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
    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
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  Static4D getQuat(int cubit, int numLayers)
176
    {
177
    if( mQuats==null ) initializeQuats();
178
    return mQuats[cubit];
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  int getNumCubitVariants(int numLayers)
184
    {
185
    return 1;
186
    }
187

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

    
190
  int getCubitVariant(int cubit, int numLayers)
191
    {
192
    return 0;
193
    }
194

    
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196

    
197
  ObjectSticker retSticker(int face)
198
    {
199
    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
    return mStickers[face/NUM_FACE_COLORS];
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213
// PUBLIC API
214

    
215
  public Static3D[] getRotationAxis()
216
    {
217
    return ROT_AXIS;
218
    }
219

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

    
222
  public Movement getMovement()
223
    {
224
    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
    return mMovement;
233
    }
234

    
235
///////////////////////////////////////////////////////////////////////////////////////////////////
236

    
237
  public int[] getBasicAngle()
238
    {
239
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
240
    return mBasicAngle;
241
    }
242

    
243
///////////////////////////////////////////////////////////////////////////////////////////////////
244

    
245
  public int getComplexity(int numLayers)
246
    {
247
    return 2;
248
    }
249
}
(29-29/48)