Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistyDino.java @ 11fa413d

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 c9c71c3f Leszek Koltunski
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
23
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
24 29b82486 Leszek Koltunski
25 82eb152a Leszek Koltunski
import java.io.InputStream;
26 29b82486 Leszek Koltunski
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
30 198c5bf0 Leszek Koltunski
import org.distorted.objectlib.helpers.ObjectShape;
31
import org.distorted.objectlib.helpers.ObjectSticker;
32
import org.distorted.objectlib.helpers.ScrambleState;
33 8592461c Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
34 386af988 Leszek Koltunski
import org.distorted.objectlib.main.ShapeHexahedron;
35 29b82486 Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 386af988 Leszek Koltunski
abstract class TwistyDino extends ShapeHexahedron
39 29b82486 Leszek Koltunski
{
40
  // the four rotation axis of a RubikDino. Must be normalized.
41
  static final Static3D[] ROT_AXIS = new Static3D[]
42
         {
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
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
47
         };
48
49
  private int[] mBasicAngle;
50
  private Static4D[] mQuats;
51
  private float[][] mCuts;
52
  private ObjectSticker[] mStickers;
53
  private float[][] mCenters;
54
  ScrambleState[] mStates;
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58 64c209f5 Leszek Koltunski
  TwistyDino(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
59 29b82486 Leszek Koltunski
    {
60 64c209f5 Leszek Koltunski
    super(numL, numL[0], quat, move, scale, stream);
61 29b82486 Leszek Koltunski
    }
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 1bb09f88 Leszek Koltunski
  public Static4D[] getQuats()
87 29b82486 Leszek Koltunski
    {
88
    if( mQuats==null ) initializeQuats();
89
    return mQuats;
90
    }
91
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93
94 7bbfc84f Leszek Koltunski
  public float[][] getCuts(int[] numLayers)
95 29b82486 Leszek Koltunski
    {
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 59c20632 Leszek Koltunski
  public boolean[][] getLayerRotatable(int[] numLayers)
108 29b82486 Leszek Koltunski
    {
109 59c20632 Leszek Koltunski
    int numAxis = ROT_AXIS.length;
110
    boolean[] tmp = new boolean[] {true,false,true};
111
    boolean[][] layerRotatable = new boolean[numAxis][];
112
    for(int i=0; i<numAxis; i++) layerRotatable[i] = tmp;
113
114
    return layerRotatable;
115
    }
116
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118
119 11fa413d Leszek Koltunski
  public int getTouchControlType()
120 59c20632 Leszek Koltunski
    {
121 c9c71c3f Leszek Koltunski
    return TC_HEXAHEDRON;
122 59c20632 Leszek Koltunski
    }
123
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125
126 11fa413d Leszek Koltunski
  public int getTouchControlSplit()
127 59c20632 Leszek Koltunski
    {
128
    return TYPE_SPLIT_CORNER;
129
    }
130
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
133
  public int[][][] getEnabled()
134
    {
135
    return new int[][][]
136 29b82486 Leszek Koltunski
      {
137 59c20632 Leszek Koltunski
          {{0,1},{3,1},{2,3},{0,2}},
138
          {{2,3},{3,1},{0,1},{0,2}},
139
          {{1,2},{0,1},{0,3},{2,3}},
140
          {{1,2},{2,3},{0,3},{0,1}},
141
          {{0,3},{0,2},{1,2},{1,3}},
142
          {{1,2},{0,2},{0,3},{1,3}},
143
      };
144
    }
145
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147
148
  public float[] getDist3D(int[] numLayers)
149
    {
150
    return null;
151 29b82486 Leszek Koltunski
    }
152
153
///////////////////////////////////////////////////////////////////////////////////////////////////
154
155 1bb09f88 Leszek Koltunski
  public int getNumStickerTypes(int[] numLayers)
156 29b82486 Leszek Koltunski
    {
157
    return 1;
158
    }
159
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162 a75ae1ee Leszek Koltunski
  public int getNumCubitFaces()
163 29b82486 Leszek Koltunski
    {
164
    return 4;
165
    }
166
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168
169 7b832206 Leszek Koltunski
  public float[][] getCubitPositions(int[] numLayers)
170 29b82486 Leszek Koltunski
    {
171
    if( mCenters ==null )
172
      {
173
      mCenters = new float[][]
174
         {
175
             { 0.0f, 1.5f, 1.5f },
176
             { 1.5f, 0.0f, 1.5f },
177
             { 0.0f,-1.5f, 1.5f },
178
             {-1.5f, 0.0f, 1.5f },
179
             { 1.5f, 1.5f, 0.0f },
180
             { 1.5f,-1.5f, 0.0f },
181
             {-1.5f,-1.5f, 0.0f },
182
             {-1.5f, 1.5f, 0.0f },
183
             { 0.0f, 1.5f,-1.5f },
184
             { 1.5f, 0.0f,-1.5f },
185
             { 0.0f,-1.5f,-1.5f },
186
             {-1.5f, 0.0f,-1.5f }
187
         };
188
      }
189
190
    return mCenters;
191
    }
192
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194
195 e30c522a Leszek Koltunski
  public ObjectShape getObjectShape(int variant)
196 29b82486 Leszek Koltunski
    {
197 57ef6378 Leszek Koltunski
    float[][] vertices  = new float[][] { {-1.5f, 0.0f, 0.0f},{ 1.5f, 0.0f, 0.0f},{ 0.0f,-1.5f, 0.0f},{ 0.0f, 0.0f,-1.5f} };
198 29b82486 Leszek Koltunski
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
199
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
200
    int[] bandIndices   = new int[] { 0,0,1,1 };
201
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
202
    int[] cornerIndices = new int[] { 0,0,1,1 };
203
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
204
    int[] centerIndices = new int[] { 0,0,0,0 };
205
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
206
    }
207
208
///////////////////////////////////////////////////////////////////////////////////////////////////
209
210 7b832206 Leszek Koltunski
  public Static4D getQuat(int cubit, int[] numLayers)
211 29b82486 Leszek Koltunski
    {
212
    if( mQuats==null ) initializeQuats();
213
    return mQuats[cubit];
214
    }
215
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217
218 e30c522a Leszek Koltunski
  public int getNumCubitVariants(int[] numLayers)
219 29b82486 Leszek Koltunski
    {
220
    return 1;
221
    }
222
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224
225 e30c522a Leszek Koltunski
  public int getCubitVariant(int cubit, int[] numLayers)
226 29b82486 Leszek Koltunski
    {
227
    return 0;
228
    }
229
230 a75ae1ee Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
231
232
  public int getVariantFaceColor(int variant, int face, int[] numLayers)
233
    {
234
    return 0;
235
    }
236
237 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
238
239 1bb09f88 Leszek Koltunski
  public ObjectSticker retSticker(int sticker)
240 29b82486 Leszek Koltunski
    {
241
    if( mStickers==null )
242
      {
243
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
244
      float radius = 0.025f;
245
      float stroke = 0.050f;
246
      float[] radii = new float[] {radius,radius,radius};
247 8592461c Leszek Koltunski
248
      if( ObjectControl.isInIconMode() )
249
        {
250
        stroke*=1.5f;
251
        }
252
253 29b82486 Leszek Koltunski
      mStickers     = new ObjectSticker[STICKERS.length];
254
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
255
      }
256
257 1bb09f88 Leszek Koltunski
    return mStickers[sticker];
258
    }
259
260 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
261
// PUBLIC API
262
263
  public Static3D[] getRotationAxis()
264
    {
265
    return ROT_AXIS;
266
    }
267
268
///////////////////////////////////////////////////////////////////////////////////////////////////
269
270
  public int[] getBasicAngle()
271
    {
272
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
273
    return mBasicAngle;
274
    }
275
276
///////////////////////////////////////////////////////////////////////////////////////////////////
277
278 e26eb4e7 Leszek Koltunski
  public int getComplexity()
279 29b82486 Leszek Koltunski
    {
280
    return 2;
281
    }
282
}