Project

General

Profile

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

magiccube / src / main / java / org / distorted / objects / TwistyKilominx.java @ f6e46300

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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
import android.graphics.Canvas;
24
import android.graphics.Paint;
25

    
26
import org.distorted.library.effect.MatrixEffectQuaternion;
27
import org.distorted.library.main.DistortedEffects;
28
import org.distorted.library.main.DistortedTexture;
29
import org.distorted.library.mesh.MeshBase;
30
import org.distorted.library.mesh.MeshSquare;
31
import org.distorted.library.type.Static3D;
32
import org.distorted.library.type.Static4D;
33
import org.distorted.main.R;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class TwistyKilominx extends TwistyMinx
38
{
39
  private static MeshBase mMesh;
40

    
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42

    
43
  TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
44
                 DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
45
    {
46
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  private int numCubitsPerCorner(int numLayers)
52
    {
53
    return 3*((numLayers-3)/2)*((numLayers-5)/2) + (numLayers>=5 ? 1 : 0);
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  private int numCubitsPerEdge(int numLayers)
59
    {
60
    return numLayers<5 ? 0 : numLayers-4;
61
    }
62

    
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

    
65
  int getNumStickerTypes(int numLayers)
66
    {
67
    return numLayers == 3 ? 1 : numLayers/2 + 1;
68
    }
69

    
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

    
72
  float getScreenRatio()
73
    {
74
    return 1.00f;
75
    }
76

    
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
// TODO
79

    
80
  float[] getCuts(int numLayers)
81
    {
82
    return new float[] { -0.5f , 0.5f };
83
    }
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86
// TODO
87

    
88
  float[][] getCubitPositions(int numLayers)
89
    {
90
    return CORNERS;
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94
// TODO
95

    
96
  private int getQuat(int cubit)
97
    {
98
    return ( cubit>=0 && cubit<20 ) ? QUAT_CORNER_INDICES[cubit] : 0;
99
    }
100

    
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
// TODO
103

    
104
  MeshBase createCubitMesh(int cubit, int numLayers)
105
    {
106
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createKilominxCornerMesh();
107
    MeshBase mesh = mMesh.copy(true);
108

    
109
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
110
    mesh.apply(quat,0xffffffff,0);
111

    
112
    return mesh;
113
    }
114

    
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116
// TODO
117

    
118
  int getFaceColor(int cubit, int cubitface, int numLayers)
119
    {
120
    return cubitface>=0 && cubitface<3 ? mCornerFaceMap[cubit][cubitface] : NUM_TEXTURES*NUM_FACES;
121
    }
122

    
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
// TODO
125

    
126
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
127
    {
128
    float S = 0.07f;
129
    float R = 0.09f;
130

    
131
    float A = 0.86f;
132
    float X1= (SQ5+1)/8;
133
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
134
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
135

    
136
    float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
137

    
138
    FactorySticker factory = FactorySticker.getInstance();
139
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
140

    
141
    float MID = TEXTURE_HEIGHT*0.5f;
142
    float WID = TEXTURE_HEIGHT*0.1f;
143
    float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
144
    canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
145
    }
146

    
147
///////////////////////////////////////////////////////////////////////////////////////////////////
148
// PUBLIC API
149

    
150
  public boolean isSolved()
151
    {
152
    int index = CUBITS[0].mQuatIndex;
153

    
154
    for(int i=1; i<NUM_CUBITS; i++)
155
      {
156
      if( thereIsVisibleDifference(CUBITS[i], index) ) return false;
157
      }
158

    
159
    return true;
160
    }
161

    
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

    
164
  public int getObjectName(int numLayers)
165
    {
166
    if( numLayers==3 ) return R.string.minx2;
167
    if( numLayers==5 ) return R.string.minx4;
168

    
169
    return 0;
170
    }
171

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

    
174
  public int getInventor(int numLayers)
175
    {
176
    if( numLayers==3 ) return R.string.minx2_inventor;
177
    if( numLayers==5 ) return R.string.minx4_inventor;
178

    
179
    return 0;
180
    }
181

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

    
184
  public int getComplexity(int numLayers)
185
    {
186
    return 3;
187
    }
188
}
(28-28/35)