Revision af8b42cc
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java | ||
---|---|---|
32 | 32 |
|
33 | 33 |
class RubikSurfaceView extends GLSurfaceView |
34 | 34 |
{ |
35 |
// Moving the finger from the middle of the vertical screen to the right edge will rotate a |
|
36 |
// given face by SWIPING_SENSITIVITY/2 degrees. |
|
37 |
private final static int SWIPING_SENSITIVITY = 240; |
|
38 |
|
|
35 | 39 |
private final static int NONE =-1; |
36 | 40 |
private final static int FRONT = 0; // has to be 6 consecutive ints |
37 | 41 |
private final static int BACK = 1; // FRONT ... BOTTOM |
... | ... | |
41 | 45 |
private final static int BOTTOM = 5; // |
42 | 46 |
|
43 | 47 |
static final int VECTX = 0; // |
44 |
static final int VECTY = 1; // dont change this |
|
48 |
static final int VECTY = 1; // don't change this
|
|
45 | 49 |
static final int VECTZ = 2; // |
46 | 50 |
|
47 | 51 |
private static final int[] VECT = {VECTX,VECTY,VECTZ}; |
... | ... | |
51 | 55 |
private Static4D mQuatCurrent, mQuatAccumulated; |
52 | 56 |
private int mRotationVect; |
53 | 57 |
private RubikRenderer mRenderer; |
54 |
private RubikCube mCube; |
|
55 | 58 |
|
56 | 59 |
private float[] mPoint, mCamera, mTouchPointCastOntoFace, mDiff, mTouchPoint; // all in screen space |
57 | 60 |
private int mLastTouchedFace; |
... | ... | |
77 | 80 |
mScreenWidth = mScreenHeight = mScreenMin = 0; |
78 | 81 |
|
79 | 82 |
mRenderer = new RubikRenderer(this); |
80 |
mCube = mRenderer.getCube();
|
|
83 |
mRenderer.createCube(RubikActivity.DEFAULT_SIZE);
|
|
81 | 84 |
|
82 | 85 |
mQuatCurrent = new Static4D(0,0,0,1); |
83 | 86 |
mQuatAccumulated = mRenderer.initializeQuat(); |
... | ... | |
89 | 92 |
} |
90 | 93 |
} |
91 | 94 |
|
92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
93 |
|
|
94 |
public RubikRenderer getRenderer() |
|
95 |
{ |
|
96 |
return mRenderer; |
|
97 |
} |
|
98 |
|
|
99 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
100 | 96 |
|
101 | 97 |
@Override |
... | ... | |
168 | 164 |
|
169 | 165 |
void setNewCubeSize(int newCubeSize) |
170 | 166 |
{ |
171 |
android.util.Log.e("view", "new size="+newCubeSize);
|
|
167 |
mRenderer.createCube(newCubeSize);
|
|
172 | 168 |
} |
173 | 169 |
|
174 | 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
175 | 171 |
|
176 | 172 |
void scrambleCube() |
177 | 173 |
{ |
178 |
android.util.Log.e("view", "scrambling...");
|
|
174 |
mRenderer.scrambleCube();
|
|
179 | 175 |
} |
180 | 176 |
|
181 | 177 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
243 | 239 |
mTouchPoint[1] = mPoint[1]; |
244 | 240 |
mTouchPoint[2] = mPoint[2]; |
245 | 241 |
|
246 |
mCube.addNewRotation(mRotationVect,offset);
|
|
242 |
mRenderer.getCube().addNewRotation(mRotationVect,offset);
|
|
247 | 243 |
} |
248 | 244 |
|
249 | 245 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
254 | 250 |
} |
255 | 251 |
|
256 | 252 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
257 |
// 240 --> moving finger from the middle of the vertical screen to the right edge will rotate a |
|
258 |
// given face by 240/2 = 120 degrees. |
|
259 | 253 |
|
260 | 254 |
private void continueRotation(int x, int y) |
261 | 255 |
{ |
... | ... | |
270 | 264 |
int sign = retFaceRotationSign(mLastTouchedFace); |
271 | 265 |
float angle = (mRotationVect==xAxis ? mDiff[yAxis] : -mDiff[xAxis]); |
272 | 266 |
|
273 |
mCube.continueRotation(240.0f*sign*angle/mScreenMin);
|
|
267 |
mRenderer.getCube().continueRotation(SWIPING_SENSITIVITY*sign*angle/mScreenMin);
|
|
274 | 268 |
} |
275 | 269 |
|
276 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Port changes from the 'distorted-cube' target.