Revision 49f67f9b
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/object/Cubit.java | ||
---|---|---|
124 | 124 |
|
125 | 125 |
private int computeNearestAngle(float angle) |
126 | 126 |
{ |
127 |
final int NEAREST = 90;
|
|
127 |
final int NEAREST = 360/mParent.getBasicAngle();
|
|
128 | 128 |
|
129 | 129 |
int tmp = (int)((angle+NEAREST/2)/NEAREST); |
130 | 130 |
if( angle< -(NEAREST*0.5) ) tmp-=1; |
... | ... | |
136 | 136 |
|
137 | 137 |
private void modifyCurrentPosition(Static3D currentPosition, Static4D quat) |
138 | 138 |
{ |
139 |
float diff = 0.5f*(mParent.mSize-1); |
|
140 |
float cubitCenterX = currentPosition.get0() - diff; |
|
141 |
float cubitCenterY = currentPosition.get1() - diff; |
|
142 |
float cubitCenterZ = currentPosition.get2() - diff; |
|
139 |
float cubitCenterX = currentPosition.get0(); |
|
140 |
float cubitCenterY = currentPosition.get1(); |
|
141 |
float cubitCenterZ = currentPosition.get2(); |
|
143 | 142 |
|
144 | 143 |
Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0); |
145 | 144 |
Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat); |
146 | 145 |
|
147 |
float rotatedX = rotatedCenter.get0() + diff;
|
|
148 |
float rotatedY = rotatedCenter.get1() + diff;
|
|
149 |
float rotatedZ = rotatedCenter.get2() + diff;
|
|
146 |
float rotatedX = rotatedCenter.get0(); |
|
147 |
float rotatedY = rotatedCenter.get1(); |
|
148 |
float rotatedZ = rotatedCenter.get2(); |
|
150 | 149 |
|
151 |
int roundedX = (int)(rotatedX+0.1f); |
|
152 |
int roundedY = (int)(rotatedY+0.1f); |
|
153 |
int roundedZ = (int)(rotatedZ+0.1f); |
|
150 |
currentPosition.set(rotatedX, rotatedY, rotatedZ); |
|
151 |
mParent.clampPos(currentPosition); |
|
154 | 152 |
|
155 |
currentPosition.set(roundedX, roundedY, roundedZ); |
|
156 | 153 |
computeRotationRow(); |
157 | 154 |
} |
158 | 155 |
|
... | ... | |
184 | 181 |
float y = position.get1(); |
185 | 182 |
float z = position.get2(); |
186 | 183 |
|
187 |
float nc = parent.mSize*0.5f; |
|
188 |
Static3D vector = new Static3D(x-nc+0.5f, y-nc+0.5f, z-nc+0.5f); |
|
184 |
Static3D vector = new Static3D(x,y,z); |
|
189 | 185 |
|
190 | 186 |
mParent = parent; |
191 | 187 |
mMesh = mesh; |
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
89 | 89 |
int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1; |
90 | 90 |
Static3D[] tmp = new Static3D[numCubits]; |
91 | 91 |
|
92 |
float diff = 0.5f*(size-1); |
|
92 | 93 |
int currentPosition = 0; |
93 | 94 |
|
94 | 95 |
for(int x = 0; x<size; x++) |
... | ... | |
96 | 97 |
for(int z = 0; z<size; z++) |
97 | 98 |
if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 ) |
98 | 99 |
{ |
99 |
tmp[currentPosition++] = new Static3D(x,y,z);
|
|
100 |
tmp[currentPosition++] = new Static3D(x-diff,y-diff,z-diff);
|
|
100 | 101 |
} |
101 | 102 |
|
102 | 103 |
return tmp; |
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
54 | 54 |
private final int NUM_CUBITS; |
55 | 55 |
private int mRotRow; |
56 | 56 |
private int mRotAxis; |
57 |
private Static3D[] mOrigPos; |
|
57 | 58 |
private Static3D mScale, mNodeScale; |
58 | 59 |
private Static4D mQuatAccumulated; |
59 | 60 |
private Cubit[] mCubits; |
61 |
private int mSize; |
|
60 | 62 |
|
61 | 63 |
float mStart, mStep; |
62 |
int mSize; |
|
63 | 64 |
|
64 | 65 |
Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal; |
65 | 66 |
DistortedTexture mTexture; |
... | ... | |
77 | 78 |
|
78 | 79 |
resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE); |
79 | 80 |
|
80 |
Static3D[] positions = getCubitPositions(size);
|
|
81 |
mOrigPos = getCubitPositions(size);
|
|
81 | 82 |
|
82 | 83 |
LEGAL_QUATS = getLegalQuats(); |
83 |
NUM_CUBITS = positions.length;
|
|
84 |
NUM_CUBITS = mOrigPos.length;
|
|
84 | 85 |
ROTATION_AXIS = getRotationAxis(); |
85 | 86 |
|
86 | 87 |
mSize = size; |
87 |
|
|
88 |
computeStartAndStep(positions); |
|
88 |
computeStartAndStep(mOrigPos); |
|
89 | 89 |
|
90 | 90 |
mRotationAngleStatic = new Static1D(0); |
91 | 91 |
mRotationAngleMiddle = new Static1D(0); |
... | ... | |
115 | 115 |
for(int i=0; i<NUM_CUBITS; i++) |
116 | 116 |
{ |
117 | 117 |
MeshBase cubitMesh = createCubitMesh(vertices); |
118 |
mCubits[i] = new Cubit(this,cubitMesh,positions[i]);
|
|
118 |
mCubits[i] = new Cubit(this,cubitMesh,mOrigPos[i]);
|
|
119 | 119 |
textureCubitMesh(cubitMesh,i); |
120 | 120 |
|
121 | 121 |
attach(mCubits[i].mNode); |
... | ... | |
143 | 143 |
{ |
144 | 144 |
for(int i=0; i<numFaces; i++) |
145 | 145 |
{ |
146 |
belongs = belongsToRotation(cubit, i, mSize-1 );
|
|
146 |
belongs = belongsToRotation(cubit, i, 0 );
|
|
147 | 147 |
maps[i] = new Static4D( (belongs?i:6)*ratio, 0.0f, ratio, 1.0f); |
148 | 148 |
} |
149 | 149 |
} |
... | ... | |
213 | 213 |
} |
214 | 214 |
} |
215 | 215 |
|
216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
217 |
// Clamp all rotated positions to one of those original ones to avoid accumulating errors. |
|
218 |
|
|
219 |
void clampPos(Static3D pos) |
|
220 |
{ |
|
221 |
float currError, minError = Float.MAX_VALUE; |
|
222 |
int minErrorIndex= -1; |
|
223 |
float x = pos.get0(); |
|
224 |
float y = pos.get1(); |
|
225 |
float z = pos.get2(); |
|
226 |
float xo,yo,zo; |
|
227 |
|
|
228 |
for(int i=0; i<NUM_CUBITS; i++) |
|
229 |
{ |
|
230 |
xo = mOrigPos[i].get0(); |
|
231 |
yo = mOrigPos[i].get1(); |
|
232 |
zo = mOrigPos[i].get2(); |
|
233 |
|
|
234 |
currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z); |
|
235 |
|
|
236 |
if( currError<minError ) |
|
237 |
{ |
|
238 |
minError = currError; |
|
239 |
minErrorIndex = i; |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
pos.set( mOrigPos[minErrorIndex] ); |
|
244 |
} |
|
245 |
|
|
216 | 246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
217 | 247 |
// the getFaceColors + final black in a horizontal strip. |
218 | 248 |
|
src/main/java/org/distorted/object/RubikObjectList.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
public enum RubikObjectList |
31 | 31 |
{ |
32 |
CUBE2 ( 2, R.drawable.button2 , RubikCube.class, RubikCubeMovement.class),
|
|
33 |
CUBE3 ( 3, R.drawable.button3 , RubikCube.class, RubikCubeMovement.class),
|
|
34 |
CUBE4 ( 4, R.drawable.button4 , RubikCube.class, RubikCubeMovement.class),
|
|
35 |
CUBE5 ( 5, R.drawable.button5 , RubikCube.class, RubikCubeMovement.class),
|
|
32 |
CUBE2 ( 1, R.drawable.cube2, RubikCube.class, RubikCubeMovement.class),
|
|
33 |
CUBE3 ( 2, R.drawable.cube3, RubikCube.class, RubikCubeMovement.class),
|
|
34 |
CUBE4 ( 3, R.drawable.cube4, RubikCube.class, RubikCubeMovement.class),
|
|
35 |
CUBE5 ( 4, R.drawable.cube5, RubikCube.class, RubikCubeMovement.class),
|
|
36 | 36 |
; |
37 | 37 |
|
38 | 38 |
public static final int LENGTH = values().length; |
... | ... | |
86 | 86 |
DistortedEffects effects = new DistortedEffects(); |
87 | 87 |
MeshRectangles mesh = new MeshRectangles(20,20); // mesh of the node, not of the cubits |
88 | 88 |
|
89 |
return new RubikCube(mObjectSize, quatCur, quatAcc, texture, mesh, effects);
|
|
89 |
return new RubikPyraminx(mObjectSize, quatCur, quatAcc, texture, mesh, effects);
|
|
90 | 90 |
} |
91 | 91 |
|
92 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
94 | 94 |
|
95 | 95 |
public RubikObjectMovement getObjectMovementClass() |
96 | 96 |
{ |
97 |
return new RubikCubeMovement();
|
|
97 |
return new RubikPyraminxMovement();
|
|
98 | 98 |
} |
99 | 99 |
} |
src/main/java/org/distorted/object/RubikPyraminx.java | ||
---|---|---|
46 | 46 |
private static final Static3D[] AXIS = new Static3D[] |
47 | 47 |
{ |
48 | 48 |
new Static3D( 0, 1, 0 ), |
49 |
new Static3D( SQ2*SQ3/3, -1.0f/3, -SQ2/3 ),
|
|
49 |
new Static3D( 0, -1.0f/3, 2*SQ2/3 ),
|
|
50 | 50 |
new Static3D(-SQ2*SQ3/3, -1.0f/3, -SQ2/3 ), |
51 |
new Static3D( 0, -1.0f/3, 2*SQ2/3 )
|
|
51 |
new Static3D( SQ2*SQ3/3, -1.0f/3, -SQ2/3 )
|
|
52 | 52 |
}; |
53 | 53 |
|
54 | 54 |
private static final int[] FACE_COLORS = new int[] |
... | ... | |
64 | 64 |
SQ3/3, -SQ3/3, SQ3/6, -SQ3/6, SQ2*SQ3/3, -SQ2*SQ3/3, SQ2*SQ3/6, -SQ2*SQ3/6 |
65 | 65 |
}; |
66 | 66 |
|
67 |
private Static4D[] mRotArray; |
|
68 |
|
|
67 | 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
68 | 70 |
|
69 | 71 |
RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects) |
... | ... | |
73 | 75 |
|
74 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
75 | 77 |
|
78 |
private void emitRow(float x, float y, float z, float dx, float dy, float dz, int n, Static4D rot, Static3D[] array, int index) |
|
79 |
{ |
|
80 |
for(int i=0; i<n; i++) |
|
81 |
{ |
|
82 |
mRotArray[i+index] = rot; |
|
83 |
array[i+index] = new Static3D(x+0.5f,y+SQ2*SQ3/12,z+SQ3/6); |
|
84 |
x += dx; |
|
85 |
y += dy; |
|
86 |
z += dz; |
|
87 |
} |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
private int emitLowermost(float x, float y, float z, int n, Static3D[] array) |
|
93 |
{ |
|
94 |
int added = 0; |
|
95 |
|
|
96 |
for(int i=n; i>=1; i--) |
|
97 |
{ |
|
98 |
emitRow(x,y,z, 1,0,0, i, null, array, added); |
|
99 |
added += i; |
|
100 |
x += 0.5f; |
|
101 |
y += 0.0f; |
|
102 |
z += SQ3/2; |
|
103 |
} |
|
104 |
|
|
105 |
return added; |
|
106 |
} |
|
107 |
|
|
108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
109 |
|
|
110 |
private int emitUpper(float x, float y, float z, int n, Static3D[] array, int index) |
|
111 |
{ |
|
112 |
if( n>1 ) |
|
113 |
{ |
|
114 |
emitRow(x,y,z, 1,0,0, n-1, null, array, index); |
|
115 |
index += (n-1); |
|
116 |
emitRow(x+0.5f,y,z+SQ3/2, 0.5f,0,SQ3/2, n-1, null, array, index); |
|
117 |
index += (n-1); |
|
118 |
emitRow( x+n-1,y,z, -0.5f, 0, SQ3/2, n-1, null, array, index); |
|
119 |
index += (n-1); |
|
120 |
} |
|
121 |
else |
|
122 |
{ |
|
123 |
mRotArray[index] = null; |
|
124 |
array[index] = new Static3D(x+0.5f,y+SQ2*SQ3/12,z+SQ3/6); |
|
125 |
index++; |
|
126 |
} |
|
127 |
|
|
128 |
return index; |
|
129 |
} |
|
130 |
|
|
131 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
132 |
// size^2 + 3*(size-1) in the lowermost layer, then 6*(size-2) in the next, 6*(size-3) in the next, |
|
133 |
// ... 6 in the forelast, 1 in the last = 4size^2 - 6size +4 (if size>1) |
|
134 |
|
|
76 | 135 |
Static3D[] getCubitPositions(int size) |
77 | 136 |
{ |
78 |
int numCubits = (size*size*size + 6*size*size -4*size)/3;
|
|
137 |
int numCubits = size>1 ? 2*size*size-4*size+4:1;//4*size*size - 6*size +4 : 1;
|
|
79 | 138 |
Static3D[] tmp = new Static3D[numCubits]; |
139 |
mRotArray = new Static4D[numCubits]; |
|
140 |
|
|
141 |
int currentIndex = emitLowermost( -0.5f*size, -(SQ2*SQ3/12)*size, -(SQ3/6)*size, size, tmp); |
|
80 | 142 |
|
81 |
int currentPosition = 0; |
|
82 |
/* |
|
83 |
?? |
|
143 |
for(int i=size-1; i>=1; i--) |
|
84 | 144 |
{ |
85 |
tmp[currentPosition++] = new Static3D(x,y,z);
|
|
145 |
currentIndex = emitUpper( -0.5f*i, ((SQ2*SQ3)/12)*(3*size-4*i), -(SQ3/6)*i, i, tmp, currentIndex);
|
|
86 | 146 |
} |
87 |
*/ |
|
147 |
|
|
88 | 148 |
return tmp; |
89 | 149 |
} |
90 | 150 |
|
... | ... | |
116 | 176 |
int xoffset = face*TEXTURE_HEIGHT; |
117 | 177 |
float STROKE = 0.05f*TEXTURE_HEIGHT; |
118 | 178 |
float OFF = STROKE/2 -1; |
119 |
float OFF2 = 0.577f*TEXTURE_HEIGHT + OFF;
|
|
179 |
float OFF2 = 0.5f*TEXTURE_HEIGHT + OFF; |
|
120 | 180 |
float HEIGHT = TEXTURE_HEIGHT - OFF; |
121 | 181 |
float RADIUS = TEXTURE_HEIGHT/12; |
122 |
float ARC1_H = 0.31f*TEXTURE_HEIGHT;
|
|
182 |
float ARC1_H = 0.2f*TEXTURE_HEIGHT;
|
|
123 | 183 |
float ARC1_W = TEXTURE_HEIGHT*0.5f; |
124 |
float ARC2_W = 0.152f*TEXTURE_HEIGHT;
|
|
125 |
float ARC2_H = 0.91f*TEXTURE_HEIGHT;
|
|
126 |
float ARC3_W = 0.847f*TEXTURE_HEIGHT;
|
|
184 |
float ARC2_W = 0.153f*TEXTURE_HEIGHT;
|
|
185 |
float ARC2_H = 0.905f*TEXTURE_HEIGHT;
|
|
186 |
float ARC3_W = TEXTURE_HEIGHT-ARC2_W;
|
|
127 | 187 |
|
128 | 188 |
paint.setAntiAlias(true); |
129 | 189 |
paint.setStrokeWidth(STROKE); |
Also available in: Unified diff
Progress with Pyraminx.