Project

General

Profile

Download (4.45 KB) Statistics
| Branch: | Revision:

distorted-objectlib / src / main / java / org / distorted / objectlib / touchcontrol / TouchControlTetrahedron.java @ 9a7e8b98

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