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
|
// Hexahedral objects: map the 2D swipes of user's fingers to 3D rotations
|
17
|
|
18
|
public class TouchControlHexahedron extends TouchControlShapeConstant
|
19
|
{
|
20
|
private static final float DIST3D = 0.5f;
|
21
|
private static final float DIST2D = 0.5f;
|
22
|
|
23
|
public static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
|
24
|
|
25
|
public static final Static3D[] FACE_AXIS = new Static3D[]
|
26
|
{
|
27
|
new Static3D(1,0,0), new Static3D(-1,0,0),
|
28
|
new Static3D(0,1,0), new Static3D(0,-1,0),
|
29
|
new Static3D(0,0,1), new Static3D(0,0,-1)
|
30
|
};
|
31
|
|
32
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
33
|
|
34
|
public TouchControlHexahedron(TwistyObject object)
|
35
|
{
|
36
|
super(object,D3D,FACE_AXIS);
|
37
|
}
|
38
|
|
39
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
40
|
|
41
|
private int partEdge(float[] point, int face)
|
42
|
{
|
43
|
boolean e0 = point[0] > 0;
|
44
|
boolean e1 = point[1] > 0;
|
45
|
return e0 ? (e1 ? 0:1) : (e1 ? 3:2);
|
46
|
}
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
private int partCorner(float[] point, int face)
|
51
|
{
|
52
|
boolean c0 = point[1] >= point[0];
|
53
|
boolean c1 = point[1] >=-point[0];
|
54
|
return c0 ? (c1 ? 0:3) : (c1 ? 1:2);
|
55
|
}
|
56
|
|
57
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58
|
// corner edge
|
59
|
// \ 0 / 3 | 0
|
60
|
// 3 \ / 1 ___ | ___
|
61
|
// / \ |
|
62
|
// / 2 \ 2 | 1
|
63
|
|
64
|
int returnPart(int type, int face, float[] point)
|
65
|
{
|
66
|
switch(type)
|
67
|
{
|
68
|
case TYPE_NOT_SPLIT : return 0;
|
69
|
case TYPE_SPLIT_EDGE : return partEdge(point,face);
|
70
|
case TYPE_SPLIT_CORNER : return partCorner(point,face);
|
71
|
case TYPE_SPLIT_EDGE_COIN: float y = point[1];
|
72
|
float x = point[0];
|
73
|
float dist = D_SQUARE*DIST2D;
|
74
|
return partEdge(point,face) + (x*x+y*y < dist*dist ? 0:4 );
|
75
|
}
|
76
|
|
77
|
return 0;
|
78
|
}
|
79
|
|
80
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81
|
|
82
|
public float returnRotationFactor(int[] numLayers, int row)
|
83
|
{
|
84
|
return 1.0f;
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
boolean isInsideFace(int face, float[] p)
|
90
|
{
|
91
|
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D );
|
92
|
}
|
93
|
}
|