Project

General

Profile

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

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

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.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.RubikSurfaceView;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

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

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

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

    
89
  private static MeshBase mMesh;
90

    
91
///////////////////////////////////////////////////////////////////////////////////////////////////
92

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
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
///////////////////////////////////////////////////////////////////////////////////////////////////
140

    
141
  float getScreenRatio()
142
    {
143
    return 0.5f;
144
    }
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
///////////////////////////////////////////////////////////////////////////////////////////////////
161

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

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  int getNumStickerTypes(int numLayers)
170
    {
171
    return 1;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  int getNumCubitFaces()
177
    {
178
    return 4;
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

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

    
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189

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

    
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

    
198
    return mesh;
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

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

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

    
214
///////////////////////////////////////////////////////////////////////////////////////////////////
215

    
216
  float returnMultiplier()
217
    {
218
    return 2.0f;
219
    }
220

    
221
///////////////////////////////////////////////////////////////////////////////////////////////////
222

    
223
  float[] getRowChances(int numLayers)
224
    {
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
///////////////////////////////////////////////////////////////////////////////////////////////////
235
// PUBLIC API
236

    
237
  public Static3D[] getRotationAxis()
238
    {
239
    return ROT_AXIS;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243

    
244
  public int getBasicAngle()
245
    {
246
    return 3;
247
    }
248

    
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250
// only needed for solvers - there are no Dino solvers ATM)
251

    
252
  public String retObjectString()
253
    {
254
    return "";
255
    }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258

    
259
  public int getComplexity(int numLayers)
260
    {
261
    return 2;
262
    }
263
}
(23-23/35)