Revision 8197c92d
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/magic/RubikCube.java | ||
|---|---|---|
| 393 | 393 |
|
| 394 | 394 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 395 | 395 |
|
| 396 |
float getSize()
|
|
| 396 |
int getSize()
|
|
| 397 | 397 |
{
|
| 398 | 398 |
return mSize; |
| 399 | 399 |
} |
| src/main/java/org/distorted/magic/RubikRenderer.java | ||
|---|---|---|
| 71 | 71 |
mFinishDragAccumulated = false; |
| 72 | 72 |
|
| 73 | 73 |
mCanRotate = true; |
| 74 |
|
|
| 75 |
mCube = new RubikCube( RubikActivity.DEFAULT_SIZE, mMove, mScale, mQuatCurrent, mQuatAccumulated); |
|
| 76 | 74 |
} |
| 77 | 75 |
|
| 78 | 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 164 | 162 |
|
| 165 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 166 | 164 |
|
| 167 |
private float computeFOV(float cameraDistance, int screenHeight)
|
|
| 168 |
{
|
|
| 169 |
double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) );
|
|
| 170 |
return (float)(2*halfFOVInRadians*(180/Math.PI));
|
|
| 171 |
}
|
|
| 165 |
private float computeFOV(float cameraDistance, int screenHeight) |
|
| 166 |
{
|
|
| 167 |
double halfFOVInRadians = Math.atan( screenHeight/(2*cameraDistance) ); |
|
| 168 |
return (float)(2*halfFOVInRadians*(180/Math.PI)); |
|
| 169 |
} |
|
| 172 | 170 |
|
| 173 | 171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 174 | 172 |
// no this will not race with onDrawFrame |
| 175 | 173 |
|
| 176 |
void finishRotation()
|
|
| 177 |
{
|
|
| 178 |
mFinishRotation = true;
|
|
| 179 |
}
|
|
| 174 |
void finishRotation() |
|
| 175 |
{
|
|
| 176 |
mFinishRotation = true; |
|
| 177 |
} |
|
| 180 | 178 |
|
| 181 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 182 | 180 |
|
| 183 |
float returnCubeSizeInScreenSpace() |
|
| 184 |
{
|
|
| 185 |
return mCubeSizeInScreenSpace; |
|
| 186 |
} |
|
| 181 |
void createCube(int newSize) |
|
| 182 |
{
|
|
| 183 |
int oldSize = mCube==null ? 0 : mCube.getSize(); |
|
| 184 |
|
|
| 185 |
if( oldSize!=newSize ) |
|
| 186 |
{
|
|
| 187 |
if( mCube!=null ) |
|
| 188 |
{
|
|
| 189 |
mScreen.detachAll(); |
|
| 190 |
} |
|
| 191 |
|
|
| 192 |
mCube = new RubikCube(newSize, mMove, mScale, mQuatCurrent, mQuatAccumulated); |
|
| 193 |
mCube.attachToScreen(mScreen); |
|
| 194 |
} |
|
| 195 |
} |
|
| 187 | 196 |
|
| 188 | 197 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 189 | 198 |
|
| 190 |
boolean canRotate()
|
|
| 191 |
{
|
|
| 192 |
return mCanRotate; |
|
| 193 |
}
|
|
| 199 |
void scrambleCube()
|
|
| 200 |
{
|
|
| 201 |
|
|
| 202 |
} |
|
| 194 | 203 |
|
| 195 | 204 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 196 | 205 |
|
| 197 |
RubikCube getCube() |
|
| 198 |
{
|
|
| 199 |
return mCube; |
|
| 200 |
} |
|
| 206 |
float returnCubeSizeInScreenSpace() |
|
| 207 |
{
|
|
| 208 |
return mCubeSizeInScreenSpace; |
|
| 209 |
} |
|
| 210 |
|
|
| 211 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 212 |
|
|
| 213 |
boolean canRotate() |
|
| 214 |
{
|
|
| 215 |
return mCanRotate; |
|
| 216 |
} |
|
| 217 |
|
|
| 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 219 |
|
|
| 220 |
RubikCube getCube() |
|
| 221 |
{
|
|
| 222 |
return mCube; |
|
| 223 |
} |
|
| 201 | 224 |
|
| 202 | 225 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 203 | 226 |
// Initial rotation of the cube. Something semi-random that looks good. |
| 204 | 227 |
|
| 205 |
Static4D initializeQuat()
|
|
| 206 |
{
|
|
| 207 |
return new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
|
|
| 208 |
}
|
|
| 228 |
Static4D initializeQuat() |
|
| 229 |
{
|
|
| 230 |
return new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f); |
|
| 231 |
} |
|
| 209 | 232 |
|
| 210 | 233 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 211 | 234 |
|
| 212 |
void setQuatCurrent(Static4D current)
|
|
| 213 |
{
|
|
| 214 |
mTempCurrent.set(current);
|
|
| 215 |
mFinishDragCurrent = true;
|
|
| 216 |
}
|
|
| 235 |
void setQuatCurrent(Static4D current) |
|
| 236 |
{
|
|
| 237 |
mTempCurrent.set(current); |
|
| 238 |
mFinishDragCurrent = true; |
|
| 239 |
} |
|
| 217 | 240 |
|
| 218 | 241 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 219 | 242 |
|
| 220 |
void setQuatAccumulated(Static4D accumulated)
|
|
| 221 |
{
|
|
| 222 |
mTempAccumulated.set(accumulated);
|
|
| 223 |
mFinishDragAccumulated = true;
|
|
| 224 |
}
|
|
| 243 |
void setQuatAccumulated(Static4D accumulated) |
|
| 244 |
{
|
|
| 245 |
mTempAccumulated.set(accumulated); |
|
| 246 |
mFinishDragAccumulated = true; |
|
| 247 |
} |
|
| 225 | 248 |
} |
| src/main/java/org/distorted/magic/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};
|
| ... | ... | |
| 77 | 81 |
mScreenWidth = mScreenHeight = mScreenMin = 0; |
| 78 | 82 |
|
| 79 | 83 |
mRenderer = new RubikRenderer(this); |
| 84 |
mRenderer.createCube(RubikActivity.DEFAULT_SIZE); |
|
| 80 | 85 |
mCube = mRenderer.getCube(); |
| 81 | 86 |
|
| 82 | 87 |
mQuatCurrent = new Static4D(0,0,0,1); |
| ... | ... | |
| 89 | 94 |
} |
| 90 | 95 |
} |
| 91 | 96 |
|
| 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 93 |
|
|
| 94 |
public RubikRenderer getRenderer() |
|
| 95 |
{
|
|
| 96 |
return mRenderer; |
|
| 97 |
} |
|
| 98 |
|
|
| 99 | 97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 100 | 98 |
|
| 101 | 99 |
@Override |
| ... | ... | |
| 168 | 166 |
|
| 169 | 167 |
void setNewCubeSize(int newCubeSize) |
| 170 | 168 |
{
|
| 171 |
android.util.Log.e("view", "new size="+newCubeSize);
|
|
| 169 |
mRenderer.createCube(newCubeSize);
|
|
| 172 | 170 |
} |
| 173 | 171 |
|
| 174 | 172 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 175 | 173 |
|
| 176 | 174 |
void scrambleCube() |
| 177 | 175 |
{
|
| 178 |
android.util.Log.e("view", "scrambling...");
|
|
| 176 |
mRenderer.scrambleCube();
|
|
| 179 | 177 |
} |
| 180 | 178 |
|
| 181 | 179 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 254 | 252 |
} |
| 255 | 253 |
|
| 256 | 254 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 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 | 255 |
|
| 260 | 256 |
private void continueRotation(int x, int y) |
| 261 | 257 |
{
|
| ... | ... | |
| 270 | 266 |
int sign = retFaceRotationSign(mLastTouchedFace); |
| 271 | 267 |
float angle = (mRotationVect==xAxis ? mDiff[yAxis] : -mDiff[xAxis]); |
| 272 | 268 |
|
| 273 |
mCube.continueRotation(240.0f*sign*angle/mScreenMin);
|
|
| 269 |
mCube.continueRotation(SWIPING_SENSITIVITY*sign*angle/mScreenMin);
|
|
| 274 | 270 |
} |
| 275 | 271 |
|
| 276 | 272 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
App: minor.