Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare.java @ d5380277

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[] FACE_COLORS = new int[]
55
    {
56
      COLOR_YELLOW, COLOR_WHITE,
57
      COLOR_BLUE  , COLOR_GREEN,
58
      COLOR_RED   , COLOR_ORANGE
59
    };
60

    
61
  int mLastRot;
62
  int[] mBasicAngle;
63
  Static4D[] mQuats;
64
  int[][] mQuatMult;
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
69
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
70
    {
71
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  void initializeQuats()
77
    {
78
    mQuats = new Static4D[]
79
      {
80
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
81
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
82
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
83
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
84
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
85
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
86
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
87
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
88
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
89
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
90
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
91
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
92

    
93
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
94
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
95
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
96
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
97
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
98
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
99
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
100
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
101
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
102
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
103
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
104
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
105
      };
106
    }
107

    
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110
// QUATS[i]*QUATS[j] = QUATS[QUAT_MULT[i][j]]
111

    
112
  void initializeQuatMult()
113
    {
114
    mQuatMult = new int[][]
115
      {
116
        {  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,},
117
        {  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12,},
118
        {  2,  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13,},
119
        {  3,  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2, 15, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14,},
120
        {  4,  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3, 16, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15,},
121
        {  5,  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4, 17, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16,},
122
        {  6,  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5, 18, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17,},
123
        {  7,  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6, 19, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18,},
124
        {  8,  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7, 20, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19,},
125
        {  9, 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8, 21, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20,},
126
        { 10, 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 22, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,},
127
        { 11,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 23, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,},
128
        { 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,},
129
        { 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,},
130
        { 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16, 15,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,  3,},
131
        { 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17, 16,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,  4,},
132
        { 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18, 17,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,  5,},
133
        { 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19, 18,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,  6,},
134
        { 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20, 19,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,  7,},
135
        { 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21, 20,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,  8,},
136
        { 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22, 21,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,  9,},
137
        { 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 22,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11, 10,},
138
        { 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 23, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0, 11,},
139
        { 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10,  9,  8,  7,  6,  5,  4,  3,  2,  1,  0,}
140
      };
141
    }
142

    
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

    
145
  void initializeBasicAngle()
146
    {
147
    mBasicAngle = new int[] {12,2,12};
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151

    
152
  Static4D[] getQuats()
153
    {
154
    if( mQuats==null ) initializeQuats();
155
    return mQuats;
156
    }
157

    
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159

    
160
  boolean shouldResetTextureMaps()
161
    {
162
    return false;
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  int getNumFaces()
168
    {
169
    return FACE_COLORS.length;
170
    }
171

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

    
174
  int getNumCubitFaces()
175
    {
176
    return 6;
177
    }
178

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

    
181
  float getScreenRatio()
182
    {
183
    return 0.5f;
184
    }
185

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

    
188
  float returnMultiplier()
189
    {
190
    return 1.0f;
191
    }
192

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

    
195
  float[][] getCuts(int numLayers)
196
    {
197
    return new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
198
    }
199

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

    
202
  int getColor(int face)
203
    {
204
    return FACE_COLORS[face];
205
    }
206

    
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208
// PUBLIC API
209

    
210
  public Static3D[] getRotationAxis()
211
    {
212
    return ROT_AXIS;
213
    }
214

    
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

    
217
  public int[] getBasicAngle()
218
    {
219
    if( mBasicAngle ==null ) initializeBasicAngle();
220
    return mBasicAngle;
221
    }
222
}
(38-38/41)