Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare.java @ 967c1d17

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 static org.distorted.objects.Movement.TYPE_NOT_SPLIT;
23

    
24
import android.content.res.Resources;
25

    
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
abstract class TwistySquare extends Twisty6
35
{
36
  static final float COS15 = (SQ6+SQ2)/4;
37
  static final float SIN15 = (SQ6-SQ2)/4;
38
  static final float     X = 3*(2-SQ3)/2;
39

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

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

    
51
  private static final int[] NUM_ENABLED = {1,1,1,1,2,2};
52

    
53
  private static final int[][][] ENABLED = new int[][][]
54
    {
55
      {{0}},{{0}},{{1}},{{1}},{{0,1}},{{0,1}}
56
    };
57

    
58
  private int[] mBasicAngle;
59
  private float[][] mCuts;
60
  private boolean[][] mLayerRotatable;
61
  private Movement mMovement;
62
  Static4D[] mQuats;
63

    
64
///////////////////////////////////////////////////////////////////////////////////////////////////
65

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

    
72
///////////////////////////////////////////////////////////////////////////////////////////////////
73

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

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

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  void initializeBasicAngle()
109
    {
110
    mBasicAngle = new int[] {12,2,12};
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  Static4D[] getQuats()
116
    {
117
    if( mQuats==null ) initializeQuats();
118
    return mQuats;
119
    }
120

    
121
///////////////////////////////////////////////////////////////////////////////////////////////////
122

    
123
  int getNumCubitFaces()
124
    {
125
    return 6;
126
    }
127

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

    
130
  float[][] getCuts(int numLayers)
131
    {
132
    if( mCuts==null )
133
      {
134
      mCuts = new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
135
      }
136

    
137
    return mCuts;
138
    }
139

    
140
///////////////////////////////////////////////////////////////////////////////////////////////////
141

    
142
  private void getLayerRotatable(int numLayers)
143
    {
144
    if( mLayerRotatable==null )
145
      {
146
      mLayerRotatable = new boolean[][] { {true,false,true}, {true,true}, {true,false,true} };
147
      }
148
    }
149

    
150
///////////////////////////////////////////////////////////////////////////////////////////////////
151
// PUBLIC API
152

    
153
  public Static3D[] getRotationAxis()
154
    {
155
    return ROT_AXIS;
156
    }
157

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

    
160
  public Movement getMovement()
161
    {
162
    if( mMovement==null )
163
      {
164
      int numLayers = getNumLayers();
165
      if( mCuts==null ) getCuts(numLayers);
166
      getLayerRotatable(numLayers);
167
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,NUM_ENABLED,ENABLED);
168
      }
169
    return mMovement;
170
    }
171

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

    
174
  public int[] getBasicAngle()
175
    {
176
    if( mBasicAngle ==null ) initializeBasicAngle();
177
    return mBasicAngle;
178
    }
179
}
(35-35/38)