Project

General

Profile

Download (4.52 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / objects / Movement4.java @ 967c1d17

1 be7c9190 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.objects;
21
22
import org.distorted.library.type.Static3D;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 c7a98f94 Leszek Koltunski
// Tetrahedral objects: map the 2D swipes of user's fingers to 3D rotations
26 be7c9190 Leszek Koltunski
27 967c1d17 Leszek Koltunski
class Movement4 extends Movement
28 be7c9190 Leszek Koltunski
{
29
  static final float DIST3D = SQ6/12;
30
  static final float DIST2D = SQ3/6;
31
32
  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 ef018c1b Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
41
42 967c1d17 Leszek Koltunski
  Movement4(Static3D[] rotAxis,float[][] cuts, boolean[][] rotatable, int size, int type, int[] numEnabled, int[][][] enabled)
43 ef018c1b Leszek Koltunski
    {
44 967c1d17 Leszek Koltunski
    super(rotAxis, FACE_AXIS, cuts, rotatable, DIST3D, size, type, numEnabled, 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 be7c9190 Leszek Koltunski
    }
85
86
///////////////////////////////////////////////////////////////////////////////////////////////////
87 c7a98f94 Leszek Koltunski
// Jing has nL=2
88 be7c9190 Leszek Koltunski
89
  public float returnRotationFactor(int numLayers, int row)
90
    {
91 c7a98f94 Leszek Koltunski
    return numLayers==2 ? 1.0f : ((float)numLayers)/(numLayers-row);
92 be7c9190 Leszek Koltunski
    }
93
94
///////////////////////////////////////////////////////////////////////////////////////////////////
95
96
  boolean isInsideFace(int face, float[] p)
97
    {
98
    float y = (face > 1 ? p[1] : -p[1]);
99
    float x = p[0];
100
    return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
101
    }
102
}