Revision d4374cd3
Added by Leszek Koltunski about 5 years ago
src/main/java/org/distorted/examples/rubik/RubikSurfaceView.java | ||
---|---|---|
45 | 45 |
|
46 | 46 |
private static final int[] VECT = {VECTX,VECTY,VECTZ}; |
47 | 47 |
|
48 |
private boolean mDragging, mBeginRot;
|
|
48 |
private boolean mDragging, mBeginningRotation, mContinuingRotation;
|
|
49 | 49 |
private int mX, mY; |
50 | 50 |
private Static4D mQuatCurrent, mQuatAccumulated; |
51 | 51 |
private int mRotationVect; |
... | ... | |
107 | 107 |
mY = y; |
108 | 108 |
mLastTouchedFace = faceTouched(x,y); |
109 | 109 |
|
110 |
if( mLastTouchedFace != NONE ) { mBeginRot = true; mDragging = false; } |
|
111 |
else { mDragging = true; mBeginRot = false; } |
|
110 |
if( mLastTouchedFace != NONE ) |
|
111 |
{ |
|
112 |
mDragging = false; |
|
113 |
mBeginningRotation = mRenderer.canRotate(); |
|
114 |
mContinuingRotation = false; |
|
115 |
} |
|
116 |
else |
|
117 |
{ |
|
118 |
mDragging = true; |
|
119 |
mBeginningRotation = false; |
|
120 |
mContinuingRotation = false; |
|
121 |
} |
|
112 | 122 |
break; |
113 | 123 |
case MotionEvent.ACTION_MOVE: if( mDragging ) |
114 | 124 |
{ |
115 | 125 |
mQuatCurrent.set(quatFromDrag(mX-x,mY-y)); |
116 | 126 |
mRenderer.setQuatCurrent(mQuatCurrent); |
117 | 127 |
} |
118 |
else if( mBeginRot )
|
|
128 |
if( mBeginningRotation )
|
|
119 | 129 |
{ |
120 | 130 |
int minimumDistToStartRotating = (mScreenMin*mScreenMin)/100; |
121 | 131 |
|
122 | 132 |
if( (mX-x)*(mX-x)+(mY-y)*(mY-y) > minimumDistToStartRotating ) |
123 | 133 |
{ |
124 | 134 |
addNewRotation(x,y); |
125 |
mBeginRot = false; |
|
135 |
mBeginningRotation = false; |
|
136 |
mContinuingRotation= true; |
|
126 | 137 |
} |
127 | 138 |
} |
128 |
else |
|
139 |
else if( mContinuingRotation )
|
|
129 | 140 |
{ |
130 | 141 |
continueRotation(x,y); |
131 | 142 |
} |
132 | 143 |
break; |
133 |
case MotionEvent.ACTION_UP : if( !mDragging ) finishRotation(); |
|
134 |
mQuatAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated)); |
|
135 |
mQuatCurrent.set(0f, 0f, 0f, 1f); |
|
136 |
mRenderer.setQuatCurrent(mQuatCurrent); |
|
137 |
mRenderer.setQuatAccumulated(mQuatAccumulated); |
|
144 |
case MotionEvent.ACTION_UP : if( mDragging ) |
|
145 |
{ |
|
146 |
mQuatAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated)); |
|
147 |
mQuatCurrent.set(0f, 0f, 0f, 1f); |
|
148 |
mRenderer.setQuatCurrent(mQuatCurrent); |
|
149 |
mRenderer.setQuatAccumulated(mQuatAccumulated); |
|
150 |
} |
|
151 |
|
|
152 |
if( mContinuingRotation ) |
|
153 |
{ |
|
154 |
finishRotation(); |
|
155 |
} |
|
156 |
|
|
138 | 157 |
break; |
139 | 158 |
} |
140 | 159 |
|
Also available in: Unified diff
RubikCube: make the post-rotation effect 'nice'.