Project

General

Profile

« Previous | Next » 

Revision 10a2e360

Added by Leszek Koltunski about 4 years ago

Progress towards generalizing belongsToRotation()

View differences:

src/main/java/org/distorted/object/Cubit.java
52 52
  DistortedNode mNode;
53 53
  DistortedEffects mEffect;
54 54
  Static4D mQuatScramble;
55
  int[] mRotationRow;
55 56

  
56 57
///////////////////////////////////////////////////////////////////////////////////////////////////
57 58
// Because of quatMultiplication, errors can accumulate - so to avoid this, we
......
149 150
    int roundedZ = (int)(rotatedZ+0.1f);
150 151

  
151 152
    currentPosition.set(roundedX, roundedY, roundedZ);
153
    computeRotationRow();
154
    }
155

  
156

  
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
// TODO: this is only right in case of RubikCube
159

  
160
  private void computeRotationRow()
161
    {
162
    mRotationRow[0] = (int)mCurrentPosition.get0();
163
    mRotationRow[1] = (int)mCurrentPosition.get1();
164
    mRotationRow[2] = (int)mCurrentPosition.get2();
152 165
    }
153 166

  
154 167
///////////////////////////////////////////////////////////////////////////////////////////////////
......
171 184
    mCurrentPosition = position;
172 185
    mRotateEffect    = new MatrixEffectRotate(mRotationAngle, mRotationAxis, matrCenter);
173 186

  
187
    mRotationRow = new int[mParent.ROTATION_AXIS.length];
188
    computeRotationRow();
189

  
174 190
    mEffect = new DistortedEffects();
175 191
    mEffect.apply(mParent.mSinkEffect);
176 192
    mEffect.apply( new MatrixEffectMove(vector) );
src/main/java/org/distorted/object/RubikCube.java
82 82

  
83 83
///////////////////////////////////////////////////////////////////////////////////////////////////
84 84

  
85
  int[][] getCubitPositions(int size)
85
  Static3D[] getCubitPositions(int size)
86 86
    {
87
    int[][] tmp = new int[getNumCubits(size)][3];
87
    int numCubits = size>1 ? 6*size*size - 12*size + 8 : 1;
88
    Static3D[] tmp = new Static3D[numCubits];
88 89

  
89 90
    int currentPosition = 0;
90 91

  
91 92
    for(int x = 0; x<size; x++)
92 93
      for(int y = 0; y<size; y++)
93 94
        for(int z = 0; z<size; z++)
94
          {
95 95
          if( x==0 || x==size-1 || y==0 || y==size-1 || z==0 || z==size-1 )
96 96
            {
97
            tmp[currentPosition][0] = x;
98
            tmp[currentPosition][1] = y;
99
            tmp[currentPosition][2] = z;
100

  
101
            currentPosition++;
97
            tmp[currentPosition++] = new Static3D(x,y,z);
102 98
            }
103
          }
104 99

  
105 100
    return tmp;
106 101
    }
107 102

  
108
///////////////////////////////////////////////////////////////////////////////////////////////////
109
// i.e. size^3 - (size-2)^3 - number of cubits in the outside wall of the Cube (we don't create or
110
// render the inside)
111

  
112
  int getNumCubits(int size)
113
    {
114
    return size>1 ? 6*size*size - 12*size + 8 : 1;
115
    }
116

  
117 103
///////////////////////////////////////////////////////////////////////////////////////////////////
118 104

  
119 105
  float[] getLegalQuats()
src/main/java/org/distorted/object/RubikObject.java
76 76

  
77 77
    resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE);
78 78

  
79
    Static3D[] positions = getCubitPositions(size);
80

  
79 81
    LEGAL_QUATS = getLegalQuats();
80
    NUM_CUBITS  = getNumCubits(size);
82
    NUM_CUBITS  = positions.length;
81 83
    ROTATION_AXIS = getRotationAxis();
82 84

  
83 85
    mSize = size;
......
106 108
    mTexture = new DistortedTexture();
107 109

  
108 110
    int vertices = (int)(24.0f/mSize + 2.0f);
109
    int[][] positions = getCubitPositions(size);
110 111

  
111 112
    for(int i=0; i<NUM_CUBITS; i++)
112 113
      {
113
      Static3D pos = new Static3D(positions[i][0],positions[i][1],positions[i][2]);
114 114
      MeshBase cubitMesh = createCubitMesh(vertices);
115
      mCubits[i] = new Cubit(this,cubitMesh,pos);
115
      mCubits[i] = new Cubit(this,cubitMesh,positions[i]);
116 116
      textureCubitMesh(cubitMesh,i);
117 117

  
118 118
      attach(mCubits[i].mNode);
......
149 149
    }
150 150

  
151 151
///////////////////////////////////////////////////////////////////////////////////////////////////
152
// TODO: only works for RubikCube
153 152

  
154 153
  private boolean belongsToRotation( int cubit, int axis, int row)
155 154
    {
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;
155
    return mCubits[cubit].mRotationRow[axis]==row;
163 156
    }
164 157

  
165 158
///////////////////////////////////////////////////////////////////////////////////////////////////
......
403 396

  
404 397
///////////////////////////////////////////////////////////////////////////////////////////////////
405 398

  
406
  abstract int getNumCubits(int size);
407
  abstract int[][] getCubitPositions(int size);
399
  public int getNumRotations()
400
    {
401
    return ROTATION_AXIS.length;
402
    }
403

  
404
///////////////////////////////////////////////////////////////////////////////////////////////////
405

  
406
  abstract Static3D[] getCubitPositions(int size);
408 407
  abstract float[] getLegalQuats();
409 408
  abstract int getNumFaces();
410 409
  abstract void createFaceTexture(Canvas canvas, Paint paint, int face);

Also available in: Unified diff