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.objectlib.touchcontrol;
|
21
|
|
22
|
import org.distorted.library.type.Static3D;
|
23
|
import org.distorted.objectlib.main.TwistyObject;
|
24
|
|
25
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
26
|
// Tetrahedral objects: map the 2D swipes of user's fingers to 3D rotations
|
27
|
|
28
|
public class TouchControlTetrahedron extends TouchControlShapeConstant
|
29
|
{
|
30
|
private static final float DIST3D = SQ6/12;
|
31
|
private static final float DIST2D = SQ3/6;
|
32
|
|
33
|
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D };
|
34
|
|
35
|
public static final Static3D[] FACE_AXIS = new Static3D[]
|
36
|
{
|
37
|
new Static3D( 0,+SQ3/3,+SQ6/3),
|
38
|
new Static3D( 0,+SQ3/3,-SQ6/3),
|
39
|
new Static3D(-SQ6/3,-SQ3/3, 0),
|
40
|
new Static3D(+SQ6/3,-SQ3/3, 0),
|
41
|
};
|
42
|
|
43
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
44
|
|
45
|
public TouchControlTetrahedron(TwistyObject object)
|
46
|
{
|
47
|
super(object,D3D,FACE_AXIS);
|
48
|
}
|
49
|
|
50
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
51
|
// corner edge
|
52
|
// | \ 0 /
|
53
|
// 2 | 0 \ /
|
54
|
// / \ 2 | 1
|
55
|
// / 1 \ |
|
56
|
|
57
|
int returnPart(int type, int face, float[] touchPoint)
|
58
|
{
|
59
|
switch(type)
|
60
|
{
|
61
|
case TYPE_NOT_SPLIT : return 0;
|
62
|
|
63
|
case TYPE_SPLIT_EDGE : float y1 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
|
64
|
float x1 = touchPoint[0];
|
65
|
|
66
|
boolean e0 = x1>0;
|
67
|
boolean e1 = y1>(+SQ3/3)*x1;
|
68
|
boolean e2 = y1>(-SQ3/3)*x1;
|
69
|
|
70
|
if( e1 && e2 ) return 0;
|
71
|
if( !e1 && e0 ) return 1;
|
72
|
if( !e0 &&!e2 ) return 2;
|
73
|
|
74
|
case TYPE_SPLIT_CORNER: float y2 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
|
75
|
float x2 = touchPoint[0];
|
76
|
|
77
|
boolean c0 = x2>0;
|
78
|
boolean c1 = y2>(+SQ3/3)*x2;
|
79
|
boolean c2 = y2>(-SQ3/3)*x2;
|
80
|
|
81
|
if( c0 && c2 ) return 0;
|
82
|
if( !c1 &&!c2 ) return 1;
|
83
|
if( !c0 && c1 ) return 2;
|
84
|
}
|
85
|
|
86
|
return 0;
|
87
|
}
|
88
|
|
89
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
90
|
// Jing has nL=2
|
91
|
|
92
|
public float returnRotationFactor(int[] numLayers, int row)
|
93
|
{
|
94
|
int numL = numLayers[0];
|
95
|
|
96
|
return numL==2 ? 1.0f : ((float)numL)/(numL-row);
|
97
|
}
|
98
|
|
99
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
100
|
|
101
|
boolean isInsideFace(int face, float[] p)
|
102
|
{
|
103
|
float y = (face > 1 ? p[1] : -p[1]);
|
104
|
float x = p[0];
|
105
|
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
|
106
|
}
|
107
|
}
|