Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / touchcontrol / TouchControlIcosahedron.java @ 509b223f

1 5caf2641 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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 99320a69 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13 5caf2641 Leszek Koltunski
import static org.distorted.objectlib.main.TwistyObject.SQ5;
14
15
import org.distorted.library.type.Static3D;
16
import org.distorted.objectlib.main.TwistyObject;
17
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
// Icosahedral objects: map the 2D swipes of user's fingers to 3D rotations
20
21
public class TouchControlIcosahedron extends TouchControlShapeConstant
22
{
23 99320a69 Leszek Koltunski
  public  static final float DIST3D = (3+SQ5)*SQ3/12;
24 5caf2641 Leszek Koltunski
  private static final float DIST2D = SQ3/6;
25
  public static final float[] D3D   = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
26
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
27
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,
28
                                        DIST3D,DIST3D,DIST3D,DIST3D,DIST3D };
29 a8efe86f Leszek Koltunski
30
  // topmost vertex (0,A,0) and 3 vertices from the second-topmost-layer, front one and two ones
31
  // to the right: (0,B,C) , (D,B,E) , (F,B,H)
32 99320a69 Leszek Koltunski
33
  private static final float Z = (float)Math.sqrt(5+SQ5);
34
35
  private static final float A = Z*(SQ2/4);
36
  private static final float B = Z*(SQ2*SQ5/20);
37
  private static final float C = Z*(SQ2*SQ5/10);
38 d54d1f8a Leszek Koltunski
  private static final float D = (SQ5+1)/4;
39
  private static final float E = Z*(SQ5-1)/(4*SQ2*SQ5);
40 99320a69 Leszek Koltunski
  private static final float F = 0.5f;
41
  private static final float H =-Z*(SQ5+1)/(4*SQ2*SQ5);
42
43
  private static final float X1 = D/3;
44
  private static final float X2 = (D+F)/3;
45
  private static final float X3 = (2*D+F)/3;
46 716f5517 Leszek Koltunski
  private static final float X4 = (D+F)/3;
47 99320a69 Leszek Koltunski
  private static final float Y1 = (A+2*B)/3;
48
  private static final float Y2 = B/3;
49
  private static final float Z1 = (C+E)/3;
50
  private static final float Z2 = (E+H)/3;
51
  private static final float Z3 = 2*H/3;
52
  private static final float Z4 = (C-2*H)/3;
53
  private static final float Z5 = -H/3;
54
  private static final float Z6 = (H-C-E)/3;
55 5caf2641 Leszek Koltunski
56
  public static final Static3D[] FACE_AXIS = new Static3D[]
57
         {
58 509b223f Leszek Koltunski
           new Static3D(    X1/DIST3D, Y1/DIST3D, Z1/DIST3D   ),
59
           new Static3D(    X2/DIST3D, Y1/DIST3D, Z2/DIST3D   ),
60
           new Static3D(  0.0f/DIST3D, Y1/DIST3D, Z3/DIST3D   ),
61
           new Static3D(   -X2/DIST3D, Y1/DIST3D, Z2/DIST3D   ),
62
           new Static3D(   -X1/DIST3D, Y1/DIST3D, Z1/DIST3D   ),
63
64
           new Static3D(  0.0f/DIST3D,-Y2/DIST3D, Z4/DIST3D   ),
65
           new Static3D(    X3/DIST3D,-Y2/DIST3D, Z5/DIST3D   ),
66
           new Static3D(    X4/DIST3D,-Y2/DIST3D, Z6/DIST3D   ),
67
           new Static3D(   -X4/DIST3D,-Y2/DIST3D, Z6/DIST3D   ),
68
           new Static3D(   -X3/DIST3D,-Y2/DIST3D, Z5/DIST3D   ),
69
70
           new Static3D(  0.0f/DIST3D, Y2/DIST3D,-Z4/DIST3D   ),
71
           new Static3D(   -X3/DIST3D, Y2/DIST3D,-Z5/DIST3D   ),
72
           new Static3D(   -X4/DIST3D, Y2/DIST3D,-Z6/DIST3D   ),
73
           new Static3D(    X4/DIST3D, Y2/DIST3D,-Z6/DIST3D   ),
74
           new Static3D(    X3/DIST3D, Y2/DIST3D,-Z5/DIST3D   ),
75
76
           new Static3D(   -X1/DIST3D,-Y1/DIST3D,-Z1/DIST3D   ),
77
           new Static3D(   -X2/DIST3D,-Y1/DIST3D,-Z2/DIST3D   ),
78
           new Static3D(  0.0f/DIST3D,-Y1/DIST3D,-Z3/DIST3D   ),
79
           new Static3D(    X2/DIST3D,-Y1/DIST3D,-Z2/DIST3D   ),
80
           new Static3D(    X1/DIST3D,-Y1/DIST3D,-Z1/DIST3D   ),
81 5caf2641 Leszek Koltunski
         };
82
83
///////////////////////////////////////////////////////////////////////////////////////////////////
84
85
  public TouchControlIcosahedron(TwistyObject object)
86
    {
87
    super(object,D3D,FACE_AXIS);
88
    }
89
90
///////////////////////////////////////////////////////////////////////////////////////////////////
91
92
  public float returnRotationFactor(int[] numLayers, int row)
93
    {
94
    return 1.0f;
95
    }
96
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98
99
  private boolean isFaceInverted(int face)
100
    {
101
    return face<10;
102
    }
103
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105
// corner    edge
106
//   |       \ 0 /
107
// 2 | 0      \ /
108
//  / \      2 | 1
109
// / 1 \       |
110
111
  int returnPart(int type, int face, float[] touchPoint)
112
    {
113
    switch(type)
114
      {
115
      case TYPE_NOT_SPLIT   : return 0;
116
117
      case TYPE_SPLIT_EDGE  : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
118
                              float x1 = touchPoint[0];
119
120
                              boolean e0 = x1>0;
121 99320a69 Leszek Koltunski
                              boolean e1 = y1>( SQ3/3)*x1;
122 5caf2641 Leszek Koltunski
                              boolean e2 = y1>(-SQ3/3)*x1;
123
124
                              if(  e1 && e2 ) return 0;
125
                              if( !e1 && e0 ) return 1;
126
                              if( !e0 &&!e2 ) return 2;
127
128
      case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
129
                              float x2 = touchPoint[0];
130
131
                              boolean c0 = x2>0;
132 99320a69 Leszek Koltunski
                              boolean c1 = y2>( SQ3/3)*x2;
133 5caf2641 Leszek Koltunski
                              boolean c2 = y2>(-SQ3/3)*x2;
134
135
                              if(  c0 && c2 ) return 0;
136
                              if( !c1 &&!c2 ) return 1;
137
                              if( !c0 && c1 ) return 2;
138
      }
139
140
    return 0;
141
    }
142
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144
145
  boolean isInsideFace(int face, float[] p)
146
    {
147
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
148
    float x = p[0];
149
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
150
    }
151
}