Project

General

Profile

Download (6.83 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistySquare.java @ 7bbfc84f

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.objectlib.objects;
21

    
22
import static org.distorted.objectlib.main.Movement.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.main.Movement.TYPE_NOT_SPLIT;
24

    
25
import android.content.res.Resources;
26

    
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshSquare;
30
import org.distorted.library.type.Static3D;
31
import org.distorted.library.type.Static4D;
32
import org.distorted.objectlib.main.Twisty6;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
abstract class TwistySquare extends Twisty6
37
{
38
  static final float COS15 = (SQ6+SQ2)/4;
39
  static final float SIN15 = (SQ6-SQ2)/4;
40
  static final float     X = 3*(2-SQ3)/2;
41

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

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

    
53
  private int[] mBasicAngle;
54
  private float[][] mCuts;
55
  Static4D[] mQuats;
56

    
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

    
59
  TwistySquare(int[] numL, Static4D quat, Static3D move, DistortedTexture texture,
60
               MeshSquare mesh, DistortedEffects effects, Resources res, int surfaceW, int surfaceH)
61
    {
62
    super(numL, numL[0], quat, move, texture, mesh, effects, res, surfaceW, surfaceH);
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  void initializeQuats()
68
    {
69
    mQuats = new Static4D[]
70
      {
71
      new Static4D(  0.0f,  0.0f,  0.0f,  1.0f ),
72
      new Static4D(  0.0f, SIN15,  0.0f, COS15 ),
73
      new Static4D(  0.0f,  0.5f,  0.0f, SQ3/2 ),
74
      new Static4D(  0.0f, SQ2/2,  0.0f, SQ2/2 ),
75
      new Static4D(  0.0f, SQ3/2,  0.0f,  0.5f ),
76
      new Static4D(  0.0f, COS15,  0.0f, SIN15 ),
77
      new Static4D(  0.0f,  1.0f,  0.0f,  0.0f ),
78
      new Static4D(  0.0f, COS15,  0.0f,-SIN15 ),
79
      new Static4D(  0.0f, SQ3/2,  0.0f, -0.5f ),
80
      new Static4D(  0.0f, SQ2/2,  0.0f,-SQ2/2 ),
81
      new Static4D(  0.0f,  0.5f,  0.0f,-SQ3/2 ),
82
      new Static4D(  0.0f, SIN15,  0.0f,-COS15 ),
83

    
84
      new Static4D(  1.0f,  0.0f,  0.0f,  0.0f ),
85
      new Static4D( COS15,  0.0f, SIN15,  0.0f ),
86
      new Static4D( SQ3/2,  0.0f,  0.5f,  0.0f ),
87
      new Static4D( SQ2/2,  0.0f, SQ2/2,  0.0f ),
88
      new Static4D(  0.5f,  0.0f, SQ3/2,  0.0f ),
89
      new Static4D( SIN15,  0.0f, COS15,  0.0f ),
90
      new Static4D(  0.0f,  0.0f,  1.0f,  0.0f ),
91
      new Static4D(-SIN15,  0.0f, COS15,  0.0f ),
92
      new Static4D( -0.5f,  0.0f, SQ3/2,  0.0f ),
93
      new Static4D(-SQ2/2,  0.0f, SQ2/2,  0.0f ),
94
      new Static4D(-SQ3/2,  0.0f,  0.5f,  0.0f ),
95
      new Static4D(-COS15,  0.0f, SIN15,  0.0f )
96
      };
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  void initializeBasicAngle()
102
    {
103
    mBasicAngle = new int[] {12,2,12};
104
    }
105

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

    
108
  protected Static4D[] getQuats()
109
    {
110
    if( mQuats==null ) initializeQuats();
111
    return mQuats;
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  protected int getNumCubitFaces()
117
    {
118
    return 6;
119
    }
120

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

    
123
  public float[][] getCuts(int[] numLayers)
124
    {
125
    if( mCuts==null )
126
      {
127
      mCuts = new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
128
      }
129

    
130
    return mCuts;
131
    }
132

    
133
///////////////////////////////////////////////////////////////////////////////////////////////////
134

    
135
  public boolean[][] getLayerRotatable(int[] numLayers)
136
    {
137
    return new boolean[][] { {true,false,true}, {true,true}, {true,false,true} };
138
    }
139

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

    
142
  public int getMovementType()
143
    {
144
    return MOVEMENT_HEXAHEDRON;
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148

    
149
  public int getMovementSplit()
150
    {
151
    return TYPE_NOT_SPLIT;
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

    
156
  public int[][][] getEnabled()
157
    {
158
    return new int[][][] { {{0}},{{0}},{{1}},{{1}},{{0,1}},{{0,1}} };
159
    }
160

    
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

    
163
  public float[] getDist3D(int[] numLayers)
164
    {
165
    return null;
166
    }
167

    
168
///////////////////////////////////////////////////////////////////////////////////////////////////
169
// PUBLIC API
170

    
171
  public Static3D[] getRotationAxis()
172
    {
173
    return ROT_AXIS;
174
    }
175

    
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

    
178
  public int[] getBasicAngle()
179
    {
180
    if( mBasicAngle ==null ) initializeBasicAngle();
181
    return mBasicAngle;
182
    }
183
}
(22-22/25)