Revision efef689c
Added by Leszek Koltunski about 4 years ago
src/main/java/org/distorted/object/RubikObject.java | ||
---|---|---|
48 | 48 |
static final int TEXTURE_HEIGHT = 128; |
49 | 49 |
static final float OBJECT_SCREEN_RATIO = 0.5f; |
50 | 50 |
final float[] LEGAL_QUATS; |
51 |
final Static3D[] ROTATION_AXIS; |
|
51 | 52 |
|
52 | 53 |
private static final int POST_ROTATION_MILLISEC = 500; |
53 | 54 |
private final int NUM_CUBITS; |
54 | 55 |
private int mRotRow; |
55 |
private Static3D mRotAxis;
|
|
56 |
private int mRotAxis;
|
|
56 | 57 |
private Static3D mScale, mNodeScale; |
57 | 58 |
private Static4D mQuatAccumulated; |
58 | 59 |
private Cubit[] mCubits; |
... | ... | |
77 | 78 |
|
78 | 79 |
LEGAL_QUATS = getLegalQuats(); |
79 | 80 |
NUM_CUBITS = getNumCubits(size); |
81 |
ROTATION_AXIS = getRotationAxis(); |
|
80 | 82 |
|
81 | 83 |
mSize = size; |
82 | 84 |
|
... | ... | |
108 | 110 |
|
109 | 111 |
for(int i=0; i<NUM_CUBITS; i++) |
110 | 112 |
{ |
111 |
int x = positions[i][0]; |
|
112 |
int y = positions[i][1]; |
|
113 |
int z = positions[i][2]; |
|
113 |
Static3D pos = new Static3D(positions[i][0],positions[i][1],positions[i][2]); |
|
114 |
MeshBase cubitMesh = createCubitMesh(vertices); |
|
115 |
mCubits[i] = new Cubit(this,cubitMesh,pos); |
|
116 |
textureCubitMesh(cubitMesh,i); |
|
114 | 117 |
|
115 |
MeshBase cubit = createCubitMesh(vertices); |
|
116 |
textureCubitMesh(cubit,x,y,z); |
|
117 |
|
|
118 |
mCubits[i] = new Cubit( this , cubit, new Static3D(x,y,z) ); |
|
119 | 118 |
attach(mCubits[i].mNode); |
120 | 119 |
} |
121 | 120 |
} |
122 | 121 |
|
122 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
123 |
|
|
124 |
private void textureCubitMesh(MeshBase mesh, int cubit) |
|
125 |
{ |
|
126 |
boolean belongs; |
|
127 |
final int numFaces = getNumFaces(); |
|
128 |
final Static4D[] maps = new Static4D[numFaces]; |
|
129 |
final float ratio = 1.0f/(numFaces+1); |
|
130 |
|
|
131 |
if( 2*ROTATION_AXIS.length == numFaces ) |
|
132 |
{ |
|
133 |
for(int i=0; i<numFaces; i++) |
|
134 |
{ |
|
135 |
belongs = belongsToRotation(cubit, i/2, i%2==0 ? mSize-1:0 ); |
|
136 |
maps[i] = new Static4D( (belongs?i:6)*ratio, 0.0f, ratio, 1.0f); |
|
137 |
} |
|
138 |
} |
|
139 |
else if( ROTATION_AXIS.length == numFaces ) |
|
140 |
{ |
|
141 |
for(int i=0; i<numFaces; i++) |
|
142 |
{ |
|
143 |
belongs = belongsToRotation(cubit, i, mSize-1 ); |
|
144 |
maps[i] = new Static4D( (belongs?i:6)*ratio, 0.0f, ratio, 1.0f); |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
mesh.setTextureMap(maps); |
|
149 |
} |
|
150 |
|
|
151 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
152 |
// TODO: only works for RubikCube |
|
153 |
|
|
154 |
private boolean belongsToRotation( int cubit, int axis, int row) |
|
155 |
{ |
|
156 |
Static3D position = mCubits[cubit].mCurrentPosition; |
|
157 |
|
|
158 |
if( axis==0 ) return position.get0()==row; |
|
159 |
if( axis==1 ) return position.get1()==row; |
|
160 |
if( axis==2 ) return position.get2()==row; |
|
161 |
|
|
162 |
return false; |
|
163 |
} |
|
164 |
|
|
123 | 165 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
124 | 166 |
|
125 | 167 |
private void resetRotationAngle(Dynamic1D rotationAngle) |
... | ... | |
229 | 271 |
|
230 | 272 |
for(int i=0; i<NUM_CUBITS; i++) |
231 | 273 |
{ |
232 |
if( belongsToRotation(mCubits[i].mCurrentPosition,mRotAxis,mRotRow) )
|
|
274 |
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
|
233 | 275 |
{ |
234 | 276 |
if( first ) |
235 | 277 |
{ |
... | ... | |
296 | 338 |
|
297 | 339 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
298 | 340 |
|
299 |
public void beginNewRotation(Static3D axis, int row )
|
|
341 |
public void beginNewRotation(int axis, int row )
|
|
300 | 342 |
{ |
301 | 343 |
mRotAxis = axis; |
302 | 344 |
mRotRow = row; |
... | ... | |
304 | 346 |
mRotationAngleStatic.set0(0.0f); |
305 | 347 |
|
306 | 348 |
for(int i=0; i<NUM_CUBITS; i++) |
307 |
if( belongsToRotation( mCubits[i].mCurrentPosition,axis,mRotRow) )
|
|
349 |
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
|
308 | 350 |
{ |
309 | 351 |
mCubits[i].beginNewRotation(axis); |
310 | 352 |
} |
... | ... | |
312 | 354 |
|
313 | 355 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
314 | 356 |
|
315 |
public long addNewRotation( Static3D axis, int row, int angle, long durationMillis, EffectListener listener )
|
|
357 |
public long addNewRotation( int axis, int row, int angle, long durationMillis, EffectListener listener )
|
|
316 | 358 |
{ |
317 | 359 |
long effectID=0; |
318 | 360 |
boolean first = true; |
... | ... | |
323 | 365 |
mRotationAngleStatic.set0(0.0f); |
324 | 366 |
|
325 | 367 |
for(int i=0; i<NUM_CUBITS; i++) |
326 |
if( belongsToRotation(mCubits[i].mCurrentPosition,axis,mRotRow) )
|
|
368 |
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
|
327 | 369 |
{ |
328 | 370 |
mCubits[i].addNewRotation(axis,durationMillis,angle); |
329 | 371 |
|
... | ... | |
345 | 387 |
Static4D quat = null; |
346 | 388 |
|
347 | 389 |
for(int i=0; i<NUM_CUBITS; i++) |
348 |
if( belongsToRotation(mCubits[i].mCurrentPosition,mRotAxis,mRotRow) )
|
|
390 |
if( belongsToRotation(i,mRotAxis,mRotRow) )
|
|
349 | 391 |
{ |
350 | 392 |
if( first ) |
351 | 393 |
{ |
... | ... | |
367 | 409 |
abstract int getNumFaces(); |
368 | 410 |
abstract void createFaceTexture(Canvas canvas, Paint paint, int face); |
369 | 411 |
abstract MeshBase createCubitMesh(int vertices); |
370 |
|
|
371 |
abstract boolean belongsToRotation(Static3D position, Static3D axis, int row); |
|
372 |
abstract void textureCubitMesh(MeshBase mesh, int x, int y, int z); |
|
412 |
abstract Static3D[] getRotationAxis(); |
|
373 | 413 |
} |
Also available in: Unified diff
Progress towards generalizing belongsToRotation()