1 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2020 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
71f8a172
|
Leszek Koltunski
|
// 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 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
9 |
|
|
|
10 |
c9c71c3f
|
Leszek Koltunski
|
package org.distorted.objectlib.touchcontrol;
|
11 |
29b82486
|
Leszek Koltunski
|
|
12 |
|
|
import org.distorted.library.type.Static3D;
|
13 |
57ef6378
|
Leszek Koltunski
|
import org.distorted.objectlib.main.TwistyObject;
|
14 |
29b82486
|
Leszek Koltunski
|
|
15 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
16 |
|
|
// Hexahedral objects: map the 2D swipes of user's fingers to 3D rotations
|
17 |
|
|
|
18 |
c9c71c3f
|
Leszek Koltunski
|
public class TouchControlHexahedron extends TouchControlShapeConstant
|
19 |
29b82486
|
Leszek Koltunski
|
{
|
20 |
6377eed5
|
leszek
|
public static final float DIST3D = 0.5f;
|
21 |
8da6b1c9
|
Leszek Koltunski
|
private static final float DIST2D = 0.5f;
|
22 |
29b82486
|
Leszek Koltunski
|
|
23 |
4c9ca251
|
Leszek Koltunski
|
public static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
|
24 |
ab31cf6f
|
Leszek Koltunski
|
|
25 |
29b82486
|
Leszek Koltunski
|
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 |
57ef6378
|
Leszek Koltunski
|
public TouchControlHexahedron(TwistyObject object)
|
35 |
29b82486
|
Leszek Koltunski
|
{
|
36 |
57ef6378
|
Leszek Koltunski
|
super(object,D3D,FACE_AXIS);
|
37 |
29b82486
|
Leszek Koltunski
|
}
|
38 |
|
|
|
39 |
aaeef328
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
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 |
29b82486
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
58 |
|
|
// corner edge
|
59 |
|
|
// \ 0 / 3 | 0
|
60 |
|
|
// 3 \ / 1 ___ | ___
|
61 |
|
|
// / \ |
|
62 |
|
|
// / 2 \ 2 | 1
|
63 |
|
|
|
64 |
aaeef328
|
Leszek Koltunski
|
int returnPart(int type, int face, float[] point)
|
65 |
29b82486
|
Leszek Koltunski
|
{
|
66 |
|
|
switch(type)
|
67 |
|
|
{
|
68 |
aaeef328
|
Leszek Koltunski
|
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 |
369e6176
|
Leszek Koltunski
|
float dist = D_SQUARE*DIST2D;
|
74 |
|
|
return partEdge(point,face) + (x*x+y*y < dist*dist ? 0:4 );
|
75 |
29b82486
|
Leszek Koltunski
|
}
|
76 |
|
|
|
77 |
|
|
return 0;
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
81 |
|
|
|
82 |
|
|
boolean isInsideFace(int face, float[] p)
|
83 |
|
|
{
|
84 |
|
|
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D );
|
85 |
|
|
}
|
86 |
|
|
}
|