Revision 473611ee
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/main/RubikPostRender.java | ||
|---|---|---|
| 451 | 451 |
|
| 452 | 452 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 453 | 453 |
|
| 454 |
public void setTextureMap(int cubit, int face, int newColor)
|
|
| 454 |
void setTextureMap(int cubit, int face, int newColor) |
|
| 455 | 455 |
{
|
| 456 | 456 |
mSetTextureMap = true; |
| 457 | 457 |
|
| src/main/java/org/distorted/main/RubikSurfaceView.java | ||
|---|---|---|
| 32 | 32 |
import org.distorted.objects.RubikObject; |
| 33 | 33 |
import org.distorted.objects.RubikObjectMovement; |
| 34 | 34 |
import org.distorted.states.RubikState; |
| 35 |
import org.distorted.states.RubikStateSolver; |
|
| 35 | 36 |
import org.distorted.states.RubikStateSolving; |
| 36 | 37 |
|
| 37 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 38 | 39 |
|
| 39 | 40 |
public class RubikSurfaceView extends GLSurfaceView |
| 40 | 41 |
{
|
| 42 |
public static final int MODE_ROTATE = 0; |
|
| 43 |
public static final int MODE_DRAG = 1; |
|
| 44 |
public static final int MODE_REPLACE = 2; |
|
| 45 |
|
|
| 41 | 46 |
// Moving the finger from the middle of the vertical screen to the right edge will rotate a |
| 42 | 47 |
// given face by SWIPING_SENSITIVITY/2 degrees. |
| 43 | 48 |
private final static int SWIPING_SENSITIVITY = 240; |
| ... | ... | |
| 170 | 175 |
|
| 171 | 176 |
private void setUpDragOrRotate(float x, float y) |
| 172 | 177 |
{
|
| 173 |
if( !RubikState.canRotate() ) |
|
| 178 |
int mode = RubikState.getMode(); |
|
| 179 |
|
|
| 180 |
if( mode==MODE_DRAG ) |
|
| 174 | 181 |
{
|
| 175 | 182 |
mDragging = true; |
| 176 | 183 |
mBeginningRotation = false; |
| ... | ... | |
| 185 | 192 |
if( mMovement!=null && mMovement.faceTouched(rotatedTouchPoint1,rotatedCamera) ) |
| 186 | 193 |
{
|
| 187 | 194 |
mDragging = false; |
| 188 |
mBeginningRotation = mPostRender.canRotate(); |
|
| 189 | 195 |
mContinuingRotation = false; |
| 196 |
|
|
| 197 |
if( mode==MODE_ROTATE ) |
|
| 198 |
{
|
|
| 199 |
mBeginningRotation= mPostRender.canRotate(); |
|
| 200 |
} |
|
| 201 |
else if( mode==MODE_REPLACE ) |
|
| 202 |
{
|
|
| 203 |
mBeginningRotation= false; |
|
| 204 |
RubikStateSolver solver = (RubikStateSolver) RubikState.SVER.getStateClass(); |
|
| 205 |
int cubit = mMovement.getTouchedCubit(); |
|
| 206 |
int face = mMovement.getTouchedFace(); |
|
| 207 |
int color = solver.getCurrentColor(); |
|
| 208 |
mPostRender.setTextureMap( cubit, face, color ); |
|
| 209 |
} |
|
| 190 | 210 |
} |
| 191 | 211 |
else |
| 192 | 212 |
{
|
| src/main/java/org/distorted/objects/RubikObjectMovement.java | ||
|---|---|---|
| 283 | 283 |
|
| 284 | 284 |
return new Static2D(rotIndex,offset); |
| 285 | 285 |
} |
| 286 |
|
|
| 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 288 |
|
|
| 289 |
public int getTouchedFace() |
|
| 290 |
{
|
|
| 291 |
return mLastTouchedAxis*mNumFacesPerAxis + mLastTouchedLR; |
|
| 292 |
} |
|
| 293 |
|
|
| 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 295 |
// TODO |
|
| 296 |
|
|
| 297 |
public int getTouchedCubit() |
|
| 298 |
{
|
|
| 299 |
return 0; |
|
| 300 |
} |
|
| 286 | 301 |
} |
| src/main/java/org/distorted/states/RubikState.java | ||
|---|---|---|
| 21 | 21 |
|
| 22 | 22 |
import android.content.SharedPreferences; |
| 23 | 23 |
import org.distorted.main.RubikActivity; |
| 24 |
import static org.distorted.main.RubikSurfaceView.*; |
|
| 24 | 25 |
|
| 25 | 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 26 | 27 |
|
| 27 | 28 |
public enum RubikState |
| 28 | 29 |
{
|
| 29 |
MAIN ( null , false, new RubikStateMain() ),
|
|
| 30 |
PLAY ( MAIN , true , new RubikStatePlay() ),
|
|
| 31 |
SOLV ( PLAY , true , new RubikStateSolving() ),
|
|
| 32 |
PATT ( MAIN , false, new RubikStatePattern() ),
|
|
| 33 |
SVER ( MAIN , false, new RubikStateSolver() ),
|
|
| 34 |
SOLU ( SVER , false, new RubikStateSolution() ),
|
|
| 30 |
MAIN ( null , MODE_DRAG , new RubikStateMain() ),
|
|
| 31 |
PLAY ( MAIN , MODE_ROTATE , new RubikStatePlay() ),
|
|
| 32 |
SOLV ( PLAY , MODE_ROTATE , new RubikStateSolving() ),
|
|
| 33 |
PATT ( MAIN , MODE_DRAG , new RubikStatePattern() ),
|
|
| 34 |
SVER ( MAIN , MODE_REPLACE, new RubikStateSolver() ),
|
|
| 35 |
SOLU ( SVER , MODE_DRAG , new RubikStateSolution() ),
|
|
| 35 | 36 |
; |
| 36 | 37 |
|
| 37 | 38 |
public static final int LENGTH = values().length; |
| 38 | 39 |
private final RubikState mBack; |
| 39 |
private boolean mCanRotate;
|
|
| 40 |
private int mMode;
|
|
| 40 | 41 |
private final RubikStateAbstract mClass; |
| 41 | 42 |
private static final RubikState[] sizes; |
| 42 | 43 |
|
| ... | ... | |
| 70 | 71 |
|
| 71 | 72 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 72 | 73 |
|
| 73 |
public static boolean canRotate()
|
|
| 74 |
public static int getMode()
|
|
| 74 | 75 |
{
|
| 75 |
return mCurrState.mCanRotate;
|
|
| 76 |
return mCurrState.mMode;
|
|
| 76 | 77 |
} |
| 77 | 78 |
|
| 78 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 122 | 123 |
|
| 123 | 124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 124 | 125 |
|
| 125 |
RubikState(RubikState back, boolean canRotate, RubikStateAbstract clazz)
|
|
| 126 |
RubikState(RubikState back, int mode, RubikStateAbstract clazz)
|
|
| 126 | 127 |
{
|
| 127 |
mBack = back;
|
|
| 128 |
mCanRotate = canRotate;
|
|
| 129 |
mClass = clazz;
|
|
| 128 |
mBack = back; |
|
| 129 |
mMode = mode;
|
|
| 130 |
mClass= clazz; |
|
| 130 | 131 |
} |
| 131 | 132 |
|
| 132 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| src/main/java/org/distorted/states/RubikStateSolver.java | ||
|---|---|---|
| 24 | 24 |
import android.graphics.Bitmap; |
| 25 | 25 |
import android.graphics.Canvas; |
| 26 | 26 |
import android.graphics.Paint; |
| 27 |
import android.graphics.PorterDuff; |
|
| 28 |
import android.graphics.drawable.Drawable; |
|
| 29 |
import android.support.v4.content.ContextCompat; |
|
| 27 | 30 |
import android.util.DisplayMetrics; |
| 28 | 31 |
import android.view.View; |
| 29 | 32 |
import android.widget.Button; |
| ... | ... | |
| 32 | 35 |
|
| 33 | 36 |
import org.distorted.main.R; |
| 34 | 37 |
import org.distorted.main.RubikActivity; |
| 35 |
import org.distorted.objects.RubikObject;
|
|
| 38 |
import org.distorted.main.RubikPostRender;
|
|
| 36 | 39 |
import org.distorted.objects.RubikObjectList; |
| 37 | 40 |
|
| 38 | 41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 123 | 126 |
|
| 124 | 127 |
void leaveState(RubikActivity act) |
| 125 | 128 |
{
|
| 126 |
RubikObject object = act.getObject();
|
|
| 127 |
object.resetAllTextureMaps();
|
|
| 129 |
RubikPostRender post = act.getPostRender();
|
|
| 130 |
post.resetAllTextureMaps();
|
|
| 128 | 131 |
} |
| 129 | 132 |
|
| 130 | 133 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 134 | 137 |
mSolving = false; |
| 135 | 138 |
|
| 136 | 139 |
act.changeObject(RubikObjectList.CUBE,3,null); |
| 140 |
RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass(); |
|
| 141 |
play.setObjectAndSize(RubikObjectList.CUBE,3); |
|
| 137 | 142 |
|
| 138 | 143 |
DisplayMetrics metrics = act.getResources().getDisplayMetrics(); |
| 139 | 144 |
final float scale = metrics.density; |
| ... | ... | |
| 145 | 150 |
if( mBitmap ==null ) setupBitmaps(scale); |
| 146 | 151 |
if( mColorButton==null ) setupColorButtons(act,scale); |
| 147 | 152 |
|
| 153 |
markButton(act); |
|
| 154 |
|
|
| 148 | 155 |
for(ImageButton button: mColorButton) layoutTop.addView(button); |
| 149 | 156 |
|
| 150 | 157 |
// BOT //////////////////////////// |
| ... | ... | |
| 222 | 229 |
@Override |
| 223 | 230 |
public void onClick(View view) |
| 224 | 231 |
{
|
| 225 |
android.util.Log.e("solver", "button "+FACE_COLORS[ii]+" clicked");
|
|
| 232 |
mCurrentColor = ii; |
|
| 233 |
markButton(act); |
|
| 226 | 234 |
} |
| 227 | 235 |
}); |
| 228 | 236 |
} |
| ... | ... | |
| 276 | 284 |
}); |
| 277 | 285 |
} |
| 278 | 286 |
|
| 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 288 |
|
|
| 289 |
private void markButton(RubikActivity act) |
|
| 290 |
{
|
|
| 291 |
for(int b=0; b<NUM_FACES; b++) |
|
| 292 |
{
|
|
| 293 |
Drawable d = mColorButton[b].getBackground(); |
|
| 294 |
|
|
| 295 |
if( b==mCurrentColor ) |
|
| 296 |
{
|
|
| 297 |
d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY); |
|
| 298 |
} |
|
| 299 |
else |
|
| 300 |
{
|
|
| 301 |
d.clearColorFilter(); |
|
| 302 |
} |
|
| 303 |
} |
|
| 304 |
} |
|
| 305 |
|
|
| 279 | 306 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 280 | 307 |
|
| 281 | 308 |
public void savePreferences(SharedPreferences.Editor editor) |
| ... | ... | |
| 293 | 320 |
{
|
| 294 | 321 |
mCurrentColor = preferences.getInt("stateSolver_color", 0);
|
| 295 | 322 |
} |
| 323 |
|
|
| 324 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 325 |
|
|
| 326 |
public int getCurrentColor() |
|
| 327 |
{
|
|
| 328 |
return mCurrentColor; |
|
| 329 |
} |
|
| 296 | 330 |
} |
Also available in: Unified diff
Progress with the 3x3x3 Solver.