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
|
// corner edge
|
41
|
// \ 0 / 3 | 0
|
42
|
// 3 \ / 1 ___ | ___
|
43
|
// / \ |
|
44
|
// / 2 \ 2 | 1
|
45
|
|
46
|
int returnPart(int type, int face, float[] touchPoint)
|
47
|
{
|
48
|
switch(type)
|
49
|
{
|
50
|
case TYPE_NOT_SPLIT : return 0;
|
51
|
case TYPE_SPLIT_EDGE : boolean e0 = touchPoint[0] > 0;
|
52
|
boolean e1 = touchPoint[1] > 0;
|
53
|
return e0 ? (e1 ? 0:1) : (e1 ? 3:2);
|
54
|
case TYPE_SPLIT_CORNER: boolean c0 = touchPoint[1] >= touchPoint[0];
|
55
|
boolean c1 = touchPoint[1] >=-touchPoint[0];
|
56
|
return c0 ? (c1 ? 0:3) : (c1 ? 1:2);
|
57
|
}
|
58
|
|
59
|
return 0;
|
60
|
}
|
61
|
|
62
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
63
|
|
64
|
public float returnRotationFactor(int[] numLayers, int row)
|
65
|
{
|
66
|
return 1.0f;
|
67
|
}
|
68
|
|
69
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
70
|
|
71
|
boolean isInsideFace(int face, float[] p)
|
72
|
{
|
73
|
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D );
|
74
|
}
|
75
|
}
|