Revision e6cf7283
Added by Leszek Koltunski over 3 years ago
src/main/java/org/distorted/objects/Cubit.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import android.content.SharedPreferences; |
23 | 23 |
|
24 |
import org.distorted.library.type.Static3D; |
|
25 | 24 |
import org.distorted.library.type.Static4D; |
26 | 25 |
import org.distorted.main.RubikSurfaceView; |
27 | 26 |
|
... | ... | |
29 | 28 |
|
30 | 29 |
class Cubit |
31 | 30 |
{ |
32 |
private final Static3D mOrigPosition;
|
|
33 |
private final Static3D mCurrentPosition;
|
|
31 |
private final float[] mOrigPosition;
|
|
32 |
private final float[] mCurrentPosition;
|
|
34 | 33 |
private TwistyObject mParent; |
35 | 34 |
private final int mNumAxis; |
35 |
private final int mLen; |
|
36 | 36 |
|
37 | 37 |
int mQuatIndex; |
38 | 38 |
int[] mRotationRow; |
39 | 39 |
|
40 | 40 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
41 | 41 |
|
42 |
Cubit(TwistyObject parent, Static3D position)
|
|
42 |
Cubit(TwistyObject parent, float[] position)
|
|
43 | 43 |
{ |
44 |
float x = position.get0();
|
|
45 |
float y = position.get1();
|
|
46 |
float z = position.get2();
|
|
44 |
mQuatIndex= 0;
|
|
45 |
mParent = parent;
|
|
46 |
mLen = position.length;
|
|
47 | 47 |
|
48 |
mParent = parent; |
|
49 |
mOrigPosition = new Static3D(x,y,z); |
|
50 |
mCurrentPosition = new Static3D(x,y,z); |
|
51 |
mQuatIndex = 0; |
|
48 |
mOrigPosition = new float[mLen]; |
|
49 |
mCurrentPosition = new float[mLen]; |
|
50 |
|
|
51 |
for(int i=0; i<mLen; i++) |
|
52 |
{ |
|
53 |
mOrigPosition[i] = position[i]; |
|
54 |
mCurrentPosition[i] = position[i]; |
|
55 |
} |
|
52 | 56 |
|
53 | 57 |
mNumAxis = mParent.ROTATION_AXIS.length; |
54 | 58 |
mRotationRow = new int[mNumAxis]; |
... | ... | |
113 | 117 |
|
114 | 118 |
private void computeRotationRow() |
115 | 119 |
{ |
116 |
float x = mCurrentPosition.get0(); |
|
117 |
float y = mCurrentPosition.get1(); |
|
118 |
float z = mCurrentPosition.get2(); |
|
119 |
|
|
120 | 120 |
for(int i=0; i<mNumAxis; i++) |
121 | 121 |
{ |
122 |
mRotationRow[i] = mParent.computeRow(x,y,z,i);
|
|
122 |
mRotationRow[i] = mParent.computeRow(mCurrentPosition,i);
|
|
123 | 123 |
} |
124 | 124 |
} |
125 | 125 |
|
126 | 126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
127 | 127 |
|
128 |
Static3D getOrigPosition()
|
|
128 |
float[] getOrigPosition()
|
|
129 | 129 |
{ |
130 | 130 |
return mOrigPosition; |
131 | 131 |
} |
... | ... | |
134 | 134 |
|
135 | 135 |
void modifyCurrentPosition(Static4D quat) |
136 | 136 |
{ |
137 |
float cubitCenterX = mCurrentPosition.get0();
|
|
138 |
float cubitCenterY = mCurrentPosition.get1();
|
|
139 |
float cubitCenterZ = mCurrentPosition.get2();
|
|
137 |
Static4D cubitCenter;
|
|
138 |
Static4D rotatedCenter;
|
|
139 |
int len = mLen/3;
|
|
140 | 140 |
|
141 |
Static4D cubitCenter = new Static4D(cubitCenterX, cubitCenterY, cubitCenterZ, 0); |
|
142 |
Static4D rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat); |
|
141 |
for(int i=0; i<len; i++) |
|
142 |
{ |
|
143 |
cubitCenter = new Static4D(mCurrentPosition[3*i], mCurrentPosition[3*i+1], mCurrentPosition[3*i+2], 0); |
|
144 |
rotatedCenter = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat); |
|
143 | 145 |
|
144 |
float rotatedX = rotatedCenter.get0();
|
|
145 |
float rotatedY = rotatedCenter.get1();
|
|
146 |
float rotatedZ = rotatedCenter.get2();
|
|
146 |
mCurrentPosition[3*i ] = rotatedCenter.get0();
|
|
147 |
mCurrentPosition[3*i+1] = rotatedCenter.get1();
|
|
148 |
mCurrentPosition[3*i+2] = rotatedCenter.get2();
|
|
147 | 149 |
|
148 |
mCurrentPosition.set(rotatedX, rotatedY, rotatedZ);
|
|
149 |
mParent.clampPos(mCurrentPosition);
|
|
150 |
mParent.clampPos(mCurrentPosition, 3*i);
|
|
151 |
}
|
|
150 | 152 |
|
151 | 153 |
computeRotationRow(); |
152 | 154 |
} |
... | ... | |
170 | 172 |
|
171 | 173 |
void savePreferences(SharedPreferences.Editor editor) |
172 | 174 |
{ |
173 |
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
|
175 |
String number = mOrigPosition[0]+"_"+mOrigPosition[1]+"_"+mOrigPosition[2];
|
|
174 | 176 |
editor.putInt("q_"+number, mQuatIndex); |
175 | 177 |
} |
176 | 178 |
|
... | ... | |
178 | 180 |
|
179 | 181 |
int restorePreferences(SharedPreferences preferences) |
180 | 182 |
{ |
181 |
String number = mOrigPosition.get0()+"_"+mOrigPosition.get1()+"_"+mOrigPosition.get2();
|
|
183 |
String number = mOrigPosition[0]+"_"+mOrigPosition[1]+"_"+mOrigPosition[2];
|
|
182 | 184 |
mQuatIndex = preferences.getInt("q_"+number, 0); |
183 | 185 |
return mQuatIndex; |
184 | 186 |
} |
... | ... | |
200 | 202 |
void solve() |
201 | 203 |
{ |
202 | 204 |
mQuatIndex = 0; |
203 |
mCurrentPosition.set(mOrigPosition);
|
|
205 |
System.arraycopy(mOrigPosition, 0, mCurrentPosition, 0, mCurrentPosition.length);
|
|
204 | 206 |
computeRotationRow(); |
205 | 207 |
} |
206 | 208 |
|
... | ... | |
212 | 214 |
} |
213 | 215 |
|
214 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
217 |
// this is only needed for MODE_REPLACE objects (i.e. - currently - CUBE_3), so it is enough to only |
|
218 |
// take into consideration the first position. |
|
215 | 219 |
|
216 | 220 |
float getDistSquared(float[] point) |
217 | 221 |
{ |
218 |
float dx = mCurrentPosition.get0() - point[0];
|
|
219 |
float dy = mCurrentPosition.get1() - point[1];
|
|
220 |
float dz = mCurrentPosition.get2() - point[2];
|
|
222 |
float dx = mCurrentPosition[0] - point[0];
|
|
223 |
float dy = mCurrentPosition[1] - point[1];
|
|
224 |
float dz = mCurrentPosition[2] - point[2];
|
|
221 | 225 |
|
222 | 226 |
return dx*dx + dy*dy + dz*dz; |
223 | 227 |
} |
src/main/java/org/distorted/objects/TwistyBandagedAbstract.java | ||
---|---|---|
193 | 193 |
|
194 | 194 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
195 | 195 |
|
196 |
Static3D[] getCubitPositions(int size)
|
|
196 |
float[][] getCubitPositions(int size)
|
|
197 | 197 |
{ |
198 | 198 |
int numCubits = getNumCubits(); |
199 |
Static3D[] tmp = new Static3D[numCubits];
|
|
199 |
float[][] tmp = new float[numCubits][];
|
|
200 | 200 |
|
201 | 201 |
for(int cubit=0; cubit<numCubits; cubit++) |
202 | 202 |
{ |
203 |
float[] pos = getCubitPosition(cubit); |
|
204 |
tmp[cubit] = new Static3D(pos[0],pos[1],pos[2]); |
|
203 |
tmp[cubit] = getCubitPosition(cubit); |
|
205 | 204 |
} |
206 | 205 |
|
207 | 206 |
return tmp; |
src/main/java/org/distorted/objects/TwistyCube.java | ||
---|---|---|
136 | 136 |
|
137 | 137 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
138 | 138 |
|
139 |
Static3D[] getCubitPositions(int size)
|
|
139 |
float[][] getCubitPositions(int size)
|
|
140 | 140 |
{ |
141 | 141 |
int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1; |
142 |
Static3D[] tmp = new Static3D[numCubits];
|
|
142 |
float[][] tmp = new float[numCubits][];
|
|
143 | 143 |
|
144 | 144 |
float diff = 0.5f*(size-1); |
145 | 145 |
int currentPosition = 0; |
... | ... | |
149 | 149 |
for(int z = 0; z<size; z++) |
150 | 150 |
if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 ) |
151 | 151 |
{ |
152 |
tmp[currentPosition++] = new Static3D(x-diff,y-diff,z-diff);
|
|
152 |
tmp[currentPosition++] = new float[] {x-diff,y-diff,z-diff};
|
|
153 | 153 |
} |
154 | 154 |
|
155 | 155 |
return tmp; |
src/main/java/org/distorted/objects/TwistyDiamond.java | ||
---|---|---|
81 | 81 |
private static final float DIST = 0.50f; |
82 | 82 |
|
83 | 83 |
// centers of the 6 octahedrons + 8 tetrahedrons ( i.e. of the all 14 cubits) |
84 |
private static final Static3D[] CENTERS = new Static3D[]
|
|
84 |
private static final float[][] CENTERS = new float[][]
|
|
85 | 85 |
{ |
86 |
new Static3D( DIST, 0, DIST ),
|
|
87 |
new Static3D( DIST, 0,-DIST ),
|
|
88 |
new Static3D(-DIST, 0,-DIST ),
|
|
89 |
new Static3D(-DIST, 0, DIST ),
|
|
90 |
new Static3D( 0, DIST*SQ2 , 0 ),
|
|
91 |
new Static3D( 0,-DIST*SQ2 , 0 ),
|
|
92 |
|
|
93 |
new Static3D( 0, DIST*SQ2/2, DIST ),
|
|
94 |
new Static3D( DIST, DIST*SQ2/2, 0 ),
|
|
95 |
new Static3D( 0, DIST*SQ2/2,-DIST ),
|
|
96 |
new Static3D(-DIST, DIST*SQ2/2, 0 ),
|
|
97 |
new Static3D( 0,-DIST*SQ2/2, DIST ),
|
|
98 |
new Static3D( DIST,-DIST*SQ2/2, 0 ),
|
|
99 |
new Static3D( 0,-DIST*SQ2/2,-DIST ),
|
|
100 |
new Static3D(-DIST,-DIST*SQ2/2, 0 )
|
|
86 |
{ DIST, 0, DIST },
|
|
87 |
{ DIST, 0,-DIST },
|
|
88 |
{-DIST, 0,-DIST },
|
|
89 |
{-DIST, 0, DIST },
|
|
90 |
{ 0, DIST*SQ2 , 0 },
|
|
91 |
{ 0,-DIST*SQ2 , 0 },
|
|
92 |
|
|
93 |
{ 0, DIST*SQ2/2, DIST },
|
|
94 |
{ DIST, DIST*SQ2/2, 0 },
|
|
95 |
{ 0, DIST*SQ2/2,-DIST },
|
|
96 |
{-DIST, DIST*SQ2/2, 0 },
|
|
97 |
{ 0,-DIST*SQ2/2, DIST },
|
|
98 |
{ DIST,-DIST*SQ2/2, 0 },
|
|
99 |
{ 0,-DIST*SQ2/2,-DIST },
|
|
100 |
{-DIST,-DIST*SQ2/2, 0 }
|
|
101 | 101 |
}; |
102 | 102 |
|
103 | 103 |
// Colors of the faces of cubits. Each cubit has 8 faces |
... | ... | |
183 | 183 |
|
184 | 184 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 | 185 |
|
186 |
Static3D[] getCubitPositions(int size)
|
|
186 |
float[][] getCubitPositions(int size)
|
|
187 | 187 |
{ |
188 | 188 |
return CENTERS; |
189 | 189 |
} |
src/main/java/org/distorted/objects/TwistyDino.java | ||
---|---|---|
74 | 74 |
}; |
75 | 75 |
|
76 | 76 |
// centers of the 12 edges. Must be in the same order like QUATs above. |
77 |
private static final Static3D[] CENTERS = new Static3D[]
|
|
77 |
private static final float[][] CENTERS = new float[][]
|
|
78 | 78 |
{ |
79 |
new Static3D( 0.0f, 1.5f, 1.5f ),
|
|
80 |
new Static3D( 1.5f, 0.0f, 1.5f ),
|
|
81 |
new Static3D( 0.0f,-1.5f, 1.5f ),
|
|
82 |
new Static3D(-1.5f, 0.0f, 1.5f ),
|
|
83 |
new Static3D( 1.5f, 1.5f, 0.0f ),
|
|
84 |
new Static3D( 1.5f,-1.5f, 0.0f ),
|
|
85 |
new Static3D(-1.5f,-1.5f, 0.0f ),
|
|
86 |
new Static3D(-1.5f, 1.5f, 0.0f ),
|
|
87 |
new Static3D( 0.0f, 1.5f,-1.5f ),
|
|
88 |
new Static3D( 1.5f, 0.0f,-1.5f ),
|
|
89 |
new Static3D( 0.0f,-1.5f,-1.5f ),
|
|
90 |
new Static3D(-1.5f, 0.0f,-1.5f )
|
|
79 |
{ 0.0f, 1.5f, 1.5f },
|
|
80 |
{ 1.5f, 0.0f, 1.5f },
|
|
81 |
{ 0.0f,-1.5f, 1.5f },
|
|
82 |
{-1.5f, 0.0f, 1.5f },
|
|
83 |
{ 1.5f, 1.5f, 0.0f },
|
|
84 |
{ 1.5f,-1.5f, 0.0f },
|
|
85 |
{-1.5f,-1.5f, 0.0f },
|
|
86 |
{-1.5f, 1.5f, 0.0f },
|
|
87 |
{ 0.0f, 1.5f,-1.5f },
|
|
88 |
{ 1.5f, 0.0f,-1.5f },
|
|
89 |
{ 0.0f,-1.5f,-1.5f },
|
|
90 |
{-1.5f, 0.0f,-1.5f }
|
|
91 | 91 |
}; |
92 | 92 |
|
93 | 93 |
private static MeshBase mMesh; |
... | ... | |
184 | 184 |
|
185 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 | 186 |
|
187 |
Static3D[] getCubitPositions(int size)
|
|
187 |
float[][] getCubitPositions(int size)
|
|
188 | 188 |
{ |
189 | 189 |
return CENTERS; |
190 | 190 |
} |
src/main/java/org/distorted/objects/TwistyHelicopter.java | ||
---|---|---|
97 | 97 |
private static final float XY_CENTER = DIST_CORNER/3; |
98 | 98 |
|
99 | 99 |
// centers of the 8 corners + 6*4 face triangles ( i.e. of the all 32 cubits) |
100 |
private static final Static3D[] CENTERS = new Static3D[]
|
|
100 |
private static final float[][] CENTERS = new float[][]
|
|
101 | 101 |
{ |
102 |
new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER ),
|
|
103 |
new Static3D( DIST_CORNER, DIST_CORNER, -DIST_CORNER ),
|
|
104 |
new Static3D( DIST_CORNER, -DIST_CORNER, DIST_CORNER ),
|
|
105 |
new Static3D( DIST_CORNER, -DIST_CORNER, -DIST_CORNER ),
|
|
106 |
new Static3D( -DIST_CORNER, DIST_CORNER, DIST_CORNER ),
|
|
107 |
new Static3D( -DIST_CORNER, DIST_CORNER, -DIST_CORNER ),
|
|
108 |
new Static3D( -DIST_CORNER, -DIST_CORNER, DIST_CORNER ),
|
|
109 |
new Static3D( -DIST_CORNER, -DIST_CORNER, -DIST_CORNER ),
|
|
110 |
|
|
111 |
new Static3D( DIST_CENTER, XY_CENTER, XY_CENTER ),
|
|
112 |
new Static3D( DIST_CENTER, XY_CENTER, -XY_CENTER ),
|
|
113 |
new Static3D( DIST_CENTER, -XY_CENTER, XY_CENTER ),
|
|
114 |
new Static3D( DIST_CENTER, -XY_CENTER, -XY_CENTER ),
|
|
115 |
|
|
116 |
new Static3D( -DIST_CENTER, XY_CENTER, XY_CENTER ),
|
|
117 |
new Static3D( -DIST_CENTER, XY_CENTER, -XY_CENTER ),
|
|
118 |
new Static3D( -DIST_CENTER, -XY_CENTER, XY_CENTER ),
|
|
119 |
new Static3D( -DIST_CENTER, -XY_CENTER, -XY_CENTER ),
|
|
120 |
|
|
121 |
new Static3D( XY_CENTER , DIST_CENTER, XY_CENTER ),
|
|
122 |
new Static3D( XY_CENTER , DIST_CENTER, -XY_CENTER ),
|
|
123 |
new Static3D( -XY_CENTER , DIST_CENTER, XY_CENTER ),
|
|
124 |
new Static3D( -XY_CENTER , DIST_CENTER, -XY_CENTER ),
|
|
125 |
|
|
126 |
new Static3D( XY_CENTER , -DIST_CENTER, XY_CENTER ),
|
|
127 |
new Static3D( XY_CENTER , -DIST_CENTER, -XY_CENTER ),
|
|
128 |
new Static3D( -XY_CENTER , -DIST_CENTER, XY_CENTER ),
|
|
129 |
new Static3D( -XY_CENTER , -DIST_CENTER, -XY_CENTER ),
|
|
130 |
|
|
131 |
new Static3D( XY_CENTER , XY_CENTER, DIST_CENTER ),
|
|
132 |
new Static3D( XY_CENTER , -XY_CENTER, DIST_CENTER ),
|
|
133 |
new Static3D( -XY_CENTER , XY_CENTER, DIST_CENTER ),
|
|
134 |
new Static3D( -XY_CENTER , -XY_CENTER, DIST_CENTER ),
|
|
135 |
|
|
136 |
new Static3D( XY_CENTER , XY_CENTER, -DIST_CENTER ),
|
|
137 |
new Static3D( XY_CENTER , -XY_CENTER, -DIST_CENTER ),
|
|
138 |
new Static3D( -XY_CENTER , XY_CENTER, -DIST_CENTER ),
|
|
139 |
new Static3D( -XY_CENTER , -XY_CENTER, -DIST_CENTER ),
|
|
102 |
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
|
103 |
{ DIST_CORNER, DIST_CORNER, -DIST_CORNER },
|
|
104 |
{ DIST_CORNER, -DIST_CORNER, DIST_CORNER },
|
|
105 |
{ DIST_CORNER, -DIST_CORNER, -DIST_CORNER },
|
|
106 |
{ -DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
|
107 |
{ -DIST_CORNER, DIST_CORNER, -DIST_CORNER },
|
|
108 |
{ -DIST_CORNER, -DIST_CORNER, DIST_CORNER },
|
|
109 |
{ -DIST_CORNER, -DIST_CORNER, -DIST_CORNER },
|
|
110 |
|
|
111 |
{ DIST_CENTER, XY_CENTER, XY_CENTER },
|
|
112 |
{ DIST_CENTER, XY_CENTER, -XY_CENTER },
|
|
113 |
{ DIST_CENTER, -XY_CENTER, XY_CENTER },
|
|
114 |
{ DIST_CENTER, -XY_CENTER, -XY_CENTER },
|
|
115 |
|
|
116 |
{ -DIST_CENTER, XY_CENTER, XY_CENTER },
|
|
117 |
{ -DIST_CENTER, XY_CENTER, -XY_CENTER },
|
|
118 |
{ -DIST_CENTER, -XY_CENTER, XY_CENTER },
|
|
119 |
{ -DIST_CENTER, -XY_CENTER, -XY_CENTER },
|
|
120 |
|
|
121 |
{ XY_CENTER , DIST_CENTER, XY_CENTER },
|
|
122 |
{ XY_CENTER , DIST_CENTER, -XY_CENTER },
|
|
123 |
{ -XY_CENTER , DIST_CENTER, XY_CENTER },
|
|
124 |
{ -XY_CENTER , DIST_CENTER, -XY_CENTER },
|
|
125 |
|
|
126 |
{ XY_CENTER , -DIST_CENTER, XY_CENTER },
|
|
127 |
{ XY_CENTER , -DIST_CENTER, -XY_CENTER },
|
|
128 |
{ -XY_CENTER , -DIST_CENTER, XY_CENTER },
|
|
129 |
{ -XY_CENTER , -DIST_CENTER, -XY_CENTER },
|
|
130 |
|
|
131 |
{ XY_CENTER , XY_CENTER, DIST_CENTER },
|
|
132 |
{ XY_CENTER , -XY_CENTER, DIST_CENTER },
|
|
133 |
{ -XY_CENTER , XY_CENTER, DIST_CENTER },
|
|
134 |
{ -XY_CENTER , -XY_CENTER, DIST_CENTER },
|
|
135 |
|
|
136 |
{ XY_CENTER , XY_CENTER, -DIST_CENTER },
|
|
137 |
{ XY_CENTER , -XY_CENTER, -DIST_CENTER },
|
|
138 |
{ -XY_CENTER , XY_CENTER, -DIST_CENTER },
|
|
139 |
{ -XY_CENTER , -XY_CENTER, -DIST_CENTER },
|
|
140 | 140 |
}; |
141 | 141 |
|
142 | 142 |
// Colors of the faces of cubits. Each cubit has 6 faces |
... | ... | |
251 | 251 |
|
252 | 252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
253 | 253 |
|
254 |
Static3D[] getCubitPositions(int size)
|
|
254 |
float[][] getCubitPositions(int size)
|
|
255 | 255 |
{ |
256 | 256 |
return CENTERS; |
257 | 257 |
} |
src/main/java/org/distorted/objects/TwistyIvy.java | ||
---|---|---|
156 | 156 |
|
157 | 157 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
158 | 158 |
|
159 |
Static3D[] getCubitPositions(int numLayers)
|
|
159 |
float[][] getCubitPositions(int numLayers)
|
|
160 | 160 |
{ |
161 | 161 |
final float DIST_CORNER = (numLayers-1)*0.50f; |
162 | 162 |
final float DIST_CENTER = (numLayers-1)*0.50f; |
163 | 163 |
|
164 |
final Static3D[] CENTERS = new Static3D[10];
|
|
165 |
|
|
166 |
CENTERS[0] = new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER );
|
|
167 |
CENTERS[1] = new Static3D(-DIST_CORNER, DIST_CORNER,-DIST_CORNER );
|
|
168 |
CENTERS[2] = new Static3D(-DIST_CORNER,-DIST_CORNER, DIST_CORNER );
|
|
169 |
CENTERS[3] = new Static3D( DIST_CORNER,-DIST_CORNER,-DIST_CORNER );
|
|
170 |
CENTERS[4] = new Static3D( DIST_CENTER, 0, 0 );
|
|
171 |
CENTERS[5] = new Static3D(-DIST_CENTER, 0, 0 );
|
|
172 |
CENTERS[6] = new Static3D( 0, DIST_CENTER, 0 );
|
|
173 |
CENTERS[7] = new Static3D( 0,-DIST_CENTER, 0 );
|
|
174 |
CENTERS[8] = new Static3D( 0, 0, DIST_CENTER );
|
|
175 |
CENTERS[9] = new Static3D( 0, 0,-DIST_CENTER );
|
|
164 |
final float[][] CENTERS = new float[10][];
|
|
165 |
|
|
166 |
CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
|
|
167 |
CENTERS[1] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
|
|
168 |
CENTERS[2] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
|
|
169 |
CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
|
|
170 |
CENTERS[4] = new float[] { DIST_CENTER, 0, 0 };
|
|
171 |
CENTERS[5] = new float[] {-DIST_CENTER, 0, 0 };
|
|
172 |
CENTERS[6] = new float[] { 0, DIST_CENTER, 0 };
|
|
173 |
CENTERS[7] = new float[] { 0,-DIST_CENTER, 0 };
|
|
174 |
CENTERS[8] = new float[] { 0, 0, DIST_CENTER };
|
|
175 |
CENTERS[9] = new float[] { 0, 0,-DIST_CENTER };
|
|
176 | 176 |
|
177 | 177 |
return CENTERS; |
178 | 178 |
} |
src/main/java/org/distorted/objects/TwistyKilominx.java | ||
---|---|---|
62 | 62 |
|
63 | 63 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
64 | 64 |
|
65 |
Static3D[] getCubitPositions(int numLayers)
|
|
65 |
float[][] getCubitPositions(int numLayers)
|
|
66 | 66 |
{ |
67 | 67 |
return CORNERS; |
68 | 68 |
} |
src/main/java/org/distorted/objects/TwistyMegaminx.java | ||
---|---|---|
125 | 125 |
{ |
126 | 126 |
int[] map = mCenterMap[center]; |
127 | 127 |
|
128 |
float x = CORNERS[map[0]].get0() +
|
|
129 |
CORNERS[map[1]].get0() +
|
|
130 |
CORNERS[map[2]].get0() +
|
|
131 |
CORNERS[map[3]].get0() +
|
|
132 |
CORNERS[map[4]].get0() ;
|
|
133 |
|
|
134 |
float y = CORNERS[map[0]].get1() +
|
|
135 |
CORNERS[map[1]].get1() +
|
|
136 |
CORNERS[map[2]].get1() +
|
|
137 |
CORNERS[map[3]].get1() +
|
|
138 |
CORNERS[map[4]].get1() ;
|
|
139 |
|
|
140 |
float z = CORNERS[map[0]].get2() +
|
|
141 |
CORNERS[map[1]].get2() +
|
|
142 |
CORNERS[map[2]].get2() +
|
|
143 |
CORNERS[map[3]].get2() +
|
|
144 |
CORNERS[map[4]].get2() ;
|
|
128 |
float x = CORNERS[map[0]][0] +
|
|
129 |
CORNERS[map[1]][0] +
|
|
130 |
CORNERS[map[2]][0] +
|
|
131 |
CORNERS[map[3]][0] +
|
|
132 |
CORNERS[map[4]][0] ;
|
|
133 |
|
|
134 |
float y = CORNERS[map[0]][1] +
|
|
135 |
CORNERS[map[1]][1] +
|
|
136 |
CORNERS[map[2]][1] +
|
|
137 |
CORNERS[map[3]][1] +
|
|
138 |
CORNERS[map[4]][1] ;
|
|
139 |
|
|
140 |
float z = CORNERS[map[0]][2] +
|
|
141 |
CORNERS[map[1]][2] +
|
|
142 |
CORNERS[map[2]][2] +
|
|
143 |
CORNERS[map[3]][2] +
|
|
144 |
CORNERS[map[4]][2] ;
|
|
145 | 145 |
|
146 | 146 |
mCenterCoords[center][0] = x/5; |
147 | 147 |
mCenterCoords[center][1] = y/5; |
... | ... | |
225 | 225 |
|
226 | 226 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
227 | 227 |
|
228 |
private void computeCenter(Static3D pos, int center, int numLayers)
|
|
228 |
private float[] computeCenter(int center, int numLayers)
|
|
229 | 229 |
{ |
230 | 230 |
float[] coords = mCenterCoords[center]; |
231 | 231 |
float A = numLayers/3.0f; |
232 | 232 |
|
233 |
pos.set( A*coords[0], A*coords[1], A*coords[2] );
|
|
233 |
return new float[] { A*coords[0], A*coords[1], A*coords[2] };
|
|
234 | 234 |
} |
235 | 235 |
|
236 | 236 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
248 | 248 |
|
249 | 249 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
250 | 250 |
|
251 |
private void computeCorner(Static3D pos, int numCubitsPerCorner, int numLayers, int corner, int part)
|
|
251 |
private float[] computeCorner(int numCubitsPerCorner, int numLayers, int corner, int part)
|
|
252 | 252 |
{ |
253 | 253 |
float D = numLayers/3.0f; |
254 |
Static3D corn = CORNERS[corner];
|
|
254 |
float[] corn = CORNERS[corner];
|
|
255 | 255 |
|
256 | 256 |
if( part==0 ) |
257 | 257 |
{ |
258 |
pos.set( corn.get0()*D, corn.get1()*D, corn.get2()*D );
|
|
258 |
return new float[] { corn[0]*D, corn[1]*D, corn[2]*D };
|
|
259 | 259 |
} |
260 | 260 |
else |
261 | 261 |
{ |
... | ... | |
269 | 269 |
int multP = (block % ((numLayers-3)/2)) + 1; |
270 | 270 |
int multS = (block / ((numLayers-3)/2)); |
271 | 271 |
|
272 |
pos.set( corn.get0()*D + (pri.get0()*multP + sec.get0()*multS)*E, |
|
273 |
corn.get1()*D + (pri.get1()*multP + sec.get1()*multS)*E, |
|
274 |
corn.get2()*D + (pri.get2()*multP + sec.get2()*multS)*E ); |
|
272 |
return new float[] { |
|
273 |
corn[0]*D + (pri.get0()*multP + sec.get0()*multS)*E, |
|
274 |
corn[1]*D + (pri.get1()*multP + sec.get1()*multS)*E, |
|
275 |
corn[2]*D + (pri.get2()*multP + sec.get2()*multS)*E |
|
276 |
}; |
|
275 | 277 |
} |
276 | 278 |
} |
277 | 279 |
|
... | ... | |
285 | 287 |
|
286 | 288 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
287 | 289 |
|
288 |
private void computeEdge(Static3D pos, int numLayers, int edge, int part)
|
|
290 |
private float[] computeEdge(int numLayers, int edge, int part)
|
|
289 | 291 |
{ |
290 | 292 |
float corr = numLayers/3.0f; |
291 | 293 |
|
292 |
Static3D c1 = CORNERS[ mEdgeMap[edge][0] ];
|
|
293 |
Static3D c2 = CORNERS[ mEdgeMap[edge][1] ];
|
|
294 |
float x = corr*(c1.get0() + c2.get0())/2;
|
|
295 |
float y = corr*(c1.get1() + c2.get1())/2;
|
|
296 |
float z = corr*(c1.get2() + c2.get2())/2;
|
|
294 |
float[] c1 = CORNERS[ mEdgeMap[edge][0] ];
|
|
295 |
float[] c2 = CORNERS[ mEdgeMap[edge][1] ];
|
|
296 |
float x = corr * (c1[0]+c2[0]) / 2;
|
|
297 |
float y = corr * (c1[1]+c2[1]) / 2;
|
|
298 |
float z = corr * (c1[2]+c2[2]) / 2;
|
|
297 | 299 |
|
298 | 300 |
if( part==0 ) |
299 | 301 |
{ |
300 |
pos.set(x,y,z);
|
|
302 |
return new float[] { x, y, z };
|
|
301 | 303 |
} |
302 | 304 |
else |
303 | 305 |
{ |
... | ... | |
312 | 314 |
float len = (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ); |
313 | 315 |
float A = mult*corr*(0.5f-MEGA_D)*COS18/((numLayers-1)*0.5f)/len; |
314 | 316 |
|
315 |
pos.set( x+A*vX, y+A*vY, z+A*vZ );
|
|
317 |
return new float[] { x+A*vX, y+A*vY, z+A*vZ };
|
|
316 | 318 |
} |
317 | 319 |
} |
318 | 320 |
|
319 | 321 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
320 | 322 |
|
321 |
Static3D[] getCubitPositions(int numLayers)
|
|
323 |
float[][] getCubitPositions(int numLayers)
|
|
322 | 324 |
{ |
323 | 325 |
int numCubitsPerCorner = numCubitsPerCorner(numLayers); |
324 | 326 |
int numCubitsPerEdge = numCubitsPerEdge(numLayers); |
325 | 327 |
int numCubits = NUM_CORNERS*numCubitsPerCorner + NUM_EDGES*numCubitsPerEdge + NUM_CENTERS; |
326 | 328 |
int index=0; |
327 | 329 |
|
328 |
final Static3D[] CENTERS = new Static3D[numCubits];
|
|
330 |
final float[][] CENTERS = new float[numCubits][];
|
|
329 | 331 |
|
330 | 332 |
for(int corner=0; corner<NUM_CORNERS; corner++) |
331 | 333 |
{ |
... | ... | |
333 | 335 |
|
334 | 336 |
for(int part=0; part<numCubitsPerCorner; part++, index++) |
335 | 337 |
{ |
336 |
CENTERS[index] = new Static3D(0,0,0); |
|
337 |
computeCorner(CENTERS[index],numCubitsPerCorner,numLayers,corner,part); |
|
338 |
CENTERS[index] = computeCorner(numCubitsPerCorner,numLayers,corner,part); |
|
338 | 339 |
} |
339 | 340 |
} |
340 | 341 |
|
... | ... | |
342 | 343 |
{ |
343 | 344 |
for(int part=0; part<numCubitsPerEdge; part++, index++) |
344 | 345 |
{ |
345 |
CENTERS[index] = new Static3D(0,0,0); |
|
346 |
computeEdge(CENTERS[index], numLayers, edge, part ); |
|
346 |
CENTERS[index] = computeEdge(numLayers, edge, part ); |
|
347 | 347 |
} |
348 | 348 |
} |
349 | 349 |
|
350 | 350 |
for(int center=0; center<NUM_CENTERS; center++, index++) |
351 | 351 |
{ |
352 |
CENTERS[index] = new Static3D(0,0,0); |
|
353 |
computeCenter(CENTERS[index], center, numLayers); |
|
352 |
CENTERS[index] = computeCenter(center, numLayers); |
|
354 | 353 |
} |
355 | 354 |
|
356 | 355 |
return CENTERS; |
src/main/java/org/distorted/objects/TwistyMinx.java | ||
---|---|---|
144 | 144 |
}; |
145 | 145 |
|
146 | 146 |
// Coordinates of all 20 corners of a Minx |
147 |
static final Static3D[] CORNERS = new Static3D[]
|
|
147 |
static final float[][] CORNERS = new float[][]
|
|
148 | 148 |
{ |
149 |
new Static3D( 0.0f, 0.5f, C2),
|
|
150 |
new Static3D( 0.0f, 0.5f, -C2),
|
|
151 |
new Static3D( 0.0f,-0.5f, C2),
|
|
152 |
new Static3D( 0.0f,-0.5f, -C2),
|
|
153 |
new Static3D( C2, 0.0f, 0.5f),
|
|
154 |
new Static3D( C2, 0.0f,-0.5f),
|
|
155 |
new Static3D( -C2, 0.0f, 0.5f),
|
|
156 |
new Static3D( -C2, 0.0f,-0.5f),
|
|
157 |
new Static3D( 0.5f, C2, 0.0f),
|
|
158 |
new Static3D( 0.5f, -C2, 0.0f),
|
|
159 |
new Static3D(-0.5f, C2, 0.0f),
|
|
160 |
new Static3D(-0.5f, -C2, 0.0f),
|
|
161 |
new Static3D( C1, C1, C1),
|
|
162 |
new Static3D( C1, C1, -C1),
|
|
163 |
new Static3D( C1, -C1, C1),
|
|
164 |
new Static3D( C1, -C1, -C1),
|
|
165 |
new Static3D( -C1, C1, C1),
|
|
166 |
new Static3D( -C1, C1, -C1),
|
|
167 |
new Static3D( -C1, -C1, C1),
|
|
168 |
new Static3D( -C1, -C1, -C1),
|
|
149 |
{ 0.0f, 0.5f, C2},
|
|
150 |
{ 0.0f, 0.5f, -C2},
|
|
151 |
{ 0.0f,-0.5f, C2},
|
|
152 |
{ 0.0f,-0.5f, -C2},
|
|
153 |
{ C2, 0.0f, 0.5f},
|
|
154 |
{ C2, 0.0f,-0.5f},
|
|
155 |
{ -C2, 0.0f, 0.5f},
|
|
156 |
{ -C2, 0.0f,-0.5f},
|
|
157 |
{ 0.5f, C2, 0.0f},
|
|
158 |
{ 0.5f, -C2, 0.0f},
|
|
159 |
{-0.5f, C2, 0.0f},
|
|
160 |
{-0.5f, -C2, 0.0f},
|
|
161 |
{ C1, C1, C1},
|
|
162 |
{ C1, C1, -C1},
|
|
163 |
{ C1, -C1, C1},
|
|
164 |
{ C1, -C1, -C1},
|
|
165 |
{ -C1, C1, C1},
|
|
166 |
{ -C1, C1, -C1},
|
|
167 |
{ -C1, -C1, C1},
|
|
168 |
{ -C1, -C1, -C1},
|
|
169 | 169 |
}; |
170 | 170 |
|
171 | 171 |
static final int[][] mCornerFaceMap = |
src/main/java/org/distorted/objects/TwistyObject.java | ||
---|---|---|
98 | 98 |
|
99 | 99 |
private static float mInitScreenRatio; |
100 | 100 |
private static float mObjectScreenRatio = 1.0f; |
101 |
private static final float[] mTmp1 = new float[4]; |
|
102 |
private static final float[] mTmp2 = new float[4]; |
|
101 | 103 |
|
102 | 104 |
private final int mNodeSize; |
103 |
private final Static3D[] mOrigPos;
|
|
105 |
private final float[][] mOrigPos;
|
|
104 | 106 |
private final Static3D mNodeScale; |
105 | 107 |
private final Static4D mQuat; |
106 | 108 |
private final int mNumLayers, mRealSize; |
... | ... | |
214 | 216 |
setProjection( fov, 0.1f); |
215 | 217 |
} |
216 | 218 |
|
219 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
220 |
|
|
221 |
private Static3D getPos(float[] origPos) |
|
222 |
{ |
|
223 |
int len = origPos.length/3; |
|
224 |
float sumX = 0.0f; |
|
225 |
float sumY = 0.0f; |
|
226 |
float sumZ = 0.0f; |
|
227 |
|
|
228 |
for(int i=0; i<len; i++) |
|
229 |
{ |
|
230 |
sumX += origPos[3*i ]; |
|
231 |
sumY += origPos[3*i+1]; |
|
232 |
sumZ += origPos[3*i+2]; |
|
233 |
} |
|
234 |
|
|
235 |
sumX /= len; |
|
236 |
sumY /= len; |
|
237 |
sumZ /= len; |
|
238 |
|
|
239 |
return new Static3D(sumX,sumY,sumZ); |
|
240 |
} |
|
241 |
|
|
217 | 242 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
218 | 243 |
|
219 | 244 |
private void createMeshAndCubits(ObjectList list, Resources res) |
... | ... | |
252 | 277 |
{ |
253 | 278 |
CUBITS[i] = new Cubit(this,mOrigPos[i]); |
254 | 279 |
cubitMesh[i] = createCubitMesh(i,mNumLayers); |
255 |
cubitMesh[i].apply(new MatrixEffectMove(mOrigPos[i]),1,0); |
|
280 |
Static3D pos = getPos(mOrigPos[i]); |
|
281 |
cubitMesh[i].apply(new MatrixEffectMove(pos),1,0); |
|
256 | 282 |
cubitMesh[i].setEffectAssociation(0, CUBITS[i].computeAssociation(), 0); |
257 | 283 |
} |
258 | 284 |
|
... | ... | |
283 | 309 |
|
284 | 310 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
285 | 311 |
|
286 |
int computeRow(float x, float y, float z, int rotIndex)
|
|
312 |
int computeRow(float[] pos, int rotIndex)
|
|
287 | 313 |
{ |
314 |
int ret=0; |
|
315 |
int len = pos.length / 3; |
|
288 | 316 |
Static3D axis = ROTATION_AXIS[rotIndex]; |
289 |
float tmp = x*axis.get0() + y*axis.get1() + z*axis.get2(); |
|
317 |
float axisX = axis.get0(); |
|
318 |
float axisY = axis.get1(); |
|
319 |
float axisZ = axis.get2(); |
|
320 |
|
|
321 |
for(int i=0; i<len; i++) |
|
322 |
{ |
|
323 |
ret |= computeRow(pos[3*i]*axisX + pos[3*i+1]*axisY + pos[3*i+2]*axisZ); |
|
324 |
} |
|
325 |
|
|
326 |
return ret; |
|
327 |
} |
|
328 |
|
|
329 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
290 | 330 |
|
331 |
private int computeRow(float casted) |
|
332 |
{ |
|
291 | 333 |
for(int i=0; i<NUM_CUTS; i++) |
292 | 334 |
{ |
293 |
if( tmp<CUTS[i] ) return (1<<i);
|
|
335 |
if( casted<CUTS[i] ) return (1<<i);
|
|
294 | 336 |
} |
295 | 337 |
|
296 | 338 |
return (1<<NUM_CUTS); |
... | ... | |
369 | 411 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
370 | 412 |
// Clamp all rotated positions to one of those original ones to avoid accumulating errors. |
371 | 413 |
|
372 |
void clampPos(Static3D pos)
|
|
414 |
void clampPos(float[] pos, int offset)
|
|
373 | 415 |
{ |
374 | 416 |
float currError, minError = Float.MAX_VALUE; |
375 |
int minErrorIndex= -1; |
|
376 |
float x = pos.get0(); |
|
377 |
float y = pos.get1(); |
|
378 |
float z = pos.get2(); |
|
417 |
int minErrorIndex1 = -1; |
|
418 |
int minErrorIndex2 = -1; |
|
419 |
|
|
420 |
float x = pos[offset ]; |
|
421 |
float y = pos[offset+1]; |
|
422 |
float z = pos[offset+2]; |
|
423 |
|
|
379 | 424 |
float xo,yo,zo; |
380 | 425 |
|
381 | 426 |
for(int i=0; i<NUM_CUBITS; i++) |
382 | 427 |
{ |
383 |
xo = mOrigPos[i].get0(); |
|
384 |
yo = mOrigPos[i].get1(); |
|
385 |
zo = mOrigPos[i].get2(); |
|
428 |
int len = mOrigPos[i].length / 3; |
|
386 | 429 |
|
387 |
currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z); |
|
388 |
|
|
389 |
if( currError<minError ) |
|
430 |
for(int j=0; j<len; j++) |
|
390 | 431 |
{ |
391 |
minError = currError; |
|
392 |
minErrorIndex = i; |
|
432 |
xo = mOrigPos[i][3*j ]; |
|
433 |
yo = mOrigPos[i][3*j+1]; |
|
434 |
zo = mOrigPos[i][3*j+2]; |
|
435 |
|
|
436 |
currError = (xo-x)*(xo-x) + (yo-y)*(yo-y) + (zo-z)*(zo-z); |
|
437 |
|
|
438 |
if( currError<minError ) |
|
439 |
{ |
|
440 |
minError = currError; |
|
441 |
minErrorIndex1 = i; |
|
442 |
minErrorIndex2 = j; |
|
443 |
} |
|
393 | 444 |
} |
394 | 445 |
} |
395 | 446 |
|
396 |
pos.set( mOrigPos[minErrorIndex] ); |
|
447 |
pos[offset ] = mOrigPos[minErrorIndex1][3*minErrorIndex2 ]; |
|
448 |
pos[offset+1] = mOrigPos[minErrorIndex1][3*minErrorIndex2+1]; |
|
449 |
pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2]; |
|
397 | 450 |
} |
398 | 451 |
|
399 | 452 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
422 | 475 |
{ |
423 | 476 |
case 0 : return false; // 'inside' cubit that does not lie on any face |
424 | 477 |
case 1 : // cubit that lies inside one of the faces |
425 |
Static3D orig = cubit.getOrigPosition();
|
|
478 |
float[] orig = cubit.getOrigPosition();
|
|
426 | 479 |
Static4D quat1 = QUATS[quatIndex]; |
427 | 480 |
Static4D quat2 = QUATS[cubit.mQuatIndex]; |
428 | 481 |
|
429 |
Static4D cubitCenter = new Static4D( orig.get0(), orig.get1(), orig.get2(), 0);
|
|
430 |
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 ); |
|
482 |
Static4D cubitCenter = new Static4D( orig[0], orig[1], orig[2], 0); // not used for bandaged objects,
|
|
483 |
Static4D rotated1 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat1 ); // only check the first position
|
|
431 | 484 |
Static4D rotated2 = RubikSurfaceView.rotateVectorByQuat( cubitCenter, quat2 ); |
432 | 485 |
|
433 |
int row1, row2; |
|
434 |
float x1 = rotated1.get0(); |
|
435 |
float y1 = rotated1.get1(); |
|
436 |
float z1 = rotated1.get2(); |
|
437 |
float x2 = rotated2.get0(); |
|
438 |
float y2 = rotated2.get1(); |
|
439 |
float z2 = rotated2.get2(); |
|
486 |
rotated1.get(mTmp1, 0, 0, 0); |
|
487 |
rotated2.get(mTmp2, 0, 0, 0); |
|
440 | 488 |
|
441 | 489 |
for(int i=0; i<NUM_AXIS; i++) |
442 | 490 |
{ |
443 |
row1 = computeRow(x1,y1,z1,i); |
|
444 |
row2 = computeRow(x2,y2,z2,i); |
|
445 |
|
|
446 |
if( ((row1 & row2) & bitmap) != 0 ) return false; |
|
491 |
if( (computeRow(mTmp1,i) & computeRow(mTmp2,i) & bitmap) != 0 ) return false; |
|
447 | 492 |
} |
448 | 493 |
return true; |
449 | 494 |
|
... | ... | |
843 | 888 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
844 | 889 |
|
845 | 890 |
abstract float getScreenRatio(); |
846 |
abstract Static3D[] getCubitPositions(int numLayers);
|
|
891 |
abstract float[][] getCubitPositions(int numLayers);
|
|
847 | 892 |
abstract Static4D[] getQuats(); |
848 | 893 |
abstract int getNumFaces(); |
849 | 894 |
abstract int getNumStickerTypes(int numLayers); |
src/main/java/org/distorted/objects/TwistyPyraminx.java | ||
---|---|---|
82 | 82 |
|
83 | 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
84 | 84 |
|
85 |
private void addTetrahedralLattice(int size, int index, Static3D[] pos)
|
|
85 |
private void addTetrahedralLattice(int size, int index, float[][] pos)
|
|
86 | 86 |
{ |
87 | 87 |
final float DX = 1.0f; |
88 | 88 |
final float DY = SQ2/2; |
... | ... | |
103 | 103 |
|
104 | 104 |
for(int z=0; z<size-layer; z++) |
105 | 105 |
{ |
106 |
pos[index] = new Static3D(currX,currY,currZ);
|
|
106 |
pos[index] = new float[] {currX,currY,currZ};
|
|
107 | 107 |
index++; |
108 | 108 |
currZ -= DZ; |
109 | 109 |
} |
... | ... | |
120 | 120 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
121 | 121 |
// there are (n^3-n)/6 octahedrons and ((n+1)^3 - (n+1))/6 tetrahedrons |
122 | 122 |
|
123 |
Static3D[] getCubitPositions(int size)
|
|
123 |
float[][] getCubitPositions(int size)
|
|
124 | 124 |
{ |
125 | 125 |
int numOcta = (size-1)*size*(size+1)/6; |
126 | 126 |
int numTetra= size*(size+1)*(size+2)/6; |
127 |
Static3D[] ret = new Static3D[numOcta+numTetra];
|
|
127 |
float[][] ret = new float[numOcta+numTetra][];
|
|
128 | 128 |
|
129 | 129 |
addTetrahedralLattice(size-1, 0,ret); |
130 | 130 |
addTetrahedralLattice(size ,numOcta,ret); |
src/main/java/org/distorted/objects/TwistyRedi.java | ||
---|---|---|
80 | 80 |
private static final float DIST_EDGE = 1.5f; |
81 | 81 |
|
82 | 82 |
// centers of the 8 corners + 12 edges ( i.e. of the all 20 cubits) |
83 |
private static final Static3D[] CENTERS = new Static3D[]
|
|
83 |
private static final float[][] CENTERS = new float[][]
|
|
84 | 84 |
{ |
85 |
new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER ),
|
|
86 |
new Static3D( DIST_CORNER, DIST_CORNER,-DIST_CORNER ),
|
|
87 |
new Static3D( DIST_CORNER,-DIST_CORNER, DIST_CORNER ),
|
|
88 |
new Static3D( DIST_CORNER,-DIST_CORNER,-DIST_CORNER ),
|
|
89 |
new Static3D(-DIST_CORNER, DIST_CORNER, DIST_CORNER ),
|
|
90 |
new Static3D(-DIST_CORNER, DIST_CORNER,-DIST_CORNER ),
|
|
91 |
new Static3D(-DIST_CORNER,-DIST_CORNER, DIST_CORNER ),
|
|
92 |
new Static3D(-DIST_CORNER,-DIST_CORNER,-DIST_CORNER ),
|
|
93 |
|
|
94 |
new Static3D( 0.0f, DIST_EDGE, DIST_EDGE ),
|
|
95 |
new Static3D( DIST_EDGE, 0.0f, DIST_EDGE ),
|
|
96 |
new Static3D( 0.0f,-DIST_EDGE, DIST_EDGE ),
|
|
97 |
new Static3D(-DIST_EDGE, 0.0f, DIST_EDGE ),
|
|
98 |
new Static3D( DIST_EDGE, DIST_EDGE, 0.0f ),
|
|
99 |
new Static3D( DIST_EDGE,-DIST_EDGE, 0.0f ),
|
|
100 |
new Static3D(-DIST_EDGE,-DIST_EDGE, 0.0f ),
|
|
101 |
new Static3D(-DIST_EDGE, DIST_EDGE, 0.0f ),
|
|
102 |
new Static3D( 0.0f, DIST_EDGE,-DIST_EDGE ),
|
|
103 |
new Static3D( DIST_EDGE, 0.0f,-DIST_EDGE ),
|
|
104 |
new Static3D( 0.0f,-DIST_EDGE,-DIST_EDGE ),
|
|
105 |
new Static3D(-DIST_EDGE, 0.0f,-DIST_EDGE )
|
|
85 |
{ DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
|
86 |
{ DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
|
87 |
{ DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
|
88 |
{ DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
|
89 |
{-DIST_CORNER, DIST_CORNER, DIST_CORNER },
|
|
90 |
{-DIST_CORNER, DIST_CORNER,-DIST_CORNER },
|
|
91 |
{-DIST_CORNER,-DIST_CORNER, DIST_CORNER },
|
|
92 |
{-DIST_CORNER,-DIST_CORNER,-DIST_CORNER },
|
|
93 |
|
|
94 |
{ 0.0f, DIST_EDGE, DIST_EDGE },
|
|
95 |
{ DIST_EDGE, 0.0f, DIST_EDGE },
|
|
96 |
{ 0.0f,-DIST_EDGE, DIST_EDGE },
|
|
97 |
{-DIST_EDGE, 0.0f, DIST_EDGE },
|
|
98 |
{ DIST_EDGE, DIST_EDGE, 0.0f },
|
|
99 |
{ DIST_EDGE,-DIST_EDGE, 0.0f },
|
|
100 |
{-DIST_EDGE,-DIST_EDGE, 0.0f },
|
|
101 |
{-DIST_EDGE, DIST_EDGE, 0.0f },
|
|
102 |
{ 0.0f, DIST_EDGE,-DIST_EDGE },
|
|
103 |
{ DIST_EDGE, 0.0f,-DIST_EDGE },
|
|
104 |
{ 0.0f,-DIST_EDGE,-DIST_EDGE },
|
|
105 |
{-DIST_EDGE, 0.0f,-DIST_EDGE }
|
|
106 | 106 |
}; |
107 | 107 |
|
108 | 108 |
// Colors of the faces of cubits. |
... | ... | |
199 | 199 |
|
200 | 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
201 | 201 |
|
202 |
Static3D[] getCubitPositions(int size)
|
|
202 |
float[][] getCubitPositions(int size)
|
|
203 | 203 |
{ |
204 | 204 |
return CENTERS; |
205 | 205 |
} |
src/main/java/org/distorted/objects/TwistyRex.java | ||
---|---|---|
189 | 189 |
|
190 | 190 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
191 | 191 |
|
192 |
Static3D[] getCubitPositions(int numLayers)
|
|
192 |
float[][] getCubitPositions(int numLayers)
|
|
193 | 193 |
{ |
194 | 194 |
final float DIST = 0.50f; |
195 | 195 |
final float DIST2= (1+2*REX_D)/6; |
196 | 196 |
|
197 |
final Static3D[] CENTERS = new Static3D[42];
|
|
198 |
|
|
199 |
CENTERS[ 0] = new Static3D( +DIST , +DIST2, +DIST2);
|
|
200 |
CENTERS[ 1] = new Static3D( +DIST , +DIST2, -DIST2);
|
|
201 |
CENTERS[ 2] = new Static3D( +DIST , -DIST2, -DIST2);
|
|
202 |
CENTERS[ 3] = new Static3D( +DIST , -DIST2, +DIST2);
|
|
203 |
CENTERS[ 4] = new Static3D( -DIST , +DIST2, +DIST2);
|
|
204 |
CENTERS[ 5] = new Static3D( -DIST , +DIST2, -DIST2);
|
|
205 |
CENTERS[ 6] = new Static3D( -DIST , -DIST2, -DIST2);
|
|
206 |
CENTERS[ 7] = new Static3D( -DIST , -DIST2, +DIST2);
|
|
207 |
CENTERS[ 8] = new Static3D( +DIST2, +DIST , +DIST2);
|
|
208 |
CENTERS[ 9] = new Static3D( +DIST2, +DIST , -DIST2);
|
|
209 |
CENTERS[10] = new Static3D( -DIST2, +DIST , -DIST2);
|
|
210 |
CENTERS[11] = new Static3D( -DIST2, +DIST , +DIST2);
|
|
211 |
CENTERS[12] = new Static3D( +DIST2, -DIST , +DIST2);
|
|
212 |
CENTERS[13] = new Static3D( +DIST2, -DIST , -DIST2);
|
|
213 |
CENTERS[14] = new Static3D( -DIST2, -DIST , -DIST2);
|
|
214 |
CENTERS[15] = new Static3D( -DIST2, -DIST , +DIST2);
|
|
215 |
CENTERS[16] = new Static3D( +DIST2, +DIST2, +DIST );
|
|
216 |
CENTERS[17] = new Static3D( +DIST2, -DIST2, +DIST );
|
|
217 |
CENTERS[18] = new Static3D( -DIST2, -DIST2, +DIST );
|
|
218 |
CENTERS[19] = new Static3D( -DIST2, +DIST2, +DIST );
|
|
219 |
CENTERS[20] = new Static3D( +DIST2, +DIST2, -DIST );
|
|
220 |
CENTERS[21] = new Static3D( +DIST2, -DIST2, -DIST );
|
|
221 |
CENTERS[22] = new Static3D( -DIST2, -DIST2, -DIST );
|
|
222 |
CENTERS[23] = new Static3D( -DIST2, +DIST2, -DIST );
|
|
223 |
|
|
224 |
CENTERS[24] = new Static3D( +DIST , +0.00f, +0.00f);
|
|
225 |
CENTERS[25] = new Static3D( -DIST , +0.00f, +0.00f);
|
|
226 |
CENTERS[26] = new Static3D( +0.00f, +DIST , +0.00f);
|
|
227 |
CENTERS[27] = new Static3D( +0.00f, -DIST , +0.00f);
|
|
228 |
CENTERS[28] = new Static3D( +0.00f, +0.00f, +DIST );
|
|
229 |
CENTERS[29] = new Static3D( +0.00f, +0.00f, -DIST );
|
|
230 |
|
|
231 |
CENTERS[30] = new Static3D( +0.00f, +DIST , +DIST );
|
|
232 |
CENTERS[31] = new Static3D( +DIST , +0.00f, +DIST );
|
|
233 |
CENTERS[32] = new Static3D( +0.00f, -DIST , +DIST );
|
|
234 |
CENTERS[33] = new Static3D( -DIST , +0.00f, +DIST );
|
|
235 |
CENTERS[34] = new Static3D( +DIST , +DIST , +0.00f);
|
|
236 |
CENTERS[35] = new Static3D( +DIST , -DIST , +0.00f);
|
|
237 |
CENTERS[36] = new Static3D( -DIST , -DIST , +0.00f);
|
|
238 |
CENTERS[37] = new Static3D( -DIST , +DIST , +0.00f);
|
|
239 |
CENTERS[38] = new Static3D( +0.00f, +DIST , -DIST );
|
|
240 |
CENTERS[39] = new Static3D( +DIST , +0.00f, -DIST );
|
|
241 |
CENTERS[40] = new Static3D( +0.00f, -DIST , -DIST );
|
|
242 |
CENTERS[41] = new Static3D( -DIST , +0.00f, -DIST );
|
|
197 |
final float[][] CENTERS = new float[42][];
|
|
198 |
|
|
199 |
CENTERS[ 0] = new float[] { +DIST , +DIST2, +DIST2};
|
|
200 |
CENTERS[ 1] = new float[] { +DIST , +DIST2, -DIST2};
|
|
201 |
CENTERS[ 2] = new float[] { +DIST , -DIST2, -DIST2};
|
|
202 |
CENTERS[ 3] = new float[] { +DIST , -DIST2, +DIST2};
|
|
203 |
CENTERS[ 4] = new float[] { -DIST , +DIST2, +DIST2};
|
|
204 |
CENTERS[ 5] = new float[] { -DIST , +DIST2, -DIST2};
|
|
205 |
CENTERS[ 6] = new float[] { -DIST , -DIST2, -DIST2};
|
|
206 |
CENTERS[ 7] = new float[] { -DIST , -DIST2, +DIST2};
|
|
207 |
CENTERS[ 8] = new float[] { +DIST2, +DIST , +DIST2};
|
|
208 |
CENTERS[ 9] = new float[] { +DIST2, +DIST , -DIST2};
|
|
209 |
CENTERS[10] = new float[] { -DIST2, +DIST , -DIST2};
|
|
210 |
CENTERS[11] = new float[] { -DIST2, +DIST , +DIST2};
|
|
211 |
CENTERS[12] = new float[] { +DIST2, -DIST , +DIST2};
|
|
212 |
CENTERS[13] = new float[] { +DIST2, -DIST , -DIST2};
|
|
213 |
CENTERS[14] = new float[] { -DIST2, -DIST , -DIST2};
|
|
214 |
CENTERS[15] = new float[] { -DIST2, -DIST , +DIST2};
|
|
215 |
CENTERS[16] = new float[] { +DIST2, +DIST2, +DIST };
|
|
216 |
CENTERS[17] = new float[] { +DIST2, -DIST2, +DIST };
|
|
217 |
CENTERS[18] = new float[] { -DIST2, -DIST2, +DIST };
|
|
218 |
CENTERS[19] = new float[] { -DIST2, +DIST2, +DIST };
|
|
219 |
CENTERS[20] = new float[] { +DIST2, +DIST2, -DIST };
|
|
220 |
CENTERS[21] = new float[] { +DIST2, -DIST2, -DIST };
|
|
221 |
CENTERS[22] = new float[] { -DIST2, -DIST2, -DIST };
|
|
222 |
CENTERS[23] = new float[] { -DIST2, +DIST2, -DIST };
|
|
223 |
|
|
224 |
CENTERS[24] = new float[] { +DIST , +0.00f, +0.00f};
|
|
225 |
CENTERS[25] = new float[] { -DIST , +0.00f, +0.00f};
|
|
226 |
CENTERS[26] = new float[] { +0.00f, +DIST , +0.00f};
|
|
227 |
CENTERS[27] = new float[] { +0.00f, -DIST , +0.00f};
|
|
228 |
CENTERS[28] = new float[] { +0.00f, +0.00f, +DIST };
|
|
229 |
CENTERS[29] = new float[] { +0.00f, +0.00f, -DIST };
|
|
230 |
|
|
231 |
CENTERS[30] = new float[] { +0.00f, +DIST , +DIST };
|
|
232 |
CENTERS[31] = new float[] { +DIST , +0.00f, +DIST };
|
|
233 |
CENTERS[32] = new float[] { +0.00f, -DIST , +DIST };
|
|
234 |
CENTERS[33] = new float[] { -DIST , +0.00f, +DIST };
|
|
235 |
CENTERS[34] = new float[] { +DIST , +DIST , +0.00f};
|
|
236 |
CENTERS[35] = new float[] { +DIST , -DIST , +0.00f};
|
|
237 |
CENTERS[36] = new float[] { -DIST , -DIST , +0.00f};
|
|
238 |
CENTERS[37] = new float[] { -DIST , +DIST , +0.00f};
|
|
239 |
CENTERS[38] = new float[] { +0.00f, +DIST , -DIST };
|
|
240 |
CENTERS[39] = new float[] { +DIST , +0.00f, -DIST };
|
|
241 |
CENTERS[40] = new float[] { +0.00f, -DIST , -DIST };
|
|
242 |
CENTERS[41] = new float[] { -DIST , +0.00f, -DIST };
|
|
243 | 243 |
|
244 | 244 |
return CENTERS; |
245 | 245 |
} |
src/main/java/org/distorted/objects/TwistySkewb.java | ||
---|---|---|
213 | 213 |
|
214 | 214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
215 | 215 |
|
216 |
Static3D[] getCubitPositions(int numLayers)
|
|
216 |
float[][] getCubitPositions(int numLayers)
|
|
217 | 217 |
{ |
218 | 218 |
final float DIST_CORNER = (numLayers-1)*0.50f; |
219 | 219 |
final float DIST_EDGE = (numLayers-1)*0.50f; |
... | ... | |
223 | 223 |
final int numEdges = getNumEdges(numLayers); |
224 | 224 |
final int numCenters = 6*getNumCentersPerFace(numLayers); |
225 | 225 |
|
226 |
final Static3D[] CENTERS = new Static3D[numCorners+numEdges+numCenters];
|
|
226 |
final float[][] CENTERS = new float[numCorners+numEdges+numCenters][];
|
|
227 | 227 |
|
228 | 228 |
/// CORNERS ////////////////////////////////////////////// |
229 | 229 |
|
230 |
CENTERS[0] = new Static3D( DIST_CORNER, DIST_CORNER, DIST_CORNER );
|
|
231 |
CENTERS[1] = new Static3D( DIST_CORNER, DIST_CORNER,-DIST_CORNER );
|
|
232 |
CENTERS[2] = new Static3D( DIST_CORNER,-DIST_CORNER, DIST_CORNER );
|
|
233 |
CENTERS[3] = new Static3D( DIST_CORNER,-DIST_CORNER,-DIST_CORNER );
|
|
234 |
CENTERS[4] = new Static3D(-DIST_CORNER, DIST_CORNER, DIST_CORNER );
|
|
235 |
CENTERS[5] = new Static3D(-DIST_CORNER, DIST_CORNER,-DIST_CORNER );
|
|
236 |
CENTERS[6] = new Static3D(-DIST_CORNER,-DIST_CORNER, DIST_CORNER );
|
|
237 |
CENTERS[7] = new Static3D(-DIST_CORNER,-DIST_CORNER,-DIST_CORNER );
|
|
230 |
CENTERS[0] = new float[] { DIST_CORNER, DIST_CORNER, DIST_CORNER };
|
|
231 |
CENTERS[1] = new float[] { DIST_CORNER, DIST_CORNER,-DIST_CORNER };
|
|
232 |
CENTERS[2] = new float[] { DIST_CORNER,-DIST_CORNER, DIST_CORNER };
|
|
233 |
CENTERS[3] = new float[] { DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
|
|
234 |
CENTERS[4] = new float[] {-DIST_CORNER, DIST_CORNER, DIST_CORNER };
|
|
235 |
CENTERS[5] = new float[] {-DIST_CORNER, DIST_CORNER,-DIST_CORNER };
|
|
236 |
CENTERS[6] = new float[] {-DIST_CORNER,-DIST_CORNER, DIST_CORNER };
|
|
237 |
CENTERS[7] = new float[] {-DIST_CORNER,-DIST_CORNER,-DIST_CORNER };
|
|
238 | 238 |
|
239 | 239 |
/// EDGES /////////////////////////////////////////////// |
240 | 240 |
|
... | ... | |
262 | 262 |
|
263 | 263 |
for (int j=0; j<numLayers-2; j++, c+=1.0f, index++) |
264 | 264 |
{ |
265 |
CENTERS[index] = new Static3D( edges[0]==0 ? c : edges[0] ,
|
|
265 |
CENTERS[index] = new float[] { edges[0]==0 ? c : edges[0] ,
|
|
266 | 266 |
edges[1]==0 ? c : edges[1] , |
267 |
edges[2]==0 ? c : edges[2] );
|
|
267 |
edges[2]==0 ? c : edges[2] };
|
|
268 | 268 |
} |
269 | 269 |
} |
270 | 270 |
|
... | ... | |
307 | 307 |
else if( centers[2]==X ) cen2 = x; |
308 | 308 |
else cen2 = centers[2]; |
309 | 309 |
|
310 |
CENTERS[index] = new Static3D(cen0,cen1,cen2);
|
|
310 |
CENTERS[index] = new float[] {cen0,cen1,cen2};
|
|
311 | 311 |
} |
312 | 312 |
} |
313 | 313 |
|
... | ... | |
331 | 331 |
else if( centers[2]==X ) cen2 = x; |
332 | 332 |
else cen2 = centers[2]; |
333 | 333 |
|
334 |
CENTERS[index] = new Static3D(cen0,cen1,cen2);
|
|
334 |
CENTERS[index] = new float[] {cen0,cen1,cen2};
|
|
335 | 335 |
} |
336 | 336 |
} |
337 | 337 |
} |
Also available in: Unified diff
Change the Cubit center from a Static3D to a float[].
The point: now we can have more than one center, and bandaged objects need more than one, because in this way they are going to fill up their RotationRow bitmaps.