Project

General

Profile

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

distorted-objectlib / src / main / java / org / distorted / objectlib / main / Movement4.java @ a57e6870

1 29b82486 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.objectlib.main;
21
22
import org.distorted.library.type.Static3D;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
// Tetrahedral objects: map the 2D swipes of user's fingers to 3D rotations
26
27
public class Movement4 extends Movement
28
{
29 8da6b1c9 Leszek Koltunski
  private static final float DIST3D = SQ6/12;
30
  private static final float DIST2D = SQ3/6;
31 29b82486 Leszek Koltunski
32
  public static final Static3D[] FACE_AXIS = new Static3D[]
33
         {
34
           new Static3D(     0,+SQ3/3,+SQ6/3),
35
           new Static3D(     0,+SQ3/3,-SQ6/3),
36
           new Static3D(-SQ6/3,-SQ3/3,     0),
37
           new Static3D(+SQ6/3,-SQ3/3,     0),
38
         };
39
40
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42
  public Movement4(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, int size, int type, int[][][] enabled)
43
    {
44
    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, enabled);
45
    }
46
47
///////////////////////////////////////////////////////////////////////////////////////////////////
48
// corner    edge
49
//   |       \ 0 /
50
// 2 | 0      \ /
51
//  / \      2 | 1
52
// / 1 \       |
53
54
  int returnPart(int type, int face, float[] touchPoint)
55
    {
56
    switch(type)
57
      {
58
      case TYPE_NOT_SPLIT   : return 0;
59
60
      case TYPE_SPLIT_EDGE  : float y1 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
61
                              float x1 = touchPoint[0];
62
63
                              boolean e0 = x1>0;
64
                              boolean e1 = y1>(+SQ3/3)*x1;
65
                              boolean e2 = y1>(-SQ3/3)*x1;
66
67
                              if(  e1 && e2 ) return 0;
68
                              if( !e1 && e0 ) return 1;
69
                              if( !e0 &&!e2 ) return 2;
70
71
      case TYPE_SPLIT_CORNER: float y2 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
72
                              float x2 = touchPoint[0];
73
74
                              boolean c0 = x2>0;
75
                              boolean c1 = y2>(+SQ3/3)*x2;
76
                              boolean c2 = y2>(-SQ3/3)*x2;
77
78
                              if(  c0 && c2 ) return 0;
79
                              if( !c1 &&!c2 ) return 1;
80
                              if( !c0 && c1 ) return 2;
81
      }
82
83
    return 0;
84
    }
85
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87
// Jing has nL=2
88
89 a57e6870 Leszek Koltunski
  public float returnRotationFactor(int[] numLayers, int row)
90 29b82486 Leszek Koltunski
    {
91 a57e6870 Leszek Koltunski
    int numL = numLayers[0];
92
93
    return numL==2 ? 1.0f : ((float)numL)/(numL-row);
94 29b82486 Leszek Koltunski
    }
95
96
///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
  boolean isInsideFace(int face, float[] p)
99
    {
100
    float y = (face > 1 ? p[1] : -p[1]);
101
    float x = p[0];
102
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
103
    }
104
}