Revision c9c71c3f
Added by Leszek Koltunski over 2 years ago
src/main/java/org/distorted/objectlib/json/JsonReader.java | ||
---|---|---|
25 | 25 |
import java.io.InputStreamReader; |
26 | 26 |
import java.nio.charset.StandardCharsets; |
27 | 27 |
|
28 |
import org.distorted.objectlib.movement.Movement;
|
|
28 |
import org.distorted.objectlib.touchcontrol.TouchControl;
|
|
29 | 29 |
import org.json.JSONArray; |
30 | 30 |
import org.json.JSONException; |
31 | 31 |
import org.json.JSONObject; |
... | ... | |
438 | 438 |
{ |
439 | 439 |
switch(mMovementType) |
440 | 440 |
{ |
441 |
case Movement.MOVEMENT_TETRAHEDRON : mNumFaces = 4; break;
|
|
442 |
case Movement.MOVEMENT_HEXAHEDRON : mNumFaces = 6; break;
|
|
443 |
case Movement.MOVEMENT_OCTAHEDRON : mNumFaces = 8; break;
|
|
444 |
case Movement.MOVEMENT_DODECAHEDRON: mNumFaces =12; break;
|
|
445 |
default : android.util.Log.e("D", "Error in parseTouchcontrol");
|
|
441 |
case TouchControl.TC_TETRAHEDRON : mNumFaces = 4; break;
|
|
442 |
case TouchControl.TC_HEXAHEDRON : mNumFaces = 6; break;
|
|
443 |
case TouchControl.TC_OCTAHEDRON : mNumFaces = 8; break;
|
|
444 |
case TouchControl.TC_DODECAHEDRON: mNumFaces =12; break;
|
|
445 |
default : android.util.Log.e("D", "Error in parseTouchcontrol"); |
|
446 | 446 |
} |
447 | 447 |
} |
448 | 448 |
} |
src/main/java/org/distorted/objectlib/main/ObjectControl.java | ||
---|---|---|
33 | 33 |
import org.distorted.objectlib.helpers.BlockController; |
34 | 34 |
import org.distorted.objectlib.helpers.MovesFinished; |
35 | 35 |
import org.distorted.objectlib.helpers.ObjectLibInterface; |
36 |
import org.distorted.objectlib.movement.Movement;
|
|
36 |
import org.distorted.objectlib.touchcontrol.TouchControl;
|
|
37 | 37 |
|
38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
39 | 39 |
|
... | ... | |
56 | 56 |
|
57 | 57 |
private final ObjectLibInterface mInterface; |
58 | 58 |
private final ObjectPreRender mPreRender; |
59 |
private Movement mMovement;
|
|
59 |
private TouchControl mTouchControl;
|
|
60 | 60 |
private TwistyObjectNode mObjectNode; |
61 | 61 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
62 | 62 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
... | ... | |
169 | 169 |
if( down ) |
170 | 170 |
{ |
171 | 171 |
int color = mInterface.getCurrentColor(); |
172 |
float[] point = mMovement.getTouchedPoint3D();
|
|
172 |
float[] point = mTouchControl.getTouchedPoint3D();
|
|
173 | 173 |
mLastCubit = object.getCubit(point); |
174 | 174 |
mLastCubitColor = mInterface.cubitIsLocked(mLastCubit); |
175 | 175 |
int face; |
... | ... | |
180 | 180 |
} |
181 | 181 |
else |
182 | 182 |
{ |
183 |
int touchedFace = mMovement.getTouchedFace();
|
|
183 |
int touchedFace = mTouchControl.getTouchedFace();
|
|
184 | 184 |
if( mLastCubit<8 ) face = touchedFace; |
185 | 185 |
else |
186 | 186 |
{ |
... | ... | |
220 | 220 |
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat); |
221 | 221 |
Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat); |
222 | 222 |
|
223 |
if( object!=null && mMovement!=null && mMovement.faceTouched(rotatedTouchPoint,rotatedCamera) )
|
|
223 |
if( object!=null && mTouchControl !=null && mTouchControl.faceTouched(rotatedTouchPoint,rotatedCamera) )
|
|
224 | 224 |
{ |
225 | 225 |
mDragging = false; |
226 | 226 |
mContinuingRotation = false; |
... | ... | |
339 | 339 |
|
340 | 340 |
Static4D touchPoint = new Static4D(x, y, 0, 0); |
341 | 341 |
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat); |
342 |
Static2D res = mMovement.newRotation(rotatedTouchPoint);
|
|
342 |
Static2D res = mTouchControl.newRotation(rotatedTouchPoint);
|
|
343 | 343 |
|
344 | 344 |
mCurrentAxis = (int)res.get0(); |
345 | 345 |
mCurrentRow = (int)res.get1(); |
346 | 346 |
|
347 |
computeCurrentAxis( mMovement.getCastedRotAxis(mCurrentAxis) );
|
|
348 |
mRotationFactor = mMovement.returnRotationFactor(numLayers,mCurrentRow);
|
|
347 |
computeCurrentAxis( mTouchControl.getCastedRotAxis(mCurrentAxis) );
|
|
348 |
mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
|
|
349 | 349 |
|
350 | 350 |
object.beginNewRotation( mCurrentAxis, mCurrentRow ); |
351 | 351 |
|
... | ... | |
530 | 530 |
|
531 | 531 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
532 | 532 |
|
533 |
void setMovement(Movement movement)
|
|
533 |
void setMovement(TouchControl touchControl)
|
|
534 | 534 |
{ |
535 |
mMovement = movement;
|
|
535 |
mTouchControl = touchControl;
|
|
536 | 536 |
} |
537 | 537 |
|
538 | 538 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/main/TwistyObject.java | ||
---|---|---|
51 | 51 |
import org.distorted.objectlib.helpers.ObjectSticker; |
52 | 52 |
import org.distorted.objectlib.helpers.ScrambleState; |
53 | 53 |
import org.distorted.objectlib.json.JsonReader; |
54 |
import org.distorted.objectlib.movement.Movement;
|
|
55 |
import org.distorted.objectlib.movement.MovementCuboids;
|
|
56 |
import org.distorted.objectlib.movement.MovementDodecahedron;
|
|
57 |
import org.distorted.objectlib.movement.MovementHexahedron;
|
|
58 |
import org.distorted.objectlib.movement.MovementOctahedron;
|
|
59 |
import org.distorted.objectlib.movement.MovementTetrahedron;
|
|
54 |
import org.distorted.objectlib.touchcontrol.TouchControl;
|
|
55 |
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
|
|
56 |
import org.distorted.objectlib.touchcontrol.TouchControlDodecahedron;
|
|
57 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
|
58 |
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
|
|
59 |
import org.distorted.objectlib.touchcontrol.TouchControlTetrahedron;
|
|
60 | 60 |
|
61 | 61 |
import java.io.DataInputStream; |
62 | 62 |
import java.io.IOException; |
63 | 63 |
import java.io.InputStream; |
64 | 64 |
import java.util.Random; |
65 | 65 |
|
66 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_TETRAHEDRON;
|
|
67 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_HEXAHEDRON;
|
|
68 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_OCTAHEDRON;
|
|
69 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_DODECAHEDRON;
|
|
70 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_SHAPECHANGE;
|
|
66 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_TETRAHEDRON;
|
|
67 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
|
|
68 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
|
|
69 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_DODECAHEDRON;
|
|
70 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
|
|
71 | 71 |
|
72 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
73 | 73 |
|
... | ... | |
136 | 136 |
private int mCurrentRotAxis; |
137 | 137 |
private MeshBase mMesh; |
138 | 138 |
private TwistyObjectScrambler mScrambler; |
139 |
private Movement mMovement;
|
|
139 |
private TouchControl mTouchControl;
|
|
140 | 140 |
private boolean[][] mLayerRotatable; |
141 | 141 |
private int[][][] mEnabled; |
142 | 142 |
private DistortedNode mNode; |
... | ... | |
1136 | 1136 |
float scale = mObjectScreenRatio*mInitScreenRatio*nodeSize/mSize; |
1137 | 1137 |
mObjectScale.set(scale,scale,scale); |
1138 | 1138 |
|
1139 |
if( mMovement==null ) mMovement = getMovement();
|
|
1140 |
mMovement.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
|
|
1139 |
if( mTouchControl ==null ) mTouchControl = getMovement();
|
|
1140 |
mTouchControl.setObjectRatio(mObjectScreenRatio*mInitScreenRatio);
|
|
1141 | 1141 |
} |
1142 | 1142 |
|
1143 | 1143 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
1327 | 1327 |
|
1328 | 1328 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
1329 | 1329 |
|
1330 |
public Movement getMovement()
|
|
1330 |
public TouchControl getMovement()
|
|
1331 | 1331 |
{ |
1332 |
if( mMovement==null )
|
|
1332 |
if( mTouchControl ==null )
|
|
1333 | 1333 |
{ |
1334 | 1334 |
int[] numLayers = getNumLayers(); |
1335 | 1335 |
if( mCuts==null ) getCuts(numLayers); |
... | ... | |
1341 | 1341 |
|
1342 | 1342 |
switch(movementType) |
1343 | 1343 |
{ |
1344 |
case MOVEMENT_TETRAHEDRON : mMovement = new MovementTetrahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1345 |
break;
|
|
1346 |
case MOVEMENT_HEXAHEDRON : mMovement = new MovementHexahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1347 |
break;
|
|
1348 |
case MOVEMENT_OCTAHEDRON : mMovement = new MovementOctahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1349 |
break;
|
|
1350 |
case MOVEMENT_DODECAHEDRON: mMovement = new MovementDodecahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1351 |
break;
|
|
1352 |
case MOVEMENT_SHAPECHANGE : float[] dist3D = getDist3D(numLayers);
|
|
1353 |
mMovement = new MovementCuboids(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled,dist3D);
|
|
1354 |
break;
|
|
1344 |
case TC_TETRAHEDRON : mTouchControl = new TouchControlTetrahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1345 |
break; |
|
1346 |
case TC_HEXAHEDRON : mTouchControl = new TouchControlHexahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1347 |
break; |
|
1348 |
case TC_OCTAHEDRON : mTouchControl = new TouchControlOctahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1349 |
break; |
|
1350 |
case TC_DODECAHEDRON: mTouchControl = new TouchControlDodecahedron(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled);
|
|
1351 |
break; |
|
1352 |
case TC_CUBOID : float[] dist3D = getDist3D(numLayers);
|
|
1353 |
mTouchControl = new TouchControlCuboids(mAxis,mCuts,mLayerRotatable,mSize,movementSplit,mEnabled,dist3D);
|
|
1354 |
break; |
|
1355 | 1355 |
} |
1356 | 1356 |
} |
1357 |
return mMovement;
|
|
1357 |
return mTouchControl;
|
|
1358 | 1358 |
} |
1359 | 1359 |
|
1360 | 1360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/movement/Movement.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
21 |
|
|
22 |
import org.distorted.library.type.Static2D; |
|
23 |
import org.distorted.library.type.Static3D; |
|
24 |
import org.distorted.library.type.Static4D; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
|
|
28 |
public abstract class Movement |
|
29 |
{ |
|
30 |
// it doesn't matter where we touch a face - the list of enabled rotAxis will always be the same |
|
31 |
public static final int TYPE_NOT_SPLIT = 0; |
|
32 |
// each face is split into several parts by lines coming from its center to the midpoints of each edge |
|
33 |
public static final int TYPE_SPLIT_EDGE = 1; |
|
34 |
// each face is split into several parts by lines coming from its center to the vertices |
|
35 |
public static final int TYPE_SPLIT_CORNER = 2; |
|
36 |
|
|
37 |
public static final int MOVEMENT_HEXAHEDRON = 6; |
|
38 |
public static final int MOVEMENT_TETRAHEDRON = 4; |
|
39 |
public static final int MOVEMENT_OCTAHEDRON = 8; |
|
40 |
public static final int MOVEMENT_DODECAHEDRON =12; |
|
41 |
public static final int MOVEMENT_SHAPECHANGE = 0; |
|
42 |
|
|
43 |
static final float SQ3 = (float)Math.sqrt(3); |
|
44 |
static final float SQ6 = (float)Math.sqrt(6); |
|
45 |
|
|
46 |
private final int mNumFaceAxis; |
|
47 |
private final float[] mPoint, mCamera, mTouch; |
|
48 |
private final float[] mPoint2D, mMove2D; |
|
49 |
private final int[] mEnabledRotAxis; |
|
50 |
private final float[] mDistanceCenterFace3D; |
|
51 |
private final Static3D[] mFaceAxis; |
|
52 |
|
|
53 |
private int mLastTouchedFace; |
|
54 |
private float[][][] mCastedRotAxis; |
|
55 |
private Static4D[][] mCastedRotAxis4D; |
|
56 |
private float[][] mTouchBorders, mA, mB; |
|
57 |
private float mObjectRatio; |
|
58 |
|
|
59 |
private final int mType; |
|
60 |
private final int[][][] mEnabled; |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
abstract int returnPart(int type, int face, float[] touchPoint); |
|
65 |
abstract boolean isInsideFace(int face, float[] point); |
|
66 |
public abstract float returnRotationFactor(int[] numLayers, int row); |
|
67 |
|
|
68 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
69 |
|
|
70 |
Movement(Static3D[] rotAxis, Static3D[] faceAxis, float[][] cuts, boolean[][] rotatable, |
|
71 |
float[] distance3D, float size, int type, int[][][] enabled) |
|
72 |
{ |
|
73 |
mPoint = new float[3]; |
|
74 |
mCamera= new float[3]; |
|
75 |
mTouch = new float[3]; |
|
76 |
|
|
77 |
mPoint2D = new float[2]; |
|
78 |
mMove2D = new float[2]; |
|
79 |
|
|
80 |
mType = type; |
|
81 |
mEnabled = enabled; |
|
82 |
mObjectRatio= 1.0f; |
|
83 |
mFaceAxis = faceAxis; |
|
84 |
mNumFaceAxis= mFaceAxis.length; |
|
85 |
|
|
86 |
mEnabledRotAxis = new int[rotAxis.length+1]; |
|
87 |
|
|
88 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces |
|
89 |
|
|
90 |
computeCastedAxis(rotAxis); |
|
91 |
computeBorders(cuts,rotatable,size); |
|
92 |
computeLinear(rotAxis,faceAxis); |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd rotAxis cast onto the face defined by the |
|
97 |
// 1st faceAxis. |
|
98 |
|
|
99 |
private void computeCastedAxis(Static3D[] rotAxis) |
|
100 |
{ |
|
101 |
mCastedRotAxis = new float[mNumFaceAxis][rotAxis.length][2]; |
|
102 |
mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length]; |
|
103 |
|
|
104 |
float fx,fy,fz,f; |
|
105 |
|
|
106 |
for( int casted=0; casted<rotAxis.length; casted++) |
|
107 |
{ |
|
108 |
Static3D a = rotAxis[casted]; |
|
109 |
mPoint[0]= a.get0(); |
|
110 |
mPoint[1]= a.get1(); |
|
111 |
mPoint[2]= a.get2(); |
|
112 |
|
|
113 |
for( int face=0; face<mNumFaceAxis; face++) |
|
114 |
{ |
|
115 |
convertTo2Dcoords( mPoint, face, mCastedRotAxis[face][casted]); |
|
116 |
normalize2D(mCastedRotAxis[face][casted]); |
|
117 |
|
|
118 |
fx = mFaceAxis[face].get0(); |
|
119 |
fy = mFaceAxis[face].get1(); |
|
120 |
fz = mFaceAxis[face].get2(); |
|
121 |
f = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz; |
|
122 |
mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0); |
|
123 |
} |
|
124 |
} |
|
125 |
} |
|
126 |
|
|
127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
128 |
|
|
129 |
private void normalize2D(float[] vect) |
|
130 |
{ |
|
131 |
float len = (float)Math.sqrt(vect[0]*vect[0] + vect[1]*vect[1]); |
|
132 |
vect[0] /= len; |
|
133 |
vect[1] /= len; |
|
134 |
} |
|
135 |
|
|
136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
137 |
// find the casted axis with which our move2D vector forms an angle closest to 90 deg. |
|
138 |
|
|
139 |
private int computeRotationIndex(int faceAxis, float[] move2D, int[] enabled) |
|
140 |
{ |
|
141 |
float cosAngle, minCosAngle = Float.MAX_VALUE; |
|
142 |
int minIndex=0, index; |
|
143 |
float m0 = move2D[0]; |
|
144 |
float m1 = move2D[1]; |
|
145 |
float len = (float)Math.sqrt(m0*m0 + m1*m1); |
|
146 |
|
|
147 |
if( len!=0.0f ) |
|
148 |
{ |
|
149 |
m0 /= len; |
|
150 |
m1 /= len; |
|
151 |
} |
|
152 |
else |
|
153 |
{ |
|
154 |
m0 = 1.0f; // arbitrarily |
|
155 |
m1 = 0.0f; // |
|
156 |
} |
|
157 |
|
|
158 |
int numAxis = enabled[0]; |
|
159 |
|
|
160 |
for(int axis=1; axis<=numAxis; axis++) |
|
161 |
{ |
|
162 |
index = enabled[axis]; |
|
163 |
cosAngle = m0*mCastedRotAxis[faceAxis][index][0] + m1*mCastedRotAxis[faceAxis][index][1]; |
|
164 |
if( cosAngle<0 ) cosAngle = -cosAngle; |
|
165 |
|
|
166 |
if( cosAngle<minCosAngle ) |
|
167 |
{ |
|
168 |
minCosAngle=cosAngle; |
|
169 |
minIndex = index; |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 |
return minIndex; |
|
174 |
} |
|
175 |
|
|
176 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
177 |
// in the center of the face offset is always 0 regardless of the axis |
|
178 |
|
|
179 |
private float computeOffset(float[] point, float[] axis) |
|
180 |
{ |
|
181 |
return point[0]*axis[0] + point[1]*axis[1]; |
|
182 |
} |
|
183 |
|
|
184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
185 |
|
|
186 |
private boolean faceIsVisible(int index) |
|
187 |
{ |
|
188 |
Static3D faceAxis = mFaceAxis[index]; |
|
189 |
float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2(); |
|
190 |
return castCameraOnAxis > mDistanceCenterFace3D[index]; |
|
191 |
} |
|
192 |
|
|
193 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
194 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace, |
|
195 |
// compute point 'output[]' which: |
|
196 |
// 1) lies on a face of the Object, i.e. surface defined by (axis, distance from (0,0,0)) |
|
197 |
// 2) is co-linear with mCamera and mPoint |
|
198 |
// |
|
199 |
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)] |
|
200 |
|
|
201 |
private void castTouchPointOntoFace(int index, float[] output) |
|
202 |
{ |
|
203 |
Static3D faceAxis = mFaceAxis[index]; |
|
204 |
|
|
205 |
float d0 = mPoint[0]-mCamera[0]; |
|
206 |
float d1 = mPoint[1]-mCamera[1]; |
|
207 |
float d2 = mPoint[2]-mCamera[2]; |
|
208 |
float a0 = faceAxis.get0(); |
|
209 |
float a1 = faceAxis.get1(); |
|
210 |
float a2 = faceAxis.get2(); |
|
211 |
|
|
212 |
float denom = a0*d0 + a1*d1 + a2*d2; |
|
213 |
|
|
214 |
if( denom != 0.0f ) |
|
215 |
{ |
|
216 |
float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2]; |
|
217 |
float alpha = (mDistanceCenterFace3D[index]-axisCam)/denom; |
|
218 |
|
|
219 |
output[0] = mCamera[0] + d0*alpha; |
|
220 |
output[1] = mCamera[1] + d1*alpha; |
|
221 |
output[2] = mCamera[2] + d2*alpha; |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
226 |
// Convert the 3D point3D into a 2D point on the same face surface, but in a different |
|
227 |
// coordinate system: a in-plane 2D coord where the origin is in the point where the axis intersects |
|
228 |
// the surface, and whose Y axis points 'north' i.e. is in the plane given by the 3D origin, the |
|
229 |
// original 3D Y axis and our 2D in-plane origin. |
|
230 |
// If those 3 points constitute a degenerate triangle which does not define a plane - which can only |
|
231 |
// happen if axis is vertical (or in theory when 2D origin and 3D origin meet, but that would have to |
|
232 |
// mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily |
|
233 |
// decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole) |
|
234 |
|
|
235 |
private void convertTo2Dcoords(float[] point3D, int index , float[] output) |
|
236 |
{ |
|
237 |
Static3D faceAxis = mFaceAxis[index]; |
|
238 |
|
|
239 |
float y0,y1,y2; // base Y vector of the 2D coord system |
|
240 |
float a0 = faceAxis.get0(); |
|
241 |
float a1 = faceAxis.get1(); |
|
242 |
float a2 = faceAxis.get2(); |
|
243 |
|
|
244 |
if( a0==0.0f && a2==0.0f ) |
|
245 |
{ |
|
246 |
y0=0; y1=0; y2=-a1; |
|
247 |
} |
|
248 |
else if( a1==0.0f ) |
|
249 |
{ |
|
250 |
y0=0; y1=1; y2=0; |
|
251 |
} |
|
252 |
else |
|
253 |
{ |
|
254 |
float norm = (float)(-a1/Math.sqrt(1-a1*a1)); |
|
255 |
y0 = norm*a0; y1= norm*(a1-1/a1); y2=norm*a2; |
|
256 |
} |
|
257 |
|
|
258 |
float x0 = y1*a2 - y2*a1; // |
|
259 |
float x1 = y2*a0 - y0*a2; // (2D coord baseY) x (axis) = 2D coord baseX |
|
260 |
float x2 = y0*a1 - y1*a0; // |
|
261 |
|
|
262 |
float originAlpha = point3D[0]*a0 + point3D[1]*a1 + point3D[2]*a2; |
|
263 |
|
|
264 |
float origin0 = originAlpha*a0; // coords of the point where axis |
|
265 |
float origin1 = originAlpha*a1; // intersects surface plane i.e. |
|
266 |
float origin2 = originAlpha*a2; // the origin of our 2D coord system |
|
267 |
|
|
268 |
float v0 = point3D[0] - origin0; |
|
269 |
float v1 = point3D[1] - origin1; |
|
270 |
float v2 = point3D[2] - origin2; |
|
271 |
|
|
272 |
output[0] = v0*x0 + v1*x1 + v2*x2; |
|
273 |
output[1] = v0*y0 + v1*y1 + v2*y2; |
|
274 |
} |
|
275 |
|
|
276 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
277 |
|
|
278 |
private float[] computeBorder(float[] cuts, boolean[] rotatable, float size) |
|
279 |
{ |
|
280 |
if( cuts==null ) return null; |
|
281 |
|
|
282 |
int len = cuts.length; |
|
283 |
float[] border = new float[len]; |
|
284 |
|
|
285 |
for(int i=0; i<len; i++) |
|
286 |
{ |
|
287 |
if( !rotatable[i] ) |
|
288 |
{ |
|
289 |
border[i] = i>0 ? border[i-1] : -Float.MAX_VALUE; |
|
290 |
} |
|
291 |
else |
|
292 |
{ |
|
293 |
if( rotatable[i+1] ) border[i] = cuts[i]/size; |
|
294 |
else |
|
295 |
{ |
|
296 |
int found = -1; |
|
297 |
|
|
298 |
for(int j=i+2; j<=len; j++) |
|
299 |
{ |
|
300 |
if( rotatable[j] ) |
|
301 |
{ |
|
302 |
found=j; |
|
303 |
break; |
|
304 |
} |
|
305 |
} |
|
306 |
|
|
307 |
border[i] = found>0 ? (cuts[i]+cuts[found-1])/(2*size) : Float.MAX_VALUE; |
|
308 |
} |
|
309 |
} |
|
310 |
} |
|
311 |
|
|
312 |
return border; |
|
313 |
} |
|
314 |
|
|
315 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
316 |
// size, not numLayers (see Master Skewb where size!=numLayers) - also cuboids. |
|
317 |
|
|
318 |
void computeBorders(float[][] cuts, boolean[][] rotatable, float size) |
|
319 |
{ |
|
320 |
int numCuts = cuts.length; |
|
321 |
mTouchBorders = new float[numCuts][]; |
|
322 |
|
|
323 |
for(int axis=0; axis<numCuts; axis++) |
|
324 |
{ |
|
325 |
mTouchBorders[axis] = computeBorder(cuts[axis],rotatable[axis],size); |
|
326 |
} |
|
327 |
} |
|
328 |
|
|
329 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
330 |
|
|
331 |
private int computeSign(Static3D a, Static3D b) |
|
332 |
{ |
|
333 |
float a1 = a.get0(); |
|
334 |
float a2 = a.get1(); |
|
335 |
float a3 = a.get2(); |
|
336 |
float b1 = b.get0(); |
|
337 |
float b2 = b.get1(); |
|
338 |
float b3 = b.get2(); |
|
339 |
|
|
340 |
return a1*b1+a2*b2+a3*b3 < 0 ? 1:-1; |
|
341 |
} |
|
342 |
|
|
343 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
344 |
|
|
345 |
private float crossProductLen(Static3D a, Static3D b) |
|
346 |
{ |
|
347 |
float a1 = a.get0(); |
|
348 |
float a2 = a.get1(); |
|
349 |
float a3 = a.get2(); |
|
350 |
float b1 = b.get0(); |
|
351 |
float b2 = b.get1(); |
|
352 |
float b3 = b.get2(); |
|
353 |
|
|
354 |
float x1 = a2*b3-a3*b2; |
|
355 |
float x2 = a3*b1-a1*b3; |
|
356 |
float x3 = a1*b2-a2*b1; |
|
357 |
|
|
358 |
return (float)Math.sqrt(x1*x1 + x2*x2 + x3*x3); |
|
359 |
} |
|
360 |
|
|
361 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
362 |
// compute the array of 'A' and 'B' coeffs of the Ax+B linear function by which we need to multiply |
|
363 |
// the 3D 'cuts' to translate it from 3D (i.e. with respect to the rotAxis) to 2D in-face (i.e. with |
|
364 |
// respect to the 2D rotAxis cast into a particular face) |
|
365 |
|
|
366 |
private void computeLinear(Static3D[] rotAxis, Static3D[] faceAxis) |
|
367 |
{ |
|
368 |
int numFaces = faceAxis.length; |
|
369 |
int numRot = rotAxis.length; |
|
370 |
|
|
371 |
mA = new float[numFaces][numRot]; |
|
372 |
mB = new float[numFaces][numRot]; |
|
373 |
|
|
374 |
for(int i=0; i<numFaces; i++) |
|
375 |
for(int j=0; j<numRot; j++) |
|
376 |
{ |
|
377 |
mA[i][j] = crossProductLen(faceAxis[i],rotAxis[j]); |
|
378 |
|
|
379 |
if( mA[i][j]!=0.0f ) |
|
380 |
{ |
|
381 |
float coeff = (float)Math.sqrt(1/(mA[i][j]*mA[i][j]) -1); |
|
382 |
int sign = computeSign(faceAxis[i],rotAxis[j]); |
|
383 |
mB[i][j] = sign*coeff*mDistanceCenterFace3D[i]; |
|
384 |
} |
|
385 |
else mB[i][j] = 0.0f; |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
390 |
|
|
391 |
private int computeRowFromOffset(int face, int axisIndex, float offset) |
|
392 |
{ |
|
393 |
float[] borders = mTouchBorders[axisIndex]; |
|
394 |
|
|
395 |
if( borders==null ) return 0; |
|
396 |
|
|
397 |
int len = borders.length; |
|
398 |
float A = mA[face][axisIndex]; |
|
399 |
|
|
400 |
if( A!=0.0f ) |
|
401 |
{ |
|
402 |
float B = mB[face][axisIndex]; |
|
403 |
|
|
404 |
for(int i=0; i<len; i++) |
|
405 |
{ |
|
406 |
float translated = B + borders[i]/A; |
|
407 |
if( offset<translated ) return i; |
|
408 |
} |
|
409 |
} |
|
410 |
|
|
411 |
return len; |
|
412 |
} |
|
413 |
|
|
414 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
415 |
|
|
416 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
417 |
{ |
|
418 |
int part = returnPart(mType,face,touchPoint); |
|
419 |
|
|
420 |
int num = mEnabled[face][0].length; |
|
421 |
enabled[0] = num; |
|
422 |
System.arraycopy(mEnabled[face][part], 0, enabled, 1, num); |
|
423 |
} |
|
424 |
|
|
425 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
426 |
// PUBLIC API |
|
427 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
428 |
|
|
429 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera) |
|
430 |
{ |
|
431 |
mPoint[0] = rotatedTouchPoint.get0()/mObjectRatio; |
|
432 |
mPoint[1] = rotatedTouchPoint.get1()/mObjectRatio; |
|
433 |
mPoint[2] = rotatedTouchPoint.get2()/mObjectRatio; |
|
434 |
|
|
435 |
mCamera[0] = rotatedCamera.get0()/mObjectRatio; |
|
436 |
mCamera[1] = rotatedCamera.get1()/mObjectRatio; |
|
437 |
mCamera[2] = rotatedCamera.get2()/mObjectRatio; |
|
438 |
|
|
439 |
for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++) |
|
440 |
{ |
|
441 |
if( faceIsVisible(mLastTouchedFace) ) |
|
442 |
{ |
|
443 |
castTouchPointOntoFace(mLastTouchedFace, mTouch); |
|
444 |
convertTo2Dcoords(mTouch, mLastTouchedFace, mPoint2D); |
|
445 |
if( isInsideFace(mLastTouchedFace,mPoint2D) ) return true; |
|
446 |
} |
|
447 |
} |
|
448 |
|
|
449 |
return false; |
|
450 |
} |
|
451 |
|
|
452 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
453 |
|
|
454 |
public Static2D newRotation(Static4D rotatedTouchPoint) |
|
455 |
{ |
|
456 |
mPoint[0] = rotatedTouchPoint.get0()/mObjectRatio; |
|
457 |
mPoint[1] = rotatedTouchPoint.get1()/mObjectRatio; |
|
458 |
mPoint[2] = rotatedTouchPoint.get2()/mObjectRatio; |
|
459 |
|
|
460 |
castTouchPointOntoFace(mLastTouchedFace, mTouch); |
|
461 |
convertTo2Dcoords(mTouch, mLastTouchedFace, mMove2D); |
|
462 |
|
|
463 |
mMove2D[0] -= mPoint2D[0]; |
|
464 |
mMove2D[1] -= mPoint2D[1]; |
|
465 |
|
|
466 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis); |
|
467 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis); |
|
468 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]); |
|
469 |
int row = computeRowFromOffset(mLastTouchedFace,rotIndex,offset); |
|
470 |
|
|
471 |
return new Static2D(rotIndex,row); |
|
472 |
} |
|
473 |
|
|
474 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
475 |
|
|
476 |
public Static4D getCastedRotAxis(int rotIndex) |
|
477 |
{ |
|
478 |
return mCastedRotAxis4D[mLastTouchedFace][rotIndex]; |
|
479 |
} |
|
480 |
|
|
481 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
482 |
|
|
483 |
public int getTouchedFace() |
|
484 |
{ |
|
485 |
return mLastTouchedFace; |
|
486 |
} |
|
487 |
|
|
488 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
489 |
|
|
490 |
public float[] getTouchedPoint3D() |
|
491 |
{ |
|
492 |
return mTouch; |
|
493 |
} |
|
494 |
|
|
495 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
496 |
|
|
497 |
public void setObjectRatio(float ratio) |
|
498 |
{ |
|
499 |
mObjectRatio = ratio; |
|
500 |
} |
|
501 |
} |
src/main/java/org/distorted/objectlib/movement/MovementCuboids.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
21 |
|
|
22 |
import org.distorted.library.type.Static3D; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
// Cuboids |
|
26 |
|
|
27 |
public class MovementCuboids extends Movement |
|
28 |
{ |
|
29 |
private final float[] mDist3D; |
|
30 |
|
|
31 |
public static final Static3D[] FACE_AXIS = new Static3D[] |
|
32 |
{ |
|
33 |
new Static3D(1,0,0), new Static3D(-1,0,0), |
|
34 |
new Static3D(0,1,0), new Static3D(0,-1,0), |
|
35 |
new Static3D(0,0,1), new Static3D(0,0,-1) |
|
36 |
}; |
|
37 |
|
|
38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
39 |
|
|
40 |
public MovementCuboids(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, |
|
41 |
int[][][] enabled, float[] dist3D) |
|
42 |
{ |
|
43 |
super(rotAxis, FACE_AXIS, cuts, rotatable, dist3D, size, type, enabled); |
|
44 |
|
|
45 |
mDist3D = dist3D; |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
|
|
50 |
int returnPart(int type, int face, float[] touchPoint) |
|
51 |
{ |
|
52 |
return 0; |
|
53 |
} |
|
54 |
|
|
55 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
56 |
|
|
57 |
public float returnRotationFactor(int[] numLayers, int row) |
|
58 |
{ |
|
59 |
return 1.0f; |
|
60 |
} |
|
61 |
|
|
62 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
63 |
|
|
64 |
boolean isInsideFace(int face, float[] p) |
|
65 |
{ |
|
66 |
switch(face/2) |
|
67 |
{ |
|
68 |
case 0: return ( p[0]<=mDist3D[4] && p[0]>=-mDist3D[4] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] ); |
|
69 |
case 1: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[4] && p[1]>=-mDist3D[4] ); |
|
70 |
case 2: return ( p[0]<=mDist3D[0] && p[0]>=-mDist3D[0] && p[1]<=mDist3D[2] && p[1]>=-mDist3D[2] ); |
|
71 |
} |
|
72 |
return false; |
|
73 |
} |
|
74 |
} |
src/main/java/org/distorted/objectlib/movement/MovementDodecahedron.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
21 |
|
|
22 |
import static org.distorted.objectlib.main.TwistyObject.SQ5; |
|
23 |
|
|
24 |
import org.distorted.library.type.Static3D; |
|
25 |
|
|
26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
27 |
// Dodecahedral objects: map the 2D swipes of user's fingers to 3D rotations |
|
28 |
|
|
29 |
public class MovementDodecahedron extends Movement |
|
30 |
{ |
|
31 |
public static final float C2 = (SQ5+3)/4; |
|
32 |
public static final float LEN = (float)(Math.sqrt(1.25f+0.5f*SQ5)); |
|
33 |
public static final float SIN54 = (SQ5+1)/4; |
|
34 |
public static final float COS54 = (float)(Math.sqrt(10-2*SQ5)/4); |
|
35 |
|
|
36 |
public static final float DIST3D = (float)Math.sqrt(0.625f+0.275f*SQ5); |
|
37 |
private static final float DIST2D = (SIN54/COS54)/2; |
|
38 |
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D, |
|
39 |
DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D }; |
|
40 |
|
|
41 |
public static final Static3D[] FACE_AXIS = new Static3D[] |
|
42 |
{ |
|
43 |
new Static3D( C2/LEN, SIN54/LEN, 0 ), |
|
44 |
new Static3D( C2/LEN,-SIN54/LEN, 0 ), |
|
45 |
new Static3D( -C2/LEN, SIN54/LEN, 0 ), |
|
46 |
new Static3D( -C2/LEN,-SIN54/LEN, 0 ), |
|
47 |
new Static3D( 0 , C2/LEN, SIN54/LEN ), |
|
48 |
new Static3D( 0 , C2/LEN,-SIN54/LEN ), |
|
49 |
new Static3D( 0 , -C2/LEN, SIN54/LEN ), |
|
50 |
new Static3D( 0 , -C2/LEN,-SIN54/LEN ), |
|
51 |
new Static3D( SIN54/LEN, 0 , C2/LEN ), |
|
52 |
new Static3D( SIN54/LEN, 0 , -C2/LEN ), |
|
53 |
new Static3D(-SIN54/LEN, 0 , C2/LEN ), |
|
54 |
new Static3D(-SIN54/LEN, 0 , -C2/LEN ) |
|
55 |
}; |
|
56 |
|
|
57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
58 |
|
|
59 |
public MovementDodecahedron(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled) |
|
60 |
{ |
|
61 |
super(rotAxis, FACE_AXIS, cuts,rotatable,D3D, size, type, enabled); |
|
62 |
} |
|
63 |
|
|
64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
65 |
|
|
66 |
public float returnRotationFactor(int[] numLayers, int row) |
|
67 |
{ |
|
68 |
return 1.0f; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
// return angle (in radians) that the line connecting the center C of the pentagonal face and the |
|
73 |
// first vertex of the pentagon makes with a vertical line coming upwards from the center C. |
|
74 |
|
|
75 |
private float returnAngle(int face) |
|
76 |
{ |
|
77 |
switch(face) |
|
78 |
{ |
|
79 |
case 0: |
|
80 |
case 2: |
|
81 |
case 6: |
|
82 |
case 7: return 0.0f; |
|
83 |
case 1: |
|
84 |
case 3: |
|
85 |
case 4: |
|
86 |
case 5: return (float)(36*Math.PI/180); |
|
87 |
case 9: |
|
88 |
case 10: return (float)(54*Math.PI/180); |
|
89 |
case 8: |
|
90 |
case 11: return (float)(18*Math.PI/180); |
|
91 |
} |
|
92 |
|
|
93 |
return 0.0f; |
|
94 |
} |
|
95 |
|
|
96 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
97 |
// The pair (distance,angle) defines a point P in R^2 in polar coordinate system. Let V be the vector |
|
98 |
// from the center of the coordinate system to P. |
|
99 |
// Let P' be the point defined by polar (distance,angle+PI/2). Let Lh be the half-line starting at |
|
100 |
// P' and going in the direction of V. |
|
101 |
// Return true iff point 'point' lies on the left of Lh, i.e. when we rotate (using the center of |
|
102 |
// the coordinate system as the center of rotation) 'point' and Lh in such a way that Lh points |
|
103 |
// directly upwards, is 'point' on the left or the right of it? |
|
104 |
|
|
105 |
private boolean isOnTheLeft(float[] point, float distance, float angle) |
|
106 |
{ |
|
107 |
float sin = (float)Math.sin(angle); |
|
108 |
float cos = (float)Math.cos(angle); |
|
109 |
|
|
110 |
float vx = point[0] + sin*distance; |
|
111 |
float vy = point[1] - cos*distance; |
|
112 |
|
|
113 |
return vx*sin < vy*cos; |
|
114 |
} |
|
115 |
|
|
116 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
117 |
|
|
118 |
int returnPart(int type, int face, float[] point) |
|
119 |
{ |
|
120 |
switch(type) |
|
121 |
{ |
|
122 |
case TYPE_SPLIT_EDGE : return partEdge(point,face); |
|
123 |
case TYPE_SPLIT_CORNER: return partCorner(point,face); |
|
124 |
default : return 0; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
129 |
// Return 0,1,2,3,4 - the vertex of the pentagon to which point 'point' is the closest, if the |
|
130 |
// 'point' is inside the pentagon - or -1 otherwise. |
|
131 |
// The 'first' vertex is the one we meet the first when we rotate clockwise starting from 12:00. |
|
132 |
// This vertex makes angle 'returnAngle()' with the line coming out upwards from the center of the |
|
133 |
// pentagon. |
|
134 |
// Distance from the center to a vertex of the pentagon = 1/(6*COS54) |
|
135 |
|
|
136 |
int partEdge(float[] point, int face) |
|
137 |
{ |
|
138 |
float angle = returnAngle(face); |
|
139 |
float A = (float)(Math.PI/5); |
|
140 |
|
|
141 |
for(int i=0; i<5; i++) |
|
142 |
{ |
|
143 |
if( isOnTheLeft(point, DIST2D, (9-2*i)*A-angle) ) return -1; |
|
144 |
} |
|
145 |
|
|
146 |
if( isOnTheLeft(point, 0, 2.5f*A-angle) ) |
|
147 |
{ |
|
148 |
if( isOnTheLeft(point, 0, 3.5f*A-angle) ) |
|
149 |
{ |
|
150 |
return isOnTheLeft(point, 0, 5.5f*A-angle) ? 3 : 4; |
|
151 |
} |
|
152 |
else return 0; |
|
153 |
} |
|
154 |
else |
|
155 |
{ |
|
156 |
if( isOnTheLeft(point, 0, 4.5f*A-angle) ) |
|
157 |
{ |
|
158 |
return 2; |
|
159 |
} |
|
160 |
else |
|
161 |
{ |
|
162 |
return isOnTheLeft(point, 0, 6.5f*A-angle) ? 1 : 0; |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
168 |
// TODO - no such object yet |
|
169 |
|
|
170 |
int partCorner(float[] point, int face) |
|
171 |
{ |
|
172 |
return 0; |
|
173 |
} |
|
174 |
|
|
175 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
176 |
|
|
177 |
boolean isInsideFace(int face, float[] p) |
|
178 |
{ |
|
179 |
float angle = returnAngle(face); |
|
180 |
float A = (float)(Math.PI/5); |
|
181 |
|
|
182 |
for(int i=0; i<5; i++) |
|
183 |
{ |
|
184 |
if( isOnTheLeft(p, DIST2D, (9-2*i)*A-angle) ) return false; |
|
185 |
} |
|
186 |
|
|
187 |
return true; |
|
188 |
} |
|
189 |
} |
src/main/java/org/distorted/objectlib/movement/MovementHexahedron.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
21 |
|
|
22 |
import org.distorted.library.type.Static3D; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
// Hexahedral objects: map the 2D swipes of user's fingers to 3D rotations |
|
26 |
|
|
27 |
public class MovementHexahedron extends Movement |
|
28 |
{ |
|
29 |
private static final float DIST3D = 0.5f; |
|
30 |
private static final float DIST2D = 0.5f; |
|
31 |
|
|
32 |
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D }; |
|
33 |
|
|
34 |
public static final Static3D[] FACE_AXIS = new Static3D[] |
|
35 |
{ |
|
36 |
new Static3D(1,0,0), new Static3D(-1,0,0), |
|
37 |
new Static3D(0,1,0), new Static3D(0,-1,0), |
|
38 |
new Static3D(0,0,1), new Static3D(0,0,-1) |
|
39 |
}; |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public MovementHexahedron(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled) |
|
44 |
{ |
|
45 |
super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled); |
|
46 |
} |
|
47 |
|
|
48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
49 |
// corner edge |
|
50 |
// \ 0 / 3 | 0 |
|
51 |
// 3 \ / 1 ___ | ___ |
|
52 |
// / \ | |
|
53 |
// / 2 \ 2 | 1 |
|
54 |
|
|
55 |
int returnPart(int type, int face, float[] touchPoint) |
|
56 |
{ |
|
57 |
switch(type) |
|
58 |
{ |
|
59 |
case TYPE_NOT_SPLIT : return 0; |
|
60 |
case TYPE_SPLIT_EDGE : boolean e0 = touchPoint[0] > 0; |
|
61 |
boolean e1 = touchPoint[1] > 0; |
|
62 |
return e0 ? (e1 ? 0:1) : (e1 ? 3:2); |
|
63 |
case TYPE_SPLIT_CORNER: boolean c0 = touchPoint[1] >= touchPoint[0]; |
|
64 |
boolean c1 = touchPoint[1] >=-touchPoint[0]; |
|
65 |
return c0 ? (c1 ? 0:3) : (c1 ? 1:2); |
|
66 |
} |
|
67 |
|
|
68 |
return 0; |
|
69 |
} |
|
70 |
|
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
72 |
|
|
73 |
public float returnRotationFactor(int[] numLayers, int row) |
|
74 |
{ |
|
75 |
return 1.0f; |
|
76 |
} |
|
77 |
|
|
78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
79 |
|
|
80 |
boolean isInsideFace(int face, float[] p) |
|
81 |
{ |
|
82 |
return ( p[0]<=DIST2D && p[0]>=-DIST2D && p[1]<=DIST2D && p[1]>=-DIST2D ); |
|
83 |
} |
|
84 |
} |
src/main/java/org/distorted/objectlib/movement/MovementOctahedron.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
21 |
|
|
22 |
import org.distorted.library.type.Static3D; |
|
23 |
|
|
24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
25 |
// Octahedral objects: map the 2D swipes of user's fingers to 3D rotations |
|
26 |
|
|
27 |
public class MovementOctahedron extends Movement |
|
28 |
{ |
|
29 |
private static final float DIST3D = SQ6/6; |
|
30 |
private static final float DIST2D = SQ3/6; |
|
31 |
|
|
32 |
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D,DIST3D }; |
|
33 |
|
|
34 |
public static final Static3D[] FACE_AXIS = new Static3D[] |
|
35 |
{ |
|
36 |
new Static3D(+SQ6/3,+SQ3/3, 0), new Static3D(-SQ6/3,-SQ3/3, 0), |
|
37 |
new Static3D(-SQ6/3,+SQ3/3, 0), new Static3D(+SQ6/3,-SQ3/3, 0), |
|
38 |
new Static3D( 0,+SQ3/3,+SQ6/3), new Static3D( 0,-SQ3/3,-SQ6/3), |
|
39 |
new Static3D( 0,+SQ3/3,-SQ6/3), new Static3D( 0,-SQ3/3,+SQ6/3) |
|
40 |
}; |
|
41 |
|
|
42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
43 |
|
|
44 |
public MovementOctahedron(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled) |
|
45 |
{ |
|
46 |
super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled); |
|
47 |
} |
|
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%2 == 0 ? 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%2 == 0 ? 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 |
|
|
90 |
public float returnRotationFactor(int[] numLayers, int row) |
|
91 |
{ |
|
92 |
return 1.0f; |
|
93 |
} |
|
94 |
|
|
95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
96 |
|
|
97 |
boolean isInsideFace(int face, float[] p) |
|
98 |
{ |
|
99 |
float y = (face%2 == 0 ? p[1] : -p[1]); |
|
100 |
float x = p[0]; |
|
101 |
return (y >= -DIST2D) && (y <= DIST2D*(2-6*x)) && (y <= DIST2D*(2+6*x)); |
|
102 |
} |
|
103 |
} |
src/main/java/org/distorted/objectlib/movement/MovementTetrahedron.java | ||
---|---|---|
1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
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.movement; |
|
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 MovementTetrahedron extends Movement |
|
28 |
{ |
|
29 |
private static final float DIST3D = SQ6/12; |
|
30 |
private static final float DIST2D = SQ3/6; |
|
31 |
|
|
32 |
private static final float[] D3D = { DIST3D,DIST3D,DIST3D,DIST3D }; |
|
33 |
|
|
34 |
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 |
public MovementTetrahedron(Static3D[] rotAxis, float[][] cuts, boolean[][] rotatable, float size, int type, int[][][] enabled) |
|
45 |
{ |
|
46 |
super(rotAxis, FACE_AXIS, cuts, rotatable, D3D, size, type, enabled); |
|
47 |
} |
|
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 |
public float returnRotationFactor(int[] numLayers, int row) |
|
92 |
{ |
|
93 |
int numL = numLayers[0]; |
|
94 |
|
|
95 |
return numL==2 ? 1.0f : ((float)numL)/(numL-row); |
|
96 |
} |
|
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 |
} |
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.objects; |
21 | 21 |
|
22 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.movement.Movement.TYPE_NOT_SPLIT;
|
|
22 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
|
24 | 24 |
|
25 | 25 |
import java.io.InputStream; |
26 | 26 |
|
27 | 27 |
import org.distorted.library.type.Static3D; |
28 | 28 |
import org.distorted.library.type.Static4D; |
29 | 29 |
|
30 |
import org.distorted.objectlib.movement.MovementHexahedron;
|
|
30 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
|
31 | 31 |
import org.distorted.objectlib.helpers.ObjectShape; |
32 | 32 |
import org.distorted.objectlib.helpers.ObjectSticker; |
33 | 33 |
import org.distorted.objectlib.helpers.ScrambleState; |
... | ... | |
121 | 121 |
{ |
122 | 122 |
if( mQuats==null ) initializeQuats(); |
123 | 123 |
int status = retCubitSolvedStatus(cubit,numLayers); |
124 |
return status<0 ? null : buildSolvedQuats(MovementHexahedron.FACE_AXIS[status],mQuats);
|
|
124 |
return status<0 ? null : buildSolvedQuats(TouchControlHexahedron.FACE_AXIS[status],mQuats);
|
|
125 | 125 |
} |
126 | 126 |
|
127 | 127 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
360 | 360 |
|
361 | 361 |
public int getMovementType() |
362 | 362 |
{ |
363 |
return MOVEMENT_HEXAHEDRON;
|
|
363 |
return TC_HEXAHEDRON;
|
|
364 | 364 |
} |
365 | 365 |
|
366 | 366 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/objects/TwistyCuboid.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.objects; |
21 | 21 |
|
22 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_SHAPECHANGE;
|
|
23 |
import static org.distorted.objectlib.movement.Movement.TYPE_NOT_SPLIT;
|
|
22 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_CUBOID;
|
|
23 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
|
24 | 24 |
|
25 | 25 |
import java.io.InputStream; |
26 | 26 |
|
27 | 27 |
import org.distorted.library.type.Static3D; |
28 | 28 |
import org.distorted.library.type.Static4D; |
29 | 29 |
|
30 |
import org.distorted.objectlib.movement.MovementCuboids;
|
|
30 |
import org.distorted.objectlib.touchcontrol.TouchControlCuboids;
|
|
31 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
32 | 32 |
import org.distorted.objectlib.main.ObjectType; |
33 | 33 |
import org.distorted.objectlib.helpers.ObjectShape; |
... | ... | |
210 | 210 |
{ |
211 | 211 |
if( mQuats ==null ) initializeQuats(); |
212 | 212 |
int status = retCubitSolvedStatus(cubit,numLayers); |
213 |
return status<0 ? null : buildSolvedQuats(MovementCuboids.FACE_AXIS[status], mQuats);
|
|
213 |
return status<0 ? null : buildSolvedQuats(TouchControlCuboids.FACE_AXIS[status], mQuats);
|
|
214 | 214 |
} |
215 | 215 |
|
216 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
644 | 644 |
|
645 | 645 |
public int getMovementType() |
646 | 646 |
{ |
647 |
return MOVEMENT_SHAPECHANGE;
|
|
647 |
return TC_CUBOID;
|
|
648 | 648 |
} |
649 | 649 |
|
650 | 650 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/objects/TwistyDiamond.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.objects; |
21 | 21 |
|
22 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_OCTAHEDRON;
|
|
23 |
import static org.distorted.objectlib.movement.Movement.TYPE_NOT_SPLIT;
|
|
22 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_OCTAHEDRON;
|
|
23 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_NOT_SPLIT;
|
|
24 | 24 |
|
25 | 25 |
import java.io.InputStream; |
26 | 26 |
|
27 | 27 |
import org.distorted.library.type.Static3D; |
28 | 28 |
import org.distorted.library.type.Static4D; |
29 | 29 |
|
30 |
import org.distorted.objectlib.movement.MovementOctahedron;
|
|
30 |
import org.distorted.objectlib.touchcontrol.TouchControlOctahedron;
|
|
31 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
32 | 32 |
import org.distorted.objectlib.main.ObjectType; |
33 | 33 |
import org.distorted.objectlib.helpers.ObjectShape; |
... | ... | |
118 | 118 |
if( mQuats==null ) initializeQuats(); |
119 | 119 |
if( mFaceMap==null ) mFaceMap = new int[] {4,0,6,2,7,3,5,1}; |
120 | 120 |
int status = retCubitSolvedStatus(cubit,numLayers); |
121 |
return status<0 ? null : buildSolvedQuats(MovementOctahedron.FACE_AXIS[mFaceMap[status]],mQuats);
|
|
121 |
return status<0 ? null : buildSolvedQuats(TouchControlOctahedron.FACE_AXIS[mFaceMap[status]],mQuats);
|
|
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
188 | 188 |
|
189 | 189 |
public int getMovementType() |
190 | 190 |
{ |
191 |
return MOVEMENT_OCTAHEDRON;
|
|
191 |
return TC_OCTAHEDRON;
|
|
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/objects/TwistyDino.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.objects; |
21 | 21 |
|
22 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.movement.Movement.TYPE_SPLIT_CORNER;
|
|
22 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_CORNER;
|
|
24 | 24 |
|
25 | 25 |
import java.io.InputStream; |
26 | 26 |
|
... | ... | |
118 | 118 |
|
119 | 119 |
public int getMovementType() |
120 | 120 |
{ |
121 |
return MOVEMENT_HEXAHEDRON;
|
|
121 |
return TC_HEXAHEDRON;
|
|
122 | 122 |
} |
123 | 123 |
|
124 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/objectlib/objects/TwistyHelicopter.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
package org.distorted.objectlib.objects; |
21 | 21 |
|
22 |
import static org.distorted.objectlib.movement.Movement.MOVEMENT_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.movement.Movement.TYPE_SPLIT_EDGE;
|
|
22 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TC_HEXAHEDRON;
|
|
23 |
import static org.distorted.objectlib.touchcontrol.TouchControl.TYPE_SPLIT_EDGE;
|
|
24 | 24 |
|
25 | 25 |
import java.io.InputStream; |
26 | 26 |
|
27 | 27 |
import org.distorted.library.type.Static3D; |
28 | 28 |
import org.distorted.library.type.Static4D; |
29 | 29 |
|
30 |
import org.distorted.objectlib.movement.MovementHexahedron;
|
|
30 |
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
|
|
31 | 31 |
import org.distorted.objectlib.main.ObjectControl; |
32 | 32 |
import org.distorted.objectlib.main.ObjectType; |
33 | 33 |
import org.distorted.objectlib.helpers.ObjectShape; |
... | ... | |
134 | 134 |
{ |
135 | 135 |
if( mQuats==null ) initializeQuats(); |
136 | 136 |
int status = retCubitSolvedStatus(cubit,numLayers); |
137 |
return status<0 ? null : buildSolvedQuats(MovementHexahedron.FACE_AXIS[status],mQuats);
|
|
137 |
return status<0 ? null : buildSolvedQuats(TouchControlHexahedron.FACE_AXIS[status],mQuats);
|
|
138 | 138 |
} |
139 | 139 |
|
140 | 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
188 | 188 |
|
189 | 189 |
public int getMovementType() |
190 | 190 |
{ |
191 |
return MOVEMENT_HEXAHEDRON;
|
|
191 |
return TC_HEXAHEDRON;
|
|
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Abstract out the TouchControl stuff in preparation for its new type - TouchControlShapeChanging.