Project

General

Profile

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

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

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 float COS15 = (SQ6+SQ2)/4;
35
  static final float SIN15 = (SQ6-SQ2)/4;
36
  static final float     X = 3*(2-SQ3)/2;
37

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

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

    
49
  static final int[] FACE_COLORS = new int[]
50
    {
51
      COLOR_YELLOW, COLOR_WHITE,
52
      COLOR_BLUE  , COLOR_GREEN,
53
      COLOR_RED   , COLOR_ORANGE
54
    };
55

    
56
  private int[] mBasicAngle;
57
  private Movement mMovement;
58
  Static4D[] mQuats;
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  TwistySquare(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
63
               DistortedEffects effects, int[][] moves, ObjectList obj, Resources res, int scrWidth)
64
    {
65
    super(size, size, quat, texture, mesh, effects, moves, obj, res, scrWidth);
66
    }
67

    
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

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

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

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

    
104
  void initializeBasicAngle()
105
    {
106
    mBasicAngle = new int[] {12,2,12};
107
    }
108

    
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

    
111
  Static4D[] getQuats()
112
    {
113
    if( mQuats==null ) initializeQuats();
114
    return mQuats;
115
    }
116

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

    
119
  boolean shouldResetTextureMaps()
120
    {
121
    return false;
122
    }
123

    
124
///////////////////////////////////////////////////////////////////////////////////////////////////
125

    
126
  int getNumFaceColors()
127
    {
128
    return FACE_COLORS.length;
129
    }
130

    
131
///////////////////////////////////////////////////////////////////////////////////////////////////
132

    
133
  int getNumCubitFaces()
134
    {
135
    return 6;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  float getScreenRatio()
141
    {
142
    return 0.5f;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  float returnMultiplier()
148
    {
149
    return 1.0f;
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  float[][] getCuts(int numLayers)
155
    {
156
    return new float[][] { {-0.5f,+0.5f}, {0.0f}, {-0.5f,+0.5f} };
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  int getColor(int face)
162
    {
163
    return FACE_COLORS[face];
164
    }
165

    
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
// PUBLIC API
168

    
169
  public Static3D[] getRotationAxis()
170
    {
171
    return ROT_AXIS;
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  public Movement getMovement()
177
    {
178
    if( mMovement==null ) mMovement = new MovementSquare();
179
    return mMovement;
180
    }
181

    
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

    
184
  public int[] getBasicAngle()
185
    {
186
    if( mBasicAngle ==null ) initializeBasicAngle();
187
    return mBasicAngle;
188
    }
189
}
(41-41/44)