1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2019 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.object;
|
21
|
|
22
|
import android.graphics.Canvas;
|
23
|
import android.graphics.Paint;
|
24
|
|
25
|
import org.distorted.library.effect.MatrixEffect;
|
26
|
import org.distorted.library.effect.MatrixEffectMove;
|
27
|
import org.distorted.library.effect.MatrixEffectRotate;
|
28
|
import org.distorted.library.effect.MatrixEffectScale;
|
29
|
import org.distorted.library.main.DistortedEffects;
|
30
|
import org.distorted.library.main.DistortedTexture;
|
31
|
import org.distorted.library.mesh.MeshBase;
|
32
|
import org.distorted.library.mesh.MeshJoined;
|
33
|
import org.distorted.library.mesh.MeshRectangles;
|
34
|
import org.distorted.library.mesh.MeshTriangles;
|
35
|
import org.distorted.library.type.Static1D;
|
36
|
import org.distorted.library.type.Static3D;
|
37
|
import org.distorted.library.type.Static4D;
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
public class RubikPyraminx extends RubikObject
|
42
|
{
|
43
|
private static final float SQ2 = (float)Math.sqrt(2);
|
44
|
private static final float SQ3 = (float)Math.sqrt(3);
|
45
|
|
46
|
private static final Static3D[] AXIS = new Static3D[]
|
47
|
{
|
48
|
new Static3D( 0, 1, 0 ),
|
49
|
new Static3D( SQ2*SQ3/3, -1.0f/3, -SQ2/3 ),
|
50
|
new Static3D(-SQ2*SQ3/3, -1.0f/3, -SQ2/3 ),
|
51
|
new Static3D( 0, -1.0f/3, 2*SQ2/3 )
|
52
|
};
|
53
|
|
54
|
private static final int[] FACE_COLORS = new int[]
|
55
|
{
|
56
|
0xffffff00, 0xff00ff00, // AXIS[0]right (YELLOW) AXIS[1]right (GREEN )
|
57
|
0xff0000ff, 0xffff0000 // AXIS[2]right (BLUE ) AXIS[3]right (RED )
|
58
|
};
|
59
|
|
60
|
// computed with res/raw/compute_quats.c
|
61
|
private static final float[] LEGALQUATS = new float[]
|
62
|
{
|
63
|
0.0f, 1.0f, -1.0f, 0.5f, -0.5f, SQ2/2, -SQ2/2, SQ3/2, -SQ3/2,
|
64
|
SQ3/3, -SQ3/3, SQ3/6, -SQ3/6, SQ2*SQ3/3, -SQ2*SQ3/3, SQ2*SQ3/6, -SQ2*SQ3/6
|
65
|
};
|
66
|
|
67
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
68
|
|
69
|
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
|
70
|
{
|
71
|
super(size,quatCur,quatAcc,texture,mesh,effects);
|
72
|
}
|
73
|
|
74
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
75
|
|
76
|
Static3D[] getCubitPositions(int size)
|
77
|
{
|
78
|
/*
|
79
|
int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1;
|
80
|
Static3D[] tmp = new Static3D[numCubits];
|
81
|
|
82
|
int currentPosition = 0;
|
83
|
|
84
|
for(int x = 0; x<size; x++)
|
85
|
for(int y = 0; y<size; y++)
|
86
|
for(int z = 0; z<size; z++)
|
87
|
if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 )
|
88
|
{
|
89
|
tmp[currentPosition++] = new Static3D(x,y,z);
|
90
|
}
|
91
|
|
92
|
return tmp;
|
93
|
*/
|
94
|
return null;
|
95
|
}
|
96
|
|
97
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
98
|
|
99
|
float[] getLegalQuats()
|
100
|
{
|
101
|
return LEGALQUATS;
|
102
|
}
|
103
|
|
104
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
105
|
|
106
|
int getNumFaces()
|
107
|
{
|
108
|
return FACE_COLORS.length;
|
109
|
}
|
110
|
|
111
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
112
|
|
113
|
Static3D[] getRotationAxis()
|
114
|
{
|
115
|
return AXIS;
|
116
|
}
|
117
|
|
118
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119
|
|
120
|
void createFaceTexture(Canvas canvas, Paint paint, int face)
|
121
|
{
|
122
|
/*
|
123
|
InputStream is = mView.getContext().getResources().openRawResource(R.raw.pyraminx);
|
124
|
Bitmap bitmap;
|
125
|
|
126
|
try
|
127
|
{
|
128
|
bitmap = BitmapFactory.decodeStream(is);
|
129
|
}
|
130
|
finally
|
131
|
{
|
132
|
try
|
133
|
{
|
134
|
is.close();
|
135
|
}
|
136
|
catch(IOException e) { }
|
137
|
}
|
138
|
|
139
|
paint.setColor(FACE_COLORS[face]);
|
140
|
canvas.drawRect(face*TEXTURE_HEIGHT,0,(face+1)*TEXTURE_HEIGHT,TEXTURE_HEIGHT,paint);
|
141
|
canvas.drawBitmap(bitmap,face*TEXTURE_HEIGHT,0,null);
|
142
|
*/
|
143
|
}
|
144
|
|
145
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
146
|
|
147
|
MeshBase createCubitMesh(int vertices)
|
148
|
{
|
149
|
final float angleFaces = (float)((180/Math.PI)*(2*Math.asin(SQ3/3))); // angle between two faces of a tetrahedron
|
150
|
final int MESHES=4;
|
151
|
|
152
|
MeshBase[] meshes = new MeshTriangles[MESHES];
|
153
|
for(int i=0; i<MESHES; i++) meshes[i] = new MeshTriangles(5);
|
154
|
|
155
|
MatrixEffect[] effects0 = new MatrixEffect[3];
|
156
|
effects0[0] = new MatrixEffectScale( new Static3D(1,SQ3/2,1) );
|
157
|
effects0[1] = new MatrixEffectRotate( new Static1D(90), new Static3D(1,0,0), new Static3D(0,0,0) );
|
158
|
effects0[2] = new MatrixEffectMove( new Static3D(0,-SQ3/6,SQ3/12) );
|
159
|
|
160
|
meshes[0].apply(effects0);
|
161
|
|
162
|
Static1D angle = new Static1D(angleFaces);
|
163
|
Static3D axis = new Static3D(-1,0,0);
|
164
|
Static3D center= new Static3D(0,-SQ3/6,-SQ3/6);
|
165
|
|
166
|
MatrixEffect[] effects1 = new MatrixEffect[5];
|
167
|
effects1[0] = effects0[0];
|
168
|
effects1[1] = effects0[1];
|
169
|
effects1[2] = effects0[2];
|
170
|
effects1[3] = new MatrixEffectRotate( new Static1D(180), new Static3D(0,0,1), center );
|
171
|
effects1[4] = new MatrixEffectRotate( angle, axis, center );
|
172
|
meshes[1].apply(effects1);
|
173
|
|
174
|
axis.set(0.5f,0,-SQ3/2);
|
175
|
center.set2(SQ3/3);
|
176
|
meshes[2].apply(effects1);
|
177
|
|
178
|
axis.set2(SQ3/2);
|
179
|
meshes[3].apply(effects1);
|
180
|
|
181
|
return new MeshJoined(meshes);
|
182
|
}
|
183
|
|
184
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
185
|
// PUBLIC API
|
186
|
|
187
|
public int getBasicAngle()
|
188
|
{
|
189
|
return 3;
|
190
|
}
|
191
|
}
|