Revision 4d696d4a
Added by Leszek Koltunski 9 months ago
| src/main/java/org/distorted/objectlib/main/TwistyObjectControllable.java | ||
|---|---|---|
| 9 | 9 |
|
| 10 | 10 |
package org.distorted.objectlib.main; |
| 11 | 11 |
|
| 12 |
import static org.distorted.objectlib.touchcontrol.TouchControl.*; |
|
| 13 |
|
|
| 14 | 12 |
import org.distorted.library.effect.VertexEffectRotate; |
| 15 | 13 |
import org.distorted.library.helpers.QuatHelper; |
| 16 | 14 |
import org.distorted.library.message.EffectListener; |
| ... | ... | |
| 19 | 17 |
import org.distorted.library.type.Static3D; |
| 20 | 18 |
import org.distorted.library.type.Static4D; |
| 21 | 19 |
import org.distorted.objectlib.helpers.OperatingSystemInterface; |
| 22 |
import org.distorted.objectlib.touchcontrol.*;
|
|
| 20 |
import org.distorted.objectlib.touchcontrol.TouchControl;
|
|
| 23 | 21 |
|
| 24 | 22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 25 | 23 |
// the fifth layer of Puzzle implementation: the touch control |
| ... | ... | |
| 109 | 107 |
|
| 110 | 108 |
public int getGhostAxis() { return 0; }
|
| 111 | 109 |
public int getGhostAngle() { return 0; }
|
| 112 |
public int[] getGhostFirstRow() { return null; }
|
|
| 110 |
public int[] getGhostRowState() { return null; }
|
|
| 113 | 111 |
|
| 114 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 115 | 113 |
|
| src/main/java/org/distorted/objectlib/main/TwistyObjectGhost.java | ||
|---|---|---|
| 35 | 35 |
|
| 36 | 36 |
private final int mGhostAngle; |
| 37 | 37 |
private final int mGhostOrigAxis; |
| 38 |
private final int[] mGhostFirstRow;
|
|
| 38 |
private final int[] mGhostRowState;
|
|
| 39 | 39 |
private boolean mGhostBlocked; |
| 40 | 40 |
private int mGhostRowBitmap; |
| 41 | 41 |
private Static3D mGhostAxis; |
| 42 |
private VertexEffectRotate mGhostEffect; |
|
| 42 |
private VertexEffectRotate[] mGhostEffect; |
|
| 43 |
private Static1D[] mGhostEffectAngle; |
|
| 43 | 44 |
private Static4D mGhostQuat; |
| 44 | 45 |
private boolean[] mGhostCubitRotated, mGhostOrigRotated; |
| 45 | 46 |
private int mGhostAxisParallelTo; |
| ... | ... | |
| 65 | 66 |
|
| 66 | 67 |
mGhostAngle = controllable.getGhostAngle(); |
| 67 | 68 |
mGhostOrigAxis = controllable.getGhostAxis(); |
| 68 |
mGhostFirstRow = controllable.getGhostFirstRow();
|
|
| 69 |
mGhostRowState = controllable.getGhostRowState();
|
|
| 69 | 70 |
|
| 70 | 71 |
UNIT_QUAT = new Static4D(0,0,0,1); |
| 71 | 72 |
GHOST_QUAT= new Static4D(0,0,0,1); |
| ... | ... | |
| 77 | 78 |
mGhostBlocked = true; |
| 78 | 79 |
mGhostAxisInverted= false; |
| 79 | 80 |
mGhostAxis = new Static3D(mAxis[mGhostOrigAxis]); |
| 80 |
Static1D stat = new Static1D(mGhostAngle); |
|
| 81 |
mGhostEffect = new VertexEffectRotate(stat, mGhostAxis, new Static3D(0,0,0)); |
|
| 82 |
effects.apply(mGhostEffect); |
|
| 81 |
mGhostEffect = new VertexEffectRotate[mMaxNumLayers]; |
|
| 82 |
mGhostEffectAngle = new Static1D[mMaxNumLayers]; |
|
| 83 |
|
|
| 84 |
for(int l=0; l<mMaxNumLayers; l++) |
|
| 85 |
{
|
|
| 86 |
mGhostEffectAngle[l] = new Static1D(mGhostRowState[l]*mGhostAngle); |
|
| 87 |
mGhostEffect[l] = new VertexEffectRotate(mGhostEffectAngle[l], mGhostAxis, new Static3D(0, 0, 0)); |
|
| 88 |
effects.apply(mGhostEffect[l]); |
|
| 89 |
} |
|
| 83 | 90 |
|
| 84 | 91 |
mGhostCubitRotated = new boolean[mNumCubits]; |
| 85 | 92 |
mGhostOrigRotated = new boolean[mNumCubits]; |
| 86 | 93 |
|
| 87 | 94 |
mGhostQuat = new Static4D(0,0,0,1); |
| 88 |
int tmp = 1<<(mNumLayers[mGhostOrigAxis]-mGhostFirstRow[mGhostOrigAxis]); |
|
| 89 |
mGhostRowBitmap = (tmp-1)<<mGhostFirstRow[mGhostOrigAxis]; |
|
| 90 | 95 |
mGhostAxisParallelTo = mGhostOrigAxis; |
| 91 | 96 |
|
| 92 | 97 |
reinitializeGhostStuff(); |
| src/main/java/org/distorted/objectlib/main/TwistyObjectWithMesh.java | ||
|---|---|---|
| 83 | 83 |
mIconMode = iconMode; // mesh might depend on this (see e.g. Morphix) |
| 84 | 84 |
mRadius = -1; |
| 85 | 85 |
|
| 86 |
mCubitOrigQuat = new Static4D[mNumCubits]; |
|
| 87 |
for(int i=0; i<mNumCubits; i++) mCubitOrigQuat[i] = getCubitOrigQuat(i); |
|
| 86 |
createOrigQuat(); |
|
| 88 | 87 |
|
| 89 | 88 |
mMaxNumLayers = -1; |
| 90 | 89 |
for(int i=0; i<mNumAxis; i++) |
| ... | ... | |
| 124 | 123 |
if( mShapes ==null ) mShapes = new ObjectShape[mNumCubitVariants]; |
| 125 | 124 |
if( mShapes[0]==null ) for(int v=0; v<mNumCubitVariants; v++) mShapes[v] = getObjectShape(v); |
| 126 | 125 |
|
| 127 |
if( mCubitOrigQuat ==null ) mCubitOrigQuat = new Static4D[mNumCubits]; |
|
| 128 |
if( mCubitOrigQuat[0] ==null ) for(int c=0; c<mNumCubits; c++) mCubitOrigQuat[c] = getCubitOrigQuat(c); |
|
| 129 |
if( mCubitGhostQuat ==null ) mCubitGhostQuat= new Static4D[mNumCubits]; |
|
| 130 |
if( mCubitGhostQuat[0]==null ) for(int c=0; c<mNumCubits; c++) mCubitGhostQuat[c] = getCubitGhostQuat(c); |
|
| 126 |
createOrigQuat(); |
|
| 127 |
createGhostQuat(); |
|
| 131 | 128 |
|
| 132 | 129 |
mCubitFaceToPuzzleFaceMap= ObjectShape.computePuzzleFaceMap(mShapes,mCubitPos, mCubitOrigQuat, mCubitGhostQuat, this); |
| 133 | 130 |
} |
| ... | ... | |
| 199 | 196 |
{
|
| 200 | 197 |
if( mShapes ==null ) mShapes = new ObjectShape[mNumCubitVariants]; |
| 201 | 198 |
if( mShapes[0]==null ) for(int v=0; v<mNumCubitVariants; v++) mShapes[v] = getObjectShape(v); |
| 202 |
if( mCubitGhostQuat ==null ) mCubitGhostQuat= new Static4D[mNumCubits]; |
|
| 203 |
if( mCubitGhostQuat[0]==null ) for(int c=0; c<mNumCubits; c++) mCubitGhostQuat[c] = getCubitGhostQuat(c); |
|
| 199 |
createGhostQuat(); |
|
| 204 | 200 |
|
| 205 | 201 |
for( int c=0; c<mNumCubits; c++ ) |
| 206 | 202 |
{
|
| ... | ... | |
| 366 | 362 |
|
| 367 | 363 |
if( !fromJSON ) |
| 368 | 364 |
{
|
| 369 |
if( mCubitGhostQuat ==null ) mCubitGhostQuat= new Static4D[mNumCubits]; |
|
| 370 |
if( mCubitGhostQuat[0]==null ) for(int c=0; c<mNumCubits; c++) mCubitGhostQuat[c] = getCubitGhostQuat(c); |
|
| 365 |
createGhostQuat(); |
|
| 371 | 366 |
mCubitFaceToPuzzleFaceMap= ObjectShape.computePuzzleFaceMap(mShapes,mCubitPos, mCubitOrigQuat, mCubitGhostQuat, this); |
| 372 | 367 |
createOuterFaces(); |
| 373 | 368 |
} |
| ... | ... | |
| 379 | 374 |
} |
| 380 | 375 |
} |
| 381 | 376 |
|
| 377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 378 |
|
|
| 379 |
private void createGhostQuat() |
|
| 380 |
{
|
|
| 381 |
if( mCubitGhostQuat ==null ) mCubitGhostQuat= new Static4D[mNumCubits]; |
|
| 382 |
if( mCubitGhostQuat[0]==null ) for(int c=0; c<mNumCubits; c++) mCubitGhostQuat[c] = getCubitGhostQuat(c); |
|
| 383 |
} |
|
| 384 |
|
|
| 385 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 386 |
|
|
| 387 |
private void createOrigQuat() |
|
| 388 |
{
|
|
| 389 |
if( mCubitOrigQuat == null ) mCubitOrigQuat=new Static4D[mNumCubits]; |
|
| 390 |
if( mCubitOrigQuat[0] == null ) for( int c=0; c<mNumCubits; c++ ) mCubitOrigQuat[c]=getCubitOrigQuat(c); |
|
| 391 |
} |
|
| 392 |
|
|
| 382 | 393 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 383 | 394 |
|
| 384 | 395 |
private int computeMaxNumCubitFaces(boolean fromJSON) |
| src/main/java/org/distorted/objectlib/objects/TwistyGhostHex.java | ||
|---|---|---|
| 45 | 45 |
private float[][] mCuts; |
| 46 | 46 |
private int[][] mBasicAngle; |
| 47 | 47 |
private float[][] mPositions; |
| 48 |
private int[] mFirstRow;
|
|
| 48 |
private int[] mRowState;
|
|
| 49 | 49 |
private float[] mDist3D, mDist; |
| 50 | 50 |
private ObjectMove[][] mAlgorithms; |
| 51 | 51 |
private ObjectShape[] mShapes; |
| 52 |
private float[][] mLeftCutPlanes, mRightCutPlanes;
|
|
| 53 |
private float[][] mLeftPotentialVertices, mRightPotentialVertices;
|
|
| 52 |
private float[][][] mCutPlanes;
|
|
| 53 |
private float[][][] mPotentialVertices;
|
|
| 54 | 54 |
private Static3D[] mRotAxis; |
| 55 | 55 |
private Static4D mPlanesRotQuat; |
| 56 | 56 |
|
| ... | ... | |
| 78 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 79 | 79 |
|
| 80 | 80 |
@Override |
| 81 |
public int[] getGhostFirstRow()
|
|
| 81 |
public int[] getGhostRowState()
|
|
| 82 | 82 |
{
|
| 83 |
if( mFirstRow==null ) mFirstRow = produceFirstRow();
|
|
| 84 |
return mFirstRow;
|
|
| 83 |
if( mRowState==null ) mRowState = produceRowState();
|
|
| 84 |
return mRowState;
|
|
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 | 87 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 102 | 102 |
@Override |
| 103 | 103 |
public ObjectMove[][] getScrambleAlgorithms() |
| 104 | 104 |
{
|
| 105 |
if( mFirstRow==null ) mFirstRow = produceFirstRow();
|
|
| 105 |
if( mRowState==null ) mRowState = produceRowState();
|
|
| 106 | 106 |
if( mAlgorithms==null ) |
| 107 | 107 |
{
|
| 108 | 108 |
int axis = getGhostAxis(); |
| 109 | 109 |
int angle= getGhostAngle(); |
| 110 |
mAlgorithms = ScrambleEdgeGenerator.getGhostScramblingAlgorithms(mBasicAngles,axis,mFirstRow[axis],angle);
|
|
| 110 |
mAlgorithms = ScrambleEdgeGenerator.getGhostScramblingAlgorithms(mBasicAngles,axis,mRowState,angle);
|
|
| 111 | 111 |
} |
| 112 | 112 |
return mAlgorithms; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 116 | 116 |
|
| 117 |
private int[] produceFirstRow()
|
|
| 117 |
private int[] produceRowState()
|
|
| 118 | 118 |
{
|
| 119 | 119 |
int[] numL = getNumLayers(); |
| 120 |
return new int[] { (1+numL[0])/2, (1+numL[1])/2, (1+numL[2])/2 };
|
|
| 120 |
int max = numL[0]>numL[1] ? Math.max(numL[0],numL[2]) : Math.max(numL[1],numL[2]); |
|
| 121 |
int[] state = new int[max]; |
|
| 122 |
int start = (1-max)/2; |
|
| 123 |
for(int i=0 ;i<max; i++) state[i] = start+i; |
|
| 124 |
|
|
| 125 |
return state; |
|
| 121 | 126 |
} |
| 122 | 127 |
|
| 123 | 128 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
minor