Project

General

Profile

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

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

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
24 749ef882 Leszek Koltunski
import org.distorted.helpers.FactoryCubit;
25 f10a88a8 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
26 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
27 8f53e513 Leszek Koltunski
import org.distorted.library.effect.MatrixEffectQuaternion;
28 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
29
import org.distorted.library.main.DistortedTexture;
30
import org.distorted.library.mesh.MeshBase;
31 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
32 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
33
import org.distorted.library.type.Static4D;
34
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 925ed78f Leszek Koltunski
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
49
50 418aa554 Leszek Koltunski
  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 121e4a39 Leszek Koltunski
  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 596d62a4 Leszek Koltunski
  private static final double[][] VERTICES = new double[][]
92 b1f2ccf5 Leszek Koltunski
          {
93 596d62a4 Leszek Koltunski
             {-1.5, 0.0, 0.0},
94
             { 1.5, 0.0, 0.0},
95
             { 0.0,-1.5, 0.0},
96
             { 0.0, 0.0,-1.5}
97 b1f2ccf5 Leszek Koltunski
          };
98
99 596d62a4 Leszek Koltunski
  private static final int[][] VERT_INDEXES = new int[][]
100 b1f2ccf5 Leszek Koltunski
          {
101
             {2,1,0},   // counterclockwise!
102 596d62a4 Leszek Koltunski
             {3,0,1},
103 b1f2ccf5 Leszek Koltunski
             {2,3,1},
104
             {3,2,0},
105
          };
106
107 596d62a4 Leszek Koltunski
  private static final float[][] STICKERS = new float[][]
108
          {
109
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
110
          };
111
112 9c06394a Leszek Koltunski
  private static final ObjectSticker[] mStickers;
113
114
  static
115
    {
116
    float radius = 0.025f;
117
    float stroke = 0.050f;
118
    float[] radii = new float[] {radius,radius,radius};
119
    mStickers = new ObjectSticker[STICKERS.length];
120
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
121
    }
122 418aa554 Leszek Koltunski
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
126
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
127 418aa554 Leszek Koltunski
    {
128 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
129 418aa554 Leszek Koltunski
    }
130
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132
133
  float getScreenRatio()
134
    {
135 c7e79b69 Leszek Koltunski
    return 0.5f;
136 418aa554 Leszek Koltunski
    }
137
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140
  Static4D[] getQuats()
141
    {
142
    return QUATS;
143
    }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
  int getNumFaces()
148
    {
149
    return FACE_COLORS.length;
150
    }
151
152 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
155 7403cdfa Leszek Koltunski
    {
156 e6734aa9 Leszek Koltunski
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
157
    return new float[][] { cut,cut,cut,cut };
158 7403cdfa Leszek Koltunski
    }
159
160 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
163 eab9d8f8 Leszek Koltunski
    {
164 596d62a4 Leszek Koltunski
    return STICKERS.length;
165 eab9d8f8 Leszek Koltunski
    }
166
167 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
168
169 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
170 418aa554 Leszek Koltunski
    {
171 8f53e513 Leszek Koltunski
    return 4;
172
    }
173
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175 418aa554 Leszek Koltunski
176 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
177 8f53e513 Leszek Koltunski
    {
178
    return CENTERS;
179 418aa554 Leszek Koltunski
    }
180
181 f10a88a8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183
  private Static4D getQuat(int cubit, int numLayers)
184
    {
185
    return QUATS[cubit];
186
    }
187
188
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190
  private int getNumCubitVariants(int numLayers)
191
    {
192
    return 1;
193
    }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
197
  int getCubitVariant(int cubit, int numLayers)
198
    {
199
    return 0;
200
    }
201
202
///////////////////////////////////////////////////////////////////////////////////////////////////
203
204
  ObjectShape getObjectShape(int cubit, int numLayers)
205
    {
206
    float[][] bands= new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
207
    int[] bandIndices   = new int[] { 0,0,1,1 };
208
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
209
    int[] cornerIndices = new int[] { 0,0,1,1 };
210
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
211
    int[] centerIndices = new int[] { 0,0,0,0 };
212
213
    return new ObjectShape(VERTICES,VERT_INDEXES,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
214
    }
215
216 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
217
218 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
219 418aa554 Leszek Koltunski
    {
220 f10a88a8 Leszek Koltunski
    int variant = getCubitVariant(cubit,numLayers);
221
222 596d62a4 Leszek Koltunski
    if( mMeshes==null )
223
      {
224
      FactoryCubit factory = FactoryCubit.getInstance();
225
      factory.clear();
226 f10a88a8 Leszek Koltunski
      mMeshes = new MeshBase[getNumCubitVariants(numLayers)];
227 596d62a4 Leszek Koltunski
      }
228
229 f10a88a8 Leszek Koltunski
    if( mMeshes[variant]==null )
230 596d62a4 Leszek Koltunski
      {
231 f10a88a8 Leszek Koltunski
      ObjectShape shape = getObjectShape(cubit,numLayers);
232 596d62a4 Leszek Koltunski
      FactoryCubit factory = FactoryCubit.getInstance();
233 f10a88a8 Leszek Koltunski
      factory.createNewFaceTransform(shape);
234
      mMeshes[variant] = factory.createRoundedSolid(shape);
235 596d62a4 Leszek Koltunski
      }
236 8f53e513 Leszek Koltunski
237 f10a88a8 Leszek Koltunski
    MeshBase mesh = mMeshes[variant].copy(true);
238
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( getQuat(cubit,numLayers), new Static3D(0,0,0) );
239 8f53e513 Leszek Koltunski
    mesh.apply(quat,0xffffffff,0);
240 418aa554 Leszek Koltunski
241 8f53e513 Leszek Koltunski
    return mesh;
242 418aa554 Leszek Koltunski
    }
243
244
///////////////////////////////////////////////////////////////////////////////////////////////////
245
246 9c06394a Leszek Koltunski
  int getColor(int face)
247 418aa554 Leszek Koltunski
    {
248 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
249
    }
250 76c2bd07 Leszek Koltunski
251 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
252
253
  ObjectSticker retSticker(int face)
254
    {
255
    return mStickers[face/NUM_FACES];
256 418aa554 Leszek Koltunski
    }
257
258 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
259
260
  float returnMultiplier()
261
    {
262
    return 2.0f;
263
    }
264
265 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
266
// PUBLIC API
267
268
  public Static3D[] getRotationAxis()
269
    {
270 ad38d800 Leszek Koltunski
    return ROT_AXIS;
271 418aa554 Leszek Koltunski
    }
272
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274
275 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
276 418aa554 Leszek Koltunski
    {
277 925ed78f Leszek Koltunski
    return BASIC_ANGLE;
278 418aa554 Leszek Koltunski
    }
279
280 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
281
282
  public int getComplexity(int numLayers)
283
    {
284
    return 2;
285
    }
286 418aa554 Leszek Koltunski
}