39 |
39 |
private final static int TOP = 4; //
|
40 |
40 |
private final static int BOTTOM = 5; //
|
41 |
41 |
|
42 |
|
private static final int DIR_UP =0;
|
43 |
|
private static final int DIR_DOWN =1;
|
44 |
|
private static final int DIR_LEFT =2;
|
45 |
|
private static final int DIR_RIGHT=3;
|
46 |
|
|
47 |
42 |
static final int VECTX = 0;
|
48 |
43 |
static final int VECTY = 1;
|
49 |
44 |
static final int VECTZ = 2;
|
... | ... | |
119 |
114 |
}
|
120 |
115 |
else if( mRotating )
|
121 |
116 |
{
|
122 |
|
int minimumToRotate = (mScreenMin*mScreenMin)/64;
|
|
117 |
int minimumToRotate = (mScreenMin*mScreenMin)/100;
|
123 |
118 |
|
124 |
119 |
if( (mX-x)*(mX-x)+(mY-y)*(mY-y)>minimumToRotate )
|
125 |
120 |
{
|
... | ... | |
156 |
151 |
fillTouchPoint(x,y);
|
157 |
152 |
|
158 |
153 |
float cubeHalfSize= mRenderer.returnCubeSize()*0.5f;
|
159 |
|
float tmp = RubikRenderer.NUM_CUBES/(2*cubeHalfSize);
|
160 |
154 |
float A=retA(mLastTouchedFace,cubeHalfSize);
|
161 |
155 |
|
162 |
156 |
float diffX = (mPoiX-mCamX)*A + mCamX - mStartX;
|
163 |
157 |
float diffY = (mPoiY-mCamY)*A + mCamY - mStartY;
|
164 |
158 |
float diffZ = (mPoiZ-mCamZ)*A + mCamZ - mStartZ;
|
165 |
159 |
|
166 |
|
int dir, row=1;
|
|
160 |
mStartX = diffX + mStartX;
|
|
161 |
mStartY = diffY + mStartY;
|
|
162 |
mStartZ = diffZ + mStartZ;
|
167 |
163 |
|
168 |
164 |
switch(mLastTouchedFace)
|
169 |
165 |
{
|
170 |
|
case FRONT : dir = retDirection( diffX, diffY);
|
171 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTX:VECTY;
|
172 |
|
row = (int)( tmp*((mRotationVect==VECTX?mStartX:mStartY)+cubeHalfSize) );
|
173 |
|
break;
|
174 |
|
case BACK : dir = retDirection(-diffX, diffY);
|
175 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTX:VECTY;
|
176 |
|
row = (int)( tmp*((mRotationVect==VECTX?mStartX:mStartY)+cubeHalfSize) );
|
177 |
|
break;
|
178 |
|
case LEFT : dir = retDirection( diffZ, diffY);
|
179 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTZ:VECTY;
|
180 |
|
row = (int)( tmp*((mRotationVect==VECTZ?mStartZ:mStartY)+cubeHalfSize) );
|
181 |
|
break;
|
182 |
|
case RIGHT : dir = retDirection(-diffZ, diffY);
|
183 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTZ:VECTY;
|
184 |
|
row = (int)( tmp*((mRotationVect==VECTZ?mStartZ:mStartY)+cubeHalfSize) );
|
185 |
|
break;
|
186 |
|
case TOP : dir = retDirection( diffX,-diffZ);
|
187 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTX:VECTZ;
|
188 |
|
row = (int)( tmp*((mRotationVect==VECTX?mStartX:mStartZ)+cubeHalfSize) );
|
189 |
|
break;
|
190 |
|
case BOTTOM: dir = retDirection( diffX, diffZ);
|
191 |
|
mRotationVect = (dir==DIR_UP || dir==DIR_DOWN) ? VECTX:VECTZ;
|
192 |
|
row = (int)( tmp*((mRotationVect==VECTX?mStartX:mStartZ)+cubeHalfSize) );
|
193 |
|
break;
|
|
166 |
case FRONT :
|
|
167 |
case BACK : mRotationVect = (isVertical(diffX, diffY) ? VECTX:VECTY); break;
|
|
168 |
case LEFT :
|
|
169 |
case RIGHT : mRotationVect = (isVertical(diffZ, diffY) ? VECTZ:VECTY); break;
|
|
170 |
case TOP :
|
|
171 |
case BOTTOM: mRotationVect = (isVertical(diffX, diffZ) ? VECTX:VECTZ); break;
|
194 |
172 |
}
|
195 |
173 |
|
196 |
|
mStartX = diffX + mStartX;
|
197 |
|
mStartY = diffY + mStartY;
|
198 |
|
mStartZ = diffZ + mStartZ;
|
|
174 |
int row=0;
|
|
175 |
float tmp = RubikRenderer.NUM_CUBES/(2*cubeHalfSize);
|
|
176 |
|
|
177 |
switch(mRotationVect)
|
|
178 |
{
|
|
179 |
case VECTX: row = (int)(tmp*(mStartX+cubeHalfSize)); break;
|
|
180 |
case VECTY: row = (int)(tmp*(mStartY+cubeHalfSize)); break;
|
|
181 |
case VECTZ: row = (int)(tmp*(mStartZ+cubeHalfSize)); break;
|
|
182 |
}
|
199 |
183 |
|
200 |
184 |
mCube.addNewRotation(mRotationVect,row);
|
201 |
185 |
}
|
202 |
186 |
|
|
187 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
188 |
|
|
189 |
private boolean isVertical(float x, float y)
|
|
190 |
{
|
|
191 |
return (y>x) ? (y>=-x) : (y< -x);
|
|
192 |
}
|
|
193 |
|
203 |
194 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
204 |
195 |
|
205 |
196 |
private void continueRotation(int x, int y)
|
206 |
197 |
{
|
207 |
198 |
fillTouchPoint(x,y);
|
208 |
199 |
|
209 |
|
int sign=1;
|
210 |
200 |
float cubeHalfSize= mRenderer.returnCubeSize()*0.5f;
|
211 |
201 |
float A=retA(mLastTouchedFace,cubeHalfSize);
|
212 |
202 |
|
... | ... | |
214 |
204 |
float diffY = (mPoiY-mCamY)*A + mCamY - mStartY;
|
215 |
205 |
float diffZ = (mPoiZ-mCamZ)*A + mCamZ - mStartZ;
|
216 |
206 |
|
|
207 |
float angle=0.0f;
|
|
208 |
|
217 |
209 |
switch(mRotationVect)
|
218 |
210 |
{
|
219 |
211 |
case VECTX: switch(mLastTouchedFace)
|
220 |
212 |
{
|
221 |
|
case FRONT : sign = returnSign(-diffY); break;
|
222 |
|
case BACK : sign = returnSign( diffY); break;
|
223 |
|
case TOP : sign = returnSign( diffZ); break;
|
224 |
|
case BOTTOM: sign = returnSign(-diffZ); break;
|
|
213 |
case FRONT : angle = -diffY; break;
|
|
214 |
case BACK : angle = diffY; break;
|
|
215 |
case TOP : angle = diffZ; break;
|
|
216 |
case BOTTOM: angle = -diffZ; break;
|
225 |
217 |
}
|
226 |
218 |
break;
|
227 |
219 |
case VECTY: switch(mLastTouchedFace)
|
228 |
220 |
{
|
229 |
|
case FRONT : sign = returnSign( diffX); break;
|
230 |
|
case BACK : sign = returnSign(-diffX); break;
|
231 |
|
case LEFT : sign = returnSign( diffZ); break;
|
232 |
|
case RIGHT : sign = returnSign(-diffZ); break;
|
|
221 |
case FRONT : angle = diffX; break;
|
|
222 |
case BACK : angle = -diffX; break;
|
|
223 |
case LEFT : angle = diffZ; break;
|
|
224 |
case RIGHT : angle = -diffZ; break;
|
233 |
225 |
}
|
234 |
226 |
break;
|
235 |
227 |
case VECTZ: switch(mLastTouchedFace)
|
236 |
228 |
{
|
237 |
|
case TOP : sign = returnSign(-diffX); break;
|
238 |
|
case BOTTOM: sign = returnSign( diffX); break;
|
239 |
|
case LEFT : sign = returnSign(-diffY); break;
|
240 |
|
case RIGHT : sign = returnSign( diffY); break;
|
|
229 |
case TOP : angle = -diffX; break;
|
|
230 |
case BOTTOM: angle = diffX; break;
|
|
231 |
case LEFT : angle = -diffY; break;
|
|
232 |
case RIGHT : angle = diffY; break;
|
241 |
233 |
}
|
242 |
234 |
break;
|
243 |
235 |
default : android.util.Log.e("View", "impossible vector: "+mRotationVect);
|
244 |
236 |
}
|
245 |
237 |
|
246 |
|
float dX = mX-x;
|
247 |
|
float dY = mY-y;
|
248 |
|
float calibration = (float)Math.sqrt(dX*dX+dY*dY);
|
249 |
|
|
250 |
|
mCube.continueRotation(calibration*sign, mScreenMin);
|
|
238 |
mCube.continueRotation(200.0f*angle/mScreenMin);
|
251 |
239 |
}
|
252 |
240 |
|
253 |
241 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
258 |
246 |
mRenderer.finishRotation();
|
259 |
247 |
}
|
260 |
248 |
|
261 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
262 |
|
|
263 |
|
private int returnSign(float diff)
|
264 |
|
{
|
265 |
|
return diff>0 ? 1 : -1;
|
266 |
|
}
|
267 |
|
|
268 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
269 |
|
|
270 |
|
private int retDirection(float a, float b)
|
271 |
|
{
|
272 |
|
if( b>a ) return a>-b ? DIR_UP :DIR_LEFT;
|
273 |
|
else return a>-b ? DIR_RIGHT:DIR_DOWN;
|
274 |
|
}
|
275 |
|
|
276 |
249 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
277 |
250 |
// return quat1*quat2
|
278 |
251 |
|
... | ... | |
312 |
285 |
return quatMultiply(tmp,quat);
|
313 |
286 |
}
|
314 |
287 |
|
315 |
|
|
316 |
288 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
317 |
289 |
// rotate 'vector' by quat ( i.e. return quat*vector*(quat^-1) )
|
318 |
290 |
|
RubikApp: simplify SurfaceView