Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / objects / TwistySquare.java @ 23afe4c4

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.movement.Movement.MOVEMENT_HEXAHEDRON;
23
import static org.distorted.objectlib.movement.Movement.TYPE_NOT_SPLIT;
24

    
25
import java.io.InputStream;
26

    
27
import org.distorted.library.type.Static3D;
28
import org.distorted.library.type.Static4D;
29
import org.distorted.objectlib.main.ShapeHexahedron;
30

    
31
///////////////////////////////////////////////////////////////////////////////////////////////////
32

    
33
abstract class TwistySquare extends ShapeHexahedron
34
{
35
  static final float COS15 = (SQ6+SQ2)/4;
36
  static final float SIN15 = (SQ6-SQ2)/4;
37
  static final float     X = 3*(2-SQ3)/2;
38

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

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

    
50
  private int[] mBasicAngle;
51
  private float[][] mCuts;
52
  Static4D[] mQuats;
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  TwistySquare(int[] numL, Static4D quat, Static3D move, float scale, InputStream stream)
57
    {
58
    super(numL, numL[0], quat, move, scale, stream);
59
    }
60

    
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62

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

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

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96

    
97
  void initializeBasicAngle()
98
    {
99
    mBasicAngle = new int[] {12,2,12};
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  public Static4D[] getQuats()
105
    {
106
    if( mQuats==null ) initializeQuats();
107
    return mQuats;
108
    }
109

    
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

    
112
  public int getNumCubitFaces()
113
    {
114
    return 6;
115
    }
116

    
117
///////////////////////////////////////////////////////////////////////////////////////////////////
118

    
119
  public float[][] getCuts(int[] numLayers)
120
    {
121
    if( mCuts==null )
122
      {
123
      mCuts = new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
124
      }
125

    
126
    return mCuts;
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  public boolean[][] getLayerRotatable(int[] numLayers)
132
    {
133
    return new boolean[][] { {true,false,true}, {true,true}, {true,false,true} };
134
    }
135

    
136
///////////////////////////////////////////////////////////////////////////////////////////////////
137

    
138
  public int getMovementType()
139
    {
140
    return MOVEMENT_HEXAHEDRON;
141
    }
142

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

    
145
  public int getMovementSplit()
146
    {
147
    return TYPE_NOT_SPLIT;
148
    }
149

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

    
152
  public int[][][] getEnabled()
153
    {
154
    return new int[][][] { {{0}},{{0}},{{1}},{{1}},{{0,1}},{{0,1}} };
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public float[] getDist3D(int[] numLayers)
160
    {
161
    return null;
162
    }
163

    
164
///////////////////////////////////////////////////////////////////////////////////////////////////
165
// PUBLIC API
166

    
167
  public Static3D[] getRotationAxis()
168
    {
169
    return ROT_AXIS;
170
    }
171

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

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