Revision d2e06841
Added by Leszek Koltunski about 2 years ago
| src/main/java/org/distorted/objectlib/bandaged/BandagedCubit.java | ||
|---|---|---|
| 47 | 47 |
|
| 48 | 48 |
private float mUnscaledX, mUnscaledY, mUnscaledZ; |
| 49 | 49 |
private float[] mPosition; |
| 50 |
private float[][] mRotRow; |
|
| 50 | 51 |
private boolean mIsAttached; |
| 51 | 52 |
private long mMarkedEffectID; |
| 52 | 53 |
|
| ... | ... | |
| 90 | 91 |
Static4D q = fact.getQuaternion(i); |
| 91 | 92 |
QuatHelper.rotateVectorByQuat(mTmp,0,0,1,0,q); |
| 92 | 93 |
int index = mObject.computeMapsIndex(mTmp); |
| 94 |
|
|
| 95 |
if( index>=mTextureMaps.length ) |
|
| 96 |
{
|
|
| 97 |
android.util.Log.e("D", "index="+index+" texMapLen="+mTextureMaps.length);
|
|
| 98 |
} |
|
| 99 |
|
|
| 93 | 100 |
maps[i] = mTextureMaps[index]; |
| 94 | 101 |
} |
| 95 | 102 |
|
| ... | ... | |
| 127 | 134 |
mObject = object; |
| 128 | 135 |
mRoundCorners = roundCorners; |
| 129 | 136 |
mPosition = position; |
| 137 |
mRotRow = mObject.getRotRows(mPosition); |
|
| 130 | 138 |
mIsAttached = true; |
| 131 | 139 |
mMarkedEffectID = -1; |
| 132 | 140 |
|
| ... | ... | |
| 165 | 173 |
System.arraycopy(mPosition, 0, tmpPosition, 0, len1); |
| 166 | 174 |
System.arraycopy(position , 0, tmpPosition, len1, len2); |
| 167 | 175 |
mPosition = tmpPosition; |
| 176 |
mRotRow = mObject.getRotRows(mPosition); |
|
| 168 | 177 |
|
| 169 | 178 |
computeMove(mPosition); |
| 170 | 179 |
MeshBase mesh = mObject.createMesh(mPosition,mRoundCorners); |
| ... | ... | |
| 256 | 265 |
return mPosition; |
| 257 | 266 |
} |
| 258 | 267 |
|
| 268 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 269 |
|
|
| 270 |
public float[][] getRotRow() |
|
| 271 |
{
|
|
| 272 |
return mRotRow; |
|
| 273 |
} |
|
| 274 |
|
|
| 259 | 275 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 260 | 276 |
|
| 261 | 277 |
public DistortedNode getNode() |
| src/main/java/org/distorted/objectlib/bandaged/BandagedObject.java | ||
|---|---|---|
| 23 | 23 |
private final DistortedScreen mScreen; |
| 24 | 24 |
private final float[][] mFaceAxis; |
| 25 | 25 |
private BandagedCubit[] mCubits; |
| 26 |
private final float[][] mRotAxis; |
|
| 26 | 27 |
|
| 28 |
float[][] mCuts; |
|
| 27 | 29 |
final int[] mSize; |
| 28 | 30 |
final float mDist2D; |
| 29 | 31 |
|
| ... | ... | |
| 32 | 34 |
|
| 33 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 36 |
|
| 35 |
BandagedObject(DistortedScreen screen, int numRotAxis)
|
|
| 37 |
BandagedObject(DistortedScreen screen) |
|
| 36 | 38 |
{
|
| 37 | 39 |
mScreen = screen; |
| 38 |
mSize = new int[numRotAxis]; |
|
| 40 |
mRotAxis = getRotAxis(); |
|
| 41 |
mSize = new int[mRotAxis.length]; |
|
| 39 | 42 |
mDist2D = getDist2D(); |
| 40 | 43 |
Static3D[] axis = getFaceAxis(); |
| 41 | 44 |
int numAxis = axis.length; |
| ... | ... | |
| 45 | 48 |
|
| 46 | 49 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 47 | 50 |
|
| 51 |
abstract float[][] getRotAxis(); |
|
| 48 | 52 |
abstract float getDist2D(); |
| 49 | 53 |
abstract int[] getColors(); |
| 50 | 54 |
abstract float[][][] getPositions(); |
| ... | ... | |
| 59 | 63 |
public abstract Static3D[] getFaceAxis(); |
| 60 | 64 |
public abstract float getScreenRatio(); |
| 61 | 65 |
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
private float getRotRow(int ax, float d) |
|
| 69 |
{
|
|
| 70 |
float[] cuts = mCuts[ax]; |
|
| 71 |
int numCuts = cuts.length; |
|
| 72 |
for(int c=0; c<numCuts; c++) if( d<=cuts[c] ) return c; |
|
| 73 |
return numCuts; |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
float[][] getRotRows(float[] pos) |
|
| 79 |
{
|
|
| 80 |
int num = pos.length/3; |
|
| 81 |
int numAx = mRotAxis.length; |
|
| 82 |
float[][] ret = new float[num][numAx]; |
|
| 83 |
|
|
| 84 |
for(int p=0; p<num; p++) |
|
| 85 |
for(int a=0; a<numAx; a++) |
|
| 86 |
{
|
|
| 87 |
float[] ax = mRotAxis[a]; |
|
| 88 |
float x = pos[3*p]; |
|
| 89 |
float y = pos[3*p+1]; |
|
| 90 |
float z = pos[3*p+2]; |
|
| 91 |
float d = ax[0]*x + ax[1]*y + ax[2]*z; |
|
| 92 |
ret[p][a] = getRotRow(a,d); |
|
| 93 |
} |
|
| 94 |
|
|
| 95 |
return ret; |
|
| 96 |
} |
|
| 97 |
|
|
| 62 | 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 63 | 99 |
|
| 64 | 100 |
public void createCubits(Static4D quatT, Static4D quatA, Static3D scale) |
| ... | ... | |
| 69 | 105 |
|
| 70 | 106 |
for(float[][] po : pos) |
| 71 | 107 |
for(float[] p : po) |
| 72 |
mCubits[c++]=new BandagedCubit(this, p, quatT, quatA, scale, false);
|
|
| 108 |
mCubits[c++] = new BandagedCubit(this, p, quatT, quatA, scale, false);
|
|
| 73 | 109 |
} |
| 74 | 110 |
|
| 75 | 111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 238 | 274 |
float y = point3D[1]*mMax; |
| 239 | 275 |
float z = point3D[2]*mMax; |
| 240 | 276 |
|
| 241 |
int minIndex = -1; |
|
| 242 |
float minDist = Float.MAX_VALUE; |
|
| 277 |
int numAxis = mRotAxis.length; |
|
| 278 |
float[] rotRow = new float[numAxis]; |
|
| 279 |
|
|
| 280 |
for(int a=0; a<numAxis; a++) |
|
| 281 |
{
|
|
| 282 |
float[] ax = mRotAxis[a]; |
|
| 283 |
float d = ax[0]*x + ax[1]*y + ax[2]*z; |
|
| 284 |
rotRow[a] = getRotRow(a,d); |
|
| 285 |
} |
|
| 286 |
|
|
| 287 |
int diff = Integer.MAX_VALUE; |
|
| 288 |
int currBest = -1; |
|
| 243 | 289 |
|
| 244 | 290 |
for(int c=0; c<mNumCubits; c++) |
| 245 | 291 |
if( mCubits[c].isAttached() ) |
| 246 | 292 |
{
|
| 247 |
float[] pos = mCubits[c].getPosition(); |
|
| 248 |
int len = pos.length/3; |
|
| 293 |
float[][] cubitRotRow = mCubits[c].getRotRow(); |
|
| 249 | 294 |
|
| 250 |
for(int p=0; p<len; p++)
|
|
| 295 |
for(float[] row : cubitRotRow)
|
|
| 251 | 296 |
{
|
| 252 |
float dx = pos[3*p ]-x; |
|
| 253 |
float dy = pos[3*p+1]-y; |
|
| 254 |
float dz = pos[3*p+2]-z; |
|
| 255 |
float dist = dx*dx + dy*dy + dz*dz; |
|
| 297 |
int currDiff = 0; |
|
| 298 |
|
|
| 299 |
for(int a=0; a<numAxis; a++) |
|
| 300 |
{
|
|
| 301 |
float d = rotRow[a]-row[a]; |
|
| 302 |
currDiff += d*d; |
|
| 303 |
} |
|
| 256 | 304 |
|
| 257 |
if( dist<minDist )
|
|
| 305 |
if( currDiff<diff )
|
|
| 258 | 306 |
{
|
| 259 |
minDist = dist;
|
|
| 260 |
minIndex = c;
|
|
| 307 |
diff = currDiff;
|
|
| 308 |
currBest = c;
|
|
| 261 | 309 |
} |
| 262 | 310 |
} |
| 263 | 311 |
} |
| 264 | 312 |
|
| 265 |
return minIndex;
|
|
| 313 |
return currBest;
|
|
| 266 | 314 |
} |
| 267 | 315 |
|
| 268 | 316 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/objectlib/bandaged/BandagedObjectCuboid.java | ||
|---|---|---|
| 22 | 22 |
|
| 23 | 23 |
public class BandagedObjectCuboid extends BandagedObject |
| 24 | 24 |
{
|
| 25 |
private float[][] getCuts(int[] numLayers) |
|
| 26 |
{
|
|
| 27 |
float[][] ret = new float[3][]; |
|
| 28 |
|
|
| 29 |
for(int axis=0; axis<3; axis++) |
|
| 30 |
{
|
|
| 31 |
int len = numLayers[axis]; |
|
| 32 |
float start = (2-len)*0.5f; |
|
| 33 |
|
|
| 34 |
if( len>=2 ) |
|
| 35 |
{
|
|
| 36 |
ret[axis] = new float[len-1]; |
|
| 37 |
for(int i=0; i<len-1; i++) ret[axis][i] = start+i; |
|
| 38 |
} |
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
return ret; |
|
| 42 |
} |
|
| 43 |
|
|
| 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 45 |
|
|
| 46 |
float[][] getRotAxis() |
|
| 47 |
{
|
|
| 48 |
return new float[][] |
|
| 49 |
{
|
|
| 50 |
{1,0,0},
|
|
| 51 |
{0,1,0},
|
|
| 52 |
{0,0,1},
|
|
| 53 |
}; |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 57 |
|
|
| 25 | 58 |
float getDist2D() |
| 26 | 59 |
{
|
| 27 | 60 |
return 0.5f; |
| ... | ... | |
| 62 | 95 |
|
| 63 | 96 |
public BandagedObjectCuboid(DistortedScreen screen) |
| 64 | 97 |
{
|
| 65 |
super(screen,3);
|
|
| 98 |
super(screen); |
|
| 66 | 99 |
} |
| 67 | 100 |
|
| 68 | 101 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 138 | 171 |
mSize[2] = z; |
| 139 | 172 |
mMax = x>y ? Math.max(x,z) : Math.max(y,z); |
| 140 | 173 |
mNumCubits = ( x<=1 || y<=1 || z<=1 ) ? x*y*z : x*y*z-(x-2)*(y-2)*(z-2); |
| 174 |
mCuts = getCuts(mSize); |
|
| 141 | 175 |
return true; |
| 142 | 176 |
} |
| 143 | 177 |
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedObjectMegaminx.java | ||
|---|---|---|
| 10 | 10 |
package org.distorted.objectlib.bandaged; |
| 11 | 11 |
|
| 12 | 12 |
import static org.distorted.objectlib.main.TwistyObject.SQ5; |
| 13 |
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.C2; |
|
| 13 | 14 |
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.COS54; |
| 15 |
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.LEN; |
|
| 14 | 16 |
import static org.distorted.objectlib.touchcontrol.TouchControlDodecahedron.SIN54; |
| 15 | 17 |
|
| 16 | 18 |
import org.distorted.library.main.DistortedScreen; |
| ... | ... | |
| 35 | 37 |
private static final int NUM_CENTERS = 12; |
| 36 | 38 |
private static final int NUM_EDGES = 30; |
| 37 | 39 |
|
| 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 41 |
|
|
| 42 |
private float[][] getCuts(int[] numLayers) |
|
| 43 |
{
|
|
| 44 |
int numL = numLayers[0]; |
|
| 45 |
int distL = numL; |
|
| 46 |
boolean megaminx = isMegaminx(numL); |
|
| 47 |
float dist = megaminx ? 0.5f-MEGA_D : 0.5f; |
|
| 48 |
if( (numL%2)==0 ) numL++; |
|
| 49 |
|
|
| 50 |
float[][] ret = new float[6][numL-1]; |
|
| 51 |
float D = distL*TouchControlDodecahedron.DIST3D; |
|
| 52 |
float X = 2*D/(2+SIN18); // height of the 'upper' part of a dodecahedron, i.e. put it on a table, |
|
| 53 |
// its height is then 2D, it has one 'lower' part of height X, one |
|
| 54 |
// 'middle' part of height Y and one upper part of height X again. |
|
| 55 |
int num = (numL-1)/2; |
|
| 56 |
float G = X*dist/num; // height of one Layer |
|
| 57 |
|
|
| 58 |
for(int i=0; i<num; i++) |
|
| 59 |
{
|
|
| 60 |
float cut = -D + (i+0.85f)*G; // 0.85? not fully correct; attempt to make it |
|
| 61 |
// easier to rotate the outer layers |
|
| 62 |
int j = 2*num-1-i; |
|
| 63 |
ret[0][i] = cut; |
|
| 64 |
ret[0][j] = -cut; |
|
| 65 |
ret[1][i] = cut; |
|
| 66 |
ret[1][j] = -cut; |
|
| 67 |
ret[2][i] = cut; |
|
| 68 |
ret[2][j] = -cut; |
|
| 69 |
ret[3][i] = cut; |
|
| 70 |
ret[3][j] = -cut; |
|
| 71 |
ret[4][i] = cut; |
|
| 72 |
ret[4][j] = -cut; |
|
| 73 |
ret[5][i] = cut; |
|
| 74 |
ret[5][j] = -cut; |
|
| 75 |
} |
|
| 76 |
|
|
| 77 |
return ret; |
|
| 78 |
} |
|
| 79 |
|
|
| 38 | 80 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 39 | 81 |
// The pair (distance,angle) defines a point P in R^2 in polar coordinate system. Let V be the vector |
| 40 | 82 |
// from the center of the coordinate system to P. |
| ... | ... | |
| 167 | 209 |
|
| 168 | 210 |
case 5: float x5_0 = 2.5f*(0.5f-MEGA_D); |
| 169 | 211 |
float x5_1 = 2.5f*(0.5f+MEGA_D); |
| 170 |
float x5_2 = 2.5f*(0.5f-MEGA_D)*COS18;
|
|
| 171 |
float x5_3 = x5_1 + 2.5f*(0.5f-MEGA_D)*SIN18;
|
|
| 172 |
float x5_4 = 2.5f*SIN54 - x5_2; |
|
| 212 |
float x5_2 = x5_0*COS18;
|
|
| 213 |
float x5_3 = x5_1 + x5_0*SIN18;
|
|
| 214 |
float x5_4 = 2.5f*SIN54/COS54 - x5_2;
|
|
| 173 | 215 |
float d5_0 = len-x5_0*x5_0; |
| 174 | 216 |
float d5_1 = len-x5_1*x5_1; |
| 175 | 217 |
float d5_2 = len-x5_2*x5_2; |
| ... | ... | |
| 186 | 228 |
return false; |
| 187 | 229 |
} |
| 188 | 230 |
|
| 231 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 232 |
|
|
| 233 |
float[][] getRotAxis() |
|
| 234 |
{
|
|
| 235 |
return new float[][] |
|
| 236 |
{
|
|
| 237 |
{ C2/LEN, SIN54/LEN, 0 },
|
|
| 238 |
{ -C2/LEN, SIN54/LEN, 0 },
|
|
| 239 |
{ 0 , C2/LEN, SIN54/LEN },
|
|
| 240 |
{ 0 , -C2/LEN, SIN54/LEN },
|
|
| 241 |
{ SIN54/LEN, 0 , C2/LEN },
|
|
| 242 |
{ SIN54/LEN, 0 , -C2/LEN }
|
|
| 243 |
}; |
|
| 244 |
} |
|
| 245 |
|
|
| 189 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 190 | 247 |
|
| 191 | 248 |
float[][][] getPositions() |
| ... | ... | |
| 229 | 286 |
|
| 230 | 287 |
public BandagedObjectMegaminx(DistortedScreen screen) |
| 231 | 288 |
{
|
| 232 |
super(screen,6);
|
|
| 289 |
super(screen); |
|
| 233 | 290 |
} |
| 234 | 291 |
|
| 235 | 292 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 269 | 326 |
|
| 270 | 327 |
mMax = x; |
| 271 | 328 |
mNumCubits = numCubits(x); |
| 329 |
mCuts = getCuts(mSize); |
|
| 272 | 330 |
return true; |
| 273 | 331 |
} |
| 274 | 332 |
|
| src/main/java/org/distorted/objectlib/bandaged/BandagedObjectPyraminx.java | ||
|---|---|---|
| 30 | 30 |
return face>1; |
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
private float[][] getCuts(int[] numLayers) |
|
| 36 |
{
|
|
| 37 |
int numL = numLayers[0]; |
|
| 38 |
float[][] ret = new float[4][numL-1]; |
|
| 39 |
|
|
| 40 |
for(int i=0; i<numL-1; i++) |
|
| 41 |
{
|
|
| 42 |
float cut = (1.0f+i-numL/4.0f)*(SQ6/3); |
|
| 43 |
ret[0][i] = cut; |
|
| 44 |
ret[1][i] = cut; |
|
| 45 |
ret[2][i] = cut; |
|
| 46 |
ret[3][i] = cut; |
|
| 47 |
} |
|
| 48 |
|
|
| 49 |
return ret; |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 53 |
|
|
| 54 |
float[][] getRotAxis() |
|
| 55 |
{
|
|
| 56 |
return new float[][] |
|
| 57 |
{
|
|
| 58 |
{ 0,-SQ3/3,-SQ6/3 },
|
|
| 59 |
{ 0,-SQ3/3, SQ6/3 },
|
|
| 60 |
{ SQ6/3, SQ3/3, 0 },
|
|
| 61 |
{-SQ6/3, SQ3/3, 0 },
|
|
| 62 |
}; |
|
| 63 |
} |
|
| 64 |
|
|
| 33 | 65 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 34 | 66 |
|
| 35 | 67 |
float getDist2D() |
| ... | ... | |
| 72 | 104 |
|
| 73 | 105 |
public BandagedObjectPyraminx(DistortedScreen screen) |
| 74 | 106 |
{
|
| 75 |
super(screen,4);
|
|
| 107 |
super(screen); |
|
| 76 | 108 |
} |
| 77 | 109 |
|
| 78 | 110 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 112 | 144 |
int numOcta = FactoryBandagedPyraminx.numEntriesInEmptyLattice(x-1); |
| 113 | 145 |
int numTetra= FactoryBandagedPyraminx.numEntriesInEmptyLattice(x); |
| 114 | 146 |
mNumCubits = numOcta + numTetra; |
| 147 |
mCuts = getCuts(mSize); |
|
| 115 | 148 |
return true; |
| 116 | 149 |
} |
| 117 | 150 |
|
| src/main/java/org/distorted/objectlib/helpers/ObjectSignature.java | ||
|---|---|---|
| 93 | 93 |
// the signature must contain ceil( 12*(N-1)^2 / 64 ) bytes. |
| 94 | 94 |
// a pyraminx of size N has 4 + 6*(N-1)(N-2) places two adjacent cubies can be 'glued' so much less. |
| 95 | 95 |
|
| 96 |
// Gigaminx has 480 such places (so more if N<=7)
|
|
| 96 |
// Gigaminx has 540 such places (so more if N<=7)
|
|
| 97 | 97 |
|
| 98 | 98 |
private static int computeNum() |
| 99 | 99 |
{
|
| 100 | 100 |
int max = MAX_SUPPORTED_SIZE-1; |
| 101 | 101 |
int ret = (int)(0.99f + (12*max*max)/64.0f); |
| 102 |
int giga= (int)(0.99f + ( 480)/64.0f);
|
|
| 102 |
int giga= (int)(0.99f + ( 540)/64.0f);
|
|
| 103 | 103 |
|
| 104 | 104 |
return Math.max(ret,giga); |
| 105 | 105 |
} |
| ... | ... | |
| 1038 | 1038 |
|
| 1039 | 1039 |
ArrayList<float[]> mTouch = new ArrayList<>(); |
| 1040 | 1040 |
|
| 1041 |
int t=0; |
|
| 1042 |
|
|
| 1043 | 1041 |
for(int i=0; i<numCubits; i++) |
| 1044 | 1042 |
{
|
| 1045 | 1043 |
float[] first = getPosition(i,centers,numVariants); |
| ... | ... | |
| 1062 | 1060 |
float zc = (tz+oz)/2; |
| 1063 | 1061 |
|
| 1064 | 1062 |
float[] touch = new float[] {xc, yc, zc};
|
| 1065 |
|
|
| 1066 |
android.util.Log.e("D", "cubit touch: "+t+" : " +xc+" "+yc+" "+zc );
|
|
| 1067 |
t++; |
|
| 1068 |
|
|
| 1069 | 1063 |
mTouch.add(touch); |
| 1070 | 1064 |
} |
| 1071 | 1065 |
} |
Also available in: Unified diff
progress with TwistyBandagedMegaminx.