Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
import static org.distorted.objectlib.main.TwistyObject.SQ2;
13
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
  public  static final float DIST3D = (3+SQ5)*SQ3/12;
24
  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

    
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

    
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
  private static final float D = (SQ5+1)/4;
39
  private static final float E = Z*(SQ5-1)/(4*SQ2*SQ5);
40
  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
  private static final float X4 = (D+F)/2;
47
  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

    
56
  private static final float LEN = (float)Math.sqrt(X1*X1 + Y1*Y1 + Z1*Z1);
57

    
58
  public static final Static3D[] FACE_AXIS = new Static3D[]
59
         {
60
           new Static3D(    X1/LEN, Y1/LEN, Z1/LEN   ),
61
           new Static3D(    X2/LEN, Y1/LEN, Z2/LEN   ),
62
           new Static3D(  0.0f/LEN, Y1/LEN, Z3/LEN   ),
63
           new Static3D(   -X2/LEN, Y1/LEN, Z2/LEN   ),
64
           new Static3D(   -X1/LEN, Y1/LEN, Z1/LEN   ),
65

    
66
           new Static3D(  0.0f/LEN,-Y2/LEN, Z4/LEN   ),
67
           new Static3D(    X3/LEN,-Y2/LEN, Z5/LEN   ),
68
           new Static3D(    X4/LEN,-Y2/LEN, Z6/LEN   ),
69
           new Static3D(   -X4/LEN,-Y2/LEN, Z6/LEN   ),
70
           new Static3D(   -X3/LEN,-Y2/LEN, Z5/LEN   ),
71

    
72
           new Static3D(  0.0f/LEN, Y2/LEN,-Z4/LEN   ),
73
           new Static3D(   -X3/LEN, Y2/LEN,-Z5/LEN   ),
74
           new Static3D(   -X4/LEN, Y2/LEN,-Z6/LEN   ),
75
           new Static3D(    X4/LEN, Y2/LEN,-Z6/LEN   ),
76
           new Static3D(    X3/LEN, Y2/LEN,-Z5/LEN   ),
77

    
78
           new Static3D(   -X1/LEN,-Y1/LEN,-Z1/LEN   ),
79
           new Static3D(   -X2/LEN,-Y1/LEN,-Z2/LEN   ),
80
           new Static3D(  0.0f/LEN,-Y1/LEN,-Z3/LEN   ),
81
           new Static3D(    X2/LEN,-Y1/LEN,-Z2/LEN   ),
82
           new Static3D(    X1/LEN,-Y1/LEN,-Z1/LEN   ),
83
         };
84

    
85
///////////////////////////////////////////////////////////////////////////////////////////////////
86

    
87
  public TouchControlIcosahedron(TwistyObject object)
88
    {
89
    super(object,D3D,FACE_AXIS);
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  public float returnRotationFactor(int[] numLayers, int row)
95
    {
96
    return 1.0f;
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  private boolean isFaceInverted(int face)
102
    {
103
    return face<10;
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107
// corner    edge
108
//   |       \ 0 /
109
// 2 | 0      \ /
110
//  / \      2 | 1
111
// / 1 \       |
112

    
113
  int returnPart(int type, int face, float[] touchPoint)
114
    {
115
    switch(type)
116
      {
117
      case TYPE_NOT_SPLIT   : return 0;
118

    
119
      case TYPE_SPLIT_EDGE  : float y1 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
120
                              float x1 = touchPoint[0];
121

    
122
                              boolean e0 = x1>0;
123
                              boolean e1 = y1>( SQ3/3)*x1;
124
                              boolean e2 = y1>(-SQ3/3)*x1;
125

    
126
                              if(  e1 && e2 ) return 0;
127
                              if( !e1 && e0 ) return 1;
128
                              if( !e0 &&!e2 ) return 2;
129

    
130
      case TYPE_SPLIT_CORNER: float y2 = (isFaceInverted(face) ? touchPoint[1] : -touchPoint[1]);
131
                              float x2 = touchPoint[0];
132

    
133
                              boolean c0 = x2>0;
134
                              boolean c1 = y2>( SQ3/3)*x2;
135
                              boolean c2 = y2>(-SQ3/3)*x2;
136

    
137
                              if(  c0 && c2 ) return 0;
138
                              if( !c1 &&!c2 ) return 1;
139
                              if( !c0 && c1 ) return 2;
140
      }
141

    
142
    return 0;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  boolean isInsideFace(int face, float[] p)
148
    {
149
    float y = (isFaceInverted(face) ? p[1] : -p[1]);
150
    float x = p[0];
151
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
152
    }
153
}
(6-6/13)