Project

General

Profile

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

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

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 f10a88a8 Leszek Koltunski
import org.distorted.helpers.ObjectShape;
25 9c06394a Leszek Koltunski
import org.distorted.helpers.ObjectSticker;
26 6cf89a3e Leszek Koltunski
import org.distorted.helpers.ScrambleState;
27 418aa554 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29 efa8aa48 Leszek Koltunski
import org.distorted.library.mesh.MeshSquare;
30 418aa554 Leszek Koltunski
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 9c2f0c91 Leszek Koltunski
public abstract class TwistyDino extends TwistyObject
36 418aa554 Leszek Koltunski
{
37
  // the four rotation axis of a RubikDino. Must be normalized.
38 ad38d800 Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
39 418aa554 Leszek Koltunski
         {
40
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
41
           new Static3D(+SQ3/3,+SQ3/3,-SQ3/3),
42
           new Static3D(+SQ3/3,-SQ3/3,+SQ3/3),
43
           new Static3D(+SQ3/3,-SQ3/3,-SQ3/3)
44
         };
45
46
  private static final int[] FACE_COLORS = new int[]
47
         {
48 ece1b58d Leszek Koltunski
           COLOR_YELLOW, COLOR_WHITE,
49
           COLOR_BLUE  , COLOR_GREEN,
50 323b217c Leszek Koltunski
           COLOR_RED   , COLOR_ORANGE
51 418aa554 Leszek Koltunski
         };
52
53 d464f54f Leszek Koltunski
  private int[] mBasicAngle;
54
  private Static4D[] mQuats;
55
  private ObjectSticker[] mStickers;
56 85449b44 Leszek Koltunski
  private float[][] mCenters;
57 d464f54f Leszek Koltunski
  ScrambleState[] mStates;
58 20898e6f Leszek Koltunski
59 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
60
61 9c2f0c91 Leszek Koltunski
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
62
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
63 418aa554 Leszek Koltunski
    {
64 db875721 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
65 418aa554 Leszek Koltunski
    }
66
67 d464f54f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
68
69
  private void initializeQuats()
70
    {
71
    mQuats = new Static4D[]
72
         {
73
         new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
74
         new Static4D(  0.5f,  0.5f,  0.5f, -0.5f ),
75
         new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
76
         new Static4D(  0.5f, -0.5f, -0.5f, -0.5f ),
77
         new Static4D(  0.5f,  0.5f,  0.5f,  0.5f ),
78
         new Static4D(  0.5f,  0.5f, -0.5f, -0.5f ),
79
         new Static4D(  0.5f, -0.5f,  0.5f, -0.5f ),
80
         new Static4D(  0.5f, -0.5f, -0.5f,  0.5f ),
81
         new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
82
         new Static4D(  0.5f, -0.5f,  0.5f,  0.5f ),
83
         new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
84
         new Static4D(  0.5f,  0.5f, -0.5f,  0.5f )
85
         };
86
    }
87
88 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
89
90
  float getScreenRatio()
91
    {
92 c7e79b69 Leszek Koltunski
    return 0.5f;
93 418aa554 Leszek Koltunski
    }
94
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
97
  Static4D[] getQuats()
98
    {
99 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
100
    return mQuats;
101 418aa554 Leszek Koltunski
    }
102
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105 abf36986 Leszek Koltunski
  int getNumFaceColors()
106 418aa554 Leszek Koltunski
    {
107
    return FACE_COLORS.length;
108
    }
109
110 7403cdfa Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
111
112 e6734aa9 Leszek Koltunski
  float[][] getCuts(int size)
113 7403cdfa Leszek Koltunski
    {
114 e6734aa9 Leszek Koltunski
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
115
    return new float[][] { cut,cut,cut,cut };
116 7403cdfa Leszek Koltunski
    }
117
118 eab9d8f8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
119
120 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
121 eab9d8f8 Leszek Koltunski
    {
122 d464f54f Leszek Koltunski
    return 1;
123 eab9d8f8 Leszek Koltunski
    }
124
125 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
126
127 8f53e513 Leszek Koltunski
  int getNumCubitFaces()
128 418aa554 Leszek Koltunski
    {
129 8f53e513 Leszek Koltunski
    return 4;
130
    }
131
132
///////////////////////////////////////////////////////////////////////////////////////////////////
133 418aa554 Leszek Koltunski
134 e6cf7283 Leszek Koltunski
  float[][] getCubitPositions(int size)
135 8f53e513 Leszek Koltunski
    {
136 d464f54f Leszek Koltunski
    if( mCenters ==null )
137
      {
138
      mCenters = new float[][]
139
         {
140
             { 0.0f, 1.5f, 1.5f },
141
             { 1.5f, 0.0f, 1.5f },
142
             { 0.0f,-1.5f, 1.5f },
143
             {-1.5f, 0.0f, 1.5f },
144
             { 1.5f, 1.5f, 0.0f },
145
             { 1.5f,-1.5f, 0.0f },
146
             {-1.5f,-1.5f, 0.0f },
147
             {-1.5f, 1.5f, 0.0f },
148
             { 0.0f, 1.5f,-1.5f },
149
             { 1.5f, 0.0f,-1.5f },
150
             { 0.0f,-1.5f,-1.5f },
151
             {-1.5f, 0.0f,-1.5f }
152
         };
153
      }
154
155
    return mCenters;
156 418aa554 Leszek Koltunski
    }
157
158 f10a88a8 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160 3e605536 Leszek Koltunski
  ObjectShape getObjectShape(int cubit, int numLayers)
161 f10a88a8 Leszek Koltunski
    {
162 d464f54f Leszek Koltunski
    double[][] vertices = new double[][] { {-1.5, 0.0, 0.0},{ 1.5, 0.0, 0.0},{ 0.0,-1.5, 0.0},{ 0.0, 0.0,-1.5} };
163
    int[][] vert_indices= new int[][] { {2,1,0},{3,0,1},{2,3,1},{3,2,0} };
164 3e605536 Leszek Koltunski
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
165
    int[] bandIndices   = new int[] { 0,0,1,1 };
166
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
167
    int[] cornerIndices = new int[] { 0,0,1,1 };
168
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
169
    int[] centerIndices = new int[] { 0,0,0,0 };
170 d464f54f Leszek Koltunski
    return new ObjectShape(vertices,vert_indices,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
171 f10a88a8 Leszek Koltunski
    }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175 3e605536 Leszek Koltunski
  Static4D getQuat(int cubit, int numLayers)
176 f10a88a8 Leszek Koltunski
    {
177 d464f54f Leszek Koltunski
    if( mQuats==null ) initializeQuats();
178
    return mQuats[cubit];
179 f10a88a8 Leszek Koltunski
    }
180
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183 3e605536 Leszek Koltunski
  int getNumCubitVariants(int numLayers)
184 f10a88a8 Leszek Koltunski
    {
185 3e605536 Leszek Koltunski
    return 1;
186 f10a88a8 Leszek Koltunski
    }
187
188 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
189
190 3e605536 Leszek Koltunski
  int getCubitVariant(int cubit, int numLayers)
191 418aa554 Leszek Koltunski
    {
192 3e605536 Leszek Koltunski
    return 0;
193 418aa554 Leszek Koltunski
    }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
197 9c06394a Leszek Koltunski
  int getColor(int face)
198 418aa554 Leszek Koltunski
    {
199 9c06394a Leszek Koltunski
    return FACE_COLORS[face];
200
    }
201 76c2bd07 Leszek Koltunski
202 9c06394a Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
203
204
  ObjectSticker retSticker(int face)
205
    {
206 d464f54f Leszek Koltunski
    if( mStickers==null )
207
      {
208
      float[][] STICKERS = new float[][] { { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 } };
209
      float radius = 0.025f;
210
      float stroke = 0.050f;
211
      float[] radii = new float[] {radius,radius,radius};
212
      mStickers     = new ObjectSticker[STICKERS.length];
213
      mStickers[0]  = new ObjectSticker(STICKERS[0],null,radii,stroke);
214
      }
215
216 abf36986 Leszek Koltunski
    return mStickers[face/NUM_FACE_COLORS];
217 418aa554 Leszek Koltunski
    }
218
219 fb377dae Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
220
221
  float returnMultiplier()
222
    {
223
    return 2.0f;
224
    }
225
226 418aa554 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
227
// PUBLIC API
228
229
  public Static3D[] getRotationAxis()
230
    {
231 ad38d800 Leszek Koltunski
    return ROT_AXIS;
232 418aa554 Leszek Koltunski
    }
233
234
///////////////////////////////////////////////////////////////////////////////////////////////////
235
236 925ed78f Leszek Koltunski
  public int[] getBasicAngle()
237 418aa554 Leszek Koltunski
    {
238 d464f54f Leszek Koltunski
    if( mBasicAngle==null ) mBasicAngle = new int[] { 3,3,3,3 };
239
    return mBasicAngle;
240 418aa554 Leszek Koltunski
    }
241
242 6fd4a72c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
243
244
  public int getComplexity(int numLayers)
245
    {
246
    return 2;
247
    }
248 418aa554 Leszek Koltunski
}