| 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 |
|
|
public float returnRotationFactor(int[] numLayers, int row)
|
| 129 |
|
|
{
|
| 130 |
|
|
return 1.0f;
|
| 131 |
|
|
}
|
| 132 |
|
|
|
| 133 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 134 |
|
|
|
| 135 |
|
|
private boolean isFaceInverted(int face)
|
| 136 |
|
|
{
|
| 137 |
|
|
return face<10;
|
| 138 |
|
|
}
|
| 139 |
|
|
|
| 140 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 141 |
|
|
// corner edge
|
| 142 |
|
|
// | \ 0 /
|
| 143 |
|
|
// 2 | 0 \ /
|
| 144 |
|
|
// / \ 2 | 1
|
| 145 |
|
|
// / 1 \ |
|
| 146 |
|
|
|
| 147 |
|
|
int returnPart(int type, int face, float[] touchPoint)
|
| 148 |
|
|
{
|
| 149 |
|
|
switch(type)
|
| 150 |
|
|
{
|
| 151 |
|
|
case TYPE_NOT_SPLIT : return 0;
|
| 152 |
|
|
|
| 153 |
|
|
case TYPE_SPLIT_EDGE : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
|
| 154 |
|
|
float x1 = touchPoint[0];
|
| 155 |
|
|
|
| 156 |
|
|
boolean e0 = x1>0;
|
| 157 |
99320a69
|
Leszek Koltunski
|
boolean e1 = y1>( SQ3/3)*x1;
|
| 158 |
5caf2641
|
Leszek Koltunski
|
boolean e2 = y1>(-SQ3/3)*x1;
|
| 159 |
|
|
|
| 160 |
|
|
if( e1 && e2 ) return 0;
|
| 161 |
|
|
if( !e1 && e0 ) return 1;
|
| 162 |
|
|
if( !e0 &&!e2 ) return 2;
|
| 163 |
9a7e8b98
|
Leszek Koltunski
|
return 0;
|
| 164 |
5caf2641
|
Leszek Koltunski
|
|
| 165 |
|
|
case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
|
| 166 |
|
|
float x2 = touchPoint[0];
|
| 167 |
|
|
|
| 168 |
|
|
boolean c0 = x2>0;
|
| 169 |
99320a69
|
Leszek Koltunski
|
boolean c1 = y2>( SQ3/3)*x2;
|
| 170 |
5caf2641
|
Leszek Koltunski
|
boolean c2 = y2>(-SQ3/3)*x2;
|
| 171 |
|
|
|
| 172 |
|
|
if( c0 && c2 ) return 0;
|
| 173 |
|
|
if( !c1 &&!c2 ) return 1;
|
| 174 |
|
|
if( !c0 && c1 ) return 2;
|
| 175 |
9a7e8b98
|
Leszek Koltunski
|
return 0;
|
| 176 |
|
|
|
| 177 |
|
|
case TYPE_SPLIT_EDGE_COIN: // not supported
|
| 178 |
5caf2641
|
Leszek Koltunski
|
}
|
| 179 |
|
|
|
| 180 |
|
|
return 0;
|
| 181 |
|
|
}
|
| 182 |
|
|
|
| 183 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 184 |
|
|
|
| 185 |
|
|
boolean isInsideFace(int face, float[] p)
|
| 186 |
|
|
{
|
| 187 |
|
|
float y = (isFaceInverted(face) ? p[1] : -p[1]);
|
| 188 |
|
|
float x = p[0];
|
| 189 |
|
|
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
|
| 190 |
|
|
}
|
| 191 |
|
|
}
|