Project

General

Profile

« Previous | Next » 

Revision d8e03a81

Added by Leszek Koltunski about 2 years ago

Improvement for solved state detection of bandaged cuboids: now it should be always correct (except if one, among the cubitPositions, specifies a completely internal cubit - i.e. one with all faces black. Do not do that!)

View differences:

src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java
86 86
  abstract float[][] getPositions();
87 87

  
88 88
///////////////////////////////////////////////////////////////////////////////////////////////////
89

  
90
  private boolean cubitIsExternal(float[] pos, int x, int y, int z)
89
// return 0 if cubit is 'external' (it has at least two walls which belong to two different faces
90
// of the cuboid, faces which do not both rotate along the same axis! So: it is an edge, a corner,
91
// or a bandaged cubit which 'comes out' in two different, non-opposite, faces.
92
// Otherwise, if the cubit only comes out in one face or in two faces which are opposite to each other,
93
// return the index of the first of the three quats which rotate stuff in this face (so right or left
94
// return 1 because quats 1,2,3 are the ones rotating along the X axis)
95

  
96
  private int cubitIsExternal(float[] pos, float dx, float dy, float dz)
91 97
    {
92 98
    int len = pos.length/3;
93
    float dx = 0.5f*(x-1) - 0.1f;
94
    float dy = 0.5f*(y-1) - 0.1f;
95
    float dz = 0.5f*(z-1) - 0.1f;
99
    int x=0, y=0, z=0;
96 100

  
97
    if( x==1 )
101
    for(int i=0; i<len; i++)
98 102
      {
99
      for(int i=0; i<len; i++)
100
        {
101
        float cy = pos[3*i+1];
102
        float cz = pos[3*i+2];
103
        if( cy>=dy || cy<=-dy || cz>=dz || cz<=-dz ) return true;
104
        }
105
      }
103
      float cx = pos[3*i  ];
104
      float cy = pos[3*i+1];
105
      float cz = pos[3*i+2];
106 106

  
107
    if( y==1 )
108
      {
109
      for(int i=0; i<len; i++)
110
        {
111
        float cx = pos[3*i  ];
112
        float cz = pos[3*i+2];
113
        if( cx>=dx || cx<=-dx || cz>=dz || cz<=-dz ) return true;
114
        }
107
      if( cx>dx || cx<-dx ) x=1;
108
      if( cy>dy || cy<-dy ) y=1;
109
      if( cz>dz || cz<-dz ) z=1;
115 110
      }
116 111

  
117
    if( z==1 )
118
      {
119
      for(int i=0; i<len; i++)
120
        {
121
        float cx = pos[3*i  ];
122
        float cy = pos[3*i+1];
123
        if( cx>=dx || cx<=-dx || cy>=dy || cy<=-dy ) return true;
124
        }
125
      }
112
    if( x+y+z>=2 ) return 0;
126 113

  
127
    return false;
114
    if( x==1 ) return 1;
115
    if( y==1 ) return 4;
116
    if( z==1 ) return 7;
117

  
118
    android.util.Log.e("D", "ERROR: unsupported: internal cubit! ");
119
    return 0;
128 120
    }
129 121

  
130 122
///////////////////////////////////////////////////////////////////////////////////////////////////
......
142 134
    if( mSolvedQuatsAbstract==null )
143 135
      {
144 136
      int[] numLayers = getNumLayers();
145
      int x = numLayers[0];
146
      int y = numLayers[1];
147
      int z = numLayers[2];
148

  
149
      if( (x==1 && y>2 && z>2) || (x>2 && y==1 && z>2) || (x>2 && y>2 && z==1) )
137
      float dx = 0.5f*(numLayers[0]-1) - 0.1f;
138
      float dy = 0.5f*(numLayers[1]-1) - 0.1f;
139
      float dz = 0.5f*(numLayers[2]-1) - 0.1f;
140

  
141
      float[][] pos = getPositions();
142
      int numTotal = pos.length;
143
      boolean[] isExternal = new boolean[numTotal];
144
      int[] internalQuat = new int[numTotal];
145
      int numExternal = 0;
146
      int pointer = 0;
147

  
148
      for(int cubit=0; cubit<numTotal; cubit++)
150 149
        {
151
        int q;
150
        int q = cubitIsExternal(pos[cubit],dx,dy,dz);
152 151

  
153
             if( x==1 )  q=1;
154
        else if( y==1 )  q=4;
155
        else             q=7;
156

  
157
        float[][] pos = getPositions();
158
        int numTotal = pos.length;
159
        boolean[] isExternal = new boolean[numTotal];
160
        int numExternal = 0;
161

  
162
        for(int cubit=0; cubit<numTotal; cubit++)
163
          if( cubitIsExternal(pos[cubit],x,y,z) )
164
            {
165
            isExternal[cubit] = true;
166
            numExternal++;
167
            }
168

  
169
        int numInternal = numTotal - numExternal;
170

  
171
        mSolvedQuatsAbstract = new int[numInternal+1][];
172

  
173
        mSolvedQuatsAbstract[0] = new int[numExternal+1];
174
        mSolvedQuatsAbstract[0][0] = numExternal;
175

  
176
        for(int i=0; i<numInternal; i++)
152
        if( q<=0 )
177 153
          {
178
          mSolvedQuatsAbstract[i+1] = new int[5];
179
          mSolvedQuatsAbstract[i+1][0] = 1;
180
          mSolvedQuatsAbstract[i+1][2] = q;
181
          mSolvedQuatsAbstract[i+1][3] = q+1;
182
          mSolvedQuatsAbstract[i+1][4] = q+2;
154
          isExternal[cubit] = true;
155
          numExternal++;
183 156
          }
184

  
185
        int pointerExternal = 1;
186
        int pointerInternal = 1;
187

  
188
        for(int cubit=0; cubit<numTotal; cubit++)
157
        else
189 158
          {
190
          if( isExternal[cubit] ) mSolvedQuatsAbstract[0][pointerExternal++] = cubit;
191
          else                    mSolvedQuatsAbstract[pointerInternal++][1] = cubit;
159
          isExternal[cubit] = false;
160
          internalQuat[pointer] = q;
161
          pointer++;
192 162
          }
193 163
        }
194
      else
164

  
165
      int numInternal = numTotal - numExternal;
166

  
167
      mSolvedQuatsAbstract = new int[numInternal+1][];
168
      mSolvedQuatsAbstract[0] = new int[numExternal+1];
169
      mSolvedQuatsAbstract[0][0] = numExternal;
170

  
171
      for(int i=0; i<numInternal; i++)
172
        {
173
        int q = internalQuat[i];
174
        mSolvedQuatsAbstract[i+1] = new int[5];
175
        mSolvedQuatsAbstract[i+1][0] = 1;
176
        mSolvedQuatsAbstract[i+1][2] = q;
177
        mSolvedQuatsAbstract[i+1][3] = q+1;
178
        mSolvedQuatsAbstract[i+1][4] = q+2;
179
        }
180

  
181
      int pointerExternal = 1;
182
      int pointerInternal = 1;
183

  
184
      for(int cubit=0; cubit<numTotal; cubit++)
195 185
        {
196
        mSolvedQuatsAbstract = super.getSolvedQuats();
186
        if( isExternal[cubit] ) mSolvedQuatsAbstract[0][pointerExternal++] = cubit;
187
        else                    mSolvedQuatsAbstract[pointerInternal++][1] = cubit;
197 188
        }
198 189
      }
199 190

  

Also available in: Unified diff