Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyDino.java @ 8db55f55

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

    
24
import org.distorted.helpers.ObjectShape;
25
import org.distorted.helpers.ObjectSticker;
26
import org.distorted.library.main.DistortedEffects;
27
import org.distorted.library.main.DistortedTexture;
28
import org.distorted.library.mesh.MeshSquare;
29
import org.distorted.library.type.Static3D;
30
import org.distorted.library.type.Static4D;
31

    
32
///////////////////////////////////////////////////////////////////////////////////////////////////
33

    
34
public abstract class TwistyDino extends TwistyObject
35
{
36
  // the four rotation axis of a RubikDino. Must be normalized.
37
  static final Static3D[] ROT_AXIS = new Static3D[]
38
         {
39
           new Static3D(+SQ3/3,+SQ3/3,+SQ3/3),
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
         };
44

    
45
  private static final int[] BASIC_ANGLE = new int[] { 3,3,3,3 };
46

    
47
  private static final int[] FACE_COLORS = new int[]
48
         {
49
           COLOR_YELLOW, COLOR_WHITE,
50
           COLOR_BLUE  , COLOR_GREEN,
51
           COLOR_RED   , COLOR_ORANGE
52
         };
53

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

    
71
  // centers of the 12 edges. Must be in the same order like QUATs above.
72
  static final float[][] CENTERS = new float[][]
73
         {
74
             { 0.0f, 1.5f, 1.5f },
75
             { 1.5f, 0.0f, 1.5f },
76
             { 0.0f,-1.5f, 1.5f },
77
             {-1.5f, 0.0f, 1.5f },
78
             { 1.5f, 1.5f, 0.0f },
79
             { 1.5f,-1.5f, 0.0f },
80
             {-1.5f,-1.5f, 0.0f },
81
             {-1.5f, 1.5f, 0.0f },
82
             { 0.0f, 1.5f,-1.5f },
83
             { 1.5f, 0.0f,-1.5f },
84
             { 0.0f,-1.5f,-1.5f },
85
             {-1.5f, 0.0f,-1.5f }
86
         };
87

    
88
  private static final double[][] VERTICES = new double[][]
89
          {
90
             {-1.5, 0.0, 0.0},
91
             { 1.5, 0.0, 0.0},
92
             { 0.0,-1.5, 0.0},
93
             { 0.0, 0.0,-1.5}
94
          };
95

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

    
104
  private static final float[][] STICKERS = new float[][]
105
          {
106
             { 0.0f, -1.0f/3, 0.5f, 1.0f/6, -0.5f, 1.0f/6 }
107
          };
108

    
109
  private static final ObjectSticker[] mStickers;
110

    
111
  static
112
    {
113
    float radius = 0.025f;
114
    float stroke = 0.050f;
115
    float[] radii = new float[] {radius,radius,radius};
116
    mStickers = new ObjectSticker[STICKERS.length];
117
    mStickers[0] = new ObjectSticker(STICKERS[0],null,radii,stroke);
118
    }
119

    
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121

    
122
  TwistyDino(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
123
             DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
124
    {
125
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
126
    }
127

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

    
130
  float getScreenRatio()
131
    {
132
    return 0.5f;
133
    }
134

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

    
137
  Static4D[] getQuats()
138
    {
139
    return QUATS;
140
    }
141

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

    
144
  int getNumFaces()
145
    {
146
    return FACE_COLORS.length;
147
    }
148

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

    
151
  float[][] getCuts(int size)
152
    {
153
    float[] cut = new float[] { -SQ3/3, +SQ3/3 };
154
    return new float[][] { cut,cut,cut,cut };
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  int getNumStickerTypes(int numLayers)
160
    {
161
    return STICKERS.length;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165

    
166
  int getNumCubitFaces()
167
    {
168
    return 4;
169
    }
170

    
171
///////////////////////////////////////////////////////////////////////////////////////////////////
172

    
173
  float[][] getCubitPositions(int size)
174
    {
175
    return CENTERS;
176
    }
177

    
178
///////////////////////////////////////////////////////////////////////////////////////////////////
179

    
180
  ObjectShape getObjectShape(int cubit, int numLayers)
181
    {
182
    float[][] bands     = new float[][] { {0.035f,30,0.16f,0.8f,6,2,2}, {0.010f,30,0.16f,0.2f,6,2,2} };
183
    int[] bandIndices   = new int[] { 0,0,1,1 };
184
    float[][] corners   = new float[][] { {0.07f,0.40f}, {0.05f,0.30f} };
185
    int[] cornerIndices = new int[] { 0,0,1,1 };
186
    float[][] centers   = new float[][] { {0.0f, -0.75f, -0.75f} };
187
    int[] centerIndices = new int[] { 0,0,0,0 };
188
    return new ObjectShape(VERTICES,VERT_INDEXES,bands,bandIndices,corners,cornerIndices,centers,centerIndices,getNumCubitFaces(), null);
189
    }
190

    
191
///////////////////////////////////////////////////////////////////////////////////////////////////
192

    
193
  Static4D getQuat(int cubit, int numLayers)
194
    {
195
    return QUATS[cubit];
196
    }
197

    
198
///////////////////////////////////////////////////////////////////////////////////////////////////
199

    
200
  int getNumCubitVariants(int numLayers)
201
    {
202
    return 1;
203
    }
204

    
205
///////////////////////////////////////////////////////////////////////////////////////////////////
206

    
207
  int getCubitVariant(int cubit, int numLayers)
208
    {
209
    return 0;
210
    }
211

    
212
///////////////////////////////////////////////////////////////////////////////////////////////////
213

    
214
  int getColor(int face)
215
    {
216
    return FACE_COLORS[face];
217
    }
218

    
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220

    
221
  ObjectSticker retSticker(int face)
222
    {
223
    return mStickers[face/NUM_FACES];
224
    }
225

    
226
///////////////////////////////////////////////////////////////////////////////////////////////////
227

    
228
  float returnMultiplier()
229
    {
230
    return 2.0f;
231
    }
232

    
233
///////////////////////////////////////////////////////////////////////////////////////////////////
234
// PUBLIC API
235

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

    
241
///////////////////////////////////////////////////////////////////////////////////////////////////
242

    
243
  public int[] getBasicAngle()
244
    {
245
    return BASIC_ANGLE;
246
    }
247

    
248
///////////////////////////////////////////////////////////////////////////////////////////////////
249

    
250
  public int getComplexity(int numLayers)
251
    {
252
    return 2;
253
    }
254
}
(24-24/41)