Project

General

Profile

Download (17.4 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ b72b71a1

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19
20
package org.distorted.bandaged;
21
22 77efd5ad Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
23
import javax.microedition.khronos.opengles.GL10;
24
25 72e386ef Leszek Koltunski
import android.app.Activity;
26 7cb8d4b0 Leszek Koltunski
import android.opengl.GLES31;
27 9530f6b0 Leszek Koltunski
import android.opengl.GLSurfaceView;
28 72e386ef Leszek Koltunski
import android.widget.Toast;
29 9530f6b0 Leszek Koltunski
30 6647b730 Leszek Koltunski
import org.distorted.dialogs.RubikDialogBandagedSave;
31 6dff7924 Leszek Koltunski
import org.distorted.library.effect.EffectType;
32 7cb8d4b0 Leszek Koltunski
import org.distorted.library.effect.PostprocessEffectBorder;
33 b3d6aff5 Leszek Koltunski
import org.distorted.library.effect.VertexEffectDeform;
34 7cb8d4b0 Leszek Koltunski
import org.distorted.library.main.DistortedEffects;
35
import org.distorted.library.main.DistortedFramebuffer;
36 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
37 da56b12f Leszek Koltunski
import org.distorted.library.main.DistortedNode;
38 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
39
40 20b60ad9 Leszek Koltunski
import org.distorted.library.main.InternalOutputSurface;
41 6dff7924 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
42 7cb8d4b0 Leszek Koltunski
import org.distorted.library.type.Static1D;
43 77efd5ad Leszek Koltunski
import org.distorted.library.type.Static3D;
44
import org.distorted.library.type.Static4D;
45 72e386ef Leszek Koltunski
import org.distorted.objectlib.json.JsonWriter;
46 7cb8d4b0 Leszek Koltunski
import org.distorted.objectlib.main.ShapeHexahedron;
47 72e386ef Leszek Koltunski
import org.distorted.objectlib.main.TwistyObject;
48
import org.distorted.objectlib.objects.TwistyBandagedGeneric;
49
import org.json.JSONException;
50
51
import java.io.File;
52
import java.io.FileNotFoundException;
53
import java.io.IOException;
54 7cb8d4b0 Leszek Koltunski
import java.nio.ByteBuffer;
55
import java.nio.ByteOrder;
56 9530f6b0 Leszek Koltunski
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58
59
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
60
{
61 7cb8d4b0 Leszek Koltunski
   public static final float BRIGHTNESS = 0.333f;
62 e0b71e6e Leszek Koltunski
   private static final int DURATION = 1000;
63
64 6f3af598 Leszek Koltunski
   private static final int COLOR_DEFAULT = 0xffffff55;
65
   private static final int COLOR_MARKED  = 0xffff0000;
66 903041cd Leszek Koltunski
67
   static final float SCREEN_RATIO = 0.5f;
68
   static final float OBJECT_SIZE  = 3.0f;
69 9530f6b0 Leszek Koltunski
70 77efd5ad Leszek Koltunski
   private final float[][] POSITIONS = new float[][]
71 da56b12f Leszek Koltunski
        {
72 50ec342b Leszek Koltunski
          {-1,  1,  1},
73
          {-1,  1,  0},
74
          {-1,  1, -1},
75
          {-1,  0,  1},
76
          {-1,  0,  0},
77
          {-1,  0, -1},
78
          {-1, -1,  1},
79
          {-1, -1,  0},
80
          {-1, -1, -1},
81
          { 0, -1,  1},
82
          { 0, -1,  0},
83
          { 0,  1,  1},
84
          { 0,  1,  0},
85
          { 0,  1, -1},
86
          { 0,  0,  1},
87
          { 0,  0, -1},
88
          { 1,  1,  1},
89
          { 1,  1,  0},
90
          { 1,  1, -1},
91
          { 1,  0,  1},
92
          { 1,  0,  0},
93
          { 1, -1,  1},
94
          { 1,  0, -1},
95
          { 1, -1, -1},
96
          { 1, -1,  0},
97
          { 0, -1, -1},
98 da56b12f Leszek Koltunski
        };
99
100 75173f81 Leszek Koltunski
   private final BandagedCreatorView mView;
101
   private final DistortedScreen mScreen;
102
   private final Static3D mScale;
103 50ec342b Leszek Koltunski
   private final Static4D mQuatT, mQuatA;
104 75173f81 Leszek Koltunski
105 5d5ed376 Leszek Koltunski
   private BandagedCubit[] mCubits;
106 e0b71e6e Leszek Koltunski
   private boolean mInitialPhase;
107
   private long mStartTime;
108
   private float mScaleValue;
109 75173f81 Leszek Koltunski
   private float mX, mY, mZ, mW;
110 e0b71e6e Leszek Koltunski
   private boolean mResetQuats, mSetQuatT, mResettingObject;
111 7cb8d4b0 Leszek Koltunski
   private int mSaveIcon;
112
   private DistortedFramebuffer mFramebuffer;
113
   private String mPath;
114 da56b12f Leszek Koltunski
115 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
116
117
   BandagedCreatorRenderer(BandagedCreatorView v)
118
     {
119 50ec342b Leszek Koltunski
     mQuatT = new Static4D(0,0,0,1);
120
     mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
121 da56b12f Leszek Koltunski
122 9530f6b0 Leszek Koltunski
     mView = v;
123 77efd5ad Leszek Koltunski
124 e0b71e6e Leszek Koltunski
     mResetQuats     = false;
125
     mSetQuatT       = false;
126
     mResettingObject= false;
127 75173f81 Leszek Koltunski
128 7cb8d4b0 Leszek Koltunski
     mSaveIcon = -1;
129
130 9530f6b0 Leszek Koltunski
     mScreen = new DistortedScreen();
131
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
132 550db260 Leszek Koltunski
     mScale = new Static3D(1,1,1);
133 da56b12f Leszek Koltunski
     }
134
135 e0b71e6e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
136
137
   private boolean isAdjacent(float[] pos1, float[] pos2)
138
     {
139
     int len1 = pos1.length/3;
140
     int len2 = pos2.length/3;
141
142
     for(int i=0; i<len1; i++)
143
       for(int j=0; j<len2; j++)
144
         {
145
         float d0 = pos1[3*i  ] - pos2[3*j  ];
146
         float d1 = pos1[3*i+1] - pos2[3*j+1];
147
         float d2 = pos1[3*i+2] - pos2[3*j+2];
148
149
         if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true;
150
         }
151
152
     return false;
153
     }
154
155 da56b12f Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
156 a76cc4f4 Leszek Koltunski
157 da56b12f Leszek Koltunski
   private BandagedCubit[] createCubits()
158
     {
159 f9526099 Leszek Koltunski
     boolean roundCorners = DistortedLibrary.fastCompilationTF();
160 da56b12f Leszek Koltunski
     int len = POSITIONS.length;
161
     BandagedCubit[] cubits = new BandagedCubit[len];
162
163
     for(int c=0; c<len; c++)
164
       {
165 5d5ed376 Leszek Koltunski
       cubits[c] = new BandagedCubit(POSITIONS[c],mQuatT,mQuatA,mScale,COLOR_DEFAULT,roundCorners);
166 da56b12f Leszek Koltunski
       }
167
168
     return cubits;
169 9530f6b0 Leszek Koltunski
     }
170 a76cc4f4 Leszek Koltunski
171 e0b71e6e Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
172
173
   private void resetObject()
174
     {
175
     mView.resetCubits();
176
177
     int len = POSITIONS.length;
178
179
     for(int c=0; c<len; c++)
180
       {
181
       if( !mCubits[c].isAttached() )
182
         {
183
         mCubits[c].attach();
184 a41e3c94 Leszek Koltunski
         mCubits[c].setTexture( COLOR_DEFAULT);
185 e0b71e6e Leszek Koltunski
         mScreen.attach(mCubits[c].getNode());
186
         }
187
       if( mCubits[c].getPosition().length>3 )
188
         {
189
         mCubits[c].reset(mScaleValue);
190
         }
191
       }
192
     }
193
194 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
195
196
   @Override
197
   public void onDrawFrame(GL10 glUnused)
198
     {
199
     long time = System.currentTimeMillis();
200
     mScreen.render(time);
201 75173f81 Leszek Koltunski
202 50ec342b Leszek Koltunski
     if( mSetQuatT )
203 75173f81 Leszek Koltunski
       {
204 50ec342b Leszek Koltunski
       mSetQuatT = false;
205
       mQuatT.set(mX,mY,mZ,mW);
206 75173f81 Leszek Koltunski
       }
207
208
     if( mResetQuats )
209
       {
210
       mResetQuats = false;
211
212 50ec342b Leszek Koltunski
       float qx = mQuatT.get0();
213
       float qy = mQuatT.get1();
214
       float qz = mQuatT.get2();
215
       float qw = mQuatT.get3();
216 75173f81 Leszek Koltunski
217 50ec342b Leszek Koltunski
       float rx = mQuatA.get0();
218
       float ry = mQuatA.get1();
219
       float rz = mQuatA.get2();
220
       float rw = mQuatA.get3();
221 75173f81 Leszek Koltunski
222
       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
223
       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
224
       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
225
       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
226
227 50ec342b Leszek Koltunski
       mQuatT.set(0f, 0f, 0f, 1f);
228
       mQuatA.set(tx, ty, tz, tw);
229 75173f81 Leszek Koltunski
       }
230 e0b71e6e Leszek Koltunski
231
     if( mResettingObject )
232
       {
233
       boolean done = continueResetting(time);
234
       if( done ) mResettingObject = false;
235
       }
236 7cb8d4b0 Leszek Koltunski
237 eb6bccbd Leszek Koltunski
     if( mSaveIcon>=0 )
238
       {
239 f203ffa0 Leszek Koltunski
       renderIcon(time); // for some reason we need to call render() twice here, otherwise the
240
       mSaveIcon++;      // icon turns out black. Probably some problem with binding the texture.
241 eb6bccbd Leszek Koltunski
       }
242
     if( mSaveIcon>=2 )
243
       {
244
       saveIcon();
245
       mSaveIcon = -1;
246
       }
247 9530f6b0 Leszek Koltunski
     }
248
249
///////////////////////////////////////////////////////////////////////////////////////////////////
250
251
   @Override
252
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
253
      {
254 903041cd Leszek Koltunski
      final float Q = SCREEN_RATIO/OBJECT_SIZE;
255 550db260 Leszek Koltunski
      mScaleValue = width<height ? Q*width : Q*height;
256 a76cc4f4 Leszek Koltunski
257 c279ea6d Leszek Koltunski
      mScreen.detachAll();
258 a76cc4f4 Leszek Koltunski
      int len = POSITIONS.length;
259 13a3dfa9 Leszek Koltunski
      int touched = mView.getTouched();
260 a76cc4f4 Leszek Koltunski
261
      for(int i=0; i<len; i++)
262 28cb1607 Leszek Koltunski
        if( mCubits[i].isAttached() )
263
          {
264
          mCubits[i].scaleMove(mScaleValue);
265 13a3dfa9 Leszek Koltunski
          mCubits[i].setTexture( touched==i ? COLOR_MARKED : COLOR_DEFAULT);
266 28cb1607 Leszek Koltunski
          DistortedNode node = mCubits[i].getNode();
267
          mScreen.attach(node);
268
          }
269 c279ea6d Leszek Koltunski
270 550db260 Leszek Koltunski
      mScale.set( mScaleValue,mScaleValue,mScaleValue );
271 28cb1607 Leszek Koltunski
      mView.setScreenSize(width,height);
272 9530f6b0 Leszek Koltunski
      mScreen.resize(width,height);
273
      }
274
275
///////////////////////////////////////////////////////////////////////////////////////////////////
276
277
   @Override
278
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
279
      {
280 2b9a8da5 Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,25);
281 b38826fe Leszek Koltunski
      MeshBase.setMaxEffComponents(50);
282 6dff7924 Leszek Koltunski
283 b3d6aff5 Leszek Koltunski
      VertexEffectDeform.enable();
284
285 9530f6b0 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(mView.getContext(),this,1);
286 6dff7924 Leszek Koltunski
      DistortedLibrary.setCull(true);
287 5d5ed376 Leszek Koltunski
288
      mCubits= createCubits();
289
      mView.setCubits(mCubits);
290 9530f6b0 Leszek Koltunski
      }
291
292
///////////////////////////////////////////////////////////////////////////////////////////////////
293
294
   public void distortedException(Exception ex)
295
     {
296
     android.util.Log.e("CREATOR", "unexpected exception: "+ex.getMessage() );
297
     }
298 550db260 Leszek Koltunski
299
///////////////////////////////////////////////////////////////////////////////////////////////////
300
301
   public BandagedCubit[] getCubits()
302
     {
303
     return mCubits;
304
     }
305
306
///////////////////////////////////////////////////////////////////////////////////////////////////
307
308
   public DistortedScreen getScreen()
309
     {
310
     return mScreen;
311
     }
312
313
///////////////////////////////////////////////////////////////////////////////////////////////////
314
315
   public void tryConnectingCubits(int index1, int index2)
316
     {
317
     if( index1!=index2 )
318
       {
319
       float[] pos1 = mCubits[index1].getPosition();
320
       float[] pos2 = mCubits[index2].getPosition();
321
322
       if( isAdjacent(pos1,pos2) )
323
         {
324 28cb1607 Leszek Koltunski
         mCubits[index2].join(pos1,mScaleValue);
325 550db260 Leszek Koltunski
         mCubits[index1].detach();
326 28cb1607 Leszek Koltunski
         mScreen.detach(mCubits[index1].getNode());
327 550db260 Leszek Koltunski
         }
328
       }
329
     }
330 75173f81 Leszek Koltunski
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332
333 50ec342b Leszek Koltunski
   public Static4D getQuatAccu()
334
     {
335
     return mQuatA;
336
     }
337 75173f81 Leszek Koltunski
338
///////////////////////////////////////////////////////////////////////////////////////////////////
339
340 50ec342b Leszek Koltunski
   public void setQuatTemp(float x, float y, float z, float w)
341
     {
342
     mX = x;
343
     mY = y;
344
     mZ = z;
345
     mW = w;
346 75173f81 Leszek Koltunski
347 50ec342b Leszek Koltunski
     mSetQuatT = true;
348
     }
349 75173f81 Leszek Koltunski
350
///////////////////////////////////////////////////////////////////////////////////////////////////
351
352 50ec342b Leszek Koltunski
   public void resetQuats()
353
     {
354
     mResetQuats = true;
355
     }
356
357
///////////////////////////////////////////////////////////////////////////////////////////////////
358
359 e0b71e6e Leszek Koltunski
   public boolean isBusy()
360 50ec342b Leszek Koltunski
     {
361 e0b71e6e Leszek Koltunski
     return mResettingObject;
362
     }
363
364
///////////////////////////////////////////////////////////////////////////////////////////////////
365
366
   public void saveObject()
367 72e386ef Leszek Koltunski
     {
368
     int len = POSITIONS.length;
369
     int numAttached=0;
370
371
     for(int i=0; i<len; i++)
372
       if( mCubits[i].isAttached() ) numAttached++;
373
374
     float[][] pos = new float[numAttached][];
375
     int attached=0;
376
377
     for(int i=0; i<len; i++)
378
       if( mCubits[i].isAttached() )
379
         {
380
         pos[attached++] = mCubits[i].getPosition();
381
         }
382
383
     TwistyBandagedGeneric.setPositions(pos);
384 20b60ad9 Leszek Koltunski
     TwistyObject obj = new TwistyBandagedGeneric( new Static4D(0,0,0,1), 1.0f, TwistyObject.MODE_NORM);
385 72e386ef Leszek Koltunski
     BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext();
386
387 e48ad1af Leszek Koltunski
     boolean success = createObjectJson(obj,act);
388 20b60ad9 Leszek Koltunski
     setupIconCreation(act);
389 e48ad1af Leszek Koltunski
390
     if( success )
391
       {
392
       act.addObject(obj.getShortName());
393
       }
394 72e386ef Leszek Koltunski
     }
395
396
///////////////////////////////////////////////////////////////////////////////////////////////////
397
398 e48ad1af Leszek Koltunski
   private boolean createObjectJson(TwistyObject object, Activity act)
399 72e386ef Leszek Koltunski
     {
400
     final String name = object.getShortName()+"_object.json";
401
     File file = new File(act.getFilesDir(), name);
402
     String filename = file.getAbsolutePath();
403
404
     try
405
       {
406
       JsonWriter writer = JsonWriter.getInstance();
407
       String json = writer.createObjectString(object,24);
408
       writer.write(filename,json);
409 e48ad1af Leszek Koltunski
       return true;
410 72e386ef Leszek Koltunski
       }
411
     catch(JSONException ex)
412
       {
413
       act.runOnUiThread(new Runnable()
414
         {
415
         public void run()
416
           {
417
           String message = "JSON Exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
418
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
419
           }
420
         });
421 e48ad1af Leszek Koltunski
422
       return false;
423 72e386ef Leszek Koltunski
       }
424
     catch(FileNotFoundException ex)
425
       {
426
       act.runOnUiThread(new Runnable()
427
         {
428
         public void run()
429
           {
430
           String message = "FileNotFound exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
431
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
432
           }
433
         });
434 e48ad1af Leszek Koltunski
435
       return false;
436 72e386ef Leszek Koltunski
       }
437
     catch(IOException ex)
438
       {
439
       act.runOnUiThread(new Runnable()
440
         {
441
         public void run()
442
           {
443
           String message = "IO exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
444
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
445
           }
446
         });
447 e48ad1af Leszek Koltunski
448
       return false;
449 72e386ef Leszek Koltunski
       }
450
     }
451
452
///////////////////////////////////////////////////////////////////////////////////////////////////
453 7cb8d4b0 Leszek Koltunski
454 20b60ad9 Leszek Koltunski
   private void setupIconCreation(Activity act)
455 72e386ef Leszek Koltunski
     {
456 f203ffa0 Leszek Koltunski
     final float R=1.0f;
457
     final int FBO_WIDTH  = (int)(R*240);
458
     final int FBO_HEIGHT = (int)(R*360);
459
     final float OBJECT_SIZE = R*0.38f;
460
461
     TwistyObject object = new TwistyBandagedGeneric(ShapeHexahedron.DEFAULT_ROT, OBJECT_SIZE, TwistyObject.MODE_ICON);
462 eb6bccbd Leszek Koltunski
     DistortedEffects effects = object.getObjectEffects();
463
     DistortedNode node = object.getNode();
464
465 20b60ad9 Leszek Koltunski
     if( mFramebuffer==null )
466
       {
467 f203ffa0 Leszek Koltunski
       mFramebuffer = new DistortedFramebuffer(FBO_WIDTH,FBO_HEIGHT,1, InternalOutputSurface.DEPTH_NO_STENCIL);
468
       mFramebuffer.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
469 20b60ad9 Leszek Koltunski
       }
470 7cb8d4b0 Leszek Koltunski
471 20b60ad9 Leszek Koltunski
     mFramebuffer.detachAll();
472
     mFramebuffer.attach(node);
473 7cb8d4b0 Leszek Koltunski
474
     Static1D halo = new Static1D(5);
475
     Static4D color = new Static4D(0,0,0,1);
476
     PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color);
477
     border.setHaloDepth(false);
478
     effects.apply(border);
479
480
     final String name = object.getShortName()+".png";
481
     File file = new File(act.getFilesDir(), name);
482
     String filename = file.getAbsolutePath();
483
484
     mSaveIcon = 0;
485
     mPath = filename;
486 72e386ef Leszek Koltunski
     }
487 7cb8d4b0 Leszek Koltunski
488
///////////////////////////////////////////////////////////////////////////////////////////////////
489
490 eb6bccbd Leszek Koltunski
   private void renderIcon(long time)
491
     {
492
     mFramebuffer.render(time);
493
     }
494 7cb8d4b0 Leszek Koltunski
495 eb6bccbd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
496 7cb8d4b0 Leszek Koltunski
497 eb6bccbd Leszek Koltunski
   private void saveIcon()
498
     {
499
     int fW = mFramebuffer.getWidth();
500
     int fH = mFramebuffer.getHeight();
501 7cb8d4b0 Leszek Koltunski
502 eb6bccbd Leszek Koltunski
     ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4);
503
     buf.order(ByteOrder.LITTLE_ENDIAN);
504
505
     mFramebuffer.setAsReadFramebuffer(0);
506
     GLES31.glReadBuffer(GLES31.GL_COLOR_ATTACHMENT0);
507
     GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf);
508
     BandagedCreatorWorkerThread.newBuffer(buf,fW,fH,6,mPath);
509
     GLES31.glBindFramebuffer(GLES31.GL_READ_FRAMEBUFFER, 0);
510
511
     mSaveIcon = -1;
512
     }
513 7cb8d4b0 Leszek Koltunski
514 72e386ef Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
515
516
   public void displaySavingDialog()
517 e0b71e6e Leszek Koltunski
     {
518 61a7b812 Leszek Koltunski
     BandagedCreatorActivity act = (BandagedCreatorActivity)mView.getContext();
519 6647b730 Leszek Koltunski
     RubikDialogBandagedSave saveDiag = new RubikDialogBandagedSave();
520 61a7b812 Leszek Koltunski
     saveDiag.show(act.getSupportFragmentManager(), null);
521 e0b71e6e Leszek Koltunski
     }
522
523
///////////////////////////////////////////////////////////////////////////////////////////////////
524
525
   public void setupReset()
526
     {
527
     mResettingObject = true;
528
     mInitialPhase    = true;
529
     mStartTime       = System.currentTimeMillis();
530
     }
531
532
///////////////////////////////////////////////////////////////////////////////////////////////////
533
534
   public boolean continueResetting(long time)
535
     {
536
     long diff = time-mStartTime;
537
     float quotient = ((float)diff)/DURATION;
538
539
     if( mInitialPhase && quotient>0.5f )
540
       {
541
       mInitialPhase=false;
542
       resetObject();
543
       }
544
545
     double angle = 2*Math.PI*quotient*quotient*(3-2*quotient);
546
547
     float sinA = (float)Math.sin(angle);
548
     float cosA = (float)Math.cos(angle);
549
550
     mQuatT.set(0, -sinA, 0, cosA);
551 50ec342b Leszek Koltunski
552 e0b71e6e Leszek Koltunski
     return quotient>1.0f;
553 50ec342b Leszek Koltunski
     }
554 6f3af598 Leszek Koltunski
555
///////////////////////////////////////////////////////////////////////////////////////////////////
556
557
  public void touchCubit(int index)
558
    {
559
    mCubits[index].setTexture(COLOR_MARKED);
560
    }
561
562
///////////////////////////////////////////////////////////////////////////////////////////////////
563
564
  public void untouchCubit(int index)
565
    {
566
    mCubits[index].setTexture(COLOR_DEFAULT);
567
    }
568 9530f6b0 Leszek Koltunski
}