21 |
21 |
|
22 |
22 |
import org.distorted.library.type.Static2D;
|
23 |
23 |
import org.distorted.library.type.Static4D;
|
24 |
|
import org.distorted.magic.RubikRenderer;
|
25 |
|
import org.distorted.magic.RubikSurfaceView;
|
26 |
24 |
|
27 |
25 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
28 |
26 |
|
... | ... | |
38 |
36 |
|
39 |
37 |
private static final int[] VECT = {RubikCube.VECTX,RubikCube.VECTY,RubikCube.VECTZ};
|
40 |
38 |
|
41 |
|
private float[] mPoint, mCamera, mTouchPointCastOntoFace, mDiff, mTouchPoint;
|
|
39 |
private float[] mPoint, mCamera, mDiff, mTouch;
|
42 |
40 |
private int mRotationVect, mLastTouchedFace;
|
43 |
41 |
|
44 |
42 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
126 |
124 |
return sign*mCamera[zAxis] > cubeHalfSize;
|
127 |
125 |
}
|
128 |
126 |
|
129 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
130 |
|
|
131 |
|
private void convertTouchPointToScreenSpace(Static4D accumulated, float x, float y)
|
132 |
|
{
|
133 |
|
Static4D touchPoint = new Static4D(x, y, 0, 0);
|
134 |
|
Static4D rotatedTouchPoint= RubikSurfaceView.rotateVectorByInvertedQuat(touchPoint, accumulated);
|
135 |
|
|
136 |
|
mPoint[0] = rotatedTouchPoint.get1();
|
137 |
|
mPoint[1] = rotatedTouchPoint.get2();
|
138 |
|
mPoint[2] = rotatedTouchPoint.get3();
|
139 |
|
}
|
140 |
|
|
141 |
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142 |
|
|
143 |
|
private void convertCameraPointToScreenSpace(Static4D accumulated)
|
144 |
|
{
|
145 |
|
Static4D cameraPoint = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0);
|
146 |
|
Static4D rotatedCamera= RubikSurfaceView.rotateVectorByInvertedQuat(cameraPoint, accumulated);
|
147 |
|
|
148 |
|
mCamera[0] = rotatedCamera.get1();
|
149 |
|
mCamera[1] = rotatedCamera.get2();
|
150 |
|
mCamera[2] = rotatedCamera.get3();
|
151 |
|
}
|
152 |
|
|
153 |
127 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
154 |
128 |
// given precomputed mCamera and mPoint, respectively camera and touch point positions in ScreenSpace,
|
155 |
129 |
// cast this touch point onto the surface defined by the 'face' and write the cast coords to 'output'.
|
... | ... | |
174 |
148 |
|
175 |
149 |
public RubikCubeMovement()
|
176 |
150 |
{
|
177 |
|
mRotationVect = VECT[0];
|
178 |
|
|
179 |
151 |
mPoint = new float[3];
|
180 |
152 |
mCamera= new float[3];
|
181 |
153 |
mDiff = new float[3];
|
182 |
|
mTouchPoint = new float[3];
|
183 |
|
mTouchPointCastOntoFace = new float[3];
|
|
154 |
mTouch = new float[3];
|
184 |
155 |
}
|
185 |
156 |
|
186 |
157 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
187 |
158 |
|
188 |
|
public boolean faceTouched(Static4D rotQuaternion, float x, float y)
|
|
159 |
public boolean faceTouched(Static4D rotatedTouchPoint, Static4D rotatedCamera)
|
189 |
160 |
{
|
190 |
161 |
float cubeHalfSize= RubikCube.CUBE_SCREEN_RATIO*0.5f;
|
191 |
162 |
|
192 |
|
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
193 |
|
convertCameraPointToScreenSpace(rotQuaternion);
|
|
163 |
mPoint[0] = rotatedTouchPoint.get1();
|
|
164 |
mPoint[1] = rotatedTouchPoint.get2();
|
|
165 |
mPoint[2] = rotatedTouchPoint.get3();
|
|
166 |
|
|
167 |
mCamera[0] = rotatedCamera.get1();
|
|
168 |
mCamera[1] = rotatedCamera.get2();
|
|
169 |
mCamera[2] = rotatedCamera.get3();
|
194 |
170 |
|
195 |
171 |
for( mLastTouchedFace=FRONT; mLastTouchedFace<=BOTTOM; mLastTouchedFace++)
|
196 |
172 |
{
|
197 |
173 |
if( faceIsVisible(mLastTouchedFace,cubeHalfSize) )
|
198 |
174 |
{
|
199 |
|
castTouchPointOntoFace(mLastTouchedFace,cubeHalfSize, mTouchPointCastOntoFace);
|
|
175 |
castTouchPointOntoFace(mLastTouchedFace,cubeHalfSize, mTouch);
|
200 |
176 |
|
201 |
|
float qX= (mTouchPointCastOntoFace[0]+cubeHalfSize) / (2*cubeHalfSize);
|
202 |
|
float qY= (mTouchPointCastOntoFace[1]+cubeHalfSize) / (2*cubeHalfSize);
|
203 |
|
float qZ= (mTouchPointCastOntoFace[2]+cubeHalfSize) / (2*cubeHalfSize);
|
|
177 |
float qX= (mTouch[0]+cubeHalfSize) / (2*cubeHalfSize);
|
|
178 |
float qY= (mTouch[1]+cubeHalfSize) / (2*cubeHalfSize);
|
|
179 |
float qZ= (mTouch[2]+cubeHalfSize) / (2*cubeHalfSize);
|
204 |
180 |
|
205 |
181 |
if( qX<=1 && qX>=0 && qY<=1 && qY>=0 && qZ<=1 && qZ>=0 ) return true;
|
206 |
182 |
}
|
... | ... | |
212 |
188 |
|
213 |
189 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
214 |
190 |
|
215 |
|
public Static2D newRotation(Static4D rotQuaternion, float x, float y)
|
|
191 |
public Static2D newRotation(Static4D rotatedTouchPoint)
|
216 |
192 |
{
|
217 |
193 |
float cubeHalfSize= RubikCube.CUBE_SCREEN_RATIO*0.5f;
|
218 |
194 |
|
219 |
|
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
|
195 |
mPoint[0] = rotatedTouchPoint.get1();
|
|
196 |
mPoint[1] = rotatedTouchPoint.get2();
|
|
197 |
mPoint[2] = rotatedTouchPoint.get3();
|
|
198 |
|
220 |
199 |
castTouchPointOntoFace(mLastTouchedFace,cubeHalfSize,mDiff);
|
221 |
200 |
|
222 |
|
mDiff[0] -= mTouchPointCastOntoFace[0];
|
223 |
|
mDiff[1] -= mTouchPointCastOntoFace[1];
|
224 |
|
mDiff[2] -= mTouchPointCastOntoFace[2];
|
|
201 |
mDiff[0] -= mTouch[0];
|
|
202 |
mDiff[1] -= mTouch[1];
|
|
203 |
mDiff[2] -= mTouch[2];
|
225 |
204 |
|
226 |
205 |
int xAxis = retFaceXaxis(mLastTouchedFace);
|
227 |
206 |
int yAxis = retFaceYaxis(mLastTouchedFace);
|
228 |
207 |
mRotationVect = (isVertical( mDiff[xAxis], mDiff[yAxis]) ? VECT[xAxis]:VECT[yAxis]);
|
229 |
|
float offset= (mTouchPointCastOntoFace[mRotationVect]+cubeHalfSize)/(2*cubeHalfSize);
|
|
208 |
float offset= (mTouch[mRotationVect]+cubeHalfSize)/(2*cubeHalfSize);
|
230 |
209 |
|
231 |
|
mTouchPoint[0] = mPoint[0];
|
232 |
|
mTouchPoint[1] = mPoint[1];
|
233 |
|
mTouchPoint[2] = mPoint[2];
|
|
210 |
mTouch[0] = mPoint[0];
|
|
211 |
mTouch[1] = mPoint[1];
|
|
212 |
mTouch[2] = mPoint[2];
|
234 |
213 |
|
235 |
214 |
return new Static2D(mRotationVect,offset);
|
236 |
215 |
}
|
237 |
216 |
|
238 |
217 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
239 |
218 |
|
240 |
|
public float continueRotation(Static4D rotQuaternion, float x, float y)
|
|
219 |
public float continueRotation(Static4D rotatedTouchPoint)
|
241 |
220 |
{
|
242 |
|
convertTouchPointToScreenSpace(rotQuaternion,x,y);
|
243 |
|
|
244 |
|
mDiff[0] = mPoint[0]-mTouchPoint[0];
|
245 |
|
mDiff[1] = mPoint[1]-mTouchPoint[1];
|
246 |
|
mDiff[2] = mPoint[2]-mTouchPoint[2];
|
|
221 |
mDiff[0] = rotatedTouchPoint.get1()-mTouch[0];
|
|
222 |
mDiff[1] = rotatedTouchPoint.get2()-mTouch[1];
|
|
223 |
mDiff[2] = rotatedTouchPoint.get3()-mTouch[2];
|
247 |
224 |
|
248 |
225 |
int xAxis= retFaceXaxis(mLastTouchedFace);
|
249 |
226 |
int yAxis= retFaceYaxis(mLastTouchedFace);
|
Movement.