Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistySquare.java @ 588ace55

1 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 588ace55 Leszek Koltunski
import static org.distorted.objectlib.Movement.TYPE_NOT_SPLIT;
23 967c1d17 Leszek Koltunski
24 e2b9e87e Leszek Koltunski
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 588ace55 Leszek Koltunski
import org.distorted.objectlib.Movement;
32
import org.distorted.objectlib.Movement6;
33
import org.distorted.objectlib.ObjectList;
34
import org.distorted.objectlib.Twisty6;
35 e2b9e87e Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 efa81f0c Leszek Koltunski
abstract class TwistySquare extends Twisty6
39 e2b9e87e Leszek Koltunski
{
40
  static final float COS15 = (SQ6+SQ2)/4;
41
  static final float SIN15 = (SQ6-SQ2)/4;
42
  static final float     X = 3*(2-SQ3)/2;
43
44 0021af58 Leszek Koltunski
  // The third, artificial axis is for the generic scrambling algorithm.
45
  // Otherwise it wouldn't be possible to rotate the LO and UP layers
46
  // consecutively.
47
48 e2b9e87e Leszek Koltunski
  static final Static3D[] ROT_AXIS = new Static3D[]
49
    {
50 0021af58 Leszek Koltunski
      new Static3D(0,+1,0),
51
      new Static3D(COS15,0,SIN15),
52
      new Static3D(0,-1,0),
53 e2b9e87e Leszek Koltunski
    };
54
55 967c1d17 Leszek Koltunski
  private static final int[][][] ENABLED = new int[][][]
56
    {
57
      {{0}},{{0}},{{1}},{{1}},{{0,1}},{{0,1}}
58
    };
59
60 91792184 Leszek Koltunski
  private int[] mBasicAngle;
61 ef018c1b Leszek Koltunski
  private float[][] mCuts;
62
  private boolean[][] mLayerRotatable;
63 e9a87113 Leszek Koltunski
  private Movement mMovement;
64 d5380277 Leszek Koltunski
  Static4D[] mQuats;
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 e2b9e87e Leszek Koltunski
    {
71 d5380277 Leszek Koltunski
    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 e2b9e87e Leszek Koltunski
      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 d5380277 Leszek Koltunski
      };
106
    }
107 e2b9e87e Leszek Koltunski
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110 d5380277 Leszek Koltunski
  void initializeBasicAngle()
111 e2b9e87e Leszek Koltunski
    {
112 d5380277 Leszek Koltunski
    mBasicAngle = new int[] {12,2,12};
113 e2b9e87e Leszek Koltunski
    }
114
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117 bdbbb4c5 Leszek Koltunski
  protected Static4D[] getQuats()
118 e2b9e87e Leszek Koltunski
    {
119 d5380277 Leszek Koltunski
    if( mQuats==null ) initializeQuats();
120
    return mQuats;
121 e2b9e87e Leszek Koltunski
    }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125 bdbbb4c5 Leszek Koltunski
  protected int getNumCubitFaces()
126 e2b9e87e Leszek Koltunski
    {
127
    return 6;
128
    }
129
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
132 bdbbb4c5 Leszek Koltunski
  protected float[][] getCuts(int numLayers)
133 e2b9e87e Leszek Koltunski
    {
134 ef018c1b Leszek Koltunski
    if( mCuts==null )
135
      {
136
      mCuts = new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
137
      }
138
139
    return mCuts;
140
    }
141
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143
144
  private void getLayerRotatable(int numLayers)
145
    {
146
    if( mLayerRotatable==null )
147
      {
148
      mLayerRotatable = new boolean[][] { {true,false,true}, {true,true}, {true,false,true} };
149
      }
150 e2b9e87e Leszek Koltunski
    }
151
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
// PUBLIC API
154
155
  public Static3D[] getRotationAxis()
156
    {
157
    return ROT_AXIS;
158
    }
159
160 e9a87113 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
161
162
  public Movement getMovement()
163
    {
164 ef018c1b Leszek Koltunski
    if( mMovement==null )
165
      {
166
      int numLayers = getNumLayers();
167
      if( mCuts==null ) getCuts(numLayers);
168
      getLayerRotatable(numLayers);
169 7ee89540 Leszek Koltunski
      mMovement = new Movement6(ROT_AXIS,mCuts,mLayerRotatable,numLayers,TYPE_NOT_SPLIT,ENABLED);
170 ef018c1b Leszek Koltunski
      }
171 e9a87113 Leszek Koltunski
    return mMovement;
172
    }
173
174 e2b9e87e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
175
176
  public int[] getBasicAngle()
177
    {
178 d5380277 Leszek Koltunski
    if( mBasicAngle ==null ) initializeBasicAngle();
179
    return mBasicAngle;
180 e2b9e87e Leszek Koltunski
    }
181
}