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