Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / touchcontrol / TouchControlOctahedron.java @ aaeef328

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
// Octahedral objects: map the 2D swipes of user's fingers to 3D rotations
17
18 c9c71c3f Leszek Koltunski
public class TouchControlOctahedron extends TouchControlShapeConstant
19 29b82486 Leszek Koltunski
{
20 8da6b1c9 Leszek Koltunski
  private static final float DIST3D = SQ6/6;
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,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( SQ6/3, SQ3/3,     0), new Static3D(-SQ6/3,-SQ3/3,     0),
28
           new Static3D(-SQ6/3, SQ3/3,     0), new Static3D( SQ6/3,-SQ3/3,     0),
29
           new Static3D(     0, SQ3/3, SQ6/3), new Static3D(     0,-SQ3/3,-SQ6/3),
30
           new Static3D(     0, SQ3/3,-SQ6/3), new Static3D(     0,-SQ3/3, SQ6/3)
31 29b82486 Leszek Koltunski
         };
32
33
///////////////////////////////////////////////////////////////////////////////////////////////////
34
35 57ef6378 Leszek Koltunski
  public TouchControlOctahedron(TwistyObject object)
36 29b82486 Leszek Koltunski
    {
37 57ef6378 Leszek Koltunski
    super(object,D3D,FACE_AXIS);
38 29b82486 Leszek Koltunski
    }
39
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42 aaeef328 Leszek Koltunski
  private boolean isFaceInverted(int face)
43 29b82486 Leszek Koltunski
    {
44 aaeef328 Leszek Koltunski
    return (face%2)==0;
45
    }
46
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
49
  private int partEdge(float[] point, int face)
50
    {
51
    float y = (isFaceInverted(face) ? point[1] : -point[1]);
52
    float x = point[0];
53
54
    boolean e0 = x>0;
55
    boolean e1 = y>( SQ3/3)*x;
56
    boolean e2 = y>(-SQ3/3)*x;
57 29b82486 Leszek Koltunski
58 aaeef328 Leszek Koltunski
    if(  e1 && e2 ) return 0;
59
    if( !e1 && e0 ) return 1;
60
    return 2;
61
    }
62 29b82486 Leszek Koltunski
63 aaeef328 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
64 29b82486 Leszek Koltunski
65 aaeef328 Leszek Koltunski
  private int partCorner(float[] point, int face)
66
    {
67
    float y = (isFaceInverted(face) ? point[1] : -point[1]);
68
    float x = point[0];
69 29b82486 Leszek Koltunski
70 aaeef328 Leszek Koltunski
    boolean c0 = x>0;
71
    boolean c1 = y>( SQ3/3)*x;
72
    boolean c2 = y>(-SQ3/3)*x;
73 29b82486 Leszek Koltunski
74 aaeef328 Leszek Koltunski
    if(  c0 && c2 ) return 0;
75
    if( !c1 &&!c2 ) return 1;
76
    return 2;
77
    }
78 29b82486 Leszek Koltunski
79 aaeef328 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
80
// corner    edge
81
//   |       \ 0 /
82
// 2 | 0      \ /
83
//  / \      2 | 1
84
// / 1 \       |
85 9a7e8b98 Leszek Koltunski
86 aaeef328 Leszek Koltunski
  int returnPart(int type, int face, float[] point)
87
    {
88
    switch(type)
89
      {
90
      case TYPE_NOT_SPLIT       : return 0;
91
      case TYPE_SPLIT_EDGE      : return partEdge(point,face);
92
      case TYPE_SPLIT_CORNER    : return partCorner(point,face);
93
      case TYPE_SPLIT_EDGE_COIN : float y = point[1];
94
                                  float x = point[0];
95
                                  return partEdge(point,face) + (x*x+y*y < DIST2D*DIST2D ? 0:3 );
96 29b82486 Leszek Koltunski
      }
97
98
    return 0;
99
    }
100
101
///////////////////////////////////////////////////////////////////////////////////////////////////
102
103 a57e6870 Leszek Koltunski
  public float returnRotationFactor(int[] numLayers, int row)
104 29b82486 Leszek Koltunski
    {
105
    return 1.0f;
106
    }
107
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
110 aaeef328 Leszek Koltunski
  boolean isInsideFace(int face, float[] point)
111 29b82486 Leszek Koltunski
    {
112 aaeef328 Leszek Koltunski
    float y = (isFaceInverted(face) ? point[1] : -point[1]);
113
    float x = point[0];
114 29b82486 Leszek Koltunski
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
115
    }
116
}