Project

General

Profile

« Previous | Next » 

Revision 27a70eae

Added by Leszek Koltunski almost 5 years ago

Make RubikCube and RubikCubeMovement generic and not visible outside of their package.

View differences:

src/main/java/org/distorted/dialog/RubikDialogScores.java
36 36
import android.widget.TextView;
37 37

  
38 38
import org.distorted.magic.R;
39
import org.distorted.object.RubikObject;
39
import org.distorted.object.RubikObjectList;
40 40

  
41 41
///////////////////////////////////////////////////////////////////////////////////////////////////
42 42

  
......
104 104

  
105 105
    viewPager.setCurrentItem(curTab);
106 106

  
107
    for (int i = 0; i< RubikObject.LENGTH; i++)
107
    for (int i = 0; i< RubikObjectList.LENGTH; i++)
108 108
      {
109 109
      ImageView imageView = new ImageView(act);
110
      imageView.setImageResource(RubikObject.getObject(i).getIconID());
110
      imageView.setImageResource(RubikObjectList.getObject(i).getIconID());
111 111
      TabLayout.Tab tab = tabLayout.getTabAt(i);
112 112
      if(tab!=null) tab.setCustomView(imageView);
113 113
      }
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
28 28
import android.widget.LinearLayout;
29 29

  
30 30
import org.distorted.network.RubikScoresDownloader;
31
import static org.distorted.object.RubikObject.LENGTH;
31
import static org.distorted.object.RubikObjectList.LENGTH;
32 32
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
33 33

  
34 34
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/effect/scramble/ScrambleEffect.java
23 23
import org.distorted.library.effect.Effect;
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.message.EffectListener;
26
import org.distorted.object.RubikCube;
27 26
import org.distorted.magic.RubikRenderer;
27
import org.distorted.object.RubikObject;
28 28

  
29 29
import java.lang.reflect.Method;
30 30
import java.util.Random;
31 31

  
32
import static org.distorted.object.RubikObjectList.VECTX;
33
import static org.distorted.object.RubikObjectList.VECTY;
34
import static org.distorted.object.RubikObjectList.VECTZ;
35

  
32 36
///////////////////////////////////////////////////////////////////////////////////////////////////
33 37

  
34 38
public abstract class ScrambleEffect extends BaseEffect implements EffectListener
......
69 73
  private int mLastVector;
70 74
  private long mDurationSingleTurn;
71 75
  private Random mRnd;
72
  private RubikCube mCube;
76
  private RubikObject mObject;
73 77

  
74 78
  Effect[] mNodeEffects;
75 79
  int[] mNodeEffectPosition;
......
123 127
        {
124 128
        switch(mRnd.nextInt(3))
125 129
          {
126
          case 0: mLastVector = RubikCube.VECTX; break;
127
          case 1: mLastVector = RubikCube.VECTY; break;
128
          case 2: mLastVector = RubikCube.VECTZ; break;
130
          case 0: mLastVector = VECTX; break;
131
          case 1: mLastVector = VECTY; break;
132
          case 2: mLastVector = VECTZ; break;
129 133
          }
130 134
        }
131 135
      else
......
134 138

  
135 139
        switch(mLastVector)
136 140
          {
137
          case RubikCube.VECTX: mLastVector = (newVector==0 ? RubikCube.VECTY: RubikCube.VECTZ); break;
138
          case RubikCube.VECTY: mLastVector = (newVector==0 ? RubikCube.VECTX: RubikCube.VECTZ); break;
139
          case RubikCube.VECTZ: mLastVector = (newVector==0 ? RubikCube.VECTX: RubikCube.VECTY); break;
141
          case VECTX: mLastVector = (newVector==0 ? VECTY: VECTZ); break;
142
          case VECTY: mLastVector = (newVector==0 ? VECTX: VECTZ); break;
143
          case VECTZ: mLastVector = (newVector==0 ? VECTX: VECTY); break;
140 144
          }
141 145
        }
142 146

  
143
      int row  = mRnd.nextInt(mCube.getSize());
147
      int row  = mRnd.nextInt(mObject.getSize());
144 148
      int angle= randomizeAngle();
145 149
      int absAngle = (angle<0 ? -angle : angle);
146 150
      long durationMillis =  absAngle*mDurationSingleTurn;
......
153 157
        android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft);
154 158
        }
155 159

  
156
      mCurrentBaseEffectID = mCube.addNewRotation(mLastVector, row, angle*90, durationMillis, this );
160
      mCurrentBaseEffectID = mObject.addNewRotation(mLastVector, row, angle*90, durationMillis, this );
157 161
      }
158 162
    else
159 163
      {
......
183 187
    {
184 188
    for(int i=0; i<mCubeEffectNumber; i++)
185 189
      {
186
      mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]);
190
      mObject.apply(mCubeEffects[i],mCubeEffectPosition[i]);
187 191
      mCubeEffects[i].notifyWhenFinished(this);
188 192
      }
189 193

  
190
    DistortedEffects nodeEffects = mCube.getEffects();
194
    DistortedEffects nodeEffects = mObject.getEffects();
191 195

  
192 196
    for(int i=0; i<mNodeEffectNumber; i++)
193 197
      {
......
202 206
    {
203 207
    for(int i=0; i<mCubeEffectNumber; i++)
204 208
      {
205
      mCube.remove(mCubeEffects[i].getID());
209
      mObject.remove(mCubeEffects[i].getID());
206 210
      }
207 211

  
208
    DistortedEffects nodeEffects = mCube.getEffects();
212
    DistortedEffects nodeEffects = mObject.getEffects();
209 213

  
210 214
    for(int i=0; i<mNodeEffectNumber; i++)
211 215
      {
......
244 248
    {
245 249
    if( effectID == mCurrentBaseEffectID )
246 250
      {
247
      mCube.removeRotationNow();
251
      mObject.removeRotationNow();
248 252
      addNewScramble();
249 253
      return;
250 254
      }
......
301 305
  @SuppressWarnings("unused")
302 306
  public long start(int duration, RubikRenderer renderer)
303 307
    {
304
    mCube     = renderer.getCube();
308
    mObject   = renderer.getObject();
305 309
    mListener = renderer;
306 310

  
307
    mCube.solve();
311
    mObject.solve();
308 312

  
309 313
    int numScrambles = renderer.getNumScrambles();
310 314
    int dura = (int)(duration*Math.pow(numScrambles,0.6f));
src/main/java/org/distorted/effect/sizechange/SizeChangeEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.object.RubikCube;
28 27
import org.distorted.magic.RubikRenderer;
28
import org.distorted.object.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
31 31

  
......
72 72
  private int[] mCubeEffectNumber, mNodeEffectNumber;
73 73
  private int[] mEffectFinished;
74 74
  private boolean[] mPhaseActive;
75
  private RubikCube[] mCube;
75
  private RubikObject[] mObject;
76 76

  
77 77
  DistortedScreen mScreen;
78 78
  Effect[][] mCubeEffects;
......
93 93
    mNodeEffectPosition = new int[NUM_PHASES][];
94 94
    mCubeEffects        = new Effect[NUM_PHASES][];
95 95
    mNodeEffects        = new Effect[NUM_PHASES][];
96
    mCube               = new RubikCube[NUM_PHASES];
96
    mObject             = new RubikObject[NUM_PHASES];
97 97
    }
98 98

  
99 99
///////////////////////////////////////////////////////////////////////////////////////////////////
......
112 112
      if( effectID == id )
113 113
        {
114 114
        effectReturned(phase);
115
        mCube[phase].remove(id);
115
        mObject[phase].remove(id);
116 116
        return;
117 117
        }
118 118
      }
......
123 123
      if( effectID == id )
124 124
        {
125 125
        effectReturned(phase);
126
        mCube[phase].getEffects().abortById(id);
126
        mObject[phase].getEffects().abortById(id);
127 127
        return;
128 128
        }
129 129
      }
......
142 142
        case 0: mPhaseActive[1] = true;
143 143
                mEffectFinished[1] = createEffectsPhase1(mDuration);
144 144
                assignEffects(1);
145
                mScreen.attach(mCube[1]);
145
                mScreen.attach(mObject[1]);
146 146
                break;
147 147
        case 1: mListener.effectFinished(FAKE_EFFECT_ID);
148 148
                break;
......
153 153
      switch(phase)
154 154
        {
155 155
        case 0: mPhaseActive[0] = false;
156
                mScreen.detach(mCube[0]);
156
                mScreen.detach(mObject[0]);
157 157
                break;
158 158
        case 1: mPhaseActive[1] = false;
159 159
                break;
......
175 175

  
176 176
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
177 177
      {
178
      mCube[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
178
      mObject[phase].apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
179 179
      mCubeEffects[phase][i].notifyWhenFinished(this);
180 180
      }
181 181

  
182
    DistortedEffects nodeEffects = mCube[phase].getEffects();
182
    DistortedEffects nodeEffects = mObject[phase].getEffects();
183 183

  
184 184
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
185 185
      {
......
227 227
  public long start(int duration, RubikRenderer renderer)
228 228
    {
229 229
    mScreen   = renderer.getScreen();
230
    mCube[0]  = renderer.getOldCube();
231
    mCube[1]  = renderer.getCube();
230
    mObject[0]= renderer.getOldObject();
231
    mObject[1]= renderer.getObject();
232 232
    mListener = renderer;
233 233
    mDuration = duration;
234 234

  
235
    if( mCube[0]!=null )
235
    if( mObject[0]!=null )
236 236
      {
237 237
      mPhaseActive[0] = true;
238 238
      mEffectFinished[0] = createEffectsPhase0(mDuration);
......
243 243
      mPhaseActive[1] = true;
244 244
      mEffectFinished[1] = createEffectsPhase1(mDuration);
245 245
      assignEffects(1);
246
      mScreen.attach(mCube[1]);
246
      mScreen.attach(mObject[1]);
247 247
      }
248 248

  
249 249
    return FAKE_EFFECT_ID;
src/main/java/org/distorted/effect/solve/SolveEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.object.RubikCube;
28 27
import org.distorted.magic.RubikRenderer;
28
import org.distorted.object.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
31 31

  
......
69 69
  private int[] mCubeEffectNumber, mNodeEffectNumber;
70 70
  private int mPhase;
71 71

  
72
  RubikCube mCube;
72
  RubikObject mObject;
73 73
  DistortedScreen mScreen;
74 74
  Effect[][] mCubeEffects;
75 75
  int[][] mCubeEffectPosition;
......
109 109

  
110 110
    for(int i=0; i<mCubeEffectNumber[phase]; i++)
111 111
      {
112
      mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
112
      mObject.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]);
113 113
      mCubeEffects[phase][i].notifyWhenFinished(this);
114 114
      }
115 115

  
116
    DistortedEffects nodeEffects = mCube.getEffects();
116
    DistortedEffects nodeEffects = mObject.getEffects();
117 117

  
118 118
    for(int i=0; i<mNodeEffectNumber[phase]; i++)
119 119
      {
......
130 130
      {
131 131
      case 0: mEffectReturned = 0;
132 132
              mPhase          = 1;
133
              mCube.solve();
133
              mObject.solve();
134 134
              createEffectsPhase1(mDuration);
135 135
              assignEffects(mPhase);
136 136
              break;
......
177 177
      if( effectID == id )
178 178
        {
179 179
        if( ++mEffectReturned == total ) effectAction(mPhase);
180
        mCube.remove(id);
180
        mObject.remove(id);
181 181
        return;
182 182
        }
183 183
      }
......
188 188
      if( effectID == id )
189 189
        {
190 190
        if( ++mEffectReturned == total ) effectAction(mPhase);
191
        mCube.getEffects().abortById(id);
191
        mObject.getEffects().abortById(id);
192 192
        return;
193 193
        }
194 194
      }
......
200 200
  public long start(int duration, RubikRenderer renderer)
201 201
    {
202 202
    mScreen   = renderer.getScreen();
203
    mCube     = renderer.getCube();
203
    mObject   = renderer.getObject();
204 204
    mListener = renderer;
205 205
    mDuration = duration;
206 206

  
src/main/java/org/distorted/effect/solve/SolveEffectSpin.java
74 74
    mCubeEffectPosition[phase] = new int[] {3};
75 75
    mCubeEffects[phase]        = new Effect[mCubeEffectPosition[0].length];
76 76

  
77
    Static4D quaternion = mCube.getRotationQuat();                        // always rotate around
77
    Static4D quaternion = mObject.getRotationQuat();                      // always rotate around
78 78
    Static4D tmpAxis    = new Static4D(0,1,0,0);                          // vert axis no matter
79 79
    Static4D rotated    = rotateVectorByInvertedQuat(tmpAxis,quaternion); // how cube is rotated
80 80

  
src/main/java/org/distorted/effect/win/WinEffect.java
24 24
import org.distorted.library.main.DistortedEffects;
25 25
import org.distorted.library.main.DistortedScreen;
26 26
import org.distorted.library.message.EffectListener;
27
import org.distorted.object.RubikCube;
28 27
import org.distorted.magic.RubikRenderer;
28
import org.distorted.object.RubikObject;
29 29

  
30 30
import java.lang.reflect.Method;
31 31

  
......
67 67
  private int mEffectReturned;
68 68
  private int mCubeEffectNumber, mNodeEffectNumber;
69 69

  
70
  RubikCube mCube;
70
  RubikObject mObject;
71 71
  DistortedScreen mScreen;
72 72
  Effect[] mCubeEffects;
73 73
  int[] mCubeEffectPosition;
......
92 92

  
93 93
    for(int i=0; i<mCubeEffectNumber; i++)
94 94
      {
95
      mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]);
95
      mObject.apply(mCubeEffects[i],mCubeEffectPosition[i]);
96 96
      mCubeEffects[i].notifyWhenFinished(this);
97 97
      }
98 98

  
99
    DistortedEffects nodeEffects = mCube.getEffects();
99
    DistortedEffects nodeEffects = mObject.getEffects();
100 100

  
101 101
    for(int i=0; i<mNodeEffectNumber; i++)
102 102
      {
......
143 143
      if( effectID == id )
144 144
        {
145 145
        if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
146
        mCube.remove(id);
146
        mObject.remove(id);
147 147
        return;
148 148
        }
149 149
      }
......
154 154
      if( effectID == id )
155 155
        {
156 156
        if( ++mEffectReturned == total ) mListener.effectFinished(FAKE_EFFECT_ID);
157
        mCube.getEffects().abortById(id);
157
        mObject.getEffects().abortById(id);
158 158
        return;
159 159
        }
160 160
      }
......
166 166
  public long start(int duration, RubikRenderer renderer)
167 167
    {
168 168
    mScreen   = renderer.getScreen();
169
    mCube     = renderer.getCube();
169
    mObject   = renderer.getObject();
170 170
    mListener = renderer;
171 171
    mDuration = duration;
172 172

  
src/main/java/org/distorted/magic/RubikActivity.java
32 32
import org.distorted.library.main.DistortedLibrary;
33 33

  
34 34
import org.distorted.network.RubikScoresDownloader;
35
import org.distorted.object.RubikObject;
35
import org.distorted.object.RubikObjectList;
36 36
import org.distorted.uistate.RubikState;
37 37
import org.distorted.uistate.RubikStateAbstract;
38 38
import org.distorted.uistate.RubikStatePlay;
......
72 72
      view.onResume();
73 73
      restorePreferences();
74 74
      RubikState.setState(this);
75
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
76
      int ordinal = play.getButton();
77
      view.getRenderer().createObject(RubikObjectList.getObject(ordinal));
75 78
      }
76 79
    
77 80
///////////////////////////////////////////////////////////////////////////////////////////////////
......
90 93
      {
91 94
      int id = v.getId();
92 95

  
93
      if( id>=0 && id< RubikObject.LENGTH )
96
      if( id>=0 && id< RubikObjectList.LENGTH )
94 97
        {
95
        int size = RubikObject.getObject(id).getObjectSize();
98
        RubikObjectList object = RubikObjectList.getObject(id);
96 99

  
97 100
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
98
        boolean success = view.getRenderer().createCube(size);
101
        boolean success = view.getRenderer().createObject(object);
99 102

  
100 103
        if( success )
101 104
          {
......
203 206
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
204 207
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
205 208
      int scramble = play.getPicker();
206
      view.getRenderer().scrambleCube(scramble);
209
      view.getRenderer().scrambleObject(scramble);
207 210
      }
208 211

  
209 212
///////////////////////////////////////////////////////////////////////////////////////////////////
......
211 214
    public void Solve(View v)
212 215
      {
213 216
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
214
      view.getRenderer().solveCube();
217
      view.getRenderer().solveObject();
215 218
      }
216 219
}
src/main/java/org/distorted/magic/RubikRenderer.java
30 30
import org.distorted.library.main.DistortedTexture;
31 31
import org.distorted.library.mesh.MeshFlat;
32 32
import org.distorted.library.message.EffectListener;
33
import org.distorted.object.RubikCube;
34 33
import org.distorted.object.RubikObject;
34
import org.distorted.object.RubikObjectList;
35 35
import org.distorted.uistate.RubikState;
36
import org.distorted.uistate.RubikStatePlay;
37 36
import org.distorted.uistate.RubikStateSolving;
38 37

  
39 38
import javax.microedition.khronos.egl.EGLConfig;
......
48 47

  
49 48
    private RubikSurfaceView mView;
50 49
    private DistortedScreen mScreen;
51
    private int mNextCubeSize, mScrambleCubeNum;
50
    private RubikObjectList mNextObject;
51
    private int mScrambleObjectNum;
52 52
    private long mRotationFinishedID;
53 53
    private long[] mEffectID;
54 54
    private boolean mFinishRotation, mRemoveRotation, mSetQuatCurrent, mSetQuatAccumulated;
55
    private boolean mSizeChangeCube, mSolveCube, mScrambleCube;
55
    private boolean mChangeObject, mSolveObject, mScrambleObject;
56 56
    private boolean mCanRotate, mCanDrag, mCanUI;
57 57
    private boolean mIsSolved;
58
    private RubikCube mOldCube, mNewCube;
58
    private RubikObject mOldObject, mNewObject;
59 59
    private int mScreenWidth, mScreenHeight;
60 60
    private MeshFlat mMesh;
61 61
    private SharedPreferences mPreferences;
......
67 67
      mView = v;
68 68
      mScreen = new DistortedScreen();
69 69

  
70
      mOldCube = null;
71
      mNewCube = null;
70
      mOldObject = null;
71
      mNewObject = null;
72 72

  
73 73
      mScreenWidth = mScreenHeight = 0;
74
      mScrambleCubeNum = 0;
74
      mScrambleObjectNum = 0;
75 75

  
76 76
      mFinishRotation     = false;
77 77
      mRemoveRotation     = false;
78 78
      mSetQuatCurrent     = false;
79 79
      mSetQuatAccumulated = false;
80
      mSizeChangeCube     = true;
81
      mSolveCube          = false;
82
      mScrambleCube       = false;
80
      mChangeObject       = false;
81
      mSolveObject        = false;
82
      mScrambleObject     = false;
83 83

  
84 84
      mCanRotate   = true;
85 85
      mCanDrag     = true;
......
88 88
      mEffectID = new long[BaseEffect.Type.LENGTH];
89 89

  
90 90
      mMesh= new MeshFlat(20,20);
91

  
92
      RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
93
      int size = play.getButton();
94
      mNextCubeSize = RubikObject.getObject(size).getObjectSize();
95 91
      }
96 92

  
97 93
///////////////////////////////////////////////////////////////////////////////////////////////////
98 94

  
99
   private void createCubeNow(int newSize)
95
   private void createObjectNow(RubikObjectList object)
100 96
     {
101
     boolean firstTime = (mOldCube==null && mNewCube==null);
97
     boolean firstTime = (mNewObject==null);
102 98

  
103
     if( mOldCube!=null ) mOldCube.releaseResources();
104
     mOldCube = mNewCube;
99
     if( mOldObject!=null ) mOldObject.releaseResources();
100
     mOldObject = mNewObject;
105 101

  
106 102
     DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
107 103
     DistortedEffects effects = new DistortedEffects();
108 104

  
109
     mNewCube = new RubikCube(newSize, mView.getQuatCurrent(), mView.getQuatAccumulated(), texture, mMesh, effects);
110
     mNewCube.createTexture();
111
     if( firstTime ) mNewCube.restorePreferences(mPreferences);
105
     mNewObject = object.create(mView.getQuatCurrent(), mView.getQuatAccumulated(), texture, mMesh, effects);
106
     mNewObject.createTexture();
107
     mView.setMovement(object.getObjectMovementClass());
108

  
109
     if( firstTime ) mNewObject.restorePreferences(mPreferences);
112 110

  
113 111
     if( mScreenWidth!=0 )
114 112
       {
115
       mNewCube.recomputeScaleFactor(mScreenWidth, mScreenHeight);
113
       mNewObject.recomputeScaleFactor(mScreenWidth, mScreenHeight);
116 114
       }
117 115

  
118 116
     mIsSolved = true;
......
143 141

  
144 142
   void savePreferences(SharedPreferences.Editor editor)
145 143
     {
146
     mNewCube.savePreferences(editor);
144
     mNewObject.savePreferences(editor);
147 145
     }
148 146

  
149 147
///////////////////////////////////////////////////////////////////////////////////////////////////
......
163 161

  
164 162
///////////////////////////////////////////////////////////////////////////////////////////////////
165 163

  
166
   boolean createCube(int newSize)
164
   boolean createObject(RubikObjectList object)
167 165
     {
168
     if( mCanDrag && mCanRotate && (mNewCube==null || newSize != mNewCube.getSize()) )
166
     if( mCanDrag && mCanRotate && object!=mNextObject )
169 167
       {
170
       mSizeChangeCube = true;
171
       mNextCubeSize = newSize;
168
       mChangeObject = true;
169
       mNextObject = object;
172 170
       return true;
173 171
       }
174 172

  
......
177 175

  
178 176
///////////////////////////////////////////////////////////////////////////////////////////////////
179 177

  
180
   void scrambleCube(int num)
178
   void scrambleObject(int num)
181 179
     {
182 180
     if( mCanUI )
183 181
       {
184
       mScrambleCube = true;
185
       mScrambleCubeNum = num;
182
       mScrambleObject = true;
183
       mScrambleObjectNum = num;
186 184
       }
187 185
     }
188 186

  
189 187
///////////////////////////////////////////////////////////////////////////////////////////////////
190 188

  
191
   void solveCube()
189
   void solveObject()
192 190
     {
193 191
     if( mCanUI )
194 192
       {
195
       mSolveCube = true;
193
       mSolveObject = true;
196 194
       }
197 195
     }
198 196

  
......
250 248
       mFinishRotation = false;
251 249
       mCanRotate      = false;
252 250
       mCanUI          = false;
253
       mRotationFinishedID = mNewCube.finishRotationNow(this);
251
       mRotationFinishedID = mNewObject.finishRotationNow(this);
254 252
       }
255 253

  
256 254
     if( mRemoveRotation )
257 255
       {
258 256
       mRemoveRotation=false;
259
       mNewCube.removeRotationNow();
257
       mNewObject.removeRotationNow();
260 258

  
261
       boolean solved = mNewCube.isSolved();
259
       boolean solved = mNewObject.isSolved();
262 260

  
263 261
       if( solved && !mIsSolved )
264 262
         {
......
283 281
       mIsSolved = solved;
284 282
       }
285 283

  
286
     if( mSizeChangeCube )
284
     if( mChangeObject )
287 285
       {
288
       mSizeChangeCube = false;
289
       mCanDrag        = false;
290
       mCanRotate      = false;
291
       mCanUI          = false;
292
       createCubeNow(mNextCubeSize);
286
       mChangeObject = false;
287
       mCanDrag      = false;
288
       mCanRotate    = false;
289
       mCanUI        = false;
290
       createObjectNow(mNextObject);
293 291
       doEffectNow( BaseEffect.Type.SIZECHANGE );
294 292
       }
295 293

  
296
     if( mSolveCube )
294
     if( mSolveObject )
297 295
       {
298
       mSolveCube      = false;
296
       mSolveObject    = false;
299 297
       mCanDrag        = false;
300 298
       mCanRotate      = false;
301 299
       mCanUI          = false;
302 300
       doEffectNow( BaseEffect.Type.SOLVE );
303 301
       }
304 302

  
305
     if( mScrambleCube )
303
     if( mScrambleObject )
306 304
       {
307
       mScrambleCube = false;
308
       mCanDrag      = false;
309
       mCanRotate    = false;
310
       mCanUI        = false;
305
       mScrambleObject = false;
306
       mCanDrag        = false;
307
       mCanRotate      = false;
308
       mCanUI          = false;
311 309
       doEffectNow( BaseEffect.Type.SCRAMBLE );
312 310
       }
313 311
     }
......
317 315
   @Override
318 316
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
319 317
      {
320
      if( mNewCube!=null ) mNewCube.createTexture();
318
      if( mNewObject!=null ) mNewObject.createTexture();
321 319

  
322 320
      double halfFOVInRadians = Math.atan( 1.0f/(2*CAMERA_DISTANCE) );
323 321
      float fovInDegrees = (float)(2*halfFOVInRadians*(180/Math.PI));
......
326 324
      mScreen.resize(width, height);
327 325
      mView.setScreenSize(width,height);
328 326

  
329
      if( mNewCube!=null )
327
      if( mNewObject!=null )
330 328
        {
331
        mNewCube.recomputeScaleFactor(width,height);
329
        mNewObject.recomputeScaleFactor(width,height);
332 330
        }
333 331

  
334 332
      mScreenHeight = height;
......
394 392

  
395 393
///////////////////////////////////////////////////////////////////////////////////////////////////
396 394

  
397
   public RubikCube getCube()
395
   public RubikObject getObject()
398 396
     {
399
     return mNewCube;
397
     return mNewObject;
400 398
     }
401 399

  
402 400
///////////////////////////////////////////////////////////////////////////////////////////////////
403 401

  
404
   public RubikCube getOldCube()
402
   public RubikObject getOldObject()
405 403
     {
406
     return mOldCube;
404
     return mOldObject;
407 405
     }
408 406

  
409 407
///////////////////////////////////////////////////////////////////////////////////////////////////
......
417 415

  
418 416
   public int getNumScrambles()
419 417
     {
420
     return mScrambleCubeNum;
418
     return mScrambleObjectNum;
421 419
     }
422 420
}
src/main/java/org/distorted/magic/RubikSurfaceView.java
28 28

  
29 29
import org.distorted.library.type.Static2D;
30 30
import org.distorted.library.type.Static4D;
31
import org.distorted.object.RubikCube;
32
import org.distorted.object.RubikCubeMovement;
31
import org.distorted.object.RubikObject;
32
import org.distorted.object.RubikObjectMovement;
33 33
import org.distorted.uistate.RubikState;
34 34
import org.distorted.uistate.RubikStateSolving;
35 35

  
......
48 48
    private final Static4D CAMERA_POINT = new Static4D(0, 0, RubikRenderer.CAMERA_DISTANCE, 0);
49 49

  
50 50
    private RubikRenderer mRenderer;
51
    private RubikCubeMovement mMovement;
51
    private RubikObjectMovement mMovement;
52 52
    private boolean mDragging, mBeginningRotation, mContinuingRotation;
53 53
    private float mX, mY;
54 54
    private int mScreenWidth, mScreenHeight, mScreenMin;
......
103 103
      return mQuatCurrent;
104 104
      }
105 105

  
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

  
108
    void setMovement(RubikObjectMovement movement)
109
      {
110
      mMovement = movement;
111
      }
112

  
106 113
///////////////////////////////////////////////////////////////////////////////////////////////////
107 114

  
108 115
    private Static4D quatFromDrag(float dragX, float dragY)
......
196 203
      if(!isInEditMode())
197 204
        {
198 205
        mRenderer = new RubikRenderer(this);
199
        mMovement = new RubikCubeMovement();
200 206

  
201 207
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
202 208
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
......
259 265
                                           Static4D rotatedTouchPoint2= rotateVectorByInvertedQuat(touchPoint2, mQuatAccumulated);
260 266

  
261 267
                                           Static2D rot = mMovement.newRotation(rotatedTouchPoint2);
262
                                           RubikCube cube = mRenderer.getCube();
268
                                           RubikObject object = mRenderer.getObject();
263 269

  
264
                                           cube.addNewRotation( (int)rot.get0(), (int)(cube.getSize()*rot.get1()) );
270
                                           object.beginNewRotation( (int)rot.get0(), (int)(object.getSize()*rot.get1()) );
265 271

  
266 272
                                           if( RubikState.getCurrentState()==RubikState.SOLV )
267 273
                                             {
......
279 285
                                         Static4D rotatedTouchPoint3= rotateVectorByInvertedQuat(touchPoint3, mQuatAccumulated);
280 286

  
281 287
                                         float angle = mMovement.continueRotation(rotatedTouchPoint3);
282
                                         mRenderer.getCube().continueRotation(SWIPING_SENSITIVITY*angle);
288
                                         mRenderer.getObject().continueRotation(SWIPING_SENSITIVITY*angle);
283 289
                                         }
284 290
                                       break;
285 291
         case MotionEvent.ACTION_UP  : if( mDragging )
src/main/java/org/distorted/network/RubikScoresDownloader.java
24 24
import java.net.URL;
25 25
import java.net.UnknownHostException;
26 26

  
27
import static org.distorted.object.RubikObject.LENGTH;
27
import static org.distorted.object.RubikObjectList.LENGTH;
28 28
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
29 29

  
30 30
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/object/RubikCube.java
28 28
import org.distorted.library.effect.MatrixEffectMove;
29 29
import org.distorted.library.effect.MatrixEffectQuaternion;
30 30
import org.distorted.library.effect.MatrixEffectRotate;
31
import org.distorted.library.effect.MatrixEffectScale;
32
import org.distorted.library.effect.VertexEffectSink;
33 31
import org.distorted.library.main.DistortedEffects;
34 32
import org.distorted.library.main.DistortedNode;
35 33
import org.distorted.library.main.DistortedTexture;
......
42 40
import org.distorted.library.type.Static4D;
43 41
import org.distorted.magic.RubikSurfaceView;
44 42

  
43
import static org.distorted.object.RubikObjectList.VECTX;
44
import static org.distorted.object.RubikObjectList.VECTY;
45
import static org.distorted.object.RubikObjectList.VECTZ;
46

  
45 47
///////////////////////////////////////////////////////////////////////////////////////////////////
46 48

  
47
public class RubikCube extends DistortedNode
49
class RubikCube extends RubikObject
48 50
{
49
            static final float CUBE_SCREEN_RATIO = 0.5f;
50
    private static final int POST_ROTATION_MILLISEC = 500;
51
    private static final int TEXTURE_SIZE = 100;
52

  
53 51
    private static final Static3D VectX = new Static3D(1,0,0);
54 52
    private static final Static3D VectY = new Static3D(0,1,0);
55 53
    private static final Static3D VectZ = new Static3D(0,0,1);
56 54

  
57
    public static final int VECTX = 0;  //
58
    public static final int VECTY = 1;  // don't change this
59
    public static final int VECTZ = 2;  //
60

  
61 55
    private DistortedNode[][][] mNodes;
62 56
    private MeshCubes[][][] mCubes;
63 57
    private DistortedEffects[][][] mEffects;
......
66 60
    private Dynamic1D[][][] mRotationAngle;
67 61
    private Static3D[][][] mCurrentPosition;
68 62
    private MatrixEffectRotate[][][] mRotateEffect;
69
    private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal;
70
    private Static3D mMove, mScale, mNodeMove, mNodeScale;
71
    private Static4D mQuatAccumulated;
72
    private DistortedTexture mTexture;
73

  
74
    private int mRotAxis, mRotRow;
75
    private int mSize;
76

  
77
    private DistortedTexture mNodeTexture;
78

  
79
///////////////////////////////////////////////////////////////////////////////////////////////////
80

  
81
    private int computeNearestAngle(float angle)
82
      {
83
      final int NEAREST = 90;
84

  
85
      int tmp = (int)((angle+NEAREST/2)/NEAREST);
86
      if( angle< -(NEAREST*0.5) ) tmp-=1;
87

  
88
      return NEAREST*tmp;
89
      }
90 63

  
91 64
///////////////////////////////////////////////////////////////////////////////////////////////////
92 65
// All legal rotation quats must have all four of their components equal to either
......
158 131
      mQuatScramble[i][j][k].set(x,y,z,w);
159 132
      }
160 133

  
161
///////////////////////////////////////////////////////////////////////////////////////////////////
162

  
163
    private float getSinkStrength()
164
      {
165
      switch(mSize)
166
        {
167
        case 1 : return 1.1f;
168
        case 2 : return 1.5f;
169
        case 3 : return 1.8f;
170
        case 4 : return 2.0f;
171
        default: return 3.0f - 4.0f/mSize;
172
        }
173
      }
174

  
175 134
///////////////////////////////////////////////////////////////////////////////////////////////////
176 135

  
177 136
    private boolean belongsToRotation(int x, int y, int z, int vector, int row)
......
212 171
      mCurrentPosition[x][y][z].set2(roundedZ);
213 172
      }
214 173

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216
// PUBLIC API
217 174
///////////////////////////////////////////////////////////////////////////////////////////////////
218 175

  
219
    public RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshFlat mesh, DistortedEffects effects)
176
    RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshFlat mesh, DistortedEffects effects)
220 177
      {
221
      super(texture,effects,mesh);
222

  
223
      mNodeTexture = texture;
224

  
225
      mSize = size;
226

  
227
      mRotationAngleStatic = new Static1D(0);
228
      mRotationAngleMiddle = new Static1D(0);
229
      mRotationAngleFinal  = new Static1D(0);
230

  
231
      mMove     = new Static3D(0,0,0);
232
      mScale    = new Static3D(1,1,1);
233
      mNodeMove = new Static3D(0,0,0);
234
      mNodeScale= new Static3D(1,1,1);
235

  
236
      mQuatAccumulated = quatAcc;
178
      super(size,quatCur,quatAcc,texture,mesh,effects);
237 179

  
238 180
      mRotAxis = VECTX;
239 181
      mTexture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
......
248 190
      mRotateEffect   = new MatrixEffectRotate[mSize][mSize][mSize];
249 191

  
250 192
      Static3D[][][] cubeVectors = new Static3D[mSize][mSize][mSize];
251

  
252
      Static3D sinkCenter = new Static3D(TEXTURE_SIZE*0.5f, TEXTURE_SIZE*0.5f, TEXTURE_SIZE*0.5f);
253 193
      Static3D matrCenter = new Static3D(0,0,0);
254
      Static4D region = new Static4D(0,0,0, TEXTURE_SIZE*0.72f);
255

  
256
      VertexEffectSink        sinkEffect = new VertexEffectSink( new Static1D(getSinkStrength()), sinkCenter, region );
257
      MatrixEffectMove        moveEffect = new MatrixEffectMove(mMove);
258
      MatrixEffectScale      scaleEffect = new MatrixEffectScale(mScale);
259
      MatrixEffectQuaternion quatCEffect = new MatrixEffectQuaternion(quatCur, matrCenter);
260
      MatrixEffectQuaternion quatAEffect = new MatrixEffectQuaternion(quatAcc, matrCenter);
261

  
262
      MatrixEffectMove       nodeMoveEffect  = new MatrixEffectMove(mNodeMove);
263
      MatrixEffectScale      nodeScaleEffect = new MatrixEffectScale(mNodeScale);
264

  
265
      effects.apply(nodeScaleEffect);
266
      effects.apply(nodeMoveEffect);
267 194

  
268 195
      // 3x2 bitmap = 6 squares:
269 196
      //
......
311 238
              mRotateEffect[x][y][z]    = new MatrixEffectRotate(mRotationAngle[x][y][z], mRotationAxis[x][y][z], matrCenter);
312 239

  
313 240
              mEffects[x][y][z] = new DistortedEffects();
314
              mEffects[x][y][z].apply(sinkEffect);
241
              mEffects[x][y][z].apply(mSinkEffect);
315 242
              mEffects[x][y][z].apply( new MatrixEffectMove(cubeVectors[x][y][z]) );
316 243
              mEffects[x][y][z].apply( new MatrixEffectQuaternion(mQuatScramble[x][y][z], matrCenter));
317 244
              mEffects[x][y][z].apply(mRotateEffect[x][y][z]);
318
              mEffects[x][y][z].apply(quatAEffect);
319
              mEffects[x][y][z].apply(quatCEffect);
320
              mEffects[x][y][z].apply(scaleEffect);
321
              mEffects[x][y][z].apply(moveEffect);
245
              mEffects[x][y][z].apply(mQuatAEffect);
246
              mEffects[x][y][z].apply(mQuatCEffect);
247
              mEffects[x][y][z].apply(mScaleEffect);
248
              mEffects[x][y][z].apply(mMoveEffect);
322 249

  
323 250
              mNodes[x][y][z] = new DistortedNode(mTexture,mEffects[x][y][z],mCubes[x][y][z]);
324 251

  
......
328 255
      }
329 256

  
330 257
///////////////////////////////////////////////////////////////////////////////////////////////////
331

  
332
    public void addNewRotation(int vector, int row )
333
      {
334
      Static3D axis = VectX;
335

  
336
      switch(vector)
337
        {
338
        case VECTX: axis = VectX; break;
339
        case VECTY: axis = VectY; break;
340
        case VECTZ: axis = VectZ; break;
341
        }
342

  
343
      mRotAxis = vector;
344
      mRotRow  = row;
345

  
346
      mRotationAngleStatic.set0(0.0f);
347

  
348
      for(int x=0; x<mSize; x++)
349
        for(int y=0; y<mSize; y++)
350
          for(int z=0; z<mSize; z++)
351
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
352
              {
353
              if( belongsToRotation(x,y,z,vector,mRotRow) )
354
                {
355
                mRotationAxis[x][y][z].set(axis);
356
                mRotationAngle[x][y][z].add(mRotationAngleStatic);
357
                }
358
              }
359
      }
360

  
361
///////////////////////////////////////////////////////////////////////////////////////////////////
362

  
363
    public void continueRotation(float angleInDegrees)
364
      {
365
      mRotationAngleStatic.set0(angleInDegrees);
366
      }
367

  
368
///////////////////////////////////////////////////////////////////////////////////////////////////
369

  
370
    public Static4D getRotationQuat()
371
      {
372
      return mQuatAccumulated;
373
      }
374

  
258
// PUBLIC API
375 259
///////////////////////////////////////////////////////////////////////////////////////////////////
376 260
// mSize already saved as RubikStatePlay.mButton
377 261

  
......
419 303

  
420 304
///////////////////////////////////////////////////////////////////////////////////////////////////
421 305

  
422
    public long finishRotationNow(EffectListener listener)
423
      {
424
      boolean first = true;
425
      long effectID=0;
426

  
427
      for(int x=0; x<mSize; x++)
428
        for(int y=0; y<mSize; y++)
429
          for(int z=0; z<mSize; z++)
430
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
431
              {
432
              if( belongsToRotation(x,y,z,mRotAxis,mRotRow) )
433
                {
434
                if( first )
435
                  {
436
                  first = false;
437
                  mRotateEffect[x][y][z].notifyWhenFinished(listener);
438
                  effectID = mRotateEffect[x][y][z].getID();
439
                  int pointNum = mRotationAngle[x][y][z].getNumPoints();
440

  
441
                  if( pointNum>=1 )
442
                    {
443
                    float startingAngle = mRotationAngle[x][y][z].getPoint(pointNum-1).get0();
444
                    int nearestAngleInDegrees = computeNearestAngle(startingAngle);
445
                    mRotationAngleStatic.set0(startingAngle);
446
                    mRotationAngleFinal.set0(nearestAngleInDegrees);
447
                    mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
448
                    }
449
                  else
450
                    {
451
                    android.util.Log.e("cube", "ERROR finishing rotation!");
452
                    return 0;
453
                    }
454
                  }
455

  
456
                mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
457
                mRotationAngle[x][y][z].resetToBeginning();
458
                mRotationAngle[x][y][z].removeAll();
459
                mRotationAngle[x][y][z].add(mRotationAngleStatic);
460
                mRotationAngle[x][y][z].add(mRotationAngleMiddle);
461
                mRotationAngle[x][y][z].add(mRotationAngleFinal);
462
                }
463
              }
306
   public long finishRotationNow(EffectListener listener)
307
     {
308
     boolean first = true;
309
     long effectID=0;
464 310

  
465
      return effectID;
466
      }
311
     for(int x=0; x<mSize; x++)
312
       for(int y=0; y<mSize; y++)
313
         for(int z=0; z<mSize; z++)
314
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
315
             {
316
             if( belongsToRotation(x,y,z,mRotAxis,mRotRow) )
317
               {
318
               if( first )
319
                 {
320
                 first = false;
321
                 mRotateEffect[x][y][z].notifyWhenFinished(listener);
322
                 effectID = mRotateEffect[x][y][z].getID();
323
                 int pointNum = mRotationAngle[x][y][z].getNumPoints();
324

  
325
                 if( pointNum>=1 )
326
                   {
327
                   float startingAngle = mRotationAngle[x][y][z].getPoint(pointNum-1).get0();
328
                   int nearestAngleInDegrees = computeNearestAngle(startingAngle);
329
                   mRotationAngleStatic.set0(startingAngle);
330
                   mRotationAngleFinal.set0(nearestAngleInDegrees);
331
                   mRotationAngleMiddle.set0( nearestAngleInDegrees + (nearestAngleInDegrees-startingAngle)*0.2f );
332
                   }
333
                 else
334
                   {
335
                   android.util.Log.e("cube", "ERROR finishing rotation!");
336
                   return 0;
337
                   }
338
                 }
339

  
340
               mRotationAngle[x][y][z].setDuration(POST_ROTATION_MILLISEC);
341
               mRotationAngle[x][y][z].resetToBeginning();
342
               mRotationAngle[x][y][z].removeAll();
343
               mRotationAngle[x][y][z].add(mRotationAngleStatic);
344
               mRotationAngle[x][y][z].add(mRotationAngleMiddle);
345
               mRotationAngle[x][y][z].add(mRotationAngleFinal);
346
               }
347
             }
348

  
349
     return effectID;
350
     }
467 351

  
468 352
///////////////////////////////////////////////////////////////////////////////////////////////////
469 353
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of
470 354
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major
471 355
// memory leak.
472 356

  
473
    public void releaseResources()
474
      {
475
      mTexture.markForDeletion();
357
   public void releaseResources()
358
     {
359
     mTexture.markForDeletion();
476 360

  
477
      for(int x=0; x<mSize; x++)
478
        for(int y=0; y<mSize; y++)
479
          for(int z=0; z<mSize; z++)
480
            {
481
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
482
              {
483
              mCubes[x][y][z].markForDeletion();
484
              mNodes[x][y][z].markForDeletion();
485
              }
486
            }
487
      }
361
     for(int x=0; x<mSize; x++)
362
       for(int y=0; y<mSize; y++)
363
         for(int z=0; z<mSize; z++)
364
           {
365
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
366
             {
367
             mCubes[x][y][z].markForDeletion();
368
             mNodes[x][y][z].markForDeletion();
369
             }
370
           }
371
     }
488 372

  
489 373
///////////////////////////////////////////////////////////////////////////////////////////////////
490 374

  
491
    public void createTexture()
492
      {
493
      Bitmap bitmap;
494

  
495
      final int S = 128;
496
      final int W = 3*S;
497
      final int H = 2*S;
498
      final int R = S/10;
499
      final int M = S/20;
500

  
501
      Paint paint = new Paint();
502
      bitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
503
      Canvas canvas = new Canvas(bitmap);
504

  
505
      paint.setAntiAlias(true);
506
      paint.setTextAlign(Paint.Align.CENTER);
507
      paint.setStyle(Paint.Style.FILL);
508

  
509
      // 3x2 bitmap = 6 squares:
510
      //
511
      // RED     GREEN   BLUE
512
      // YELLOW  WHITE   BROWN
513

  
514
      paint.setColor(0xff000000);                                  // BLACK BACKGROUND
515
      canvas.drawRect(0, 0, W, H, paint);                          //
516

  
517
      paint.setColor(0xffff0000);                                  // RED
518
      canvas.drawRoundRect(    M,   M,   S-M,   S-M, R, R, paint); //
519
      paint.setColor(0xff00ff00);                                  // GREEN
520
      canvas.drawRoundRect(  S+M,   M, 2*S-M,   S-M, R, R, paint); //
521
      paint.setColor(0xff0000ff);                                  // BLUE
522
      canvas.drawRoundRect(2*S+M,   M, 3*S-M,   S-M, R, R, paint); //
523
      paint.setColor(0xffffff00);                                  // YELLOW
524
      canvas.drawRoundRect(    M, S+M,   S-M, 2*S-M, R, R, paint); //
525
      paint.setColor(0xffffffff);                                  // WHITE
526
      canvas.drawRoundRect(  S+M, S+M, 2*S-M, 2*S-M, R, R, paint); //
527
      paint.setColor(0xffb5651d);                                  // BROWN
528
      canvas.drawRoundRect(2*S+M, S+M, 3*S-M, 2*S-M, R, R, paint); //
529

  
530
      mTexture.setTexture(bitmap);
531
      }
375
   public void createTexture()
376
     {
377
     Bitmap bitmap;
378

  
379
     final int S = 128;
380
     final int W = 3*S;
381
     final int H = 2*S;
382
     final int R = S/10;
383
     final int M = S/20;
384

  
385
     Paint paint = new Paint();
386
     bitmap = Bitmap.createBitmap(W,H, Bitmap.Config.ARGB_8888);
387
     Canvas canvas = new Canvas(bitmap);
388

  
389
     paint.setAntiAlias(true);
390
     paint.setTextAlign(Paint.Align.CENTER);
391
     paint.setStyle(Paint.Style.FILL);
392

  
393
     // 3x2 bitmap = 6 squares:
394
     //
395
     // RED     GREEN   BLUE
396
     // YELLOW  WHITE   BROWN
397

  
398
     paint.setColor(0xff000000);                                  // BLACK BACKGROUND
399
     canvas.drawRect(0, 0, W, H, paint);                          //
400

  
401
     paint.setColor(0xffff0000);                                  // RED
402
     canvas.drawRoundRect(    M,   M,   S-M,   S-M, R, R, paint); //
403
     paint.setColor(0xff00ff00);                                  // GREEN
404
     canvas.drawRoundRect(  S+M,   M, 2*S-M,   S-M, R, R, paint); //
405
     paint.setColor(0xff0000ff);                                  // BLUE
406
     canvas.drawRoundRect(2*S+M,   M, 3*S-M,   S-M, R, R, paint); //
407
     paint.setColor(0xffffff00);                                  // YELLOW
408
     canvas.drawRoundRect(    M, S+M,   S-M, 2*S-M, R, R, paint); //
409
     paint.setColor(0xffffffff);                                  // WHITE
410
     canvas.drawRoundRect(  S+M, S+M, 2*S-M, 2*S-M, R, R, paint); //
411
     paint.setColor(0xffb5651d);                                  // BROWN
412
     canvas.drawRoundRect(2*S+M, S+M, 3*S-M, 2*S-M, R, R, paint); //
413

  
414
     mTexture.setTexture(bitmap);
415
     }
532 416

  
533 417
///////////////////////////////////////////////////////////////////////////////////////////////////
534 418

  
535
    public void recomputeScaleFactor(int screenWidth, int screenHeight)
536
      {
537
      int texW = mNodeTexture.getWidth();
538
      int texH = mNodeTexture.getHeight();
539

  
540
      if( (float)texH/texW > (float)screenHeight/screenWidth )
541
        {
542
        int w = (screenHeight*texW)/texH;
543
        float factor = (float)screenHeight/texH;
544
        mNodeMove.set((screenWidth-w)*0.5f ,0, 0);
545
        mNodeScale.set(factor,factor,factor);
546
        }
547
      else
548
        {
549
        int h = (screenWidth*texH)/texW;
550
        float factor = (float)screenWidth/texW;
551
        mNodeMove.set(0,(screenHeight-h)*0.5f,0);
552
        mNodeScale.set(factor,factor,factor);
553
        }
554

  
555
      float scaleFactor = (CUBE_SCREEN_RATIO*texW/(TEXTURE_SIZE*mSize));
556

  
557
      mMove.set( texW*0.5f , texH*0.5f , 0.0f );
558
      mScale.set(scaleFactor,scaleFactor,scaleFactor);
419
   public void apply(Effect effect, int position)
420
     {
421
     for(int x=0; x<mSize; x++)
422
       for(int y=0; y<mSize; y++)
423
         for(int z=0; z<mSize; z++)
424
           {
425
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
426
             {
427
             mEffects[x][y][z].apply(effect, position);
428
             }
429
           }
559 430
      }
560 431

  
561 432
///////////////////////////////////////////////////////////////////////////////////////////////////
562 433

  
563
    public void apply(Effect effect, int position)
564
      {
565
      for(int x=0; x<mSize; x++)
566
        for(int y=0; y<mSize; y++)
567
          for(int z=0; z<mSize; z++)
568
            {
569
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
570
              {
571
              mEffects[x][y][z].apply(effect, position);
572
              }
573
            }
434
   public void remove(long effectID)
435
     {
436
     for(int x=0; x<mSize; x++)
437
       for(int y=0; y<mSize; y++)
438
         for(int z=0; z<mSize; z++)
439
           {
440
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
441
             {
442
             mEffects[x][y][z].abortById(effectID);
443
             }
444
           }
574 445
      }
575 446

  
576 447
///////////////////////////////////////////////////////////////////////////////////////////////////
577 448

  
578
    public void remove(long effectID)
579
      {
580
      for(int x=0; x<mSize; x++)
581
        for(int y=0; y<mSize; y++)
582
          for(int z=0; z<mSize; z++)
583
            {
584
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
585
              {
586
              mEffects[x][y][z].abortById(effectID);
587
              }
588
            }
449
   public void solve()
450
     {
451
     for(int x=0; x<mSize; x++)
452
       for(int y=0; y<mSize; y++)
453
         for(int z=0; z<mSize; z++)
454
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
455
             {
456
             mQuatScramble[x][y][z].set(0,0,0,1);
457
             mCurrentPosition[x][y][z].set(x,y,z);
458
             }
589 459
      }
590 460

  
591 461
///////////////////////////////////////////////////////////////////////////////////////////////////
592 462

  
593
    public void solve()
594
      {
595
      for(int x=0; x<mSize; x++)
596
        for(int y=0; y<mSize; y++)
597
          for(int z=0; z<mSize; z++)
598
            if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
599
              {
600
              mQuatScramble[x][y][z].set(0,0,0,1);
601
              mCurrentPosition[x][y][z].set(x,y,z);
602
              }
603
      }
463
   public boolean isSolved()
464
     {
465
     Static4D q = mQuatScramble[0][0][0];
466

  
467
     float x = q.get0();
468
     float y = q.get1();
469
     float z = q.get2();
470
     float w = q.get3();
471

  
472
     for(int i = 0; i< mSize; i++)
473
       for(int j = 0; j< mSize; j++)
474
         for(int k = 0; k< mSize; k++)
475
           {
476
           if( i==0 || i==mSize-1 || j==0 || j==mSize-1 || k==0 || k==mSize-1 )
477
             {
478
             q = mQuatScramble[i][j][k];
479

  
480
             if( q.get0()!=x || q.get1()!=y || q.get2()!=z || q.get3()!=w )
481
               {
482
               return false;
483
               }
484
             }
485
           }
486

  
487
     return true;
488
     }
604 489

  
605 490
///////////////////////////////////////////////////////////////////////////////////////////////////
606 491

  
607
    public boolean isSolved()
608
      {
609
      Static4D q = mQuatScramble[0][0][0];
610

  
611
      float x = q.get0();
612
      float y = q.get1();
613
      float z = q.get2();
614
      float w = q.get3();
615

  
616
      for(int i = 0; i< mSize; i++)
617
        for(int j = 0; j< mSize; j++)
618
          for(int k = 0; k< mSize; k++)
619
            {
620
            if( i==0 || i==mSize-1 || j==0 || j==mSize-1 || k==0 || k==mSize-1 )
621
              {
622
              q = mQuatScramble[i][j][k];
492
   public void beginNewRotation(int vector, int row )
493
     {
494
     Static3D axis = VectX;
623 495

  
624
              if( q.get0()!=x || q.get1()!=y || q.get2()!=z || q.get3()!=w )
625
                {
626
                return false;
627
                }
628
              }
629
            }
496
     switch(vector)
497
       {
498
       case VECTX: axis = VectX; break;
499
       case VECTY: axis = VectY; break;
500
       case VECTZ: axis = VectZ; break;
501
       }
630 502

  
631
      return true;
632
      }
503
     mRotAxis = vector;
504
     mRotRow  = row;
633 505

  
634
///////////////////////////////////////////////////////////////////////////////////////////////////
506
     mRotationAngleStatic.set0(0.0f);
635 507

  
636
    public int getSize()
637
      {
638
      return mSize;
639
      }
508
     for(int x=0; x<mSize; x++)
509
       for(int y=0; y<mSize; y++)
510
         for(int z=0; z<mSize; z++)
511
           if( x==0 || x==mSize-1 || y==0 || y==mSize-1 || z==0 || z==mSize-1 )
512
             {
513
             if( belongsToRotation(x,y,z,vector,mRotRow) )
514
               {
515
               mRotationAxis[x][y][z].set(axis);
516
               mRotationAngle[x][y][z].add(mRotationAngleStatic);
517
               }
518
             }
519
     }
640 520

  
641 521
///////////////////////////////////////////////////////////////////////////////////////////////////
642 522

  
643
    public long addNewRotation(int vector, int row, int angle, long durationMillis, EffectListener listener )
523
   public long addNewRotation(int vector, int row, int angle, long durationMillis, EffectListener listener )
644 524
      {
645 525
      Static3D axis = VectX;
646 526
      long effectID=0;
......
685 565

  
686 566
///////////////////////////////////////////////////////////////////////////////////////////////////
687 567

  
688
    public void removeRotationNow()
568
   public void removeRotationNow()
689 569
      {
690 570
      float qx=0,qy=0,qz=0;
691 571
      boolean first = true;
src/main/java/org/distorted/object/RubikCubeMovement.java
22 22
import org.distorted.library.type.Static2D;
23 23
import org.distorted.library.type.Static4D;
24 24

  
25
import static org.distorted.object.RubikObjectList.VECTX;
26
import static org.distorted.object.RubikObjectList.VECTY;
27
import static org.distorted.object.RubikObjectList.VECTZ;
28

  
25 29
///////////////////////////////////////////////////////////////////////////////////////////////////
26 30

  
27
public class RubikCubeMovement
31
class RubikCubeMovement extends RubikObjectMovement
28 32
{
29 33
    private final static int NONE   =-1;
30 34
    private final static int FRONT  = 0;  // has to be 6 consecutive ints
......
34 38
    private final static int TOP    = 4;  //
35 39
    private final static int BOTTOM = 5;  //
36 40

  
37
    private static final int[] VECT = {RubikCube.VECTX,RubikCube.VECTY,RubikCube.VECTZ};
41
    private static final int[] VECT = {VECTX,VECTY,VECTZ};
38 42

  
39 43
    private float[] mPoint, mCamera, mDiff, mTouch;
40 44
    private int mRotationVect, mLastTouchedFace;
......
70 74
      switch(face)
71 75
        {
72 76
        case FRONT :
73
        case BACK  : return RubikCube.VECTX;
77
        case BACK  : return VECTX;
74 78
        case LEFT  :
75
        case RIGHT : return RubikCube.VECTZ;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff