| 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 |
23afe4c4
|
Leszek Koltunski
|
package org.distorted.objectlib.movement;
|
| 21 |
29b82486
|
Leszek Koltunski
|
|
| 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 |
f86b282a
|
Leszek Koltunski
|
public class MovementTetrahedron extends Movement
|
| 28 |
29b82486
|
Leszek Koltunski
|
{
|
| 29 |
8da6b1c9
|
Leszek Koltunski
|
private static final float DIST3D = SQ6/12;
|
| 30 |
|
|
private static final float DIST2D = SQ3/6;
|
| 31 |
29b82486
|
Leszek Koltunski
|
|
| 32 |
ab31cf6f
|
Leszek Koltunski
|
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D };
|
| 33 |
|
|
|
| 34 |
29b82486
|
Leszek Koltunski
|
public static final Static3D[] FACE_AXIS = new Static3D[]
|
| 35 |
|
|
{
|
| 36 |
|
|
new Static3D( 0,+SQ3/3,+SQ6/3),
|
| 37 |
|
|
new Static3D( 0,+SQ3/3,-SQ6/3),
|
| 38 |
|
|
new Static3D(-SQ6/3,-SQ3/3, 0),
|
| 39 |
|
|
new Static3D(+SQ6/3,-SQ3/3, 0),
|
| 40 |
|
|
};
|
| 41 |
|
|
|
| 42 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 43 |
|
|
|
| 44 |
f86b282a
|
Leszek Koltunski
|
public MovementTetrahedron(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled)
|
| 45 |
29b82486
|
Leszek Koltunski
|
{
|
| 46 |
ab31cf6f
|
Leszek Koltunski
|
super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled);
|
| 47 |
29b82486
|
Leszek Koltunski
|
}
|
| 48 |
|
|
|
| 49 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 50 |
|
|
// corner edge
|
| 51 |
|
|
// | \ 0 /
|
| 52 |
|
|
// 2 | 0 \ /
|
| 53 |
|
|
// / \ 2 | 1
|
| 54 |
|
|
// / 1 \ |
|
| 55 |
|
|
|
| 56 |
|
|
int returnPart(int type, int face, float[] touchPoint)
|
| 57 |
|
|
{
|
| 58 |
|
|
switch(type)
|
| 59 |
|
|
{
|
| 60 |
|
|
case TYPE_NOT_SPLIT : return 0;
|
| 61 |
|
|
|
| 62 |
|
|
case TYPE_SPLIT_EDGE : float y1 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
|
| 63 |
|
|
float x1 = touchPoint[0];
|
| 64 |
|
|
|
| 65 |
|
|
boolean e0 = x1>0;
|
| 66 |
|
|
boolean e1 = y1>(+SQ3/3)*x1;
|
| 67 |
|
|
boolean e2 = y1>(-SQ3/3)*x1;
|
| 68 |
|
|
|
| 69 |
|
|
if( e1 && e2 ) return 0;
|
| 70 |
|
|
if( !e1 && e0 ) return 1;
|
| 71 |
|
|
if( !e0 &&!e2 ) return 2;
|
| 72 |
|
|
|
| 73 |
|
|
case TYPE_SPLIT_CORNER: float y2 = (face > 1 ? touchPoint[1] : -touchPoint[1]);
|
| 74 |
|
|
float x2 = touchPoint[0];
|
| 75 |
|
|
|
| 76 |
|
|
boolean c0 = x2>0;
|
| 77 |
|
|
boolean c1 = y2>(+SQ3/3)*x2;
|
| 78 |
|
|
boolean c2 = y2>(-SQ3/3)*x2;
|
| 79 |
|
|
|
| 80 |
|
|
if( c0 && c2 ) return 0;
|
| 81 |
|
|
if( !c1 &&!c2 ) return 1;
|
| 82 |
|
|
if( !c0 && c1 ) return 2;
|
| 83 |
|
|
}
|
| 84 |
|
|
|
| 85 |
|
|
return 0;
|
| 86 |
|
|
}
|
| 87 |
|
|
|
| 88 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 89 |
|
|
// Jing has nL=2
|
| 90 |
|
|
|
| 91 |
a57e6870
|
Leszek Koltunski
|
public float returnRotationFactor(int[] numLayers, int row)
|
| 92 |
29b82486
|
Leszek Koltunski
|
{
|
| 93 |
a57e6870
|
Leszek Koltunski
|
int numL = numLayers[0];
|
| 94 |
|
|
|
| 95 |
|
|
return numL==2 ? 1.0f : ((float)numL)/(numL-row);
|
| 96 |
29b82486
|
Leszek Koltunski
|
}
|
| 97 |
|
|
|
| 98 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 99 |
|
|
|
| 100 |
|
|
boolean isInsideFace(int face, float[] p)
|
| 101 |
|
|
{
|
| 102 |
|
|
float y = (face > 1 ? p[1] : -p[1]);
|
| 103 |
|
|
float x = p[0];
|
| 104 |
|
|
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x));
|
| 105 |
|
|
}
|
| 106 |
|
|
}
|