Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 121e4a39

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

    
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

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

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

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

    
90
  private static final double[][] VERTICES = new double[][]
91
          {
92
             {-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
          };
97

    
98
  private static final int[][] VERT_INDEXES = new int[][]
99
          {
100
             {2,1,0},   // counterclockwise!
101
             {3,0,1},
102
             {2,3,1},
103
             {3,2,0},
104
          };
105

    
106
  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

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
116
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
117
    {
118
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  float getScreenRatio()
124
    {
125
    return 0.5f;
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  Static4D[] getQuats()
131
    {
132
    return QUATS;
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136

    
137
  int getNumFaces()
138
    {
139
    return FACE_COLORS.length;
140
    }
141

    
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

    
144
  float[] getCuts(int size)
145
    {
146
    return new float[] { -SQ3/3, +SQ3/3 };
147
    }
148

    
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

    
151
  int getNumStickerTypes(int numLayers)
152
    {
153
    return STICKERS.length;
154
    }
155

    
156
///////////////////////////////////////////////////////////////////////////////////////////////////
157

    
158
  int getNumCubitFaces()
159
    {
160
    return 4;
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  float[][] getCubitPositions(int size)
166
    {
167
    return CENTERS;
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  MeshBase createCubitMesh(int cubit, int numLayers)
173
    {
174
    if( mMeshes==null )
175
      {
176
      FactoryCubit factory = FactoryCubit.getInstance();
177
      factory.clear();
178
      mMeshes = new MeshBase[1];
179
      }
180

    
181
    if( mMeshes[0]==null )
182
      {
183
      float[][] bands= new float[][]
184
          {
185
             {0.035f,30,0.16f,0.8f,7,2,5},
186
             {0.020f,45,0.16f,0.2f,3,1,2}
187
          };
188
      int[] bandIndexes   = new int[] { 0,0,1,1 };
189
      float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
190
      int[] cornerIndexes = new int[] { 0,0,1,1 };
191
      float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
192
      int[] centerIndexes = new int[] { 0,0,0,0 };
193

    
194
      FactoryCubit factory = FactoryCubit.getInstance();
195

    
196
      factory.createNewFaceTransform(VERTICES,VERT_INDEXES);
197
      mMeshes[0] = factory.createRoundedSolid(VERTICES, VERT_INDEXES,
198
                                              bands, bandIndexes,
199
                                              corners, cornerIndexes,
200
                                              centers, centerIndexes,
201
                                              getNumCubitFaces() );
202
      }
203

    
204
    MeshBase mesh = mMeshes[0].copy(true);
205
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[cubit], new Static3D(0,0,0) );
206
    mesh.apply(quat,0xffffffff,0);
207

    
208
    return mesh;
209
    }
210

    
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

    
213
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
214
    {
215
    float R = 0.025f;
216
    float S = 0.05f;
217

    
218
    FactorySticker factory = FactorySticker.getInstance();
219
    factory.drawRoundedPolygon(canvas, paint, left, top, STICKERS[0], S, FACE_COLORS[face], R);
220
    }
221

    
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223

    
224
  float returnMultiplier()
225
    {
226
    return 2.0f;
227
    }
228

    
229
///////////////////////////////////////////////////////////////////////////////////////////////////
230

    
231
  float[] getRowChances(int numLayers)
232
    {
233
    float[] chances = new float[3];
234

    
235
    chances[0] = 0.5f;
236
    chances[1] = 0.5f;
237
    chances[2] = 1.0f;
238

    
239
    return chances;
240
    }
241

    
242
///////////////////////////////////////////////////////////////////////////////////////////////////
243
// PUBLIC API
244

    
245
  public Static3D[] getRotationAxis()
246
    {
247
    return ROT_AXIS;
248
    }
249

    
250
///////////////////////////////////////////////////////////////////////////////////////////////////
251

    
252
  public int getBasicAngle()
253
    {
254
    return 3;
255
    }
256

    
257
///////////////////////////////////////////////////////////////////////////////////////////////////
258
// only needed for solvers - there are no Dino solvers ATM)
259

    
260
  public String retObjectString()
261
    {
262
    return "";
263
    }
264

    
265
///////////////////////////////////////////////////////////////////////////////////////////////////
266

    
267
  public int getComplexity(int numLayers)
268
    {
269
    return 2;
270
    }
271
}
(21-21/33)