Revision 94cc96ff
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java | ||
---|---|---|
31 | 31 |
|
32 | 32 |
class RubikSurfaceView extends GLSurfaceView |
33 | 33 |
{ |
34 |
private final static int ERROR =-1;
|
|
34 |
private final static int NONE =-1;
|
|
35 | 35 |
private final static int FRONT = 0; |
36 | 36 |
private final static int BACK = 1; |
37 | 37 |
private final static int LEFT = 2; |
... | ... | |
42 | 42 |
private boolean mDragging; |
43 | 43 |
private int mX, mY; |
44 | 44 |
private int mTouchedRow, mTouchedCol, mTouchedSli; |
45 |
private Static4D mQuatCurrent, mQuatAccumulated; |
|
45 | 46 |
private RubikRenderer mRenderer; |
46 | 47 |
|
47 | 48 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
52 | 53 |
|
53 | 54 |
mDragging = false; |
54 | 55 |
mRenderer = new RubikRenderer(this); |
56 |
|
|
57 |
mQuatCurrent = new Static4D(0,0,0,1); |
|
58 |
mQuatAccumulated = mRenderer.initializeQuat(); |
|
59 |
|
|
55 | 60 |
final ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); |
56 | 61 |
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo(); |
57 | 62 |
setEGLContextClientVersion( (configurationInfo.reqGlEsVersion>>16) >= 3 ? 3:2 ); |
... | ... | |
76 | 81 |
|
77 | 82 |
switch(action) |
78 | 83 |
{ |
79 |
case MotionEvent.ACTION_DOWN: if( faceTouched(x,y) != ERROR )
|
|
84 |
case MotionEvent.ACTION_DOWN: if( faceTouched(x,y) != NONE )
|
|
80 | 85 |
{ |
81 | 86 |
mRenderer.abortLastEffect(); |
82 | 87 |
mRenderer.applyNewEffect(mTouchedCol, mTouchedRow, mTouchedSli); |
... | ... | |
88 | 93 |
mDragging = true; |
89 | 94 |
} |
90 | 95 |
break; |
91 |
case MotionEvent.ACTION_MOVE: if( mDragging ) mRenderer.mQuatCurrent.set(quatFromDrag(mX-x,mY-y)); |
|
96 |
case MotionEvent.ACTION_MOVE: if( mDragging ) |
|
97 |
{ |
|
98 |
mQuatCurrent.set(quatFromDrag(mX-x,mY-y)); |
|
99 |
mRenderer.setQuatCurrent(mQuatCurrent); |
|
100 |
} |
|
92 | 101 |
break; |
93 | 102 |
case MotionEvent.ACTION_UP : mDragging = false; |
94 |
mRenderer.mQuatAccumulated.set(quatMultiply(mRenderer.mQuatCurrent, mRenderer.mQuatAccumulated)); |
|
95 |
mRenderer.mQuatCurrent.set(0f, 0f, 0f, 1f); |
|
103 |
mQuatAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated)); |
|
104 |
mQuatCurrent.set(0f, 0f, 0f, 1f); |
|
105 |
|
|
106 |
mRenderer.setQuatCurrent(mQuatCurrent); |
|
107 |
mRenderer.setQuatAccumulated(mQuatAccumulated); |
|
96 | 108 |
break; |
97 | 109 |
} |
98 | 110 |
|
... | ... | |
164 | 176 |
if( absY>absX && absY>absZ ) return rotatedY>0 ? TOP:BOTTOM; |
165 | 177 |
if( absZ>absX && absZ>absY ) return rotatedZ>0 ? FRONT:BACK; |
166 | 178 |
|
167 |
return ERROR;
|
|
179 |
return NONE;
|
|
168 | 180 |
} |
169 | 181 |
|
170 | 182 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
194 | 206 |
|
195 | 207 |
private Static4D rotateVector(Static4D vector) |
196 | 208 |
{ |
197 |
float qx = mRenderer.mQuatAccumulated.get1();
|
|
198 |
float qy = mRenderer.mQuatAccumulated.get2();
|
|
199 |
float qz = mRenderer.mQuatAccumulated.get3();
|
|
200 |
float qw = mRenderer.mQuatAccumulated.get4();
|
|
209 |
float qx = mQuatAccumulated.get1(); |
|
210 |
float qy = mQuatAccumulated.get2(); |
|
211 |
float qz = mQuatAccumulated.get3(); |
|
212 |
float qw = mQuatAccumulated.get4(); |
|
201 | 213 |
|
202 | 214 |
Static4D quatInverted= new Static4D(-qx,-qy,-qz,qw); |
203 | 215 |
Static4D tmp = quatMultiply(quatInverted,vector); |
204 | 216 |
|
205 |
return quatMultiply(tmp,mRenderer.mQuatAccumulated);
|
|
217 |
return quatMultiply(tmp,mQuatAccumulated); |
|
206 | 218 |
} |
207 | 219 |
|
208 | 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
347 | 359 |
mTouchedCol = -1; |
348 | 360 |
mTouchedSli = -1; |
349 | 361 |
|
350 |
return ERROR;
|
|
362 |
return NONE;
|
|
351 | 363 |
} |
352 | 364 |
} |
353 | 365 |
|
Also available in: Unified diff
Improve the Rubik App.