Project

General

Profile

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

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

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