Project

General

Profile

« Previous | Next » 

Revision 3c4a326c

Added by Leszek Koltunski about 4 years ago

More work on making new types of RubikObjects easily creatable.

View differences:

src/main/java/org/distorted/object/RubikObject.java
37 37
import org.distorted.library.type.Static3D;
38 38
import org.distorted.library.type.Static4D;
39 39

  
40
import static org.distorted.object.RubikObjectList.*;
41

  
42 40
///////////////////////////////////////////////////////////////////////////////////////////////////
43 41

  
44 42
public abstract class RubikObject extends DistortedNode
......
50 48
  private static final int POST_ROTATION_MILLISEC = 500;
51 49
  private final int NUM_CUBITS;
52 50
  private final int[][] CUBIT_POSITIONS;
53
  private int mRotAxis, mRotRow;
54

  
51
  private int mRotRow;
52
  private Static3D mRotAxis;
55 53
  private Static3D mMove, mScale, mNodeMove, mNodeScale;
56 54
  private Static4D mQuatAccumulated;
57 55
  private DistortedTexture mNodeTexture;
......
292 290

  
293 291
///////////////////////////////////////////////////////////////////////////////////////////////////
294 292

  
295
  public void beginNewRotation(int vector, int row )
293
  public void beginNewRotation(Static3D axis, int row )
296 294
    {
297
    Static3D axis = VectX;
298

  
299
    switch(vector)
300
      {
301
      case VECTX: axis = VectX; break;
302
      case VECTY: axis = VectY; break;
303
      case VECTZ: axis = VectZ; break;
304
      }
305

  
306
    mRotAxis = vector;
295
    mRotAxis = axis;
307 296
    mRotRow  = row;
308 297

  
309 298
    mRotationAngleStatic.set0(0.0f);
310 299

  
311 300
    for(int i=0; i<NUM_CUBITS; i++)
312
      if( belongsToRotation( mCubits[i].mCurrentPosition,vector,mRotRow) )
301
      if( belongsToRotation( mCubits[i].mCurrentPosition,axis,mRotRow) )
313 302
        {
314 303
        mCubits[i].beginNewRotation(axis);
315 304
        }
......
317 306

  
318 307
///////////////////////////////////////////////////////////////////////////////////////////////////
319 308

  
320
  public long addNewRotation(int vector, int row, int angle, long durationMillis, EffectListener listener )
309
  public long addNewRotation( Static3D axis, int row, int angle, long durationMillis, EffectListener listener )
321 310
     {
322
     Static3D axis = VectX;
323 311
     long effectID=0;
324 312
     boolean first = true;
325 313

  
326
     switch(vector)
327
       {
328
       case VECTX: axis = VectX; break;
329
       case VECTY: axis = VectY; break;
330
       case VECTZ: axis = VectZ; break;
331
       }
332

  
333
     mRotAxis = vector;
314
     mRotAxis = axis;
334 315
     mRotRow  = row;
335 316

  
336 317
     mRotationAngleStatic.set0(0.0f);
337 318

  
338 319
     for(int i=0; i<NUM_CUBITS; i++)
339
       if( belongsToRotation(mCubits[i].mCurrentPosition,vector,mRotRow) )
320
       if( belongsToRotation(mCubits[i].mCurrentPosition,axis,mRotRow) )
340 321
         {
341 322
         mCubits[i].addNewRotation(axis,durationMillis,angle);
342 323

  
......
354 335

  
355 336
  public void removeRotationNow()
356 337
     {
357
     float qx=0,qy=0,qz=0;
358 338
     boolean first = true;
359 339
     Static4D quat = null;
360 340

  
361
     switch(mRotAxis)
362
       {
363
       case VECTX: qx=1; break;
364
       case VECTY: qy=1; break;
365
       case VECTZ: qz=1; break;
366
       }
367

  
368 341
     for(int i=0; i<NUM_CUBITS; i++)
369 342
       if( belongsToRotation(mCubits[i].mCurrentPosition,mRotAxis,mRotRow) )
370 343
         {
371 344
         if( first )
372 345
           {
373 346
           first = false;
374
           quat = mCubits[i].returnRotationQuat(qx,qy,qz);
347
           quat = mCubits[i].returnRotationQuat(mRotAxis);
375 348
           }
376 349

  
377 350
         mCubits[i].removeRotationNow(quat);
......
385 358
  abstract int getNumCubits(int size);
386 359
  abstract int[][] getCubitPositions(int size);
387 360
  abstract float[] getLegalQuats();
388
  abstract boolean belongsToRotation(Static3D position, int axis, int row);
361
  abstract boolean belongsToRotation(Static3D position, Static3D axis, int row);
389 362
  abstract MeshCubes createMesh(int vertices,int x, int y, int z);
390 363

  
391 364
  public abstract void createTexture();

Also available in: Unified diff