Revision 123d6172
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/object/RubikCubeMovement.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
import org.distorted.library.type.Static2D; |
23 | 23 |
import org.distorted.library.type.Static4D; |
24 |
import org.distorted.magic.RubikRenderer; |
|
24 | 25 |
import org.distorted.magic.RubikSurfaceView; |
25 | 26 |
|
26 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
38 | 39 |
private static final int[] VECT = {RubikCube.VECTX,RubikCube.VECTY,RubikCube.VECTZ}; |
39 | 40 |
|
40 | 41 |
private float[] mPoint, mCamera, mTouchPointCastOntoFace, mDiff, mTouchPoint; |
41 |
private int mRotationVect; |
|
42 |
private int mRotationVect, mLastTouchedFace;
|
|
42 | 43 |
|
43 | 44 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
44 | 45 |
|
... | ... | |
139 | 140 |
|
140 | 141 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
141 | 142 |
|
142 |
private void convertCameraPointToScreenSpace(Static4D accumulated, float cameraDistance)
|
|
143 |
private void convertCameraPointToScreenSpace(Static4D accumulated) |
|
143 | 144 |
{ |
144 |
Static4D cameraPoint = new Static4D(0, 0, cameraDistance, 0);
|
|
145 |
Static4D cameraPoint = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0);
|
|
145 | 146 |
Static4D rotatedCamera= RubikSurfaceView.rotateVectorByInvertedQuat(cameraPoint, accumulated); |
146 | 147 |
|
147 | 148 |
mCamera[0] = rotatedCamera.get1(); |
... | ... | |
184 | 185 |
|
185 | 186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
186 | 187 |
|
187 |
public int faceTouched(Static4D accumulated, float cameraDistance, float x, float y)
|
|
188 |
public boolean faceTouched(Static4D rotQuaternion, float x, float y)
|
|
188 | 189 |
{ |
189 | 190 |
float cubeHalfSize= RubikCube.CUBE_SCREEN_RATIO*0.5f; |
190 | 191 |
|
191 |
convertTouchPointToScreenSpace(accumulated,x,y);
|
|
192 |
convertCameraPointToScreenSpace(accumulated, cameraDistance);
|
|
192 |
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
|
193 |
convertCameraPointToScreenSpace(rotQuaternion);
|
|
193 | 194 |
|
194 |
for(int face=FRONT; face<=BOTTOM; face++)
|
|
195 |
for( mLastTouchedFace=FRONT; mLastTouchedFace<=BOTTOM; mLastTouchedFace++)
|
|
195 | 196 |
{ |
196 |
if( faceIsVisible(face,cubeHalfSize) )
|
|
197 |
if( faceIsVisible(mLastTouchedFace,cubeHalfSize) )
|
|
197 | 198 |
{ |
198 |
castTouchPointOntoFace(face,cubeHalfSize, mTouchPointCastOntoFace);
|
|
199 |
castTouchPointOntoFace(mLastTouchedFace,cubeHalfSize, mTouchPointCastOntoFace);
|
|
199 | 200 |
|
200 | 201 |
float qX= (mTouchPointCastOntoFace[0]+cubeHalfSize) / (2*cubeHalfSize); |
201 | 202 |
float qY= (mTouchPointCastOntoFace[1]+cubeHalfSize) / (2*cubeHalfSize); |
202 | 203 |
float qZ= (mTouchPointCastOntoFace[2]+cubeHalfSize) / (2*cubeHalfSize); |
203 | 204 |
|
204 |
if( qX<=1 && qX>=0 && qY<=1 && qY>=0 && qZ<=1 && qZ>=0 ) return face;
|
|
205 |
if( qX<=1 && qX>=0 && qY<=1 && qY>=0 && qZ<=1 && qZ>=0 ) return true;
|
|
205 | 206 |
} |
206 | 207 |
} |
207 | 208 |
|
208 |
return NONE; |
|
209 |
mLastTouchedFace = NONE; |
|
210 |
return false; |
|
209 | 211 |
} |
210 | 212 |
|
211 | 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
212 | 214 |
|
213 |
public Static2D newRotation(Static4D accumulated, int lastTouchedFace, float x, float y)
|
|
215 |
public Static2D newRotation(Static4D rotQuaternion, float x, float y)
|
|
214 | 216 |
{ |
215 | 217 |
float cubeHalfSize= RubikCube.CUBE_SCREEN_RATIO*0.5f; |
216 | 218 |
|
217 |
convertTouchPointToScreenSpace(accumulated,x,y);
|
|
218 |
castTouchPointOntoFace(lastTouchedFace,cubeHalfSize,mDiff);
|
|
219 |
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
|
220 |
castTouchPointOntoFace(mLastTouchedFace,cubeHalfSize,mDiff);
|
|
219 | 221 |
|
220 | 222 |
mDiff[0] -= mTouchPointCastOntoFace[0]; |
221 | 223 |
mDiff[1] -= mTouchPointCastOntoFace[1]; |
222 | 224 |
mDiff[2] -= mTouchPointCastOntoFace[2]; |
223 | 225 |
|
224 |
int xAxis = retFaceXaxis(lastTouchedFace);
|
|
225 |
int yAxis = retFaceYaxis(lastTouchedFace);
|
|
226 |
int xAxis = retFaceXaxis(mLastTouchedFace);
|
|
227 |
int yAxis = retFaceYaxis(mLastTouchedFace);
|
|
226 | 228 |
mRotationVect = (isVertical( mDiff[xAxis], mDiff[yAxis]) ? VECT[xAxis]:VECT[yAxis]); |
227 | 229 |
float offset= (mTouchPointCastOntoFace[mRotationVect]+cubeHalfSize)/(2*cubeHalfSize); |
228 | 230 |
|
... | ... | |
235 | 237 |
|
236 | 238 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
237 | 239 |
|
238 |
public float continueRotation(Static4D accumulated, int lastTouchedFace, float x, float y)
|
|
240 |
public float continueRotation(Static4D rotQuaternion, float x, float y)
|
|
239 | 241 |
{ |
240 |
convertTouchPointToScreenSpace(accumulated,x,y);
|
|
242 |
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
|
241 | 243 |
|
242 | 244 |
mDiff[0] = mPoint[0]-mTouchPoint[0]; |
243 | 245 |
mDiff[1] = mPoint[1]-mTouchPoint[1]; |
244 | 246 |
mDiff[2] = mPoint[2]-mTouchPoint[2]; |
245 | 247 |
|
246 |
int xAxis= retFaceXaxis(lastTouchedFace);
|
|
247 |
int yAxis= retFaceYaxis(lastTouchedFace);
|
|
248 |
int sign = retFaceRotationSign(lastTouchedFace);
|
|
248 |
int xAxis= retFaceXaxis(mLastTouchedFace);
|
|
249 |
int yAxis= retFaceYaxis(mLastTouchedFace);
|
|
250 |
int sign = retFaceRotationSign(mLastTouchedFace);
|
|
249 | 251 |
float angle = (mRotationVect==xAxis ? mDiff[yAxis] : -mDiff[xAxis]); |
250 | 252 |
|
251 | 253 |
return sign*angle; |
Also available in: Unified diff
Further simplifications for object movement.