Project

General

Profile

« Previous | Next » 

Revision 45686da2

Added by Leszek Koltunski almost 5 years ago

RubikCube: remove all awareness of rotations from RubikRenderer.

View differences:

src/main/java/org/distorted/magic/RubikRenderer.java
29 29
import org.distorted.library.main.DistortedTexture;
30 30
import org.distorted.library.mesh.MeshFlat;
31 31
import org.distorted.library.message.EffectListener;
32
import org.distorted.library.type.Static4D;
33 32

  
34 33
import javax.microedition.khronos.egl.EGLConfig;
35 34
import javax.microedition.khronos.opengles.GL10;
......
44 43

  
45 44
    private RubikSurfaceView mView;
46 45
    private DistortedScreen mScreen;
47
    private Static4D mQuatCurrent, mQuatAccumulated;
48
    private Static4D mTempCurrent, mTempAccumulated;
49 46
    private float mCubeSizeInScreenSpace;
50 47
    private int mNextCubeSize, mScrambleCubeNum;
51 48
    private long mRotationFinishedID;
52 49
    private long[] mEffectID;
53 50
    private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated, mSolveCube, mScrambleCube;
54
    private boolean mCanRotate, mCanDrag, mCanScramble, mCanSolve;
51
    private boolean mCanRotate, mCanDrag, mCanUI;
55 52
    private RubikCube mOldCube, mNewCube;
56 53
    private int mScreenWidth, mScreenHeight;
57 54
    private MeshFlat mMesh;
......
67 64
      mOldCube = null;
68 65
      mNewCube = null;
69 66

  
70
      mTempCurrent     = new Static4D(0,0,0,1);
71
      mTempAccumulated = new Static4D(0,0,0,1);
72
      mQuatCurrent     = new Static4D(0,0,0,1);
73
      mQuatAccumulated = new Static4D(0,0,0,1);
74

  
75 67
      mScreenWidth = mScreenHeight = 0;
76 68
      mScrambleCubeNum = 0;
77 69

  
......
84 76

  
85 77
      mCanRotate   = true;
86 78
      mCanDrag     = true;
87
      mCanScramble = true;
88
      mCanSolve    = true;
79
      mCanUI       = true;
89 80

  
90 81
      mEffectID = new long[BaseEffect.Type.LENGTH];
91 82

  
......
105 96
      if( mFinishDragCurrent )
106 97
        {
107 98
        mFinishDragCurrent = false;
108
        mQuatCurrent.set(mTempCurrent);
99
        mView.setQuatCurrent();
109 100
        }
110 101

  
111 102
      if( mFinishDragAccumulated )
112 103
        {
113 104
        mFinishDragAccumulated = false;
114
        mQuatAccumulated.set(mTempAccumulated);
105
        mView.setQuatAccumulated();
115 106
        }
116 107

  
117 108
      if( mFinishRotation )
......
142 133
        mSolveCube   = false;
143 134
        mCanDrag     = false;
144 135
        mCanRotate   = false;
145
        mCanScramble = false;
146
        mCanSolve    = false;
136
        mCanUI       = false;
147 137
        doEffectNow(1);
148 138
        }
149 139

  
......
152 142
        mScrambleCube = false;
153 143
        mCanDrag      = false;
154 144
        mCanRotate    = false;
155
        mCanScramble  = false;
156
        mCanSolve     = false;
145
        mCanUI        = false;
157 146
        doEffectNow(2);
158 147
        }
159 148
      }
......
201 190

  
202 191
   public void effectFinished(final long effectID)
203 192
     {
204
     if(      effectID == mRotationFinishedID )
193
     if( effectID == mRotationFinishedID )
205 194
       {
206 195
       mRemoveRotation = true;
207 196
       }
208
     else if( effectID == mEffectID[0] )
209
       {
210
       mCanRotate   = true;
211
       mCanDrag     = true;
212
       }
213
     else if( effectID == mEffectID[1] )
214
       {
215
       mCanRotate   = true;
216
       mCanDrag     = true;
217
       mCanSolve    = true;
218
       mCanScramble = true;
219
       }
220
     else if( effectID == mEffectID[2] )
197
     else
221 198
       {
222
       mCanRotate   = true;
223
       mCanDrag     = true;
224
       mCanSolve    = true;
225
       mCanScramble = true;
199
       for(int i=0; i<BaseEffect.Type.LENGTH; i++)
200
         {
201
         if( effectID == mEffectID[i] )
202
           {
203
           mCanRotate   = true;
204
           mCanDrag     = true;
205
           mCanUI       = true;
206
           break;
207
           }
208
         }
226 209
       }
227 210
     }
228 211

  
......
271 254

  
272 255
   void scrambleCube(int num)
273 256
     {
274
     if( mCanScramble )
257
     if( mCanUI )
275 258
       {
276 259
       mScrambleCube = true;
277 260
       mScrambleCubeNum = num;
......
282 265

  
283 266
   void solveCube()
284 267
     {
285
     if( mCanSolve )
268
     if( mCanUI )
286 269
       {
287 270
       mSolveCube = true;
288 271
       }
......
298 281
     DistortedTexture texture = new DistortedTexture(TEXTURE_SIZE,TEXTURE_SIZE);
299 282
     DistortedEffects effects = new DistortedEffects();
300 283

  
301
     mNewCube = new RubikCube(newSize, mQuatCurrent, mQuatAccumulated, texture, mMesh, effects);
284
     mNewCube = new RubikCube(newSize, mView.getQuatCurrent(), mView.getQuatAccumulated(), texture, mMesh, effects);
302 285
     mNewCube.createTexture();
303 286

  
304 287
     if( mScreenWidth!=0 )
......
371 354

  
372 355
///////////////////////////////////////////////////////////////////////////////////////////////////
373 356

  
374
   void setQuatCurrent(Static4D current)
357
   void setQuatCurrentOnNextRender()
375 358
     {
376
     mTempCurrent.set(current);
377 359
     mFinishDragCurrent = true;
378 360
     }
379 361

  
380 362
///////////////////////////////////////////////////////////////////////////////////////////////////
381 363

  
382
   void setQuatAccumulated(Static4D accumulated)
364
   void setQuatAccumulatedOnNextRender()
383 365
     {
384
     mTempAccumulated.set(accumulated);
385 366
     mFinishDragAccumulated = true;
386 367
     }
387 368
}
src/main/java/org/distorted/magic/RubikSurfaceView.java
59 59
    private int mScreenWidth, mScreenHeight, mScreenMin;
60 60
    private float mCameraDistance;
61 61

  
62
    private static Static4D mQuatCurrent    =new Static4D(0,0,0,1);
63
    private static Static4D mQuatAccumulated=new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
62
    private static Static4D mQuatCurrent    = new Static4D(0,0,0,1);
63
    private static Static4D mQuatAccumulated= new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
64
    private static Static4D mTempCurrent    = new Static4D(0,0,0,1);
65
    private static Static4D mTempAccumulated= new Static4D(0,0,0,1);
64 66

  
65 67
///////////////////////////////////////////////////////////////////////////////////////////////////
66 68

  
......
81 83
        mScreenWidth = mScreenHeight = mScreenMin = 0;
82 84

  
83 85
        mRenderer = new RubikRenderer(this);
84
        mRenderer.setQuatAccumulated(mQuatAccumulated);
85 86

  
86 87
        final ActivityManager activityManager     = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
87 88
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
......
120 121
                                       break;
121 122
         case MotionEvent.ACTION_MOVE: if( mDragging )
122 123
                                         {
123
                                         mQuatCurrent.set(quatFromDrag(mX-x,mY-y));
124
                                         mRenderer.setQuatCurrent(mQuatCurrent);
124
                                         mTempCurrent.set(quatFromDrag(mX-x,mY-y));
125
                                         mRenderer.setQuatCurrentOnNextRender();
125 126
                                         }
126 127
                                       if( mBeginningRotation )
127 128
                                         {
......
141 142
                                       break;
142 143
         case MotionEvent.ACTION_UP  : if( mDragging )
143 144
                                         {
144
                                         mQuatAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
145
                                         mQuatCurrent.set(0f, 0f, 0f, 1f);
146
                                         mRenderer.setQuatCurrent(mQuatCurrent);
147
                                         mRenderer.setQuatAccumulated(mQuatAccumulated);
145
                                         mTempAccumulated.set(quatMultiply(mQuatCurrent, mQuatAccumulated));
146
                                         mTempCurrent.set(0f, 0f, 0f, 1f);
147
                                         mRenderer.setQuatCurrentOnNextRender();
148
                                         mRenderer.setQuatAccumulatedOnNextRender();
148 149
                                         }
149 150

  
150 151
                                       if( mContinuingRotation )
......
158 159
      return true;
159 160
      }
160 161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
    void setQuatAccumulated()
165
      {
166
      mQuatAccumulated.set(mTempAccumulated);
167
      }
168

  
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

  
171
    void setQuatCurrent()
172
      {
173
      mQuatCurrent.set(mTempCurrent);
174
      }
175

  
176
///////////////////////////////////////////////////////////////////////////////////////////////////
177

  
178
    Static4D getQuatAccumulated()
179
      {
180
      return mQuatAccumulated;
181
      }
182

  
183
///////////////////////////////////////////////////////////////////////////////////////////////////
184

  
185
    Static4D getQuatCurrent()
186
      {
187
      return mQuatCurrent;
188
      }
189

  
161 190
///////////////////////////////////////////////////////////////////////////////////////////////////
162 191

  
163 192
    RubikRenderer getRenderer()

Also available in: Unified diff