Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 749ef882

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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

    
26
import org.distorted.helpers.FactoryCubit;
27
import org.distorted.helpers.FactorySticker;
28
import org.distorted.library.effect.MatrixEffectQuaternion;
29
import org.distorted.library.main.DistortedEffects;
30
import org.distorted.library.main.DistortedTexture;
31
import org.distorted.library.mesh.MeshBase;
32
import org.distorted.library.mesh.MeshSquare;
33
import org.distorted.library.type.Static3D;
34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.RubikSurfaceView;
36

    
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

    
39
public abstract class TwistyDino extends TwistyObject
40
{
41
  // the four rotation axis of a RubikDino. Must be normalized.
42
  static final Static3D[] ROT_AXIS = new Static3D[]
43
         {
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
           COLOR_YELLOW, COLOR_WHITE,
53
           COLOR_BLUE  , COLOR_GREEN,
54
           COLOR_RED   , COLOR_ORANGE
55
         };
56

    
57
  // All legal rotation quats of a RubikDino
58
  static final Static4D[] QUATS = new Static4D[]
59
         {
60
           new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
61
           new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
62
           new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
63
           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
           new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
67
           new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
68
           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
         };
73

    
74
  // centers of the 12 edges. Must be in the same order like QUATs above.
75
  private static final float[][] CENTERS = new float[][]
76
         {
77
             { 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
         };
90

    
91
  private static MeshBase mMesh;
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
96
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
97
    {
98
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102

    
103
  int mulQuat(int q1, int q2)
104
    {
105
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
106

    
107
    float rX = result.get0();
108
    float rY = result.get1();
109
    float rZ = result.get2();
110
    float rW = result.get3();
111

    
112
    final float MAX_ERROR = 0.1f;
113
    float dX,dY,dZ,dW;
114

    
115
    for(int i=0; i<QUATS.length; i++)
116
      {
117
      dX = QUATS[i].get0() - rX;
118
      dY = QUATS[i].get1() - rY;
119
      dZ = QUATS[i].get2() - rZ;
120
      dW = QUATS[i].get3() - rW;
121

    
122
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
123
          dY<MAX_ERROR && dY>-MAX_ERROR &&
124
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
125
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
126

    
127
      dX = QUATS[i].get0() + rX;
128
      dY = QUATS[i].get1() + rY;
129
      dZ = QUATS[i].get2() + rZ;
130
      dW = QUATS[i].get3() + rW;
131

    
132
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
133
          dY<MAX_ERROR && dY>-MAX_ERROR &&
134
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
135
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
136
      }
137

    
138
    return -1;
139
    }
140

    
141
///////////////////////////////////////////////////////////////////////////////////////////////////
142

    
143
  float getScreenRatio()
144
    {
145
    return 0.5f;
146
    }
147

    
148
///////////////////////////////////////////////////////////////////////////////////////////////////
149

    
150
  Static4D[] getQuats()
151
    {
152
    return QUATS;
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  int getNumFaces()
158
    {
159
    return FACE_COLORS.length;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  float[] getCuts(int size)
165
    {
166
    return new float[] { -SQ3/3, +SQ3/3 };
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  int getNumStickerTypes(int numLayers)
172
    {
173
    return 1;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  int getNumCubitFaces()
179
    {
180
    return 4;
181
    }
182

    
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

    
185
  float[][] getCubitPositions(int size)
186
    {
187
    return CENTERS;
188
    }
189

    
190
///////////////////////////////////////////////////////////////////////////////////////////////////
191

    
192
  MeshBase createCubitMesh(int cubit, int numLayers)
193
    {
194
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createDinoMesh();
195

    
196
    MeshBase mesh = mMesh.copy(true);
197
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
198
    mesh.apply(quat,0xffffffff,0);
199

    
200
    return mesh;
201
    }
202

    
203
///////////////////////////////////////////////////////////////////////////////////////////////////
204

    
205
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
206
    {
207
    float F = 0.5f;
208
    float R = 0.025f;
209
    float S = 0.05f;
210
    float[] vertices = { -F,F/3, 0,-2*F/3, +F,F/3 };
211

    
212
    FactorySticker factory = FactorySticker.getInstance();
213
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
214
    }
215

    
216
///////////////////////////////////////////////////////////////////////////////////////////////////
217

    
218
  float returnMultiplier()
219
    {
220
    return 2.0f;
221
    }
222

    
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

    
225
  float[] getRowChances(int numLayers)
226
    {
227
    float[] chances = new float[3];
228

    
229
    chances[0] = 0.5f;
230
    chances[1] = 0.5f;
231
    chances[2] = 1.0f;
232

    
233
    return chances;
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237
// PUBLIC API
238

    
239
  public Static3D[] getRotationAxis()
240
    {
241
    return ROT_AXIS;
242
    }
243

    
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245

    
246
  public int getBasicAngle()
247
    {
248
    return 3;
249
    }
250

    
251
///////////////////////////////////////////////////////////////////////////////////////////////////
252
// only needed for solvers - there are no Dino solvers ATM)
253

    
254
  public String retObjectString()
255
    {
256
    return "";
257
    }
258

    
259
///////////////////////////////////////////////////////////////////////////////////////////////////
260

    
261
  public int getComplexity(int numLayers)
262
    {
263
    return 2;
264
    }
265
}
(21-21/33)