Project

General

Profile

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

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

1 bbc6da6c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
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 a64e07d0 Leszek Koltunski
public class TwistyKilominx extends TwistyMinx
38 bbc6da6c Leszek Koltunski
{
39
  private static MeshBase mMesh;
40
41
///////////////////////////////////////////////////////////////////////////////////////////////////
42
43 a64e07d0 Leszek Koltunski
  TwistyKilominx(int size, Static4D quat, DistortedTexture texture, MeshSquare mesh,
44
                 DistortedEffects effects, int[][] moves, Resources res, int scrWidth)
45 bbc6da6c Leszek Koltunski
    {
46 a64e07d0 Leszek Koltunski
    super(size, size, quat, texture, mesh, effects, moves, ObjectList.KILO, res, scrWidth);
47 bbc6da6c Leszek Koltunski
    }
48
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51 a64e07d0 Leszek Koltunski
  int getNumStickerTypes(int numLayers)
52 bbc6da6c Leszek Koltunski
    {
53
    return 1;
54
    }
55
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57
58
  float[] getCuts(int numLayers)
59
    {
60
    return new float[] { -0.5f , 0.5f };
61
    }
62
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64
65
  Static3D[] getCubitPositions(int numLayers)
66
    {
67 a64e07d0 Leszek Koltunski
    return CORNERS;
68 bbc6da6c Leszek Koltunski
    }
69
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71
72
  private int getQuat(int cubit)
73
    {
74 a64e07d0 Leszek Koltunski
    return ( cubit>=0 && cubit<20 ) ? QUAT_INDICES[cubit] : 0;
75 bbc6da6c Leszek Koltunski
    }
76
77
///////////////////////////////////////////////////////////////////////////////////////////////////
78
79 a64e07d0 Leszek Koltunski
  MeshBase createCubitMesh(int cubit, int numLayers)
80 bbc6da6c Leszek Koltunski
    {
81 a64e07d0 Leszek Koltunski
    if( mMesh==null ) mMesh = FactoryCubit.getInstance().createKilominxCornerMesh();
82 bbc6da6c Leszek Koltunski
    MeshBase mesh = mMesh.copy(true);
83
84
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion( QUATS[getQuat(cubit)], new Static3D(0,0,0) );
85
    mesh.apply(quat,0xffffffff,0);
86
87
    return mesh;
88
    }
89
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
  int getFaceColor(int cubit, int cubitface, int numLayers)
93
    {
94 a64e07d0 Leszek Koltunski
    return cubitface>=0 && cubitface<3 ? mCornerFaceMap[cubit][cubitface] : NUM_TEXTURES*NUM_FACES;
95 bbc6da6c Leszek Koltunski
    }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
  void createFaceTexture(Canvas canvas, Paint paint, int face, int left, int top)
100
    {
101 a2398d6b Leszek Koltunski
    float S = 0.07f;
102
    float R = 0.09f;
103 bbc6da6c Leszek Koltunski
104 4b4c217e Leszek Koltunski
    float A = 0.86f;
105 4e627d8b Leszek Koltunski
    float X1= (SQ5+1)/8;
106
    float Y1= (float)(Math.sqrt(2+0.4f*SQ5)/4);
107
    float Y2= Y1 - (float)(Math.sqrt(10-2*SQ5)/8);
108
109 4b4c217e Leszek Koltunski
    float[] vertices = { -X1, Y2, 0, -A*Y1, X1, Y2, 0, Y1 };
110 bbc6da6c Leszek Koltunski
111
    FactorySticker factory = FactorySticker.getInstance();
112
    factory.drawRoundedPolygon(canvas, paint, left, top, vertices, S, FACE_COLORS[face], R);
113 4b4c217e Leszek Koltunski
114
    float MID = TEXTURE_HEIGHT*0.5f;
115
    float WID = TEXTURE_HEIGHT*0.1f;
116
    float HEI = TEXTURE_HEIGHT*(0.47f+Y1);
117
    canvas.drawLine(left+MID-WID,top+HEI,left+MID+WID,top+HEI,paint);
118 bbc6da6c Leszek Koltunski
    }
119
120
///////////////////////////////////////////////////////////////////////////////////////////////////
121
// PUBLIC API
122
// The Kilominx is solved if and only if:
123
//
124 a64e07d0 Leszek Koltunski
// All cubits are rotated with the same quat.
125 bbc6da6c Leszek Koltunski
126
  public boolean isSolved()
127
    {
128
    int q = CUBITS[0].mQuatIndex;
129
130
    for(int i=0; i<NUM_CUBITS; i++)
131
      {
132
      if( CUBITS[i].mQuatIndex != q ) return false;
133
      }
134
135
    return true;
136
    }
137
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140
  public int getObjectName(int numLayers)
141
    {
142
    return R.string.minx2;
143
    }
144
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146
147
  public int getInventor(int numLayers)
148
    {
149
    return R.string.minx2_inventor;
150
    }
151
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153
154
  public int getComplexity(int numLayers)
155
    {
156
    return 3;
157
    }
158
}