Project

General

Profile

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

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

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