Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare.java @ 0021af58

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2021 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.library.main.DistortedEffects;
25
import org.distorted.library.main.DistortedTexture;
26
import org.distorted.library.mesh.MeshSquare;
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
abstract class TwistySquare extends TwistyObject
33
{
34
  static final int LAST_SL = 0; // automatic rotations: last rot was a 'slash' i.e. along ROT_AXIS[1]
35
  static final int LAST_UP = 1; // last rot was along ROT_AXIS[0], upper layer and forelast was a slash
36
  static final int LAST_LO = 2; // last rot was along ROT_AXIS[0], lower layer and forelast was a slash
37
  static final int LAST_UL = 3; // two last rots were along ROT_AXIS[0] (so the next must be a slash)
38

    
39
  static final float COS15 = (SQ6+SQ2)/4;
40
  static final float SIN15 = (SQ6-SQ2)/4;
41
  static final float     X = 3*(2-SQ3)/2;
42

    
43
  // The third, artificial axis is for the generic scrambling algorithm.
44
  // Otherwise it wouldn't be possible to rotate the LO and UP layers
45
  // consecutively.
46

    
47
  static final Static3D[] ROT_AXIS = new Static3D[]
48
    {
49
      new Static3D(0,+1,0),
50
      new Static3D(COS15,0,SIN15),
51
      new Static3D(0,-1,0),
52
    };
53

    
54
  static final int[] BASIC_ANGLE = new int[] { 12,2,12 };
55

    
56
  static final int[] FACE_COLORS = new int[]
57
    {
58
      COLOR_YELLOW, COLOR_WHITE,
59
      COLOR_BLUE  , COLOR_GREEN,
60
      COLOR_RED   , COLOR_ORANGE
61
    };
62

    
63
  static final Static4D[] QUATS = new Static4D[]
64
    {
65
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
66
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
67
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
68
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
69
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
70
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
71
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
72
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
73
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
74
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
75
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
76
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
77

    
78
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
79
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
80
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
81
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
82
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
83
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
84
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
85
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
86
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
87
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
88
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
89
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
90
    };
91

    
92
  static final double[][] VERTICES_MIDDLE = new double[][]
93
    {
94
      { -1.5-X, 0.5, 1.5 },
95
      {    0.0, 0.5, 1.5 },
96
      {    0.0, 0.5,-1.5 },
97
      { -1.5+X, 0.5,-1.5 },
98
      { -1.5-X,-0.5, 1.5 },
99
      {    0.0,-0.5, 1.5 },
100
      {    0.0,-0.5,-1.5 },
101
      { -1.5+X,-0.5,-1.5 }
102
    };
103

    
104
  static final int[][] VERT_INDEXES_MIDDLE = new int[][]
105
    {
106
      {0,1,2,3},   // counterclockwise!
107
      {4,5,6,7},
108
      {4,5,1,0},
109
      {5,6,2,1},
110
      {6,7,3,2},
111
      {7,4,0,3}
112
    };
113

    
114
  static final double[][] VERTICES_EDGE = new double[][]
115
    {
116
      { -X, 0.5, 0.0 },
117
      { +X, 0.5, 0.0 },
118
      {0.0, 0.5,-1.5 },
119
      { -X,-0.5, 0.0 },
120
      { +X,-0.5, 0.0 },
121
      {0.0,-0.5,-1.5 },
122
    };
123

    
124
  static final int[][] VERT_INDEXES_EDGE = new int[][]
125
    {
126
      {0,1,2},   // counterclockwise!
127
      {3,4,5},
128
      {3,4,1,0},
129
      {4,5,2,1},
130
      {5,3,0,2}
131
    };
132

    
133
  // QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
134
  static final int[][] QUAT_MULT = new int[][]
135
    {
136
      {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
137
      {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
138
      {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
139
      {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
140
      {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
141
      {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
142
      {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
143
      {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
144
      {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
145
      {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
146
      { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
147
      { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
148
      { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
149
      { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
150
      { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
151
      { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
152
      { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
153
      { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
154
      { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
155
      { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
156
      { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
157
      { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
158
      { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
159
      { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
160
    };
161

    
162
  int mLastRot;
163

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

    
166
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
167
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
168
    {
169
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
170
    }
171

    
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173

    
174
  Static4D[] getQuats()
175
    {
176
    return QUATS;
177
    }
178

    
179
///////////////////////////////////////////////////////////////////////////////////////////////////
180

    
181
  boolean shouldResetTextureMaps()
182
    {
183
    return false;
184
    }
185

    
186
///////////////////////////////////////////////////////////////////////////////////////////////////
187

    
188
  int getNumFaces()
189
    {
190
    return FACE_COLORS.length;
191
    }
192

    
193
///////////////////////////////////////////////////////////////////////////////////////////////////
194

    
195
  int getNumCubitFaces()
196
    {
197
    return 6;
198
    }
199

    
200
///////////////////////////////////////////////////////////////////////////////////////////////////
201

    
202
  float getScreenRatio()
203
    {
204
    return 0.5f;
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

    
209
  float returnMultiplier()
210
    {
211
    return 1.0f;
212
    }
213

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

    
216
  float[][] getCuts(int numLayers)
217
    {
218
    return new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
219
    }
220

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

    
223
  int getColor(int face)
224
    {
225
    return FACE_COLORS[face];
226
    }
227

    
228
///////////////////////////////////////////////////////////////////////////////////////////////////
229
// PUBLIC API
230

    
231
  public Static3D[] getRotationAxis()
232
    {
233
    return ROT_AXIS;
234
    }
235

    
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237

    
238
  public int[] getBasicAngle()
239
    {
240
    return BASIC_ANGLE;
241
    }
242
}
(38-38/41)