Revision 775e675d
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/object/RubikCube.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
public class RubikCube extends DistortedNode |
47 | 47 |
{ |
48 |
private static final float CUBE_SCREEN_RATIO = 0.5f;
|
|
48 |
static final float CUBE_SCREEN_RATIO = 0.5f;
|
|
49 | 49 |
private static final int POST_ROTATION_MILLISEC = 500; |
50 | 50 |
private static final int TEXTURE_SIZE = 100; |
51 | 51 |
|
... | ... | |
74 | 74 |
private int mSize; |
75 | 75 |
|
76 | 76 |
private DistortedTexture mNodeTexture; |
77 |
private float mCubeSizeInScreenSpace; |
|
78 | 77 |
|
79 | 78 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
80 | 79 |
|
... | ... | |
212 | 211 |
mCurrentPosition[x][y][z].set3(roundedZ); |
213 | 212 |
} |
214 | 213 |
|
215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
216 |
|
|
217 |
void addNewRotation(int vector, int row ) |
|
218 |
{ |
|
219 |
Static3D axis = VectX; |
|
220 |
|
|
221 |
switch(vector) |
|
222 |
{ |
|
223 |
case VECTX: axis = VectX; break; |
|
224 |
case VECTY: axis = VectY; break; |
|
225 |
case VECTZ: axis = VectZ; break; |
|
226 |
} |
|
227 |
|
|
228 |
mRotAxis = vector; |
|
229 |
mRotRow = row; |
|
230 |
|
|
231 |
mRotationAngleStatic.set1(0.0f); |
|
232 |
|
|
233 |
for(int x=0; x<mSize; x++) |
|
234 |
for(int y=0; y<mSize; y++) |
|
235 |
for(int z=0; z<mSize; z++) |
|
236 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
237 |
{ |
|
238 |
if( belongsToRotation(x,y,z,vector,mRotRow) ) |
|
239 |
{ |
|
240 |
mRotationAxis[x][y][z].set(axis); |
|
241 |
mRotationAngle[x][y][z].add(mRotationAngleStatic); |
|
242 |
} |
|
243 |
} |
|
244 |
} |
|
245 |
|
|
246 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
247 |
|
|
248 |
void continueRotation(float angleInDegrees) |
|
249 |
{ |
|
250 |
mRotationAngleStatic.set1(angleInDegrees); |
|
251 |
} |
|
252 |
|
|
253 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
254 |
|
|
255 |
float returnCubeSizeInScreenSpace() |
|
256 |
{ |
|
257 |
return mCubeSizeInScreenSpace; |
|
258 |
} |
|
259 |
|
|
260 | 214 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
261 | 215 |
// PUBLIC API |
262 | 216 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
372 | 326 |
} |
373 | 327 |
} |
374 | 328 |
|
329 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
330 |
|
|
331 |
public void addNewRotation(int vector, int row ) |
|
332 |
{ |
|
333 |
Static3D axis = VectX; |
|
334 |
|
|
335 |
switch(vector) |
|
336 |
{ |
|
337 |
case VECTX: axis = VectX; break; |
|
338 |
case VECTY: axis = VectY; break; |
|
339 |
case VECTZ: axis = VectZ; break; |
|
340 |
} |
|
341 |
|
|
342 |
mRotAxis = vector; |
|
343 |
mRotRow = row; |
|
344 |
|
|
345 |
mRotationAngleStatic.set1(0.0f); |
|
346 |
|
|
347 |
for(int x=0; x<mSize; x++) |
|
348 |
for(int y=0; y<mSize; y++) |
|
349 |
for(int z=0; z<mSize; z++) |
|
350 |
if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 ) |
|
351 |
{ |
|
352 |
if( belongsToRotation(x,y,z,vector,mRotRow) ) |
|
353 |
{ |
|
354 |
mRotationAxis[x][y][z].set(axis); |
|
355 |
mRotationAngle[x][y][z].add(mRotationAngleStatic); |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
|
|
360 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
361 |
|
|
362 |
public void continueRotation(float angleInDegrees) |
|
363 |
{ |
|
364 |
mRotationAngleStatic.set1(angleInDegrees); |
|
365 |
} |
|
366 |
|
|
375 | 367 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
376 | 368 |
|
377 | 369 |
public Static4D getRotationQuat() |
... | ... | |
496 | 488 |
|
497 | 489 |
public void recomputeScaleFactor(int screenWidth, int screenHeight) |
498 | 490 |
{ |
499 |
mCubeSizeInScreenSpace = CUBE_SCREEN_RATIO*(screenWidth>screenHeight ? screenHeight:screenWidth); |
|
500 |
|
|
501 | 491 |
int texW = mNodeTexture.getWidth(); |
502 | 492 |
int texH = mNodeTexture.getHeight(); |
503 | 493 |
|
... | ... | |
516 | 506 |
mNodeScale.set(factor,factor,factor); |
517 | 507 |
} |
518 | 508 |
|
519 |
float scaleFactor = (mCubeSizeInScreenSpace/(TEXTURE_SIZE*mSize)) * (float)texW/(screenWidth>screenHeight ? screenHeight:screenWidth);
|
|
509 |
float scaleFactor = (CUBE_SCREEN_RATIO*texW/(TEXTURE_SIZE*mSize));
|
|
520 | 510 |
|
521 | 511 |
mMove.set( texW*0.5f , texH*0.5f , 0.0f ); |
522 | 512 |
mScale.set(scaleFactor,scaleFactor,scaleFactor); |
Also available in: Unified diff
Further simplifications for object movement - remove from it a reference to the Object altogether.