Project

General

Profile

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

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

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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25
26 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28 8f53e513 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
29 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
33 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 9c2f0c91 Leszek Koltunski
public abstract class TwistyDino extends TwistyObject
39 418aa554 Leszek Koltunski
{
40
  // the four rotation axis of a RubikDino. Must be normalized.
41 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
42 418aa554 Leszek Koltunski
         {
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 static final int[] FACE_COLORS = new int[]
50
         {
51 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
52
           COLOR_BLUE  , COLOR_GREEN,
53 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
54 418aa554 Leszek Koltunski
         };
55
56
  // All legal rotation quats of a RubikDino
57 eaee1ddc Leszek Koltunski
  static final Static4D[] QUATS = new Static4D[]
58 418aa554 Leszek Koltunski
         {
59
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
60 380162cb Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
61 8f53e513 Leszek Koltunski
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
62 380162cb Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
63 418aa554 Leszek Koltunski
           new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
64
           new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
65
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
66 8f53e513 Leszek Koltunski
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
67 380162cb Leszek Koltunski
           new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
68
           new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
69
           new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
70
           new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
71 8f53e513 Leszek Koltunski
         };
72
73
  // centers of the 12 edges. Must be in the same order like QUATs above.
74 e6cf7283 Leszek Koltunski
  private static final float[][] CENTERS = new float[][]
75 8f53e513 Leszek Koltunski
         {
76 e6cf7283 Leszek Koltunski
             { 0.0f, 1.5f, 1.5f },
77
             { 1.5f, 0.0f, 1.5f },
78
             { 0.0f,-1.5f, 1.5f },
79
             {-1.5f, 0.0f, 1.5f },
80
             { 1.5f, 1.5f, 0.0f },
81
             { 1.5f,-1.5f, 0.0f },
82
             {-1.5f,-1.5f, 0.0f },
83
             {-1.5f, 1.5f, 0.0f },
84
             { 0.0f, 1.5f,-1.5f },
85
             { 1.5f, 0.0f,-1.5f },
86
             { 0.0f,-1.5f,-1.5f },
87
             {-1.5f, 0.0f,-1.5f }
88 418aa554 Leszek Koltunski
         };
89
90 596d62a4 Leszek Koltunski
  private static final double[][] VERTICES = new double[][]
91 b1f2ccf5 Leszek Koltunski
          {
92 596d62a4 Leszek Koltunski
             {-1.5, 0.0, 0.0},
93
             { 1.5, 0.0, 0.0},
94
             { 0.0,-1.5, 0.0},
95
             { 0.0, 0.0,-1.5}
96 b1f2ccf5 Leszek Koltunski
          };
97
98 596d62a4 Leszek Koltunski
  private static final int[][] VERT_INDEXES = new int[][]
99 b1f2ccf5 Leszek Koltunski
          {
100
             {2,1,0},   // counterclockwise!
101 596d62a4 Leszek Koltunski
             {3,0,1},
102 b1f2ccf5 Leszek Koltunski
             {2,3,1},
103
             {3,2,0},
104
          };
105
106 596d62a4 Leszek Koltunski
  private static final float[][] STICKERS = new float[][]
107
          {
108
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
109
          };
110
111
  private static MeshBase[] mMeshes;
112 418aa554 Leszek Koltunski
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114
115 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
116
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
117 418aa554 Leszek Koltunski
    {
118 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
119 418aa554 Leszek Koltunski
    }
120
121 b1f2ccf5 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
122
123
  double[][] getVertices(int cubitType)
124
    {
125
    return VERTICES;
126
    }
127
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129
130
  int[][] getVertIndexes(int cubitType)
131
    {
132
    return VERT_INDEXES;
133
    }
134
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137
  int getNumCubitTypes(int numLayers)
138
    {
139
    return 1;
140
    }
141
142 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144
  float getScreenRatio()
145
    {
146 c7e79b69 Leszek Koltunski
    return 0.5f;
147 418aa554 Leszek Koltunski
    }
148
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150
151
  Static4D[] getQuats()
152
    {
153
    return QUATS;
154
    }
155
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157
158
  int getNumFaces()
159
    {
160
    return FACE_COLORS.length;
161
    }
162
163 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
164
165 a97e02b7 Leszek Koltunski
  float[] getCuts(int size)
166 7403cdfa Leszek Koltunski
    {
167 80ec6abf Leszek Koltunski
    return new float[] { -SQ3/3, +SQ3/3 };
168 7403cdfa Leszek Koltunski
    }
169
170 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
171
172 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
173 eab9d8f8 Leszek Koltunski
    {
174 596d62a4 Leszek Koltunski
    return STICKERS.length;
175 eab9d8f8 Leszek Koltunski
    }
176
177 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
178
179 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
180 418aa554 Leszek Koltunski
    {
181 8f53e513 Leszek Koltunski
    return 4;
182
    }
183
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185 418aa554 Leszek Koltunski
186 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
187 8f53e513 Leszek Koltunski
    {
188
    return CENTERS;
189 418aa554 Leszek Koltunski
    }
190
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192
193 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
194 418aa554 Leszek Koltunski
    {
195 596d62a4 Leszek Koltunski
    if( mMeshes==null )
196
      {
197
      FactoryCubit factory = FactoryCubit.getInstance();
198
      factory.clear();
199
      mMeshes = new MeshBase[1];
200
      }
201
202
    if( mMeshes[0]==null )
203
      {
204
      float[][] bands= new float[][]
205
          {
206
             {0.035f,30,0.16f,0.8f,7,2,5},
207
             {0.020f,45,0.16f,0.2f,3,1,2}
208
          };
209
      int[] bandIndexes   = new int[] { 0,0,1,1 };
210
      float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
211
      int[] cornerIndexes = new int[] { 0,0,1,1 };
212 b3c9061a Leszek Koltunski
      float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
213
      int[] centerIndexes = new int[] { 0,0,0,0 };
214 596d62a4 Leszek Koltunski
215
      FactoryCubit factory = FactoryCubit.getInstance();
216
217
      factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
218
      mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
219
                                              bands, bandIndexes,
220
                                              corners, cornerIndexes,
221 b3c9061a Leszek Koltunski
                                              centers, centerIndexes,
222 596d62a4 Leszek Koltunski
                                              getNumCubitFaces() );
223
      }
224 8f53e513 Leszek Koltunski
225 596d62a4 Leszek Koltunski
    MeshBase mesh = mMeshes[0].copy(true);
226 8f53e513 Leszek Koltunski
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
227
    mesh.apply(quat,0xffffffff,0);
228 418aa554 Leszek Koltunski
229 8f53e513 Leszek Koltunski
    return mesh;
230 418aa554 Leszek Koltunski
    }
231
232
///////////////////////////////////////////////////////////////////////////////////////////////////
233
234 ae755eda Leszek Koltunski
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
235 418aa554 Leszek Koltunski
    {
236 2fcfce81 Leszek Koltunski
    float R = 0.025f;
237 76c2bd07 Leszek Koltunski
    float S = 0.05f;
238
239 b89898c5 Leszek Koltunski
    FactorySticker factory = FactorySticker.getInstance();
240 596d62a4 Leszek Koltunski
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
241 418aa554 Leszek Koltunski
    }
242
243 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
244
245
  float returnMultiplier()
246
    {
247
    return 2.0f;
248
    }
249
250 7c969a6d Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
251
252 a64e07d0 Leszek Koltunski
  float[] getRowChances(int numLayers)
253 7c969a6d Leszek Koltunski
    {
254
    float[] chances = new float[3];
255
256
    chances[0] = 0.5f;
257
    chances[1] = 0.5f;
258
    chances[2] = 1.0f;
259
260
    return chances;
261
    }
262
263 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
264
// PUBLIC API
265
266
  public Static3D[] getRotationAxis()
267
    {
268 ad38d800 Leszek Koltunski
    return ROT_AXIS;
269 418aa554 Leszek Koltunski
    }
270
271
///////////////////////////////////////////////////////////////////////////////////////////////////
272
273
  public int getBasicAngle()
274
    {
275
    return 3;
276
    }
277
278
///////////////////////////////////////////////////////////////////////////////////////////////////
279 ee35e63c Leszek Koltunski
// only needed for solvers - there are no Dino solvers ATM)
280 418aa554 Leszek Koltunski
281
  public String retObjectString()
282
    {
283
    return "";
284
    }
285 6fd4a72c Leszek Koltunski
286
///////////////////////////////////////////////////////////////////////////////////////////////////
287
288
  public int getComplexity(int numLayers)
289
    {
290
    return 2;
291
    }
292 418aa554 Leszek Koltunski
}