Project

General

Profile

« Previous | Next » 

Revision b2a92941

Added by Leszek Koltunski over 3 years ago

Again abandon RubikControl (after bumping into hard-to-solve issues)

View differences:

src/main/java/org/distorted/control/RubikControlRotate.java
19 19

  
20 20
package org.distorted.control;
21 21

  
22
import android.graphics.Bitmap;
23
import android.graphics.BitmapFactory;
24

  
22 25
import org.distorted.helpers.QuatHelper;
26
import org.distorted.library.effect.MatrixEffectQuaternion;
23 27
import org.distorted.library.effect.MatrixEffectScale;
24 28
import org.distorted.library.main.DistortedEffects;
25 29
import org.distorted.library.main.DistortedNode;
26 30
import org.distorted.library.main.DistortedScreen;
27 31
import org.distorted.library.main.DistortedTexture;
28 32
import org.distorted.library.mesh.MeshQuad;
33
import org.distorted.library.message.EffectListener;
29 34
import org.distorted.library.type.Dynamic;
30 35
import org.distorted.library.type.Dynamic3D;
36
import org.distorted.library.type.Dynamic4D;
31 37
import org.distorted.library.type.Static3D;
32 38
import org.distorted.library.type.Static4D;
39
import org.distorted.main.R;
40
import org.distorted.main.RubikActivity;
33 41
import org.distorted.objects.TwistyObject;
34 42

  
43
import java.io.IOException;
44
import java.io.InputStream;
45

  
35 46
///////////////////////////////////////////////////////////////////////////////////////////////////
36 47

  
37
class RubikControlRotate
48
class RubikControlRotate implements EffectListener
38 49
  {
39 50
  private static final int NUM_SCREEN = 0;
40 51
  private static final int NUM_OBJECT = 1;
......
44 55
  private final RubikControl mControl;
45 56
  private DistortedEffects[] mScreenEffects, mObjectEffects;
46 57
  private DistortedNode[] mScreenNodes, mObjectNodes;
47
  private long mScreenEffectID, mObjectEffectID;
58
  private long mScreenEffectID, mObjectEffectID, mCubeEffectID;
48 59
  private Static4D mObjRotQuat;
49 60

  
50
  private Dynamic3D mDynamic;
61
  private Dynamic3D mDynamic3;
62
  private Dynamic4D mDynamic4;
51 63
  private MatrixEffectScale mScale;
64
  private MatrixEffectQuaternion mQuaternion;
52 65
  private MeshQuad mScreenQuad, mObjectQuad;
53 66

  
67
///////////////////////////////////////////////////////////////////////////////////////////////////
68

  
69
   private Bitmap openBitmap(RubikActivity act, int resource)
70
     {
71
     try( InputStream is = act.getResources().openRawResource(resource) )
72
       {
73
       return BitmapFactory.decodeStream(is);
74
       }
75
     catch( IOException e )
76
       {
77
       // ignore
78
       }
79

  
80
     return null;
81
     }
82

  
54 83
///////////////////////////////////////////////////////////////////////////////////////////////////
55 84

  
56 85
  private void computeInitQuat()
57 86
    {
58
    double alphaZ = -Math.PI* 0.1250f;
59
    double alphaY = -Math.PI* 0.0625f;
87
    double alphaZ = 0;//-Math.PI* 0.1250f;
88
    double alphaY = 0;//-Math.PI* 0.0625f;
60 89

  
61 90
    alphaY /= 2;
62 91
    alphaZ /= 2;
......
107 136
      quat = computeQuat(axis[a],objCurrQuat,axX,axY,axZ);
108 137
      cos = quat.get3();
109 138

  
139
android.util.Log.e("D", "axis="+a+" "+quat.get0()+" "+quat.get1()+" "+quat.get2()+" "+quat.get3() );
140

  
110 141
      if (cos > maxCos)
111 142
        {
112 143
        maxCos = cos;
113 144
        chosen = a;
114
        mObjRotQuat = quat;
145
        if( mObjRotQuat==null ) mObjRotQuat = new Static4D(quat);
146
        else mObjRotQuat.set(quat);
115 147
        }
116 148
      }
117 149

  
118 150
    android.util.Log.e("D", "axis chosen: "+chosen);
151

  
152

  
153
android.util.Log.e("D", mObjRotQuat.get0()+" "+mObjRotQuat.get1()+" "+mObjRotQuat.get2()+" "+mObjRotQuat.get3() );
119 154
    }
120 155

  
121 156
///////////////////////////////////////////////////////////////////////////////////////////////////
122 157

  
123 158
  private void setScreenEffectsStage1()
124 159
    {
125
    mDynamic.resetToBeginning();
160
    mDynamic3.resetToBeginning();
126 161
    mScale.notifyWhenFinished(mControl);
127 162
    }
128 163

  
129 164
///////////////////////////////////////////////////////////////////////////////////////////////////
165
// the whole cube rotates so that its axis is alignled according to the Euler angles defined in
166
// computeInitQuat()
130 167

  
131 168
  private void setObjectEffectsStage1()
132 169
    {
133
    mDynamic.resetToBeginning();
134
    mScale.notifyWhenFinished(mControl);
170
    TwistyObject obj = mControl.getObject();
171
    obj.apply(mQuaternion,0);
172
    mDynamic4.resetToBeginning();
173
    mQuaternion.notifyWhenFinished(this);
174

  
175

  
176
Static4D d = mDynamic4.getPoint(1);
177

  
178
android.util.Log.e("D", "set: "+d.get0()+" "+d.get1()+" "+d.get2()+" "+d.get3() );
179

  
180
    }
181

  
182
///////////////////////////////////////////////////////////////////////////////////////////////////
183

  
184
  private void setObjectEffectsStage2()
185
    {
186

  
135 187
    }
136 188

  
137 189
///////////////////////////////////////////////////////////////////////////////////////////////////
......
147 199
    Static3D scaleStart= new Static3D(1,1,1);
148 200
    Static3D scaleEnd  = new Static3D(wid,wid,wid);
149 201

  
150
    mDynamic = new Dynamic3D(10000,0.5f);
151
    mDynamic.add(scaleStart);
152
    mDynamic.add(scaleEnd  );
153
    mDynamic.add(scaleStart);
154
    mDynamic.setMode(Dynamic.MODE_PATH);
202
    mDynamic3 = new Dynamic3D(10000,0.5f);
203
    mDynamic3.add(scaleStart);
204
    mDynamic3.add(scaleEnd  );
205
    mDynamic3.add(scaleStart);
206
    mDynamic3.setMode(Dynamic.MODE_PATH);
155 207

  
156
    mScale = new MatrixEffectScale(mDynamic);
208
    mScale = new MatrixEffectScale(mDynamic3);
157 209
    mScreenEffectID = mScale.getID();
158 210
    mScreenEffects[0].apply(mScale);
159 211
    }
......
165 217
    mObjectEffects   = new DistortedEffects[NUM_OBJECT];
166 218
    mObjectEffects[0]= new DistortedEffects();
167 219

  
168
    DistortedScreen screen = mControl.getScreen();
169
    int wid = screen.getWidth();
220
    mDynamic4 = new Dynamic4D(5000,0.5f);
221
    mDynamic4.add(new Static4D(0,0,0,1));
222
    mDynamic4.add(mObjRotQuat);
223
    mDynamic4.add(mObjRotQuat);
224
    mDynamic4.add(mObjRotQuat);
225
    mDynamic4.setMode(Dynamic.MODE_PATH);
170 226

  
171
    Static3D scaleStart= new Static3D(1,1,1);
172
    Static3D scaleEnd  = new Static3D(wid,wid,wid);
227
android.util.Log.e("D", "create: "+mObjRotQuat.get0()+" "+mObjRotQuat.get1()+" "+mObjRotQuat.get2()+" "+mObjRotQuat.get3() );
228

  
229
TwistyObject obj = mControl.getObject();
230
Static3D ax = obj.getRotationAxis()[0];
231
Static4D axis = new Static4D(ax.get0(), ax.get1(), ax.get2(), 0);
232

  
233
Static4D v1 = QuatHelper.rotateVectorByQuat( new Static4D(1,0,0,0), INIT_QUAT);
234
Static4D v2 = QuatHelper.rotateVectorByQuat( axis                 , mObjRotQuat);
173 235

  
174
    mDynamic = new Dynamic3D(10000,0.5f);
175
    mDynamic.add(scaleStart);
176
    mDynamic.add(scaleEnd  );
177
    mDynamic.add(scaleStart);
178
    mDynamic.setMode(Dynamic.MODE_PATH);
236
android.util.Log.e("D", "v1: "+v1.get0()+" "+v1.get1()+" "+v1.get2()+" "+v1.get3());
237
android.util.Log.e("D", "v2: "+v2.get0()+" "+v2.get1()+" "+v2.get2()+" "+v2.get3());
238
android.util.Log.e("D", "ax: "+ax.get0()+" "+ax.get1()+" "+ax.get2());
179 239

  
180
    mScale = new MatrixEffectScale(mDynamic);
181
    mObjectEffectID = mScale.getID();
182
    mObjectEffects[0].apply(mScale);
240

  
241
    Static3D center = new Static3D(0,0,0);
242
    mQuaternion = new MatrixEffectQuaternion(mDynamic4, center);
243
    mCubeEffectID = mQuaternion.getID();
244

  
245
    DistortedScreen screen = mControl.getScreen();
246
    int wid = screen.getWidth();
247
    Static3D scaleFactor = new Static3D(wid,wid*0.1f,10);
248
    MatrixEffectScale scale = new MatrixEffectScale(scaleFactor);
249
    MatrixEffectQuaternion quat = new MatrixEffectQuaternion(INIT_QUAT,center);
250

  
251
    mObjectEffects[0].apply(scale);
252
    mObjectEffects[0].apply(quat);
183 253
    }
184 254

  
185 255
///////////////////////////////////////////////////////////////////////////////////////////////////
......
207 277
      mObjectQuad = new MeshQuad();
208 278
      }
209 279

  
210
    if( INIT_QUAT==null ) computeInitQuat();
211

  
212
    computeRotQuat();
213

  
214
    DistortedTexture texture = new DistortedTexture();
215
    texture.setColorARGB(0xff00ff00);
216
    mObjectNodes[0] = new DistortedNode(texture, mObjectEffects[0], mObjectQuad);
217
    }
218

  
219
///////////////////////////////////////////////////////////////////////////////////////////////////
220
// ??
280
    RubikActivity act = mControl.getActivity();
221 281

  
222
  long getEffectID()
223
    {
224
    return mObjectEffectID;
225
    }
282
    if( act!=null )
283
      {
284
      Bitmap bmpArrow = openBitmap(act, R.drawable.ui_axis_arrow);
285
      DistortedTexture textureArrow = new DistortedTexture();
226 286

  
227
///////////////////////////////////////////////////////////////////////////////////////////////////
287
      if( bmpArrow!=null ) textureArrow.setTexture(bmpArrow);
228 288

  
229
  long getScreenEffectID()
230
    {
231
    return mScreenEffectID;
289
      mObjectNodes[0] = new DistortedNode(textureArrow, mObjectEffects[0], mObjectQuad);
290
      }
291
    else
292
      {
293
      android.util.Log.e("D", "Activity NULL!!");
294
      }
232 295
    }
233 296

  
234 297
///////////////////////////////////////////////////////////////////////////////////////////////////
235 298

  
236
  long getObjectEffectID()
299
  long getEffectID()
237 300
    {
238 301
    return mObjectEffectID;
239 302
    }
......
265 328
    {
266 329
    if( NUM_OBJECT>0 )
267 330
      {
331
      if( INIT_QUAT==null ) computeInitQuat();
332
      computeRotQuat();
268 333
      if( mObjectEffects==null ) createObjectEffects();
269 334
      createObjectNodes();
270 335
      setObjectEffectsStage1();
......
286 351
    {
287 352
    mControl = control;
288 353
    }
354

  
355
///////////////////////////////////////////////////////////////////////////////////////////////////
356

  
357
  @Override
358
  public void effectFinished(long effectID)
359
    {
360
    if( effectID==mCubeEffectID)
361
      {
362
      setObjectEffectsStage2();
363

  
364
      TwistyObject obj = mControl.getObject();
365
      obj.remove(mCubeEffectID);
366
      mObjectEffectID = -1;
367
      mControl.effectFinished(mObjectEffectID);
368
      }
369
    }
289 370
  }
src/main/java/org/distorted/screens/RubikScreenPlay.java
57 57

  
58 58
  private static final int[] BUTTON_LABELS = { R.string.scores,
59 59
                                               R.string.patterns,
60
                                               R.string.control,
60
                                            //   R.string.control,
61 61
                                               R.string.solver,
62 62
                                               R.string.tutorials,
63 63
                                               R.string.about };
......
377 377
              pDiag.setArguments(pBundle);
378 378
              pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
379 379
              break;
380
/*
380 381
      case 2: RubikControl control = RubikControl.getInstance();
381 382
              //control.animateAll(act);
382 383
              control.animateRotate(act);
383 384
              break;
384
      case 3: ScreenList.switchScreen(act, ScreenList.SVER);
385
 */
386
      case 2: ScreenList.switchScreen(act, ScreenList.SVER);
385 387
              break;
386
      case 4: RubikDialogTutorial tDiag = new RubikDialogTutorial();
388
      case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
387 389
              Bundle tBundle = new Bundle();
388 390
              int tOrd = getTutorialOrdinal();
389 391
              tBundle.putInt("tab", tOrd );
390 392
              tDiag.setArguments(tBundle);
391 393
              tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
392 394
              break;
393
      case 5: RubikDialogAbout aDiag = new RubikDialogAbout();
395
      case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
394 396
              aDiag.show(act.getSupportFragmentManager(), null);
395 397
              break;
396 398
      }

Also available in: Unified diff