1 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2019 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Magic Cube. //
|
5 |
|
|
// //
|
6 |
|
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7 |
|
|
// it under the terms of the GNU General Public License as published by //
|
8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
9 |
|
|
// (at your option) any later version. //
|
10 |
|
|
// //
|
11 |
|
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12 |
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14 |
|
|
// GNU General Public License for more details. //
|
15 |
|
|
// //
|
16 |
|
|
// You should have received a copy of the GNU General Public License //
|
17 |
|
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
|
|
package org.distorted.objectlib.main;
|
21 |
|
|
|
22 |
e1a86bf2
|
Leszek Koltunski
|
import java.io.InputStream;
|
23 |
|
|
|
24 |
b3fff6fb
|
Leszek Koltunski
|
import android.app.Activity;
|
25 |
9276dced
|
Leszek Koltunski
|
import android.content.SharedPreferences;
|
26 |
880beeea
|
Leszek Koltunski
|
import android.util.DisplayMetrics;
|
27 |
|
|
import android.view.MotionEvent;
|
28 |
|
|
|
29 |
|
|
import org.distorted.library.main.QuatHelper;
|
30 |
|
|
import org.distorted.library.type.Static4D;
|
31 |
|
|
|
32 |
2fca02cf
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.BlockController;
|
33 |
9276dced
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.MovesFinished;
|
34 |
b3fff6fb
|
Leszek Koltunski
|
import org.distorted.objectlib.helpers.ObjectLibInterface;
|
35 |
c9c71c3f
|
Leszek Koltunski
|
import org.distorted.objectlib.touchcontrol.TouchControl;
|
36 |
11fa413d
|
Leszek Koltunski
|
import org.distorted.objectlib.touchcontrol.TouchControlShapeChanging;
|
37 |
880beeea
|
Leszek Koltunski
|
|
38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
39 |
|
|
|
40 |
|
|
public class ObjectControl
|
41 |
|
|
{
|
42 |
|
|
public static final int NUM_SPEED_PROBES = 10;
|
43 |
|
|
public static final int INVALID_POINTER_ID = -1;
|
44 |
|
|
|
45 |
|
|
public static final int MODE_ROTATE = 0;
|
46 |
|
|
public static final int MODE_DRAG = 1;
|
47 |
|
|
public static final int MODE_REPLACE = 2;
|
48 |
|
|
|
49 |
|
|
// Moving the finger from the middle of the vertical screen to the right edge will rotate a
|
50 |
|
|
// given face by SWIPING_SENSITIVITY/2 degrees.
|
51 |
|
|
public final static int SWIPING_SENSITIVITY = 240;
|
52 |
|
|
// Moving the finger by 0.3 of an inch will start a Rotation.
|
53 |
|
|
public final static float ROTATION_SENSITIVITY = 0.3f;
|
54 |
|
|
|
55 |
|
|
private final Static4D CAMERA_POINT = new Static4D(0, 0, 0, 0);
|
56 |
|
|
|
57 |
b3fff6fb
|
Leszek Koltunski
|
private final ObjectLibInterface mInterface;
|
58 |
880beeea
|
Leszek Koltunski
|
private final ObjectPreRender mPreRender;
|
59 |
11fa413d
|
Leszek Koltunski
|
private TouchControl mTouchControl, mTouchControlBackup;
|
60 |
7ba38dd4
|
Leszek Koltunski
|
private TwistyObjectNode mObjectNode;
|
61 |
880beeea
|
Leszek Koltunski
|
private boolean mDragging, mBeginningRotation, mContinuingRotation;
|
62 |
|
|
private int mScreenWidth, mScreenHeight, mScreenMin;
|
63 |
72d6857c
|
Leszek Koltunski
|
private float mMoveX, mMoveY;
|
64 |
11fa413d
|
Leszek Koltunski
|
private int mLastMode;
|
65 |
880beeea
|
Leszek Koltunski
|
|
66 |
|
|
private float mRotAngle, mInitDistance;
|
67 |
|
|
private float mStartRotX, mStartRotY;
|
68 |
|
|
private float mRotationFactor;
|
69 |
|
|
private int mCurrentAxis, mCurrentRow;
|
70 |
|
|
private float mCurrentAngle, mCurrRotSpeed;
|
71 |
|
|
private final float[] mLastX;
|
72 |
|
|
private final float[] mLastY;
|
73 |
|
|
private final long[] mLastT;
|
74 |
|
|
private int mFirstIndex, mLastIndex;
|
75 |
|
|
private final int mDensity;
|
76 |
|
|
|
77 |
|
|
private int mPointer1, mPointer2;
|
78 |
|
|
private float mX1, mY1, mX2, mY2, mX, mY;
|
79 |
046104f5
|
Leszek Koltunski
|
private final boolean mIsAutomatic;
|
80 |
880beeea
|
Leszek Koltunski
|
|
81 |
b9956428
|
Leszek Koltunski
|
private boolean mIsLocked, mRemLocked;
|
82 |
57ef6378
|
Leszek Koltunski
|
private final int[] mBuffer;
|
83 |
|
|
private final float[] mAxis;
|
84 |
3bf19410
|
Leszek Koltunski
|
private int mMeshState, mIconMode;
|
85 |
4a389a4e
|
Leszek Koltunski
|
private boolean mRotateOnCreation;
|
86 |
b9956428
|
Leszek Koltunski
|
|
87 |
880beeea
|
Leszek Koltunski
|
private static final Static4D mQuat= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
|
88 |
|
|
private static final Static4D mTemp= new Static4D(0,0,0,1);
|
89 |
|
|
|
90 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
91 |
|
|
|
92 |
|
|
private void addSpeedProbe(float x, float y)
|
93 |
|
|
{
|
94 |
|
|
long currTime = System.currentTimeMillis();
|
95 |
|
|
boolean theSame = mLastIndex==mFirstIndex;
|
96 |
|
|
|
97 |
|
|
mLastIndex++;
|
98 |
|
|
if( mLastIndex>=NUM_SPEED_PROBES ) mLastIndex=0;
|
99 |
|
|
|
100 |
|
|
mLastT[mLastIndex] = currTime;
|
101 |
|
|
mLastX[mLastIndex] = x;
|
102 |
|
|
mLastY[mLastIndex] = y;
|
103 |
|
|
|
104 |
|
|
if( mLastIndex==mFirstIndex)
|
105 |
|
|
{
|
106 |
|
|
mFirstIndex++;
|
107 |
|
|
if( mFirstIndex>=NUM_SPEED_PROBES ) mFirstIndex=0;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
if( theSame )
|
111 |
|
|
{
|
112 |
|
|
mLastT[mFirstIndex] = currTime;
|
113 |
|
|
mLastX[mFirstIndex] = x;
|
114 |
|
|
mLastY[mFirstIndex] = y;
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
119 |
|
|
|
120 |
|
|
private void computeCurrentSpeedInInchesPerSecond()
|
121 |
|
|
{
|
122 |
|
|
long firstTime = mLastT[mFirstIndex];
|
123 |
|
|
long lastTime = mLastT[mLastIndex];
|
124 |
|
|
float fX = mLastX[mFirstIndex];
|
125 |
|
|
float fY = mLastY[mFirstIndex];
|
126 |
|
|
float lX = mLastX[mLastIndex];
|
127 |
|
|
float lY = mLastY[mLastIndex];
|
128 |
|
|
|
129 |
|
|
long timeDiff = lastTime-firstTime;
|
130 |
|
|
|
131 |
|
|
mLastIndex = 0;
|
132 |
|
|
mFirstIndex= 0;
|
133 |
|
|
|
134 |
78108318
|
Leszek Koltunski
|
mCurrRotSpeed = timeDiff>0 ? 1000*retFingerDragDistanceInInches(fX-lX,fY-lY)/timeDiff : 0;
|
135 |
880beeea
|
Leszek Koltunski
|
}
|
136 |
|
|
|
137 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
138 |
|
|
|
139 |
78108318
|
Leszek Koltunski
|
private float retFingerDragDistanceInInches(float xd, float yd)
|
140 |
880beeea
|
Leszek Koltunski
|
{
|
141 |
78108318
|
Leszek Koltunski
|
float xDist = mScreenWidth*xd;
|
142 |
|
|
float yDist = mScreenHeight*yd;
|
143 |
880beeea
|
Leszek Koltunski
|
float distInPixels = (float)Math.sqrt(xDist*xDist + yDist*yDist);
|
144 |
|
|
|
145 |
|
|
return distInPixels/mDensity;
|
146 |
|
|
}
|
147 |
|
|
|
148 |
3d093961
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149 |
|
|
|
150 |
57ef6378
|
Leszek Koltunski
|
private void replaceMode(boolean down)
|
151 |
3d093961
|
Leszek Koltunski
|
{
|
152 |
|
|
mBeginningRotation= false;
|
153 |
|
|
|
154 |
|
|
if( down )
|
155 |
|
|
{
|
156 |
11fa413d
|
Leszek Koltunski
|
int cubit = mTouchControl.getTouchedCubit();
|
157 |
|
|
int face = mTouchControl.getTouchedCubitFace();
|
158 |
|
|
mInterface.onReplaceModeDown(cubit,face);
|
159 |
3d093961
|
Leszek Koltunski
|
}
|
160 |
|
|
}
|
161 |
|
|
|
162 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
11fa413d
|
Leszek Koltunski
|
private void setUpDragOrRotate(boolean down, float x, float y)
|
165 |
880beeea
|
Leszek Koltunski
|
{
|
166 |
11fa413d
|
Leszek Koltunski
|
if( mLastMode==MODE_DRAG )
|
167 |
880beeea
|
Leszek Koltunski
|
{
|
168 |
|
|
mDragging = true;
|
169 |
|
|
mBeginningRotation = false;
|
170 |
|
|
mContinuingRotation = false;
|
171 |
|
|
}
|
172 |
|
|
else
|
173 |
|
|
{
|
174 |
57ef6378
|
Leszek Koltunski
|
CAMERA_POINT.set2( mObjectNode.getCameraDist() );
|
175 |
880beeea
|
Leszek Koltunski
|
Static4D touchPoint = new Static4D(x, y, 0, 0);
|
176 |
|
|
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
|
177 |
|
|
Static4D rotatedCamera= QuatHelper.rotateVectorByInvertedQuat(CAMERA_POINT, mQuat);
|
178 |
|
|
|
179 |
57ef6378
|
Leszek Koltunski
|
if( mTouchControl!=null && mTouchControl.objectTouched(rotatedTouchPoint,rotatedCamera) )
|
180 |
880beeea
|
Leszek Koltunski
|
{
|
181 |
|
|
mDragging = false;
|
182 |
|
|
mContinuingRotation = false;
|
183 |
|
|
|
184 |
11fa413d
|
Leszek Koltunski
|
if( mLastMode==MODE_ROTATE ) mBeginningRotation = !mPreRender.isTouchBlocked();
|
185 |
|
|
else if( mLastMode==MODE_REPLACE ) replaceMode(down);
|
186 |
880beeea
|
Leszek Koltunski
|
}
|
187 |
|
|
else
|
188 |
|
|
{
|
189 |
b9956428
|
Leszek Koltunski
|
mDragging = (!mIsLocked || mIsAutomatic);
|
190 |
880beeea
|
Leszek Koltunski
|
mBeginningRotation = false;
|
191 |
|
|
mContinuingRotation = false;
|
192 |
b3fff6fb
|
Leszek Koltunski
|
if( !mDragging ) mInterface.failedToDrag();
|
193 |
880beeea
|
Leszek Koltunski
|
}
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
|
199 |
|
|
private void drag(float x, float y)
|
200 |
|
|
{
|
201 |
|
|
if( mPointer1!=INVALID_POINTER_ID && mPointer2!=INVALID_POINTER_ID)
|
202 |
|
|
{
|
203 |
|
|
float x2 = (mX2 - mScreenWidth*0.5f)/mScreenMin;
|
204 |
|
|
float y2 = (mScreenHeight*0.5f - mY2)/mScreenMin;
|
205 |
|
|
|
206 |
|
|
float angleNow = getAngle(x,y,x2,y2);
|
207 |
|
|
float angleDiff = angleNow-mRotAngle;
|
208 |
|
|
float sinA =-(float)Math.sin(angleDiff);
|
209 |
|
|
float cosA = (float)Math.cos(angleDiff);
|
210 |
|
|
|
211 |
|
|
Static4D dragQuat = QuatHelper.quatMultiply(new Static4D(0,0,sinA,cosA), mQuat);
|
212 |
|
|
mTemp.set(dragQuat);
|
213 |
|
|
|
214 |
|
|
mRotAngle = angleNow;
|
215 |
|
|
|
216 |
|
|
float distNow = (float)Math.sqrt( (x-x2)*(x-x2) + (y-y2)*(y-y2) );
|
217 |
|
|
float distQuot = mInitDistance<0 ? 1.0f : distNow/ mInitDistance;
|
218 |
|
|
mInitDistance = distNow;
|
219 |
|
|
TwistyObject object = mPreRender.getObject();
|
220 |
64c209f5
|
Leszek Koltunski
|
if( object!=null ) object.setObjectRatio(distQuot, mObjectNode.getMinSize() );
|
221 |
880beeea
|
Leszek Koltunski
|
}
|
222 |
|
|
else
|
223 |
|
|
{
|
224 |
|
|
Static4D dragQuat = QuatHelper.quatMultiply(QuatHelper.quatFromDrag(mX-x,y-mY), mQuat);
|
225 |
|
|
mTemp.set(dragQuat);
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
mPreRender.setQuatOnNextRender();
|
229 |
|
|
mX = x;
|
230 |
|
|
mY = y;
|
231 |
|
|
}
|
232 |
|
|
|
233 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
234 |
|
|
|
235 |
|
|
private void finishRotation()
|
236 |
|
|
{
|
237 |
2df35810
|
Leszek Koltunski
|
TwistyObject object = mPreRender.getObject();
|
238 |
beee90ab
|
Leszek Koltunski
|
int[][] angles = object.getBasicAngles();
|
239 |
880beeea
|
Leszek Koltunski
|
|
240 |
a1bcb301
|
Leszek Koltunski
|
if( mCurrentAxis<angles.length )
|
241 |
880beeea
|
Leszek Koltunski
|
{
|
242 |
a1bcb301
|
Leszek Koltunski
|
computeCurrentSpeedInInchesPerSecond();
|
243 |
beee90ab
|
Leszek Koltunski
|
int basic = angles[mCurrentAxis][mCurrentRow];
|
244 |
|
|
int angle = object.computeNearestAngle(basic,mCurrentAngle, mCurrRotSpeed);
|
245 |
a1bcb301
|
Leszek Koltunski
|
mPreRender.finishRotation(angle);
|
246 |
|
|
mPreRender.rememberMove(mCurrentAxis,mCurrentRow,angle);
|
247 |
|
|
|
248 |
|
|
if( angle!=0 )
|
249 |
|
|
{
|
250 |
beee90ab
|
Leszek Koltunski
|
int realAngle = (angle*basic)/360;
|
251 |
a1bcb301
|
Leszek Koltunski
|
mInterface.onFinishRotation(mCurrentAxis,mCurrentRow,realAngle);
|
252 |
|
|
}
|
253 |
880beeea
|
Leszek Koltunski
|
|
254 |
a1bcb301
|
Leszek Koltunski
|
mContinuingRotation = false;
|
255 |
|
|
mBeginningRotation = false;
|
256 |
|
|
mDragging = true;
|
257 |
|
|
}
|
258 |
880beeea
|
Leszek Koltunski
|
}
|
259 |
|
|
|
260 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
261 |
|
|
|
262 |
|
|
private void continueRotation(float x, float y)
|
263 |
|
|
{
|
264 |
|
|
float dx = x-mStartRotX;
|
265 |
|
|
float dy = y-mStartRotY;
|
266 |
57ef6378
|
Leszek Koltunski
|
float alpha = dx*mAxis[0] + dy*mAxis[1];
|
267 |
|
|
float x2 = dx - alpha*mAxis[0];
|
268 |
|
|
float y2 = dy - alpha*mAxis[1];
|
269 |
880beeea
|
Leszek Koltunski
|
|
270 |
|
|
float len = (float)Math.sqrt(x2*x2 + y2*y2);
|
271 |
|
|
|
272 |
|
|
// we have the length of 1D vector 'angle', now the direction:
|
273 |
57ef6378
|
Leszek Koltunski
|
float tmp = mAxis[1]==0 ? -mAxis[0]*y2 : mAxis[1]*x2;
|
274 |
880beeea
|
Leszek Koltunski
|
|
275 |
|
|
float angle = (tmp>0 ? 1:-1)*len*mRotationFactor;
|
276 |
|
|
mCurrentAngle = SWIPING_SENSITIVITY*angle;
|
277 |
|
|
mPreRender.getObject().continueRotation(mCurrentAngle);
|
278 |
|
|
|
279 |
|
|
addSpeedProbe(x2,y2);
|
280 |
|
|
}
|
281 |
|
|
|
282 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
283 |
|
|
|
284 |
|
|
private void beginRotation(float x, float y)
|
285 |
|
|
{
|
286 |
|
|
mStartRotX = x;
|
287 |
|
|
mStartRotY = y;
|
288 |
|
|
|
289 |
|
|
TwistyObject object = mPreRender.getObject();
|
290 |
a57e6870
|
Leszek Koltunski
|
int[] numLayers = object.getNumLayers();
|
291 |
880beeea
|
Leszek Koltunski
|
|
292 |
43a4ccff
|
Leszek Koltunski
|
Static4D touchPoint = new Static4D(x, y, 0, 0);
|
293 |
|
|
Static4D rotatedTouchPoint= QuatHelper.rotateVectorByInvertedQuat(touchPoint, mQuat);
|
294 |
cd2e8d4c
|
Leszek Koltunski
|
mTouchControl.newRotation(mBuffer,rotatedTouchPoint,mQuat);
|
295 |
880beeea
|
Leszek Koltunski
|
|
296 |
57ef6378
|
Leszek Koltunski
|
mCurrentAxis = mBuffer[0];
|
297 |
|
|
mCurrentRow = mBuffer[1];
|
298 |
880beeea
|
Leszek Koltunski
|
|
299 |
57ef6378
|
Leszek Koltunski
|
mTouchControl.getCastedRotAxis(mAxis,mQuat,mCurrentAxis);
|
300 |
c9c71c3f
|
Leszek Koltunski
|
mRotationFactor = mTouchControl.returnRotationFactor(numLayers,mCurrentRow);
|
301 |
880beeea
|
Leszek Koltunski
|
|
302 |
|
|
object.beginNewRotation( mCurrentAxis, mCurrentRow );
|
303 |
|
|
|
304 |
b3fff6fb
|
Leszek Koltunski
|
mInterface.onBeginRotation();
|
305 |
880beeea
|
Leszek Koltunski
|
|
306 |
|
|
addSpeedProbe(x,y);
|
307 |
|
|
|
308 |
|
|
mBeginningRotation = false;
|
309 |
|
|
mContinuingRotation= true;
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
313 |
|
|
|
314 |
|
|
private float getAngle(float x1, float y1, float x2, float y2)
|
315 |
|
|
{
|
316 |
|
|
return (float) Math.atan2(y1-y2, x1-x2);
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
320 |
|
|
|
321 |
|
|
private void prepareDown(MotionEvent event)
|
322 |
|
|
{
|
323 |
|
|
mPointer1 = event.getPointerId(0);
|
324 |
72d6857c
|
Leszek Koltunski
|
mX1 = event.getX() - mMoveX;
|
325 |
|
|
mY1 = event.getY() + mMoveY;
|
326 |
880beeea
|
Leszek Koltunski
|
mPointer2 = INVALID_POINTER_ID;
|
327 |
|
|
}
|
328 |
|
|
|
329 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
330 |
|
|
|
331 |
|
|
private void prepareMove(MotionEvent event)
|
332 |
|
|
{
|
333 |
|
|
int index1 = event.findPointerIndex(mPointer1);
|
334 |
|
|
|
335 |
|
|
if( index1>=0 )
|
336 |
|
|
{
|
337 |
72d6857c
|
Leszek Koltunski
|
mX1 = event.getX(index1) - mMoveX;
|
338 |
|
|
mY1 = event.getY(index1) + mMoveY;
|
339 |
880beeea
|
Leszek Koltunski
|
}
|
340 |
|
|
|
341 |
|
|
int index2 = event.findPointerIndex(mPointer2);
|
342 |
|
|
|
343 |
|
|
if( index2>=0 )
|
344 |
|
|
{
|
345 |
72d6857c
|
Leszek Koltunski
|
mX2 = event.getX(index2) - mMoveX;
|
346 |
|
|
mY2 = event.getY(index2) + mMoveY;
|
347 |
880beeea
|
Leszek Koltunski
|
}
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
351 |
|
|
|
352 |
|
|
private void prepareUp(MotionEvent event)
|
353 |
|
|
{
|
354 |
|
|
mPointer1 = INVALID_POINTER_ID;
|
355 |
|
|
mPointer2 = INVALID_POINTER_ID;
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
359 |
|
|
|
360 |
|
|
private void prepareDown2(MotionEvent event)
|
361 |
|
|
{
|
362 |
|
|
int index = event.getActionIndex();
|
363 |
|
|
|
364 |
|
|
if( mPointer1==INVALID_POINTER_ID )
|
365 |
|
|
{
|
366 |
|
|
mPointer1 = event.getPointerId(index);
|
367 |
72d6857c
|
Leszek Koltunski
|
mX1 = event.getX(index) - mMoveX;
|
368 |
|
|
mY1 = event.getY(index) + mMoveY;
|
369 |
880beeea
|
Leszek Koltunski
|
}
|
370 |
|
|
else if( mPointer2==INVALID_POINTER_ID )
|
371 |
|
|
{
|
372 |
|
|
mPointer2 = event.getPointerId(index);
|
373 |
72d6857c
|
Leszek Koltunski
|
mX2 = event.getX(index) - mMoveX;
|
374 |
|
|
mY2 = event.getY(index) + mMoveY;
|
375 |
880beeea
|
Leszek Koltunski
|
}
|
376 |
|
|
}
|
377 |
|
|
|
378 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
379 |
|
|
|
380 |
|
|
private void prepareUp2(MotionEvent event)
|
381 |
|
|
{
|
382 |
|
|
int index = event.getActionIndex();
|
383 |
|
|
|
384 |
|
|
if( index==event.findPointerIndex(mPointer1) ) mPointer1 = INVALID_POINTER_ID;
|
385 |
|
|
else if( index==event.findPointerIndex(mPointer2) ) mPointer2 = INVALID_POINTER_ID;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
389 |
|
|
|
390 |
11fa413d
|
Leszek Koltunski
|
private void actionMove(float x1, float y1, float x2, float y2)
|
391 |
880beeea
|
Leszek Koltunski
|
{
|
392 |
|
|
float pX = mPointer1 != INVALID_POINTER_ID ? x1 : x2;
|
393 |
|
|
float pY = mPointer1 != INVALID_POINTER_ID ? y1 : y2;
|
394 |
|
|
|
395 |
|
|
float x = (pX - mScreenWidth*0.5f)/mScreenMin;
|
396 |
|
|
float y = (mScreenHeight*0.5f -pY)/mScreenMin;
|
397 |
|
|
|
398 |
|
|
if( mBeginningRotation )
|
399 |
|
|
{
|
400 |
78108318
|
Leszek Koltunski
|
if( retFingerDragDistanceInInches(mX-x,mY-y) > ROTATION_SENSITIVITY )
|
401 |
880beeea
|
Leszek Koltunski
|
{
|
402 |
|
|
beginRotation(x,y);
|
403 |
|
|
}
|
404 |
|
|
}
|
405 |
|
|
else if( mContinuingRotation )
|
406 |
|
|
{
|
407 |
|
|
continueRotation(x,y);
|
408 |
|
|
}
|
409 |
|
|
else if( mDragging )
|
410 |
|
|
{
|
411 |
|
|
drag(x,y);
|
412 |
|
|
}
|
413 |
|
|
else
|
414 |
|
|
{
|
415 |
11fa413d
|
Leszek Koltunski
|
setUpDragOrRotate(false,x,y);
|
416 |
880beeea
|
Leszek Koltunski
|
}
|
417 |
|
|
}
|
418 |
|
|
|
419 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
420 |
|
|
|
421 |
11fa413d
|
Leszek Koltunski
|
private void actionDown(float x, float y)
|
422 |
880beeea
|
Leszek Koltunski
|
{
|
423 |
|
|
mX = (x - mScreenWidth*0.5f)/mScreenMin;
|
424 |
|
|
mY = (mScreenHeight*0.5f - y)/mScreenMin;
|
425 |
|
|
|
426 |
11fa413d
|
Leszek Koltunski
|
setUpDragOrRotate(true,mX,mY);
|
427 |
880beeea
|
Leszek Koltunski
|
}
|
428 |
|
|
|
429 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
430 |
|
|
|
431 |
|
|
private void actionUp()
|
432 |
|
|
{
|
433 |
|
|
if( mContinuingRotation )
|
434 |
|
|
{
|
435 |
|
|
finishRotation();
|
436 |
|
|
}
|
437 |
|
|
|
438 |
11fa413d
|
Leszek Koltunski
|
if( mLastMode==MODE_REPLACE ) mInterface.onReplaceModeUp();
|
439 |
880beeea
|
Leszek Koltunski
|
}
|
440 |
|
|
|
441 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
442 |
|
|
|
443 |
|
|
private void actionDown2(float x1, float y1, float x2, float y2)
|
444 |
|
|
{
|
445 |
|
|
mRotAngle = getAngle(x1,-y1, x2,-y2);
|
446 |
|
|
mInitDistance = -1;
|
447 |
|
|
|
448 |
|
|
mX = (x1 - mScreenWidth*0.5f )/mScreenMin;
|
449 |
|
|
mY = (mScreenHeight*0.5f - y1)/mScreenMin;
|
450 |
|
|
|
451 |
|
|
if( mBeginningRotation )
|
452 |
|
|
{
|
453 |
|
|
mContinuingRotation = false;
|
454 |
|
|
mBeginningRotation = false;
|
455 |
|
|
mDragging = true;
|
456 |
|
|
}
|
457 |
|
|
else if( mContinuingRotation )
|
458 |
|
|
{
|
459 |
|
|
finishRotation();
|
460 |
|
|
}
|
461 |
|
|
}
|
462 |
|
|
|
463 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
464 |
|
|
|
465 |
|
|
private void actionUp2(boolean p1isUp, float x1, float y1, boolean p2isUp, float x2, float y2)
|
466 |
|
|
{
|
467 |
|
|
if( p1isUp )
|
468 |
|
|
{
|
469 |
|
|
mX = (x2 - mScreenWidth*0.5f)/mScreenMin;
|
470 |
|
|
mY = (mScreenHeight*0.5f - y2)/mScreenMin;
|
471 |
|
|
}
|
472 |
|
|
if( p2isUp )
|
473 |
|
|
{
|
474 |
|
|
mX = (x1 - mScreenWidth*0.5f)/mScreenMin;
|
475 |
|
|
mY = (mScreenHeight*0.5f - y1)/mScreenMin;
|
476 |
|
|
}
|
477 |
|
|
}
|
478 |
|
|
|
479 |
a20e56fc
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
480 |
|
|
|
481 |
|
|
private void switchTouchControl(int oldMode, int newMode)
|
482 |
|
|
{
|
483 |
|
|
if( newMode==MODE_REPLACE )
|
484 |
|
|
{
|
485 |
|
|
if( mTouchControlBackup!=null )
|
486 |
|
|
{
|
487 |
|
|
TouchControl tmp = mTouchControlBackup;
|
488 |
|
|
mTouchControlBackup = mTouchControl;
|
489 |
|
|
mTouchControl = tmp;
|
490 |
|
|
}
|
491 |
|
|
else
|
492 |
|
|
{
|
493 |
|
|
mTouchControlBackup = mTouchControl;
|
494 |
|
|
TwistyObject object = getObject();
|
495 |
|
|
mTouchControl = new TouchControlShapeChanging(object);
|
496 |
|
|
float ratio = object.getObjectRatio();
|
497 |
|
|
mTouchControl.setObjectRatio(ratio);
|
498 |
|
|
}
|
499 |
|
|
}
|
500 |
|
|
if( oldMode==MODE_REPLACE )
|
501 |
|
|
{
|
502 |
|
|
if( mTouchControlBackup!=null )
|
503 |
|
|
{
|
504 |
|
|
TouchControl tmp = mTouchControlBackup;
|
505 |
|
|
mTouchControlBackup = mTouchControl;
|
506 |
|
|
mTouchControl = tmp;
|
507 |
|
|
}
|
508 |
|
|
else
|
509 |
|
|
{
|
510 |
|
|
mTouchControlBackup = mTouchControl;
|
511 |
|
|
TwistyObject object = getObject();
|
512 |
|
|
mTouchControl = object.getTouchControl();
|
513 |
|
|
float ratio = object.getObjectRatio();
|
514 |
|
|
mTouchControl.setObjectRatio(ratio);
|
515 |
|
|
}
|
516 |
|
|
}
|
517 |
|
|
}
|
518 |
|
|
|
519 |
e32d318a
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
520 |
|
|
|
521 |
11fa413d
|
Leszek Koltunski
|
void setTouchControl(TwistyObject object)
|
522 |
e32d318a
|
Leszek Koltunski
|
{
|
523 |
11fa413d
|
Leszek Koltunski
|
if( mLastMode!=MODE_REPLACE ) mTouchControl = object.getTouchControl();
|
524 |
|
|
else mTouchControl = new TouchControlShapeChanging(object);
|
525 |
e32d318a
|
Leszek Koltunski
|
}
|
526 |
|
|
|
527 |
9276dced
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
528 |
|
|
// INTERNAL API (for AutomaticControl)
|
529 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
530 |
|
|
|
531 |
|
|
public ObjectPreRender getPreRender()
|
532 |
|
|
{
|
533 |
|
|
return mPreRender;
|
534 |
|
|
}
|
535 |
|
|
|
536 |
b3fff6fb
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
537 |
|
|
|
538 |
|
|
public ObjectLibInterface getInterface()
|
539 |
|
|
{
|
540 |
|
|
return mInterface;
|
541 |
|
|
}
|
542 |
|
|
|
543 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
544 |
|
|
// PUBLIC API
|
545 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
546 |
|
|
|
547 |
b3fff6fb
|
Leszek Koltunski
|
public ObjectControl(Activity act, ObjectLibInterface actioner)
|
548 |
880beeea
|
Leszek Koltunski
|
{
|
549 |
|
|
mIsAutomatic = false;
|
550 |
|
|
|
551 |
57ef6378
|
Leszek Koltunski
|
mBuffer = new int[2];
|
552 |
|
|
mAxis = new float[2];
|
553 |
|
|
|
554 |
11fa413d
|
Leszek Koltunski
|
mCurrRotSpeed= 0.0f;
|
555 |
|
|
mLastMode = -1;
|
556 |
4a389a4e
|
Leszek Koltunski
|
mRotateOnCreation = false;
|
557 |
880beeea
|
Leszek Koltunski
|
|
558 |
|
|
mLastX = new float[NUM_SPEED_PROBES];
|
559 |
|
|
mLastY = new float[NUM_SPEED_PROBES];
|
560 |
|
|
mLastT = new long[NUM_SPEED_PROBES];
|
561 |
c3a033e9
|
Leszek Koltunski
|
mFirstIndex= 0;
|
562 |
|
|
mLastIndex = 0;
|
563 |
|
|
mMeshState =-1;
|
564 |
3bf19410
|
Leszek Koltunski
|
mIconMode =-1;
|
565 |
880beeea
|
Leszek Koltunski
|
|
566 |
|
|
DisplayMetrics dm = new DisplayMetrics();
|
567 |
|
|
act.getWindowManager().getDefaultDisplay().getMetrics(dm);
|
568 |
|
|
|
569 |
|
|
mDensity = dm.densityDpi;
|
570 |
|
|
|
571 |
15e5214c
|
Leszek Koltunski
|
mPreRender = new ObjectPreRender(act,this,actioner);
|
572 |
b3fff6fb
|
Leszek Koltunski
|
mInterface = actioner;
|
573 |
880beeea
|
Leszek Koltunski
|
}
|
574 |
|
|
|
575 |
4a389a4e
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
576 |
|
|
|
577 |
|
|
public void setRotateOnCreation(boolean rotate)
|
578 |
|
|
{
|
579 |
|
|
mRotateOnCreation = rotate;
|
580 |
|
|
}
|
581 |
|
|
|
582 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
583 |
|
|
|
584 |
|
|
public boolean getRotateOnCreation()
|
585 |
|
|
{
|
586 |
|
|
return mRotateOnCreation;
|
587 |
|
|
}
|
588 |
|
|
|
589 |
7ba38dd4
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
590 |
|
|
|
591 |
|
|
public TwistyObjectNode getNode()
|
592 |
|
|
{
|
593 |
|
|
return mObjectNode;
|
594 |
|
|
}
|
595 |
|
|
|
596 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
597 |
|
|
|
598 |
|
|
public void createNode(int width, int height)
|
599 |
|
|
{
|
600 |
|
|
if( mObjectNode==null ) mObjectNode = new TwistyObjectNode(width,height);
|
601 |
|
|
}
|
602 |
|
|
|
603 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
604 |
|
|
|
605 |
|
|
public void setScreenSize(int width, int height)
|
606 |
|
|
{
|
607 |
|
|
mScreenWidth = width;
|
608 |
|
|
mScreenHeight= height;
|
609 |
7ba38dd4
|
Leszek Koltunski
|
mScreenMin = Math.min(width,height);
|
610 |
|
|
|
611 |
45e0065d
|
Leszek Koltunski
|
if( mObjectNode!=null ) mObjectNode.setSize(width,height);
|
612 |
|
|
|
613 |
7fe64077
|
Leszek Koltunski
|
TwistyObject object = mPreRender.getObject();
|
614 |
fd6e2b3b
|
Leszek Koltunski
|
|
615 |
|
|
if( object!=null )
|
616 |
|
|
{
|
617 |
|
|
object.setTexture();
|
618 |
45e0065d
|
Leszek Koltunski
|
object.setNodeSize(mScreenMin);
|
619 |
fd6e2b3b
|
Leszek Koltunski
|
}
|
620 |
880beeea
|
Leszek Koltunski
|
}
|
621 |
|
|
|
622 |
ecf3d6e3
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
623 |
|
|
|
624 |
64c209f5
|
Leszek Koltunski
|
public void setObjectMove(int xmove, int ymove)
|
625 |
ecf3d6e3
|
Leszek Koltunski
|
{
|
626 |
72d6857c
|
Leszek Koltunski
|
mMoveX = xmove;
|
627 |
|
|
mMoveY = ymove;
|
628 |
|
|
|
629 |
|
|
mPreRender.setMove(xmove,ymove);
|
630 |
ecf3d6e3
|
Leszek Koltunski
|
}
|
631 |
|
|
|
632 |
64c209f5
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
633 |
|
|
|
634 |
|
|
public void setObjectScale(float scale)
|
635 |
|
|
{
|
636 |
|
|
mPreRender.setScale(scale);
|
637 |
|
|
}
|
638 |
|
|
|
639 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
640 |
|
|
|
641 |
2fca02cf
|
Leszek Koltunski
|
public void onPause()
|
642 |
|
|
{
|
643 |
|
|
BlockController.onPause();
|
644 |
|
|
}
|
645 |
|
|
|
646 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
647 |
|
|
|
648 |
|
|
public void onResume()
|
649 |
880beeea
|
Leszek Koltunski
|
{
|
650 |
|
|
mPointer1 = INVALID_POINTER_ID;
|
651 |
|
|
mPointer2 = INVALID_POINTER_ID;
|
652 |
b9956428
|
Leszek Koltunski
|
|
653 |
|
|
unlock();
|
654 |
2fca02cf
|
Leszek Koltunski
|
|
655 |
|
|
BlockController.onResume();
|
656 |
880beeea
|
Leszek Koltunski
|
}
|
657 |
|
|
|
658 |
2289cab1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
659 |
|
|
|
660 |
|
|
public void rotateNow(Static4D quat)
|
661 |
|
|
{
|
662 |
|
|
mTemp.set(quat);
|
663 |
|
|
mQuat.set(mTemp);
|
664 |
|
|
}
|
665 |
|
|
|
666 |
ee6bb8d7
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
667 |
|
|
|
668 |
|
|
public void scaleNow(float scale)
|
669 |
|
|
{
|
670 |
64c209f5
|
Leszek Koltunski
|
mPreRender.getObject().setObjectRatioNow(scale,mObjectNode.getMinSize() );
|
671 |
ee6bb8d7
|
Leszek Koltunski
|
}
|
672 |
|
|
|
673 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
674 |
|
|
|
675 |
|
|
public void setQuat()
|
676 |
|
|
{
|
677 |
|
|
mQuat.set(mTemp);
|
678 |
|
|
}
|
679 |
|
|
|
680 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
681 |
|
|
|
682 |
|
|
public Static4D getQuat()
|
683 |
|
|
{
|
684 |
|
|
return mQuat;
|
685 |
|
|
}
|
686 |
|
|
|
687 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
688 |
|
|
|
689 |
9276dced
|
Leszek Koltunski
|
public void preRender()
|
690 |
880beeea
|
Leszek Koltunski
|
{
|
691 |
9276dced
|
Leszek Koltunski
|
mPreRender.preRender();
|
692 |
|
|
}
|
693 |
|
|
|
694 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
695 |
|
|
|
696 |
|
|
public void blockEverything(int place)
|
697 |
|
|
{
|
698 |
b9956428
|
Leszek Koltunski
|
setLock(true);
|
699 |
9276dced
|
Leszek Koltunski
|
mPreRender.blockEverything(place);
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
703 |
|
|
|
704 |
|
|
public void blockTouch(int place)
|
705 |
|
|
{
|
706 |
b9956428
|
Leszek Koltunski
|
setLock(true);
|
707 |
9276dced
|
Leszek Koltunski
|
mPreRender.blockTouch(place);
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
711 |
|
|
|
712 |
|
|
public void unblockEverything()
|
713 |
|
|
{
|
714 |
b9956428
|
Leszek Koltunski
|
unsetLock();
|
715 |
9276dced
|
Leszek Koltunski
|
mPreRender.unblockEverything();
|
716 |
|
|
}
|
717 |
|
|
|
718 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
719 |
|
|
|
720 |
|
|
public void unblockTouch()
|
721 |
|
|
{
|
722 |
b9956428
|
Leszek Koltunski
|
unsetLock();
|
723 |
9276dced
|
Leszek Koltunski
|
mPreRender.unblockTouch();
|
724 |
|
|
}
|
725 |
|
|
|
726 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
727 |
|
|
|
728 |
|
|
public void unblockUI()
|
729 |
|
|
{
|
730 |
|
|
mPreRender.unblockUI();
|
731 |
|
|
}
|
732 |
|
|
|
733 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
734 |
|
|
|
735 |
|
|
public boolean isTouchBlocked()
|
736 |
|
|
{
|
737 |
|
|
return mPreRender.isTouchBlocked();
|
738 |
|
|
}
|
739 |
|
|
|
740 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
741 |
|
|
|
742 |
|
|
public boolean isUINotBlocked()
|
743 |
|
|
{
|
744 |
|
|
return mPreRender.isUINotBlocked();
|
745 |
|
|
}
|
746 |
|
|
|
747 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
748 |
|
|
|
749 |
|
|
public void initializeObject(int[][] moves)
|
750 |
|
|
{
|
751 |
|
|
mPreRender.initializeObject(moves);
|
752 |
|
|
}
|
753 |
|
|
|
754 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
755 |
|
|
|
756 |
3bf19410
|
Leszek Koltunski
|
public void changeObject(int ordinal, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
|
757 |
9276dced
|
Leszek Koltunski
|
{
|
758 |
3bf19410
|
Leszek Koltunski
|
mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
|
759 |
9276dced
|
Leszek Koltunski
|
}
|
760 |
|
|
|
761 |
568d4698
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
762 |
|
|
|
763 |
3bf19410
|
Leszek Koltunski
|
public void changeIfDifferent(int ordinal, String oldName, int meshState, int iconMode, InputStream jsonStream, InputStream meshStream)
|
764 |
568d4698
|
Leszek Koltunski
|
{
|
765 |
e1a86bf2
|
Leszek Koltunski
|
TwistyObject object = mPreRender.getObject();
|
766 |
402038ae
|
Leszek Koltunski
|
String newName = object==null ? "" : object.getShortName();
|
767 |
e1a86bf2
|
Leszek Koltunski
|
|
768 |
3bf19410
|
Leszek Koltunski
|
if( !oldName.equals(newName) || mMeshState!=meshState || mIconMode!=iconMode )
|
769 |
e1a86bf2
|
Leszek Koltunski
|
{
|
770 |
c3a033e9
|
Leszek Koltunski
|
mMeshState = meshState;
|
771 |
3bf19410
|
Leszek Koltunski
|
mIconMode = iconMode;
|
772 |
|
|
mPreRender.changeObject(ordinal, meshState, iconMode, jsonStream, meshStream);
|
773 |
e1a86bf2
|
Leszek Koltunski
|
}
|
774 |
568d4698
|
Leszek Koltunski
|
}
|
775 |
|
|
|
776 |
9276dced
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
777 |
a20e56fc
|
Leszek Koltunski
|
// if one or more fingers currently touch the screen, and we just pressed the 'scramble' button, do
|
778 |
|
|
// not scramble - otherwise a kind of a cheat is possible where user touches the screen, starts
|
779 |
|
|
// scrambling, then lifts the finger and the act of lifting screws the scrambling - no further
|
780 |
|
|
// scrambles take any effect!
|
781 |
9276dced
|
Leszek Koltunski
|
|
782 |
|
|
public void scrambleObject(int num)
|
783 |
|
|
{
|
784 |
a20e56fc
|
Leszek Koltunski
|
if( !mBeginningRotation && !mContinuingRotation )
|
785 |
|
|
{
|
786 |
|
|
mPreRender.scrambleObject(num);
|
787 |
|
|
}
|
788 |
9276dced
|
Leszek Koltunski
|
}
|
789 |
|
|
|
790 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
791 |
|
|
|
792 |
|
|
public void solveObject()
|
793 |
|
|
{
|
794 |
|
|
mPreRender.solveObject();
|
795 |
|
|
}
|
796 |
|
|
|
797 |
17d623f1
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
798 |
|
|
|
799 |
|
|
public void solveOnly()
|
800 |
|
|
{
|
801 |
|
|
mPreRender.solveOnly();
|
802 |
|
|
}
|
803 |
|
|
|
804 |
9276dced
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
805 |
|
|
|
806 |
2df35810
|
Leszek Koltunski
|
public void addRotation(MovesFinished listener, int axis, int rowBitmap, int angle, int duration)
|
807 |
9276dced
|
Leszek Koltunski
|
{
|
808 |
|
|
mPreRender.addRotation(listener,axis,rowBitmap,angle,duration);
|
809 |
|
|
}
|
810 |
|
|
|
811 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
812 |
|
|
|
813 |
|
|
public void resetAllTextureMaps()
|
814 |
|
|
{
|
815 |
|
|
mPreRender.resetAllTextureMaps();
|
816 |
|
|
}
|
817 |
|
|
|
818 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
819 |
|
|
|
820 |
|
|
public TwistyObject getObject()
|
821 |
|
|
{
|
822 |
|
|
return mPreRender.getObject();
|
823 |
|
|
}
|
824 |
|
|
|
825 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
826 |
|
|
|
827 |
|
|
public void savePreferences(SharedPreferences.Editor editor)
|
828 |
|
|
{
|
829 |
|
|
mPreRender.savePreferences(editor);
|
830 |
|
|
}
|
831 |
|
|
|
832 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
833 |
|
|
|
834 |
|
|
public void restorePreferences(SharedPreferences preferences)
|
835 |
|
|
{
|
836 |
|
|
mPreRender.restorePreferences(preferences);
|
837 |
880beeea
|
Leszek Koltunski
|
}
|
838 |
c3a033e9
|
Leszek Koltunski
|
|
839 |
b9956428
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
840 |
|
|
|
841 |
81141862
|
Leszek Koltunski
|
public boolean retLocked()
|
842 |
b9956428
|
Leszek Koltunski
|
{
|
843 |
|
|
return mIsLocked;
|
844 |
|
|
}
|
845 |
|
|
|
846 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
847 |
|
|
|
848 |
81141862
|
Leszek Koltunski
|
public void toggleLock()
|
849 |
b9956428
|
Leszek Koltunski
|
{
|
850 |
|
|
mIsLocked = !mIsLocked;
|
851 |
|
|
}
|
852 |
|
|
|
853 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
854 |
|
|
|
855 |
81141862
|
Leszek Koltunski
|
public void unlock()
|
856 |
|
|
{
|
857 |
|
|
mIsLocked = false;
|
858 |
|
|
}
|
859 |
b9956428
|
Leszek Koltunski
|
|
860 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
861 |
|
|
|
862 |
81141862
|
Leszek Koltunski
|
public void setLock(boolean value)
|
863 |
|
|
{
|
864 |
|
|
mRemLocked = mIsLocked;
|
865 |
|
|
mIsLocked = value;
|
866 |
|
|
}
|
867 |
b9956428
|
Leszek Koltunski
|
|
868 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
869 |
|
|
|
870 |
81141862
|
Leszek Koltunski
|
public void unsetLock()
|
871 |
|
|
{
|
872 |
|
|
mIsLocked = mRemLocked;
|
873 |
|
|
}
|
874 |
880beeea
|
Leszek Koltunski
|
|
875 |
11fa413d
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
876 |
|
|
|
877 |
|
|
public void setTextureMap(int cubit, int face, int newColor)
|
878 |
|
|
{
|
879 |
|
|
mPreRender.setTextureMap(cubit,face,newColor);
|
880 |
|
|
}
|
881 |
|
|
|
882 |
880beeea
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
883 |
|
|
|
884 |
|
|
public boolean onTouchEvent(MotionEvent event, int mode)
|
885 |
|
|
{
|
886 |
53e85349
|
Leszek Koltunski
|
if( mObjectNode==null ) return true;
|
887 |
|
|
|
888 |
880beeea
|
Leszek Koltunski
|
int action = event.getActionMasked();
|
889 |
|
|
|
890 |
11fa413d
|
Leszek Koltunski
|
if( mode!=mLastMode)
|
891 |
|
|
{
|
892 |
|
|
switchTouchControl(mLastMode,mode);
|
893 |
|
|
mLastMode = mode;
|
894 |
|
|
}
|
895 |
|
|
|
896 |
880beeea
|
Leszek Koltunski
|
switch(action)
|
897 |
|
|
{
|
898 |
|
|
case MotionEvent.ACTION_DOWN : prepareDown(event);
|
899 |
11fa413d
|
Leszek Koltunski
|
actionDown(mX1, mY1);
|
900 |
880beeea
|
Leszek Koltunski
|
break;
|
901 |
|
|
case MotionEvent.ACTION_MOVE : prepareMove(event);
|
902 |
11fa413d
|
Leszek Koltunski
|
actionMove(mX1, mY1, mX2, mY2);
|
903 |
880beeea
|
Leszek Koltunski
|
break;
|
904 |
|
|
case MotionEvent.ACTION_UP : prepareUp(event);
|
905 |
|
|
actionUp();
|
906 |
|
|
break;
|
907 |
|
|
case MotionEvent.ACTION_POINTER_DOWN: prepareDown2(event);
|
908 |
|
|
actionDown2(mX1, mY1, mX2, mY2);
|
909 |
|
|
break;
|
910 |
|
|
case MotionEvent.ACTION_POINTER_UP : prepareUp2(event);
|
911 |
|
|
boolean p1isUp = mPointer1==INVALID_POINTER_ID;
|
912 |
|
|
boolean p2isUp = mPointer2==INVALID_POINTER_ID;
|
913 |
|
|
actionUp2(p1isUp, mX1, mY1, p2isUp, mX2, mY2);
|
914 |
|
|
break;
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
return true;
|
918 |
|
|
}
|
919 |
|
|
}
|