78 |
78 |
{
|
79 |
79 |
mGhostEffectAngle[l] = new Static1D(mGhostRowState[l]*mGhostAngle);
|
80 |
80 |
mGhostEffect[l] = new VertexEffectRotate(mGhostEffectAngle[l], mGhostAxis, new Static3D(0, 0, 0));
|
|
81 |
mGhostEffect[l].setMeshAssociation( 1<<(mGhostAxisParallelTo*mMaxNumLayers + l), -1 );
|
81 |
82 |
effects.apply(mGhostEffect[l]);
|
82 |
83 |
computeGhostQuaternion(mGhostOrigQuat[l],mGhostOrigAxis,mGhostRowState[l]*mGhostAngle);
|
83 |
84 |
}
|
... | ... | |
110 |
111 |
}
|
111 |
112 |
|
112 |
113 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
113 |
|
// If such a move is possible, return + or - mGhostAngle. Else, return 0.
|
114 |
|
// When is it possible? This depends of the value of mGhostRowBitmap's 'left' and 'right' bits.
|
115 |
|
//
|
116 |
|
// If 'row' is one of the left bits, and
|
117 |
|
// it is 0: move 'up' possible iff all bits are zeroes [ so now it is -10000 -> rotate to 01111]
|
118 |
|
// move 'down' possible iff all right bits are ones
|
119 |
|
// it is 1: move 'up' always possible
|
120 |
|
// move 'down' never possible
|
121 |
|
//
|
122 |
|
// If 'row' is one of the right bits, and
|
123 |
|
// it is 0: move 'up' never possible
|
124 |
|
// move 'down' always possible
|
125 |
|
// it is 1: move 'up' possible iff all the left bits are zeroes
|
126 |
|
// move 'down' possible iff all the bits are ones [so now it is 11112 -> contr-rotate to 00001]
|
|
114 |
// If we are not blocked, or we are blocked but the move is along the currently unblocked axis,
|
|
115 |
// then we can always move any row 1 or 2 ghostAngles up or down.
|
|
116 |
// If 'angle' is closest to such multiples of ghostAngles, then return the closest multiple.
|
|
117 |
// Otherwise return 0.
|
127 |
118 |
|
128 |
|
int ghostNearestAngle(int axis, int row, float angle)
|
|
119 |
int nearestGhostAngle(int axis, float angle, int basicDeg)
|
129 |
120 |
{
|
130 |
|
int ret = 0;
|
131 |
|
|
132 |
121 |
if( mGhostAngle!=0 )
|
133 |
122 |
{
|
134 |
|
boolean moveDo = angleIsDown(axis,row,angle);
|
135 |
|
boolean moveUp = angleIsUp(axis,row,angle);
|
136 |
|
boolean isLeft = (row<mGhostFirstRow[axis])^mGhostAxisInverted;
|
137 |
|
boolean isZero = (mGhostRowBitmap&(1<<row))==0;
|
|
123 |
int numRot = (int)(angle/basicDeg + 0.5f);
|
|
124 |
if( angle< -(basicDeg*0.5) ) numRot-=1;
|
|
125 |
int intAngle = (int)angle;
|
|
126 |
int distToNormalAngle = Math.abs(intAngle - numRot*basicDeg);
|
|
127 |
int distTo1 = Math.abs(intAngle - mGhostAngle);
|
|
128 |
int distTo2 = Math.abs(intAngle - 2*mGhostAngle);
|
|
129 |
int distTo3 = Math.abs(intAngle + mGhostAngle);
|
|
130 |
int distTo4 = Math.abs(intAngle + 2*mGhostAngle);
|
|
131 |
int min12 = Math.min(distTo1,distTo2);
|
|
132 |
int min34 = Math.min(distTo3,distTo4);
|
|
133 |
int min = Math.min( min12,min34 );
|
|
134 |
|
|
135 |
if( distToNormalAngle<=min ) return 0;
|
138 |
136 |
|
139 |
137 |
if( !mGhostBlocked )
|
140 |
138 |
{
|
141 |
|
ret = retAngle(axis,isLeft,isZero,moveUp,moveDo);
|
142 |
|
|
143 |
|
if( ret!=0 )
|
144 |
|
{
|
145 |
|
mGhostAxis.set(mAxis[axis]);
|
146 |
|
mGhostAxisParallelTo = axis;
|
147 |
|
mGhostAxisInverted = false;
|
148 |
|
}
|
149 |
|
}
|
150 |
|
else if( axis==mGhostAxisParallelTo )
|
151 |
|
{
|
152 |
|
ret = retAngle(axis,isLeft,isZero,moveUp,moveDo);
|
|
139 |
mGhostAxis.set(mAxis[axis]);
|
|
140 |
mGhostAxisParallelTo = axis;
|
|
141 |
mGhostAxisInverted = false;
|
153 |
142 |
}
|
154 |
|
}
|
155 |
|
|
156 |
|
return ret;
|
157 |
|
}
|
158 |
|
/*
|
159 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
160 |
|
|
161 |
|
private boolean angleIsDown(int axis, int row, float angle)
|
162 |
|
{
|
163 |
|
int basicDeg = 360/mBasicAngles[axis][row];
|
164 |
|
boolean moveDo = moveIsDown(basicDeg,angle);
|
165 |
|
boolean moveUp = moveIsUp(basicDeg,angle);
|
166 |
|
|
167 |
|
return ((moveDo&(!mGhostAxisInverted)) || moveUp&mGhostAxisInverted);
|
168 |
|
}
|
169 |
|
|
170 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
171 |
|
|
172 |
|
private boolean angleIsUp(int axis, int row, float angle)
|
173 |
|
{
|
174 |
|
int basicDeg = 360/mBasicAngles[axis][row];
|
175 |
|
boolean moveDo = moveIsDown(basicDeg,angle);
|
176 |
|
boolean moveUp = moveIsUp(basicDeg,angle);
|
177 |
|
|
178 |
|
return ((moveUp&(!mGhostAxisInverted)) || moveDo&mGhostAxisInverted);
|
179 |
|
}
|
180 |
|
|
181 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
182 |
143 |
|
183 |
|
private boolean moveIsDown(int basic, float angle)
|
184 |
|
{
|
185 |
|
float A = (2*angle-mGhostAngle)/basic;
|
186 |
|
boolean even = ((int)A)%2 == 0;
|
187 |
|
return (A>=0) == even;
|
188 |
|
}
|
189 |
|
|
190 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
191 |
|
|
192 |
|
private boolean moveIsUp(int basic, float angle)
|
193 |
|
{
|
194 |
|
float A = (2*angle+mGhostAngle)/basic;
|
195 |
|
boolean even = ((int)A)%2 == 0;
|
196 |
|
return (A>=0) != even;
|
197 |
|
}
|
198 |
|
|
199 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
200 |
|
|
201 |
|
private int retAngle(int axis, boolean isLeft, boolean isZero, boolean moveUp, boolean moveDo)
|
202 |
|
{
|
203 |
|
int mult = mGhostAxisInverted ? -1 : 1;
|
204 |
|
|
205 |
|
if( isLeft )
|
206 |
|
{
|
207 |
|
if( isZero )
|
208 |
|
{
|
209 |
|
if( moveUp ) return allBitsAreZeroes() ? -mult*mGhostAngle : 0;
|
210 |
|
if( moveDo ) return rightBitsAreOnes(axis) ? mult*mGhostAngle : 0;
|
211 |
|
}
|
212 |
|
else
|
|
144 |
if( !mGhostBlocked || axis==mGhostAxisParallelTo )
|
213 |
145 |
{
|
214 |
|
if( moveUp ) return -mult*mGhostAngle;
|
215 |
|
}
|
216 |
|
}
|
217 |
|
else
|
218 |
|
{
|
219 |
|
if( isZero )
|
220 |
|
{
|
221 |
|
if( moveDo ) return mult*mGhostAngle;
|
222 |
|
}
|
223 |
|
else
|
224 |
|
{
|
225 |
|
if( moveUp ) return leftBitsAreZeroes(axis) ? -mult*mGhostAngle : 0;
|
226 |
|
if( moveDo ) return allBitsAreOnes(axis) ? mult*mGhostAngle : 0;
|
|
146 |
if( min12<min34 ) return distTo1<distTo2 ? +mGhostAngle : +2*mGhostAngle;
|
|
147 |
else return distTo3<distTo4 ? -mGhostAngle : -2*mGhostAngle;
|
227 |
148 |
}
|
228 |
149 |
}
|
229 |
150 |
|
230 |
151 |
return 0;
|
231 |
152 |
}
|
232 |
|
*/
|
|
153 |
|
233 |
154 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234 |
155 |
// Called when removing a rotation, before all cubits have been rotated.
|
235 |
156 |
// Return only the 'nonGhostAngle' i.e. one from which ghostAngle has been removed.
|
... | ... | |
241 |
162 |
|
242 |
163 |
if( mGhostAngle!=0 && nonGhostAngle!=0 )
|
243 |
164 |
{
|
244 |
|
boolean moveDo = angleIsDown(axis,0,angleInDegrees);
|
245 |
|
boolean moveUp = angleIsUp(axis,0,angleInDegrees);
|
246 |
|
boolean ghostMove = ( moveUp || moveDo );
|
247 |
|
int mult = mGhostAxisInverted ? -1 : 1;
|
248 |
|
|
249 |
|
if( moveDo ) nonGhostAngle -= mult*mGhostAngle;
|
250 |
|
if( moveUp ) nonGhostAngle += mult*mGhostAngle;
|
|
165 |
// ....
|
251 |
166 |
|
252 |
167 |
if( mGhostBlocked && axis!=mGhostAxisParallelTo )
|
253 |
168 |
{
|
... | ... | |
262 |
177 |
mGhostAxis.set(mAxis[axis]);
|
263 |
178 |
mGhostAxisParallelTo = axis;
|
264 |
179 |
mGhostAxisInverted = false;
|
|
180 |
|
|
181 |
for(int l=0; l<mMaxNumLayers; l++)
|
|
182 |
mGhostEffect[l].setMeshAssociation( 1<<(mGhostAxisParallelTo*mMaxNumLayers + l), -1);
|
265 |
183 |
}
|
266 |
184 |
}
|
267 |
185 |
|
268 |
186 |
mGhostBlocked = ( mGhostRowBitmap!=0 );
|
269 |
|
mGhostEffect.setMeshAssociation(mGhostRowBitmap<<(mGhostAxisParallelTo*mMaxNumLayers),-1);
|
270 |
187 |
}
|
271 |
188 |
|
272 |
189 |
return nonGhostAngle;
|
progress