Revision ca3300c3
Added by Leszek Koltunski about 5 years ago
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 33 | 33 |
import org.distorted.library.type.Static2D; |
| 34 | 34 |
import org.distorted.library.type.Static4D; |
| 35 | 35 |
import org.distorted.objects.RubikObject; |
| 36 |
import org.distorted.objects.RubikMovement;
|
|
| 36 |
import org.distorted.objects.Movement; |
|
| 37 | 37 |
import org.distorted.solvers.SolverMain; |
| 38 | 38 |
import org.distorted.states.RubikState; |
| 39 | 39 |
import org.distorted.states.RubikStatePlay; |
| ... | ... | |
| 61 | 61 |
|
| 62 | 62 |
private RubikRenderer mRenderer; |
| 63 | 63 |
private RubikPreRender mPreRender; |
| 64 |
private RubikMovement mMovement;
|
|
| 64 |
private Movement mMovement; |
|
| 65 | 65 |
private boolean mDragging, mBeginningRotation, mContinuingRotation; |
| 66 | 66 |
private int mScreenWidth, mScreenHeight, mScreenMin; |
| 67 | 67 |
|
| ... | ... | |
| 130 | 130 |
|
| 131 | 131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 132 | 132 |
|
| 133 |
void setMovement(RubikMovement movement)
|
|
| 133 |
void setMovement(Movement movement) |
|
| 134 | 134 |
{
|
| 135 | 135 |
mMovement = movement; |
| 136 | 136 |
} |
| src/main/java/org/distorted/objects/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.objects; |
|
| 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 |
private int mLastTouchedFace, mNumFaceAxis; |
|
| 31 |
private float[] mPoint, mCamera, mTouch; |
|
| 32 |
private float[] mPoint2D, mMove2D; |
|
| 33 |
private float[][][] mCastedRotAxis; |
|
| 34 |
private Static4D[][] mCastedRotAxis4D; |
|
| 35 |
private int[] mEnabledRotAxis; |
|
| 36 |
private float mDistanceCenterFace3D, mDistanceCenterFace2D; |
|
| 37 |
private Static3D[] mFaceAxis; |
|
| 38 |
|
|
| 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 40 |
|
|
| 41 |
abstract boolean isInsideFace(float[] point); |
|
| 42 |
abstract void computeEnabledAxis(int face, float[] touchPoint, int[] enabledAxis); |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
Movement(Static3D[] rotAxis, Static3D[] faceAxis, float distance3D, float distance2D) |
|
| 47 |
{
|
|
| 48 |
mPoint = new float[3]; |
|
| 49 |
mCamera= new float[3]; |
|
| 50 |
mTouch = new float[3]; |
|
| 51 |
|
|
| 52 |
mPoint2D = new float[2]; |
|
| 53 |
mMove2D = new float[2]; |
|
| 54 |
|
|
| 55 |
mFaceAxis = faceAxis; |
|
| 56 |
mNumFaceAxis= mFaceAxis.length; |
|
| 57 |
|
|
| 58 |
mEnabledRotAxis = new int[rotAxis.length+1]; |
|
| 59 |
|
|
| 60 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces |
|
| 61 |
mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge |
|
| 62 |
|
|
| 63 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
|
|
| 64 |
// 1st pair (axis,lr) |
|
| 65 |
mCastedRotAxis = new float[mNumFaceAxis][rotAxis.length][2]; |
|
| 66 |
mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length]; |
|
| 67 |
|
|
| 68 |
float fx,fy,fz,f; |
|
| 69 |
|
|
| 70 |
for( int casted=0; casted<rotAxis.length; casted++) |
|
| 71 |
{
|
|
| 72 |
Static3D a = rotAxis[casted]; |
|
| 73 |
mPoint[0]= a.get0(); |
|
| 74 |
mPoint[1]= a.get1(); |
|
| 75 |
mPoint[2]= a.get2(); |
|
| 76 |
|
|
| 77 |
for( int face=0; face<mNumFaceAxis; face++) |
|
| 78 |
{
|
|
| 79 |
convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]); |
|
| 80 |
normalize2D(mCastedRotAxis[face][casted]); |
|
| 81 |
|
|
| 82 |
fx = faceAxis[face].get0(); |
|
| 83 |
fy = faceAxis[face].get1(); |
|
| 84 |
fz = faceAxis[face].get2(); |
|
| 85 |
f = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz; |
|
| 86 |
mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
private void normalize2D(float[] vect) |
|
| 94 |
{
|
|
| 95 |
float len = (float)Math.sqrt(vect[0]*vect[0] + vect[1]*vect[1]); |
|
| 96 |
vect[0] /= len; |
|
| 97 |
vect[1] /= len; |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 101 |
// find the casted axis with which our move2D vector forms an angle closest to 90 deg. |
|
| 102 |
|
|
| 103 |
private int computeRotationIndex(int faceAxis, float[] move2D, int[] enabled) |
|
| 104 |
{
|
|
| 105 |
float cosAngle, minCosAngle = Float.MAX_VALUE; |
|
| 106 |
int minIndex=-1, index; |
|
| 107 |
float m0 = move2D[0]; |
|
| 108 |
float m1 = move2D[1]; |
|
| 109 |
float len = (float)Math.sqrt(m0*m0 + m1*m1); |
|
| 110 |
|
|
| 111 |
if( len!=0.0f ) |
|
| 112 |
{
|
|
| 113 |
m0 /= len; |
|
| 114 |
m1 /= len; |
|
| 115 |
} |
|
| 116 |
else |
|
| 117 |
{
|
|
| 118 |
m0 = 1.0f; // arbitrarily |
|
| 119 |
m1 = 0.0f; // |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
int numAxis = enabled[0]; |
|
| 123 |
|
|
| 124 |
for(int axis=1; axis<=numAxis; axis++) |
|
| 125 |
{
|
|
| 126 |
index = enabled[axis]; |
|
| 127 |
cosAngle = m0*mCastedRotAxis[faceAxis][index][0] + m1*mCastedRotAxis[faceAxis][index][1]; |
|
| 128 |
if( cosAngle<0 ) cosAngle = -cosAngle; |
|
| 129 |
|
|
| 130 |
if( cosAngle<minCosAngle ) |
|
| 131 |
{
|
|
| 132 |
minCosAngle=cosAngle; |
|
| 133 |
minIndex = index; |
|
| 134 |
} |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
return minIndex; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
|
|
| 142 |
private float computeOffset(float[] point, float[] axis) |
|
| 143 |
{
|
|
| 144 |
return point[0]*axis[0] + point[1]*axis[1] + mDistanceCenterFace2D; |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
|
|
| 149 |
private boolean faceIsVisible(Static3D faceAxis) |
|
| 150 |
{
|
|
| 151 |
float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2(); |
|
| 152 |
return castCameraOnAxis > mDistanceCenterFace3D; |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 156 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace, |
|
| 157 |
// compute point 'output[]' which: |
|
| 158 |
// 1) lies on a face of the Object, i.e. surface defined by (axis, distance from (0,0,0)) [and this |
|
| 159 |
// distance is +-mDistanceCenterFace, depending if it is the face on the left or the right end of |
|
| 160 |
// the axis] (lr=0 or 1, so (2lr-1)*mDistanceCenterFace) |
|
| 161 |
// 2) is co-linear with mCamera and mPoint |
|
| 162 |
// |
|
| 163 |
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)] |
|
| 164 |
|
|
| 165 |
private void castTouchPointOntoFace(Static3D faceAxis, float[] output) |
|
| 166 |
{
|
|
| 167 |
float d0 = mPoint[0]-mCamera[0]; |
|
| 168 |
float d1 = mPoint[1]-mCamera[1]; |
|
| 169 |
float d2 = mPoint[2]-mCamera[2]; |
|
| 170 |
float a0 = faceAxis.get0(); |
|
| 171 |
float a1 = faceAxis.get1(); |
|
| 172 |
float a2 = faceAxis.get2(); |
|
| 173 |
|
|
| 174 |
float denom = a0*d0 + a1*d1 + a2*d2; |
|
| 175 |
|
|
| 176 |
if( denom != 0.0f ) |
|
| 177 |
{
|
|
| 178 |
float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2]; |
|
| 179 |
float distance = mDistanceCenterFace3D; |
|
| 180 |
float alpha = (distance-axisCam)/denom; |
|
| 181 |
|
|
| 182 |
output[0] = mCamera[0] + d0*alpha; |
|
| 183 |
output[1] = mCamera[1] + d1*alpha; |
|
| 184 |
output[2] = mCamera[2] + d2*alpha; |
|
| 185 |
} |
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 189 |
// Convert the 3D point3D into a 2D point on the same face surface, but in a different |
|
| 190 |
// coordinate system: a in-plane 2D coord where the origin is in the point where the axis intersects |
|
| 191 |
// the surface, and whose Y axis points 'north' i.e. is in the plane given by the 3D origin, the |
|
| 192 |
// original 3D Y axis and our 2D in-plane origin. |
|
| 193 |
// If those 3 points constitute a degenerate triangle which does not define a plane - which can only |
|
| 194 |
// happen if axis is vertical (or in theory when 2D origin and 3D origin meet, but that would have to |
|
| 195 |
// mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily |
|
| 196 |
// decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole) |
|
| 197 |
|
|
| 198 |
private void convertTo2Dcoords(float[] point3D, Static3D faceAxis, float[] output) |
|
| 199 |
{
|
|
| 200 |
float y0,y1,y2; // base Y vector of the 2D coord system |
|
| 201 |
float a0 = faceAxis.get0(); |
|
| 202 |
float a1 = faceAxis.get1(); |
|
| 203 |
float a2 = faceAxis.get2(); |
|
| 204 |
|
|
| 205 |
if( a0==0.0f && a2==0.0f ) |
|
| 206 |
{
|
|
| 207 |
y0=0; y1=0; y2=-a1; |
|
| 208 |
} |
|
| 209 |
else if( a1==0.0f ) |
|
| 210 |
{
|
|
| 211 |
y0=0; y1=1; y2=0; |
|
| 212 |
} |
|
| 213 |
else |
|
| 214 |
{
|
|
| 215 |
float norm = (float)(-a1/Math.sqrt(1-a1*a1)); |
|
| 216 |
y0 = norm*a0; y1= norm*(a1-1/a1); y2=norm*a2; |
|
| 217 |
} |
|
| 218 |
|
|
| 219 |
float x0 = y1*a2 - y2*a1; // |
|
| 220 |
float x1 = y2*a0 - y0*a2; // (2D coord baseY) x (axis) = 2D coord baseX |
|
| 221 |
float x2 = y0*a1 - y1*a0; // |
|
| 222 |
|
|
| 223 |
float originAlpha = point3D[0]*a0 + point3D[1]*a1 + point3D[2]*a2; |
|
| 224 |
|
|
| 225 |
float origin0 = originAlpha*a0; // coords of the point where axis |
|
| 226 |
float origin1 = originAlpha*a1; // intersects surface plane i.e. |
|
| 227 |
float origin2 = originAlpha*a2; // the origin of our 2D coord system |
|
| 228 |
|
|
| 229 |
float v0 = point3D[0] - origin0; |
|
| 230 |
float v1 = point3D[1] - origin1; |
|
| 231 |
float v2 = point3D[2] - origin2; |
|
| 232 |
|
|
| 233 |
output[0] = v0*x0 + v1*x1 + v2*x2; |
|
| 234 |
output[1] = v0*y0 + v1*y1 + v2*y2; |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
// PUBLIC API |
|
| 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 240 |
|
|
| 241 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera) |
|
| 242 |
{
|
|
| 243 |
float objectRatio = RubikObject.getObjectRatio(); |
|
| 244 |
|
|
| 245 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
| 246 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
| 247 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
| 248 |
|
|
| 249 |
mCamera[0] = rotatedCamera.get0()/objectRatio; |
|
| 250 |
mCamera[1] = rotatedCamera.get1()/objectRatio; |
|
| 251 |
mCamera[2] = rotatedCamera.get2()/objectRatio; |
|
| 252 |
|
|
| 253 |
for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++) |
|
| 254 |
{
|
|
| 255 |
if( faceIsVisible(mFaceAxis[mLastTouchedFace]) ) |
|
| 256 |
{
|
|
| 257 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch); |
|
| 258 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mPoint2D); |
|
| 259 |
if( isInsideFace(mPoint2D) ) return true; |
|
| 260 |
} |
|
| 261 |
} |
|
| 262 |
|
|
| 263 |
return false; |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
|
|
| 268 |
public Static2D newRotation(Static4D rotatedTouchPoint) |
|
| 269 |
{
|
|
| 270 |
float objectRatio = RubikObject.getObjectRatio(); |
|
| 271 |
|
|
| 272 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
| 273 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
| 274 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
| 275 |
|
|
| 276 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch); |
|
| 277 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mMove2D); |
|
| 278 |
|
|
| 279 |
mMove2D[0] -= mPoint2D[0]; |
|
| 280 |
mMove2D[1] -= mPoint2D[1]; |
|
| 281 |
|
|
| 282 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis); |
|
| 283 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis); |
|
| 284 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]); |
|
| 285 |
|
|
| 286 |
return new Static2D(rotIndex,offset); |
|
| 287 |
} |
|
| 288 |
|
|
| 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 290 |
|
|
| 291 |
public Static4D getCastedRotAxis(int rotIndex) |
|
| 292 |
{
|
|
| 293 |
return mCastedRotAxis4D[mLastTouchedFace][rotIndex]; |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 297 |
|
|
| 298 |
public int getTouchedFace() |
|
| 299 |
{
|
|
| 300 |
return mLastTouchedFace; |
|
| 301 |
} |
|
| 302 |
|
|
| 303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 304 |
|
|
| 305 |
public float[] getTouchedPoint3D() |
|
| 306 |
{
|
|
| 307 |
return mTouch; |
|
| 308 |
} |
|
| 309 |
} |
|
| src/main/java/org/distorted/objects/MovementCube.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementCube extends Movement |
|
| 25 |
{
|
|
| 26 |
MovementCube() |
|
| 27 |
{
|
|
| 28 |
super(RubikCube.ROT_AXIS, RubikCube.FACE_AXIS, 0.5f, 0.5f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
boolean isInsideFace(float[] p) |
|
| 34 |
{
|
|
| 35 |
return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f ); |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
|
|
| 40 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 41 |
{
|
|
| 42 |
enabled[0] = 2; |
|
| 43 |
|
|
| 44 |
switch(face) |
|
| 45 |
{
|
|
| 46 |
case 0: |
|
| 47 |
case 1: enabled[1]=1; enabled[2]=2; break; |
|
| 48 |
case 2: |
|
| 49 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 50 |
case 4: |
|
| 51 |
case 5: enabled[1]=0; enabled[2]=1; break; |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
} |
|
| src/main/java/org/distorted/objects/MovementDiamond.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementDiamond extends Movement |
|
| 25 |
{
|
|
| 26 |
MovementDiamond() |
|
| 27 |
{
|
|
| 28 |
super(RubikDiamond.ROT_AXIS, RubikDiamond.FACE_AXIS, 0.25f, 0.25f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
// _____________ |
|
| 33 |
// | \ 0 / | |
|
| 34 |
// | \ / | |
|
| 35 |
// | 3 | | 1 | |
|
| 36 |
// | / \ | |
|
| 37 |
// | / 2 \ | |
|
| 38 |
// ------------- |
|
| 39 |
|
|
| 40 |
private int getQuarter(float[] touchPoint) |
|
| 41 |
{
|
|
| 42 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
| 43 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
| 44 |
|
|
| 45 |
if( p0 ) return p1 ? 0:3; |
|
| 46 |
else return p1 ? 1:2; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
boolean isInsideFace(float[] p) |
|
| 52 |
{
|
|
| 53 |
return ( p[0]<=0.25f && p[0]>=-0.25f && p[1]<=0.25f && p[1]>=-0.25f ); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 59 |
{
|
|
| 60 |
enabled[0] = 2; |
|
| 61 |
|
|
| 62 |
int quarter = getQuarter(touchPoint); |
|
| 63 |
|
|
| 64 |
switch(face) |
|
| 65 |
{
|
|
| 66 |
case 0: switch(quarter) |
|
| 67 |
{
|
|
| 68 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
| 69 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 70 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
| 71 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 72 |
} |
|
| 73 |
break; |
|
| 74 |
case 1: switch(quarter) |
|
| 75 |
{
|
|
| 76 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
| 77 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 78 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
| 79 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 80 |
} |
|
| 81 |
break; |
|
| 82 |
case 2: switch(quarter) |
|
| 83 |
{
|
|
| 84 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 85 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
| 86 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 87 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
| 88 |
} |
|
| 89 |
break; |
|
| 90 |
case 3: switch(quarter) |
|
| 91 |
{
|
|
| 92 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 93 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
| 94 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 95 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
case 4: switch(quarter) |
|
| 99 |
{
|
|
| 100 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
| 101 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 102 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
| 103 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 104 |
} |
|
| 105 |
break; |
|
| 106 |
case 5: switch(quarter) |
|
| 107 |
{
|
|
| 108 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 109 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 110 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 111 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 112 |
} |
|
| 113 |
break; |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| src/main/java/org/distorted/objects/MovementDino.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementDino extends Movement |
|
| 25 |
{
|
|
| 26 |
MovementDino() |
|
| 27 |
{
|
|
| 28 |
super(RubikDino.ROT_AXIS, RubikDino.FACE_AXIS, 0.5f, 0.5f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
// _____________ |
|
| 33 |
// | \ 0 / | |
|
| 34 |
// | \ / | |
|
| 35 |
// | 3 | | 1 | |
|
| 36 |
// | / \ | |
|
| 37 |
// | / 2 \ | |
|
| 38 |
// ------------- |
|
| 39 |
|
|
| 40 |
private int getQuarter(float[] touchPoint) |
|
| 41 |
{
|
|
| 42 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
| 43 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
| 44 |
|
|
| 45 |
if( p0 ) return p1 ? 0:3; |
|
| 46 |
else return p1 ? 1:2; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
boolean isInsideFace(float[] p) |
|
| 52 |
{
|
|
| 53 |
return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f ); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 59 |
{
|
|
| 60 |
enabled[0] = 2; |
|
| 61 |
|
|
| 62 |
int quarter = getQuarter(touchPoint); |
|
| 63 |
|
|
| 64 |
switch(face) |
|
| 65 |
{
|
|
| 66 |
case 0: switch(quarter) |
|
| 67 |
{
|
|
| 68 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
| 69 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 70 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
| 71 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 72 |
} |
|
| 73 |
break; |
|
| 74 |
case 1: switch(quarter) |
|
| 75 |
{
|
|
| 76 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
| 77 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 78 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
| 79 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 80 |
} |
|
| 81 |
break; |
|
| 82 |
case 2: switch(quarter) |
|
| 83 |
{
|
|
| 84 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 85 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
| 86 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 87 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
| 88 |
} |
|
| 89 |
break; |
|
| 90 |
case 3: switch(quarter) |
|
| 91 |
{
|
|
| 92 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 93 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
| 94 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 95 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
case 4: switch(quarter) |
|
| 99 |
{
|
|
| 100 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
| 101 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 102 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
| 103 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 104 |
} |
|
| 105 |
break; |
|
| 106 |
case 5: switch(quarter) |
|
| 107 |
{
|
|
| 108 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 109 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 110 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 111 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 112 |
} |
|
| 113 |
break; |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| src/main/java/org/distorted/objects/MovementHelicopter.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementHelicopter extends Movement |
|
| 25 |
{
|
|
| 26 |
MovementHelicopter() |
|
| 27 |
{
|
|
| 28 |
super(RubikHelicopter.ROT_AXIS, RubikHelicopter.FACE_AXIS, 0.166f, 0.166f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
// _____________ |
|
| 33 |
// | | | |
|
| 34 |
// | 3 | 0 | |
|
| 35 |
// |-----------| |
|
| 36 |
// | | | |
|
| 37 |
// | 2 | 1 | |
|
| 38 |
// ------------- |
|
| 39 |
|
|
| 40 |
private int getQuarter(float[] touchPoint) |
|
| 41 |
{
|
|
| 42 |
boolean p0 = touchPoint[0] > 0; |
|
| 43 |
boolean p1 = touchPoint[1] > 0; |
|
| 44 |
|
|
| 45 |
if( p0 ) return p1 ? 0:1; |
|
| 46 |
else return p1 ? 3:2; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
boolean isInsideFace(float[] p) |
|
| 52 |
{
|
|
| 53 |
return ( p[0]<=0.166f && p[0]>=-0.166f && p[1]<=0.166f && p[1]>=-0.166f ); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 59 |
{
|
|
| 60 |
enabled[0] = 2; |
|
| 61 |
|
|
| 62 |
int quarter = getQuarter(touchPoint); |
|
| 63 |
|
|
| 64 |
switch(face) |
|
| 65 |
{
|
|
| 66 |
case 0: switch(quarter) |
|
| 67 |
{
|
|
| 68 |
case 0: enabled[1]=2; enabled[2]=5; break; |
|
| 69 |
case 1: enabled[1]=2; enabled[2]=4; break; |
|
| 70 |
case 2: enabled[1]=3; enabled[2]=4; break; |
|
| 71 |
case 3: enabled[1]=3; enabled[2]=5; break; |
|
| 72 |
} |
|
| 73 |
break; |
|
| 74 |
case 1: switch(quarter) |
|
| 75 |
{
|
|
| 76 |
case 0: enabled[1]=2; enabled[2]=4; break; |
|
| 77 |
case 1: enabled[1]=2; enabled[2]=5; break; |
|
| 78 |
case 2: enabled[1]=5; enabled[2]=3; break; |
|
| 79 |
case 3: enabled[1]=3; enabled[2]=4; break; |
|
| 80 |
} |
|
| 81 |
break; |
|
| 82 |
case 2: switch(quarter) |
|
| 83 |
{
|
|
| 84 |
case 0: enabled[1]=0; enabled[2]=5; break; |
|
| 85 |
case 1: enabled[1]=1; enabled[2]=5; break; |
|
| 86 |
case 2: enabled[1]=1; enabled[2]=4; break; |
|
| 87 |
case 3: enabled[1]=0; enabled[2]=4; break; |
|
| 88 |
} |
|
| 89 |
break; |
|
| 90 |
case 3: switch(quarter) |
|
| 91 |
{
|
|
| 92 |
case 0: enabled[1]=0; enabled[2]=4; break; |
|
| 93 |
case 1: enabled[1]=1; enabled[2]=4; break; |
|
| 94 |
case 2: enabled[1]=1; enabled[2]=5; break; |
|
| 95 |
case 3: enabled[1]=0; enabled[2]=5; break; |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
case 4: switch(quarter) |
|
| 99 |
{
|
|
| 100 |
case 0: enabled[1]=1; enabled[2]=3; break; |
|
| 101 |
case 1: enabled[1]=0; enabled[2]=3; break; |
|
| 102 |
case 2: enabled[1]=0; enabled[2]=2; break; |
|
| 103 |
case 3: enabled[1]=1; enabled[2]=2; break; |
|
| 104 |
} |
|
| 105 |
break; |
|
| 106 |
case 5: switch(quarter) |
|
| 107 |
{
|
|
| 108 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
| 109 |
case 1: enabled[1]=1; enabled[2]=3; break; |
|
| 110 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
| 111 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 112 |
} |
|
| 113 |
break; |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| src/main/java/org/distorted/objects/MovementPyraminx.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementPyraminx extends Movement |
|
| 25 |
{
|
|
| 26 |
private static final float SQ6 = (float)Math.sqrt(6); |
|
| 27 |
private static final float SQ3 = (float)Math.sqrt(3); |
|
| 28 |
|
|
| 29 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 30 |
|
|
| 31 |
MovementPyraminx() |
|
| 32 |
{
|
|
| 33 |
super(RubikPyraminx.ROT_AXIS, RubikPyraminx.FACE_AXIS, SQ6/12, SQ3/6); |
|
| 34 |
} |
|
| 35 |
|
|
| 36 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 37 |
|
|
| 38 |
boolean isInsideFace(float[] p) |
|
| 39 |
{
|
|
| 40 |
boolean a1 = p[1] >= -SQ3/6; |
|
| 41 |
boolean a2 = p[1] <= SQ3*(1.0f/3 + p[0]); |
|
| 42 |
boolean a3 = p[1] <= SQ3*(1.0f/3 - p[0]); |
|
| 43 |
|
|
| 44 |
return a1 && a2 && a3; |
|
| 45 |
} |
|
| 46 |
|
|
| 47 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 48 |
|
|
| 49 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 50 |
{
|
|
| 51 |
enabled[0] = 3; |
|
| 52 |
|
|
| 53 |
switch(face) |
|
| 54 |
{
|
|
| 55 |
case 0: enabled[1]=1; enabled[2]=2; enabled[3]=3; break; |
|
| 56 |
case 1: enabled[1]=0; enabled[2]=2; enabled[3]=3; break; |
|
| 57 |
case 2: enabled[1]=0; enabled[2]=1; enabled[3]=3; break; |
|
| 58 |
case 3: enabled[1]=0; enabled[2]=1; enabled[3]=2; break; |
|
| 59 |
} |
|
| 60 |
} |
|
| 61 |
} |
|
| src/main/java/org/distorted/objects/MovementSkewb.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class MovementSkewb extends Movement |
|
| 25 |
{
|
|
| 26 |
MovementSkewb() |
|
| 27 |
{
|
|
| 28 |
super(RubikSkewb.ROT_AXIS, RubikSkewb.FACE_AXIS, 0.25f, 0.25f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
// _____________ |
|
| 33 |
// | \ 0 / | |
|
| 34 |
// | \ / | |
|
| 35 |
// | 3 | | 1 | |
|
| 36 |
// | / \ | |
|
| 37 |
// | / 2 \ | |
|
| 38 |
// ------------- |
|
| 39 |
|
|
| 40 |
private int getQuarter(float[] touchPoint) |
|
| 41 |
{
|
|
| 42 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
| 43 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
| 44 |
|
|
| 45 |
if( p0 ) return p1 ? 0:3; |
|
| 46 |
else return p1 ? 1:2; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
boolean isInsideFace(float[] p) |
|
| 52 |
{
|
|
| 53 |
return ( p[0]<=0.25f && p[0]>=-0.25f && p[1]<=0.25f && p[1]>=-0.25f ); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 59 |
{
|
|
| 60 |
enabled[0] = 2; |
|
| 61 |
|
|
| 62 |
int quarter = getQuarter(touchPoint); |
|
| 63 |
|
|
| 64 |
switch(face) |
|
| 65 |
{
|
|
| 66 |
case 0: switch(quarter) |
|
| 67 |
{
|
|
| 68 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
| 69 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 70 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
| 71 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 72 |
} |
|
| 73 |
break; |
|
| 74 |
case 1: switch(quarter) |
|
| 75 |
{
|
|
| 76 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
| 77 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 78 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
| 79 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 80 |
} |
|
| 81 |
break; |
|
| 82 |
case 2: switch(quarter) |
|
| 83 |
{
|
|
| 84 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 85 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
| 86 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 87 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
| 88 |
} |
|
| 89 |
break; |
|
| 90 |
case 3: switch(quarter) |
|
| 91 |
{
|
|
| 92 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 93 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
| 94 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 95 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
case 4: switch(quarter) |
|
| 99 |
{
|
|
| 100 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
| 101 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 102 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
| 103 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 104 |
} |
|
| 105 |
break; |
|
| 106 |
case 5: switch(quarter) |
|
| 107 |
{
|
|
| 108 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 109 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 110 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 111 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 112 |
} |
|
| 113 |
break; |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| src/main/java/org/distorted/objects/RubikMovement.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.objects; |
|
| 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 RubikMovement |
|
| 29 |
{
|
|
| 30 |
private int mLastTouchedFace, mNumFaceAxis; |
|
| 31 |
private float[] mPoint, mCamera, mTouch; |
|
| 32 |
private float[] mPoint2D, mMove2D; |
|
| 33 |
private float[][][] mCastedRotAxis; |
|
| 34 |
private Static4D[][] mCastedRotAxis4D; |
|
| 35 |
private int[] mEnabledRotAxis; |
|
| 36 |
private float mDistanceCenterFace3D, mDistanceCenterFace2D; |
|
| 37 |
private Static3D[] mFaceAxis; |
|
| 38 |
|
|
| 39 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 40 |
|
|
| 41 |
abstract boolean isInsideFace(float[] point); |
|
| 42 |
abstract void computeEnabledAxis(int face, float[] touchPoint, int[] enabledAxis); |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
RubikMovement(Static3D[] rotAxis, Static3D[] faceAxis, float distance3D, float distance2D) |
|
| 47 |
{
|
|
| 48 |
mPoint = new float[3]; |
|
| 49 |
mCamera= new float[3]; |
|
| 50 |
mTouch = new float[3]; |
|
| 51 |
|
|
| 52 |
mPoint2D = new float[2]; |
|
| 53 |
mMove2D = new float[2]; |
|
| 54 |
|
|
| 55 |
mFaceAxis = faceAxis; |
|
| 56 |
mNumFaceAxis= mFaceAxis.length; |
|
| 57 |
|
|
| 58 |
mEnabledRotAxis = new int[rotAxis.length+1]; |
|
| 59 |
|
|
| 60 |
mDistanceCenterFace3D = distance3D; // distance from the center of the object to each of its faces |
|
| 61 |
mDistanceCenterFace2D = distance2D; // distance from the center of a face to its edge |
|
| 62 |
|
|
| 63 |
// mCastedRotAxis[1][2]{0,1} are the 2D coords of the 2nd axis cast onto the face defined by the
|
|
| 64 |
// 1st pair (axis,lr) |
|
| 65 |
mCastedRotAxis = new float[mNumFaceAxis][rotAxis.length][2]; |
|
| 66 |
mCastedRotAxis4D = new Static4D[mNumFaceAxis][rotAxis.length]; |
|
| 67 |
|
|
| 68 |
float fx,fy,fz,f; |
|
| 69 |
|
|
| 70 |
for( int casted=0; casted<rotAxis.length; casted++) |
|
| 71 |
{
|
|
| 72 |
Static3D a = rotAxis[casted]; |
|
| 73 |
mPoint[0]= a.get0(); |
|
| 74 |
mPoint[1]= a.get1(); |
|
| 75 |
mPoint[2]= a.get2(); |
|
| 76 |
|
|
| 77 |
for( int face=0; face<mNumFaceAxis; face++) |
|
| 78 |
{
|
|
| 79 |
convertTo2Dcoords( mPoint, mFaceAxis[face], mCastedRotAxis[face][casted]); |
|
| 80 |
normalize2D(mCastedRotAxis[face][casted]); |
|
| 81 |
|
|
| 82 |
fx = faceAxis[face].get0(); |
|
| 83 |
fy = faceAxis[face].get1(); |
|
| 84 |
fz = faceAxis[face].get2(); |
|
| 85 |
f = mPoint[0]*fx + mPoint[1]*fy + mPoint[2]*fz; |
|
| 86 |
mCastedRotAxis4D[face][casted] = new Static4D( mPoint[0]-f*fx, mPoint[1]-f*fy, mPoint[2]-f*fz, 0); |
|
| 87 |
} |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
private void normalize2D(float[] vect) |
|
| 94 |
{
|
|
| 95 |
float len = (float)Math.sqrt(vect[0]*vect[0] + vect[1]*vect[1]); |
|
| 96 |
vect[0] /= len; |
|
| 97 |
vect[1] /= len; |
|
| 98 |
} |
|
| 99 |
|
|
| 100 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 101 |
// find the casted axis with which our move2D vector forms an angle closest to 90 deg. |
|
| 102 |
|
|
| 103 |
private int computeRotationIndex(int faceAxis, float[] move2D, int[] enabled) |
|
| 104 |
{
|
|
| 105 |
float cosAngle, minCosAngle = Float.MAX_VALUE; |
|
| 106 |
int minIndex=-1, index; |
|
| 107 |
float m0 = move2D[0]; |
|
| 108 |
float m1 = move2D[1]; |
|
| 109 |
float len = (float)Math.sqrt(m0*m0 + m1*m1); |
|
| 110 |
|
|
| 111 |
if( len!=0.0f ) |
|
| 112 |
{
|
|
| 113 |
m0 /= len; |
|
| 114 |
m1 /= len; |
|
| 115 |
} |
|
| 116 |
else |
|
| 117 |
{
|
|
| 118 |
m0 = 1.0f; // arbitrarily |
|
| 119 |
m1 = 0.0f; // |
|
| 120 |
} |
|
| 121 |
|
|
| 122 |
int numAxis = enabled[0]; |
|
| 123 |
|
|
| 124 |
for(int axis=1; axis<=numAxis; axis++) |
|
| 125 |
{
|
|
| 126 |
index = enabled[axis]; |
|
| 127 |
cosAngle = m0*mCastedRotAxis[faceAxis][index][0] + m1*mCastedRotAxis[faceAxis][index][1]; |
|
| 128 |
if( cosAngle<0 ) cosAngle = -cosAngle; |
|
| 129 |
|
|
| 130 |
if( cosAngle<minCosAngle ) |
|
| 131 |
{
|
|
| 132 |
minCosAngle=cosAngle; |
|
| 133 |
minIndex = index; |
|
| 134 |
} |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
return minIndex; |
|
| 138 |
} |
|
| 139 |
|
|
| 140 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 141 |
|
|
| 142 |
private float computeOffset(float[] point, float[] axis) |
|
| 143 |
{
|
|
| 144 |
return point[0]*axis[0] + point[1]*axis[1] + mDistanceCenterFace2D; |
|
| 145 |
} |
|
| 146 |
|
|
| 147 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 148 |
|
|
| 149 |
private boolean faceIsVisible(Static3D faceAxis) |
|
| 150 |
{
|
|
| 151 |
float castCameraOnAxis = mCamera[0]*faceAxis.get0() + mCamera[1]*faceAxis.get1() + mCamera[2]*faceAxis.get2(); |
|
| 152 |
return castCameraOnAxis > mDistanceCenterFace3D; |
|
| 153 |
} |
|
| 154 |
|
|
| 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 156 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace, |
|
| 157 |
// compute point 'output[]' which: |
|
| 158 |
// 1) lies on a face of the Object, i.e. surface defined by (axis, distance from (0,0,0)) [and this |
|
| 159 |
// distance is +-mDistanceCenterFace, depending if it is the face on the left or the right end of |
|
| 160 |
// the axis] (lr=0 or 1, so (2lr-1)*mDistanceCenterFace) |
|
| 161 |
// 2) is co-linear with mCamera and mPoint |
|
| 162 |
// |
|
| 163 |
// output = camera + alpha*(point-camera), where alpha = [dist-axis*camera] / [axis*(point-camera)] |
|
| 164 |
|
|
| 165 |
private void castTouchPointOntoFace(Static3D faceAxis, float[] output) |
|
| 166 |
{
|
|
| 167 |
float d0 = mPoint[0]-mCamera[0]; |
|
| 168 |
float d1 = mPoint[1]-mCamera[1]; |
|
| 169 |
float d2 = mPoint[2]-mCamera[2]; |
|
| 170 |
float a0 = faceAxis.get0(); |
|
| 171 |
float a1 = faceAxis.get1(); |
|
| 172 |
float a2 = faceAxis.get2(); |
|
| 173 |
|
|
| 174 |
float denom = a0*d0 + a1*d1 + a2*d2; |
|
| 175 |
|
|
| 176 |
if( denom != 0.0f ) |
|
| 177 |
{
|
|
| 178 |
float axisCam = a0*mCamera[0] + a1*mCamera[1] + a2*mCamera[2]; |
|
| 179 |
float distance = mDistanceCenterFace3D; |
|
| 180 |
float alpha = (distance-axisCam)/denom; |
|
| 181 |
|
|
| 182 |
output[0] = mCamera[0] + d0*alpha; |
|
| 183 |
output[1] = mCamera[1] + d1*alpha; |
|
| 184 |
output[2] = mCamera[2] + d2*alpha; |
|
| 185 |
} |
|
| 186 |
} |
|
| 187 |
|
|
| 188 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 189 |
// Convert the 3D point3D into a 2D point on the same face surface, but in a different |
|
| 190 |
// coordinate system: a in-plane 2D coord where the origin is in the point where the axis intersects |
|
| 191 |
// the surface, and whose Y axis points 'north' i.e. is in the plane given by the 3D origin, the |
|
| 192 |
// original 3D Y axis and our 2D in-plane origin. |
|
| 193 |
// If those 3 points constitute a degenerate triangle which does not define a plane - which can only |
|
| 194 |
// happen if axis is vertical (or in theory when 2D origin and 3D origin meet, but that would have to |
|
| 195 |
// mean that the distance between the center of the Object and its faces is 0) - then we arbitrarily |
|
| 196 |
// decide that 2D Y = (0,0,-1) in the North Pole and (0,0,1) in the South Pole) |
|
| 197 |
|
|
| 198 |
private void convertTo2Dcoords(float[] point3D, Static3D faceAxis, float[] output) |
|
| 199 |
{
|
|
| 200 |
float y0,y1,y2; // base Y vector of the 2D coord system |
|
| 201 |
float a0 = faceAxis.get0(); |
|
| 202 |
float a1 = faceAxis.get1(); |
|
| 203 |
float a2 = faceAxis.get2(); |
|
| 204 |
|
|
| 205 |
if( a0==0.0f && a2==0.0f ) |
|
| 206 |
{
|
|
| 207 |
y0=0; y1=0; y2=-a1; |
|
| 208 |
} |
|
| 209 |
else if( a1==0.0f ) |
|
| 210 |
{
|
|
| 211 |
y0=0; y1=1; y2=0; |
|
| 212 |
} |
|
| 213 |
else |
|
| 214 |
{
|
|
| 215 |
float norm = (float)(-a1/Math.sqrt(1-a1*a1)); |
|
| 216 |
y0 = norm*a0; y1= norm*(a1-1/a1); y2=norm*a2; |
|
| 217 |
} |
|
| 218 |
|
|
| 219 |
float x0 = y1*a2 - y2*a1; // |
|
| 220 |
float x1 = y2*a0 - y0*a2; // (2D coord baseY) x (axis) = 2D coord baseX |
|
| 221 |
float x2 = y0*a1 - y1*a0; // |
|
| 222 |
|
|
| 223 |
float originAlpha = point3D[0]*a0 + point3D[1]*a1 + point3D[2]*a2; |
|
| 224 |
|
|
| 225 |
float origin0 = originAlpha*a0; // coords of the point where axis |
|
| 226 |
float origin1 = originAlpha*a1; // intersects surface plane i.e. |
|
| 227 |
float origin2 = originAlpha*a2; // the origin of our 2D coord system |
|
| 228 |
|
|
| 229 |
float v0 = point3D[0] - origin0; |
|
| 230 |
float v1 = point3D[1] - origin1; |
|
| 231 |
float v2 = point3D[2] - origin2; |
|
| 232 |
|
|
| 233 |
output[0] = v0*x0 + v1*x1 + v2*x2; |
|
| 234 |
output[1] = v0*y0 + v1*y1 + v2*y2; |
|
| 235 |
} |
|
| 236 |
|
|
| 237 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 238 |
// PUBLIC API |
|
| 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 240 |
|
|
| 241 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera) |
|
| 242 |
{
|
|
| 243 |
float objectRatio = RubikObject.getObjectRatio(); |
|
| 244 |
|
|
| 245 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
| 246 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
| 247 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
| 248 |
|
|
| 249 |
mCamera[0] = rotatedCamera.get0()/objectRatio; |
|
| 250 |
mCamera[1] = rotatedCamera.get1()/objectRatio; |
|
| 251 |
mCamera[2] = rotatedCamera.get2()/objectRatio; |
|
| 252 |
|
|
| 253 |
for( mLastTouchedFace=0; mLastTouchedFace<mNumFaceAxis; mLastTouchedFace++) |
|
| 254 |
{
|
|
| 255 |
if( faceIsVisible(mFaceAxis[mLastTouchedFace]) ) |
|
| 256 |
{
|
|
| 257 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch); |
|
| 258 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mPoint2D); |
|
| 259 |
if( isInsideFace(mPoint2D) ) return true; |
|
| 260 |
} |
|
| 261 |
} |
|
| 262 |
|
|
| 263 |
return false; |
|
| 264 |
} |
|
| 265 |
|
|
| 266 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 267 |
|
|
| 268 |
public Static2D newRotation(Static4D rotatedTouchPoint) |
|
| 269 |
{
|
|
| 270 |
float objectRatio = RubikObject.getObjectRatio(); |
|
| 271 |
|
|
| 272 |
mPoint[0] = rotatedTouchPoint.get0()/objectRatio; |
|
| 273 |
mPoint[1] = rotatedTouchPoint.get1()/objectRatio; |
|
| 274 |
mPoint[2] = rotatedTouchPoint.get2()/objectRatio; |
|
| 275 |
|
|
| 276 |
castTouchPointOntoFace(mFaceAxis[mLastTouchedFace], mTouch); |
|
| 277 |
convertTo2Dcoords(mTouch, mFaceAxis[mLastTouchedFace], mMove2D); |
|
| 278 |
|
|
| 279 |
mMove2D[0] -= mPoint2D[0]; |
|
| 280 |
mMove2D[1] -= mPoint2D[1]; |
|
| 281 |
|
|
| 282 |
computeEnabledAxis(mLastTouchedFace, mPoint2D, mEnabledRotAxis); |
|
| 283 |
int rotIndex = computeRotationIndex(mLastTouchedFace, mMove2D, mEnabledRotAxis); |
|
| 284 |
float offset = computeOffset(mPoint2D, mCastedRotAxis[mLastTouchedFace][rotIndex]); |
|
| 285 |
|
|
| 286 |
return new Static2D(rotIndex,offset); |
|
| 287 |
} |
|
| 288 |
|
|
| 289 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 290 |
|
|
| 291 |
public Static4D getCastedRotAxis(int rotIndex) |
|
| 292 |
{
|
|
| 293 |
return mCastedRotAxis4D[mLastTouchedFace][rotIndex]; |
|
| 294 |
} |
|
| 295 |
|
|
| 296 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 297 |
|
|
| 298 |
public int getTouchedFace() |
|
| 299 |
{
|
|
| 300 |
return mLastTouchedFace; |
|
| 301 |
} |
|
| 302 |
|
|
| 303 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 304 |
|
|
| 305 |
public float[] getTouchedPoint3D() |
|
| 306 |
{
|
|
| 307 |
return mTouch; |
|
| 308 |
} |
|
| 309 |
} |
|
| src/main/java/org/distorted/objects/RubikMovementCube.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class RubikMovementCube extends RubikMovement |
|
| 25 |
{
|
|
| 26 |
RubikMovementCube() |
|
| 27 |
{
|
|
| 28 |
super(RubikCube.ROT_AXIS, RubikCube.FACE_AXIS, 0.5f, 0.5f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
|
|
| 33 |
boolean isInsideFace(float[] p) |
|
| 34 |
{
|
|
| 35 |
return ( p[0]<=0.5f && p[0]>=-0.5f && p[1]<=0.5f && p[1]>=-0.5f ); |
|
| 36 |
} |
|
| 37 |
|
|
| 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 39 |
|
|
| 40 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 41 |
{
|
|
| 42 |
enabled[0] = 2; |
|
| 43 |
|
|
| 44 |
switch(face) |
|
| 45 |
{
|
|
| 46 |
case 0: |
|
| 47 |
case 1: enabled[1]=1; enabled[2]=2; break; |
|
| 48 |
case 2: |
|
| 49 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 50 |
case 4: |
|
| 51 |
case 5: enabled[1]=0; enabled[2]=1; break; |
|
| 52 |
} |
|
| 53 |
} |
|
| 54 |
} |
|
| src/main/java/org/distorted/objects/RubikMovementDiamond.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class RubikMovementDiamond extends RubikMovement |
|
| 25 |
{
|
|
| 26 |
RubikMovementDiamond() |
|
| 27 |
{
|
|
| 28 |
super(RubikDiamond.ROT_AXIS, RubikDiamond.FACE_AXIS, 0.25f, 0.25f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 32 |
// _____________ |
|
| 33 |
// | \ 0 / | |
|
| 34 |
// | \ / | |
|
| 35 |
// | 3 | | 1 | |
|
| 36 |
// | / \ | |
|
| 37 |
// | / 2 \ | |
|
| 38 |
// ------------- |
|
| 39 |
|
|
| 40 |
private int getQuarter(float[] touchPoint) |
|
| 41 |
{
|
|
| 42 |
boolean p0 = touchPoint[1] >= touchPoint[0]; |
|
| 43 |
boolean p1 = touchPoint[1] >=-touchPoint[0]; |
|
| 44 |
|
|
| 45 |
if( p0 ) return p1 ? 0:3; |
|
| 46 |
else return p1 ? 1:2; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 50 |
|
|
| 51 |
boolean isInsideFace(float[] p) |
|
| 52 |
{
|
|
| 53 |
return ( p[0]<=0.25f && p[0]>=-0.25f && p[1]<=0.25f && p[1]>=-0.25f ); |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 58 |
void computeEnabledAxis(int face, float[] touchPoint, int[] enabled) |
|
| 59 |
{
|
|
| 60 |
enabled[0] = 2; |
|
| 61 |
|
|
| 62 |
int quarter = getQuarter(touchPoint); |
|
| 63 |
|
|
| 64 |
switch(face) |
|
| 65 |
{
|
|
| 66 |
case 0: switch(quarter) |
|
| 67 |
{
|
|
| 68 |
case 0: enabled[1]=0; enabled[2]=1; break; |
|
| 69 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 70 |
case 2: enabled[1]=2; enabled[2]=3; break; |
|
| 71 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 72 |
} |
|
| 73 |
break; |
|
| 74 |
case 1: switch(quarter) |
|
| 75 |
{
|
|
| 76 |
case 0: enabled[1]=2; enabled[2]=3; break; |
|
| 77 |
case 1: enabled[1]=3; enabled[2]=1; break; |
|
| 78 |
case 2: enabled[1]=0; enabled[2]=1; break; |
|
| 79 |
case 3: enabled[1]=0; enabled[2]=2; break; |
|
| 80 |
} |
|
| 81 |
break; |
|
| 82 |
case 2: switch(quarter) |
|
| 83 |
{
|
|
| 84 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 85 |
case 1: enabled[1]=0; enabled[2]=1; break; |
|
| 86 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 87 |
case 3: enabled[1]=2; enabled[2]=3; break; |
|
| 88 |
} |
|
| 89 |
break; |
|
| 90 |
case 3: switch(quarter) |
|
| 91 |
{
|
|
| 92 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 93 |
case 1: enabled[1]=2; enabled[2]=3; break; |
|
| 94 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 95 |
case 3: enabled[1]=0; enabled[2]=1; break; |
|
| 96 |
} |
|
| 97 |
break; |
|
| 98 |
case 4: switch(quarter) |
|
| 99 |
{
|
|
| 100 |
case 0: enabled[1]=0; enabled[2]=3; break; |
|
| 101 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 102 |
case 2: enabled[1]=1; enabled[2]=2; break; |
|
| 103 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 104 |
} |
|
| 105 |
break; |
|
| 106 |
case 5: switch(quarter) |
|
| 107 |
{
|
|
| 108 |
case 0: enabled[1]=1; enabled[2]=2; break; |
|
| 109 |
case 1: enabled[1]=0; enabled[2]=2; break; |
|
| 110 |
case 2: enabled[1]=0; enabled[2]=3; break; |
|
| 111 |
case 3: enabled[1]=1; enabled[2]=3; break; |
|
| 112 |
} |
|
| 113 |
break; |
|
| 114 |
} |
|
| 115 |
} |
|
| 116 |
} |
|
| src/main/java/org/distorted/objects/RubikMovementDino.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.objects; |
|
| 21 |
|
|
| 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 23 |
|
|
| 24 |
class RubikMovementDino extends RubikMovement |
|
| 25 |
{
|
|
| 26 |
RubikMovementDino() |
|
| 27 |
{
|
|
| 28 |
super(RubikDino.ROT_AXIS, RubikDino.FACE_AXIS, 0.5f, 0.5f); |
|
| 29 |
} |
|
| 30 |
|
|
| 31 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
Also available in: Unified diff
Rename 'RubikMovement' to 'Movement'