1 |
5caf2641
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2022 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is proprietary software licensed under an EULA which you should have received //
|
7 |
|
|
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html //
|
8 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
|
|
package org.distorted.objectlib.touchcontrol;
|
11 |
|
|
|
12 |
99320a69
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ2;
|
13 |
5caf2641
|
Leszek Koltunski
|
import static org.distorted.objectlib.main.TwistyObject.SQ5;
|
14 |
|
|
|
15 |
|
|
import org.distorted.library.type.Static3D;
|
16 |
|
|
import org.distorted.objectlib.main.TwistyObject;
|
17 |
|
|
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
// Icosahedral objects: map the 2D swipes of user's fingers to 3D rotations
|
20 |
|
|
|
21 |
|
|
public class TouchControlIcosahedron extends TouchControlShapeConstant
|
22 |
|
|
{
|
23 |
99320a69
|
Leszek Koltunski
|
public static final float DIST3D = (3+SQ5)*SQ3/12;
|
24 |
5caf2641
|
Leszek Koltunski
|
private static final float DIST2D = SQ3/6;
|
25 |
|
|
public static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
|
26 |
|
|
DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
|
27 |
|
|
DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
|
28 |
|
|
DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
|
29 |
a8efe86f
|
Leszek Koltunski
|
|
30 |
eeabbae3
|
Leszek Koltunski
|
// VEC_0: topmost one. Then 3 vertices from the second-topmost-layer,
|
31 |
|
|
// front one and two ones to the right.
|
32 |
99320a69
|
Leszek Koltunski
|
|
33 |
|
|
private static final float Z = (float)Math.sqrt(5+SQ5);
|
34 |
|
|
|
35 |
eeabbae3
|
Leszek Koltunski
|
private static final float VEC_0_X = 0;
|
36 |
|
|
private static final float VEC_0_Y = Z*(SQ2/4);
|
37 |
|
|
private static final float VEC_0_Z = 0;
|
38 |
|
|
|
39 |
|
|
private static final float VEC_1_X = 0;
|
40 |
|
|
private static final float VEC_1_Y = Z*(SQ2*SQ5/20);
|
41 |
|
|
private static final float VEC_1_Z = Z*(SQ2*SQ5/10);
|
42 |
|
|
|
43 |
|
|
private static final float VEC_2_X = (SQ5+1)/4;
|
44 |
|
|
private static final float VEC_2_Y = Z*(SQ2*SQ5/20);
|
45 |
|
|
private static final float VEC_2_Z = Z*(SQ5-1)/(4*SQ2*SQ5);
|
46 |
|
|
|
47 |
|
|
private static final float VEC_3_X = 0.5f;
|
48 |
|
|
private static final float VEC_3_Y = Z*(SQ2*SQ5/20);
|
49 |
|
|
private static final float VEC_3_Z =-Z*(SQ5+1)/(4*SQ2*SQ5);
|
50 |
|
|
|
51 |
|
|
private static final float X1 = VEC_2_X/3;
|
52 |
|
|
private static final float X2 = (VEC_2_X + VEC_3_X)/3;
|
53 |
|
|
private static final float X3 = (2*VEC_2_X + VEC_3_X)/3;
|
54 |
|
|
private static final float X4 = (VEC_2_X + VEC_3_X)/3;
|
55 |
|
|
private static final float Y1 = (VEC_0_Y + 2*VEC_1_Y)/3;
|
56 |
|
|
private static final float Y2 = VEC_1_Y/3;
|
57 |
|
|
private static final float Z1 = (VEC_1_Z + VEC_2_Z)/3;
|
58 |
|
|
private static final float Z2 = (VEC_2_Z + VEC_3_Z)/3;
|
59 |
|
|
private static final float Z3 = 2*VEC_3_Z/3;
|
60 |
|
|
private static final float Z4 = (VEC_1_Z - 2*VEC_3_Z)/3;
|
61 |
|
|
private static final float Z5 = -VEC_3_Z/3;
|
62 |
|
|
private static final float Z6 = (VEC_3_Z - VEC_1_Z - VEC_2_Z)/3;
|
63 |
|
|
|
64 |
|
|
public static final float[][] VEC = new float[][]
|
65 |
|
|
{
|
66 |
|
|
{ VEC_0_X, VEC_0_Y, VEC_0_Z},
|
67 |
|
|
|
68 |
|
|
{ VEC_1_X, VEC_1_Y, VEC_1_Z},
|
69 |
|
|
{ VEC_2_X, VEC_2_Y, VEC_2_Z},
|
70 |
|
|
{ VEC_3_X, VEC_3_Y, VEC_3_Z},
|
71 |
|
|
{-VEC_3_X, VEC_3_Y, VEC_3_Z},
|
72 |
|
|
{-VEC_2_X, VEC_2_Y, VEC_2_Z},
|
73 |
|
|
|
74 |
|
|
{-VEC_1_X,-VEC_1_Y,-VEC_1_Z},
|
75 |
|
|
{-VEC_2_X,-VEC_2_Y,-VEC_2_Z},
|
76 |
|
|
{-VEC_3_X,-VEC_3_Y,-VEC_3_Z},
|
77 |
|
|
{ VEC_3_X,-VEC_3_Y,-VEC_3_Z},
|
78 |
|
|
{ VEC_2_X,-VEC_2_Y,-VEC_2_Z},
|
79 |
|
|
|
80 |
|
|
{-VEC_0_X,-VEC_0_Y,-VEC_0_Z},
|
81 |
|
|
};
|
82 |
|
|
|
83 |
|
|
public static final int[][] EDGE_INDICES = new int[][]
|
84 |
|
|
{
|
85 |
|
|
{0,1}, {0,2}, {0,3}, {0,4}, {0,5},
|
86 |
|
|
{1,2}, {2,3}, {3,4}, {4,5}, {5,1},
|
87 |
|
|
{1,9}, {9,2}, {2,10}, {10,3}, {3,6}, {6,4}, {4,7}, {7,5}, {5,8}, {8,1},
|
88 |
|
|
{6,7}, {7,8}, {8,9}, {9,10}, {10,6},
|
89 |
|
|
{11,6}, {11,7}, {11,8}, {11,9}, {11,10}
|
90 |
|
|
};
|
91 |
5caf2641
|
Leszek Koltunski
|
|
92 |
|
|
public static final Static3D[] FACE_AXIS = new Static3D[]
|
93 |
|
|
{
|
94 |
509b223f
|
Leszek Koltunski
|
new Static3D( X1/DIST3D, Y1/DIST3D, Z1/DIST3D ),
|
95 |
|
|
new Static3D( X2/DIST3D, Y1/DIST3D, Z2/DIST3D ),
|
96 |
eeabbae3
|
Leszek Koltunski
|
new Static3D( 0/DIST3D, Y1/DIST3D, Z3/DIST3D ),
|
97 |
509b223f
|
Leszek Koltunski
|
new Static3D( -X2/DIST3D, Y1/DIST3D, Z2/DIST3D ),
|
98 |
|
|
new Static3D( -X1/DIST3D, Y1/DIST3D, Z1/DIST3D ),
|
99 |
|
|
|
100 |
eeabbae3
|
Leszek Koltunski
|
new Static3D( 0/DIST3D,-Y2/DIST3D, Z4/DIST3D ),
|
101 |
509b223f
|
Leszek Koltunski
|
new Static3D( X3/DIST3D,-Y2/DIST3D, Z5/DIST3D ),
|
102 |
|
|
new Static3D( X4/DIST3D,-Y2/DIST3D, Z6/DIST3D ),
|
103 |
|
|
new Static3D( -X4/DIST3D,-Y2/DIST3D, Z6/DIST3D ),
|
104 |
|
|
new Static3D( -X3/DIST3D,-Y2/DIST3D, Z5/DIST3D ),
|
105 |
|
|
|
106 |
eeabbae3
|
Leszek Koltunski
|
new Static3D( 0/DIST3D, Y2/DIST3D,-Z4/DIST3D ),
|
107 |
509b223f
|
Leszek Koltunski
|
new Static3D( -X3/DIST3D, Y2/DIST3D,-Z5/DIST3D ),
|
108 |
|
|
new Static3D( -X4/DIST3D, Y2/DIST3D,-Z6/DIST3D ),
|
109 |
|
|
new Static3D( X4/DIST3D, Y2/DIST3D,-Z6/DIST3D ),
|
110 |
|
|
new Static3D( X3/DIST3D, Y2/DIST3D,-Z5/DIST3D ),
|
111 |
|
|
|
112 |
|
|
new Static3D( -X1/DIST3D,-Y1/DIST3D,-Z1/DIST3D ),
|
113 |
|
|
new Static3D( -X2/DIST3D,-Y1/DIST3D,-Z2/DIST3D ),
|
114 |
eeabbae3
|
Leszek Koltunski
|
new Static3D( 0/DIST3D,-Y1/DIST3D,-Z3/DIST3D ),
|
115 |
509b223f
|
Leszek Koltunski
|
new Static3D( X2/DIST3D,-Y1/DIST3D,-Z2/DIST3D ),
|
116 |
|
|
new Static3D( X1/DIST3D,-Y1/DIST3D,-Z1/DIST3D ),
|
117 |
5caf2641
|
Leszek Koltunski
|
};
|
118 |
|
|
|
119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120 |
|
|
|
121 |
|
|
public TouchControlIcosahedron(TwistyObject object)
|
122 |
|
|
{
|
123 |
|
|
super(object,D3D,FACE_AXIS);
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
127 |
|
|
|
128 |
|
|
private boolean isFaceInverted(int face)
|
129 |
|
|
{
|
130 |
|
|
return face<10;
|
131 |
|
|
}
|
132 |
|
|
|
133 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
134 |
|
|
|
135 |
aaeef328
|
Leszek Koltunski
|
private int partEdge(float[] point, int face)
|
136 |
5caf2641
|
Leszek Koltunski
|
{
|
137 |
aaeef328
|
Leszek Koltunski
|
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
138 |
|
|
float x = point[0];
|
139 |
5caf2641
|
Leszek Koltunski
|
|
140 |
aaeef328
|
Leszek Koltunski
|
boolean e0 = x>0;
|
141 |
|
|
boolean e1 = y>( SQ3/3)*x;
|
142 |
|
|
boolean e2 = y>(-SQ3/3)*x;
|
143 |
5caf2641
|
Leszek Koltunski
|
|
144 |
aaeef328
|
Leszek Koltunski
|
if( e1 && e2 ) return 0;
|
145 |
|
|
if( !e1 && e0 ) return 1;
|
146 |
|
|
return 2;
|
147 |
|
|
}
|
148 |
5caf2641
|
Leszek Koltunski
|
|
149 |
aaeef328
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
150 |
5caf2641
|
Leszek Koltunski
|
|
151 |
aaeef328
|
Leszek Koltunski
|
private int partCorner(float[] point, int face)
|
152 |
|
|
{
|
153 |
|
|
float y2 = (isFaceInverted(face) ? point[1] : -point[1]);
|
154 |
|
|
float x2 = point[0];
|
155 |
5caf2641
|
Leszek Koltunski
|
|
156 |
aaeef328
|
Leszek Koltunski
|
boolean c0 = x2>0;
|
157 |
|
|
boolean c1 = y2>( SQ3/3)*x2;
|
158 |
|
|
boolean c2 = y2>(-SQ3/3)*x2;
|
159 |
5caf2641
|
Leszek Koltunski
|
|
160 |
aaeef328
|
Leszek Koltunski
|
if( c0 && c2 ) return 0;
|
161 |
|
|
if( !c1 &&!c2 ) return 1;
|
162 |
|
|
return 2;
|
163 |
|
|
}
|
164 |
9a7e8b98
|
Leszek Koltunski
|
|
165 |
aaeef328
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
166 |
|
|
// corner edge
|
167 |
|
|
// | \ 0 /
|
168 |
|
|
// 2 | 0 \ /
|
169 |
|
|
// / \ 2 | 1
|
170 |
|
|
// / 1 \ |
|
171 |
|
|
|
172 |
|
|
int returnPart(int type, int face, float[] point)
|
173 |
|
|
{
|
174 |
|
|
switch(type)
|
175 |
|
|
{
|
176 |
|
|
case TYPE_NOT_SPLIT : return 0;
|
177 |
|
|
case TYPE_SPLIT_EDGE : return partEdge(point,face);
|
178 |
|
|
case TYPE_SPLIT_CORNER : return partCorner(point,face);
|
179 |
|
|
case TYPE_SPLIT_EDGE_COIN: float y = point[1];
|
180 |
|
|
float x = point[0];
|
181 |
369e6176
|
Leszek Koltunski
|
float dist = D_TRIANGLE*DIST2D;
|
182 |
|
|
return partEdge(point,face) + (x*x+y*y < dist*dist ? 0:3 );
|
183 |
5caf2641
|
Leszek Koltunski
|
}
|
184 |
|
|
|
185 |
|
|
return 0;
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
189 |
|
|
|
190 |
aaeef328
|
Leszek Koltunski
|
boolean isInsideFace(int face, float[] point)
|
191 |
5caf2641
|
Leszek Koltunski
|
{
|
192 |
aaeef328
|
Leszek Koltunski
|
float y = (isFaceInverted(face) ? point[1] : -point[1]);
|
193 |
|
|
float x = point[0];
|
194 |
5caf2641
|
Leszek Koltunski
|
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
|
195 |
|
|
}
|
196 |
|
|
}
|