Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ 5a4ee169

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 44fec653 Leszek Koltunski
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 b4a6e84d Leszek Koltunski
import java.io.File;
13
import java.io.FileNotFoundException;
14
import java.io.IOException;
15 d0ad3964 Leszek Koltunski
import java.io.InputStream;
16 b4a6e84d Leszek Koltunski
import java.nio.ByteBuffer;
17
import java.nio.ByteOrder;
18
19 77efd5ad Leszek Koltunski
import javax.microedition.khronos.egl.EGLConfig;
20
import javax.microedition.khronos.opengles.GL10;
21
22 72e386ef Leszek Koltunski
import android.app.Activity;
23 d0ad3964 Leszek Koltunski
import android.content.res.Resources;
24 7cb8d4b0 Leszek Koltunski
import android.opengl.GLES31;
25 9530f6b0 Leszek Koltunski
import android.opengl.GLSurfaceView;
26 72e386ef Leszek Koltunski
import android.widget.Toast;
27 9530f6b0 Leszek Koltunski
28 6647b730 Leszek Koltunski
import org.distorted.dialogs.RubikDialogBandagedSave;
29 6dff7924 Leszek Koltunski
import org.distorted.library.effect.EffectType;
30 1a106eb8 Leszek Koltunski
import org.distorted.library.effect.FragmentEffectBrightness;
31 7cb8d4b0 Leszek Koltunski
import org.distorted.library.effect.PostprocessEffectBorder;
32
import org.distorted.library.main.DistortedEffects;
33
import org.distorted.library.main.DistortedFramebuffer;
34 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedLibrary;
35 da56b12f Leszek Koltunski
import org.distorted.library.main.DistortedNode;
36 9530f6b0 Leszek Koltunski
import org.distorted.library.main.DistortedScreen;
37 20b60ad9 Leszek Koltunski
import org.distorted.library.main.InternalOutputSurface;
38 6dff7924 Leszek Koltunski
import org.distorted.library.mesh.MeshBase;
39 7cb8d4b0 Leszek Koltunski
import org.distorted.library.type.Static1D;
40 77efd5ad Leszek Koltunski
import org.distorted.library.type.Static3D;
41
import org.distorted.library.type.Static4D;
42 e514732c leszek
import org.distorted.objectlib.bandaged.BandagedObject;
43 7da27d2b leszek
import org.distorted.objectlib.bandaged.LocallyBandagedList;
44 72e386ef Leszek Koltunski
import org.distorted.objectlib.json.JsonWriter;
45
import org.distorted.objectlib.main.TwistyObject;
46 f404152d Leszek Koltunski
47 72e386ef Leszek Koltunski
import org.json.JSONException;
48
49 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
50
51 d0ad3964 Leszek Koltunski
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.LibraryUser
52 9530f6b0 Leszek Koltunski
{
53 7cb8d4b0 Leszek Koltunski
   public static final float BRIGHTNESS = 0.333f;
54 213c15de Leszek Koltunski
   private static final int RESET_DURATION = 1000;
55 f6bf4e77 Leszek Koltunski
   private static final float MAX_SIZE_CHANGE = 1.70f;
56
   private static final float MIN_SIZE_CHANGE = 0.50f;
57 9530f6b0 Leszek Koltunski
58 75173f81 Leszek Koltunski
   private final BandagedCreatorView mView;
59 d0ad3964 Leszek Koltunski
   private final Resources mResources;
60 75173f81 Leszek Koltunski
   private final DistortedScreen mScreen;
61
   private final Static3D mScale;
62 50ec342b Leszek Koltunski
   private final Static4D mQuatT, mQuatA;
63 f404152d Leszek Koltunski
   private final BandagedObject mObject;
64 4dcfb7a9 leszek
   private final float mInitRatio;
65 75173f81 Leszek Koltunski
66 e0b71e6e Leszek Koltunski
   private boolean mInitialPhase;
67
   private long mStartTime;
68 b9d062cf Leszek Koltunski
   private float mQuatX, mQuatY, mQuatZ, mQuatW;
69 f6bf4e77 Leszek Koltunski
   private boolean mResetQuats, mSetQuatT, mResettingObject, mConnectingCubits, mCreatingCubits, mRescaling;
70 1d4592a2 Leszek Koltunski
   private int mIndex1, mIndex2;
71 7cb8d4b0 Leszek Koltunski
   private int mSaveIcon;
72
   private DistortedFramebuffer mFramebuffer;
73
   private String mPath;
74 b9d062cf Leszek Koltunski
   private boolean mCubitsCreated;
75 a8aa49dc Leszek Koltunski
   private int mWidth, mHeight;
76 f6bf4e77 Leszek Koltunski
   private float mScaleValue, mObjectScreenRatio;
77 da56b12f Leszek Koltunski
78 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
79
80 7da27d2b leszek
   BandagedCreatorRenderer(BandagedCreatorView v, int ordinal)
81 9530f6b0 Leszek Koltunski
     {
82 d0ad3964 Leszek Koltunski
     mView = v;
83
     mResources = v.getResources();
84
85 50ec342b Leszek Koltunski
     mQuatT = new Static4D(0,0,0,1);
86
     mQuatA = new Static4D(-0.25189602f,0.3546389f,0.009657208f,0.90038127f);
87 da56b12f Leszek Koltunski
88 1d4592a2 Leszek Koltunski
     mResetQuats       = false;
89
     mSetQuatT         = false;
90
     mResettingObject  = false;
91
     mConnectingCubits = false;
92 b9d062cf Leszek Koltunski
     mCubitsCreated    = false;
93 227e8c1f Leszek Koltunski
     mCreatingCubits   = false;
94 f6bf4e77 Leszek Koltunski
     mRescaling        = false;
95 75173f81 Leszek Koltunski
96 7cb8d4b0 Leszek Koltunski
     mSaveIcon = -1;
97
98 9530f6b0 Leszek Koltunski
     mScreen = new DistortedScreen();
99
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
100 550db260 Leszek Koltunski
     mScale = new Static3D(1,1,1);
101 7da27d2b leszek
     mObject= LocallyBandagedList.create(ordinal,mScreen);
102 4dcfb7a9 leszek
103
     mInitRatio = mObject.getScreenRatio();
104
     mObjectScreenRatio= mInitRatio;
105 e0b71e6e Leszek Koltunski
     }
106
107 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
108
109
   @Override
110
   public void onDrawFrame(GL10 glUnused)
111
     {
112
     long time = System.currentTimeMillis();
113
     mScreen.render(time);
114 75173f81 Leszek Koltunski
115 50ec342b Leszek Koltunski
     if( mSetQuatT )
116 75173f81 Leszek Koltunski
       {
117 50ec342b Leszek Koltunski
       mSetQuatT = false;
118 b9d062cf Leszek Koltunski
       mQuatT.set(mQuatX,mQuatY,mQuatZ,mQuatW);
119 75173f81 Leszek Koltunski
       }
120
121
     if( mResetQuats )
122
       {
123
       mResetQuats = false;
124
125 50ec342b Leszek Koltunski
       float qx = mQuatT.get0();
126
       float qy = mQuatT.get1();
127
       float qz = mQuatT.get2();
128
       float qw = mQuatT.get3();
129 75173f81 Leszek Koltunski
130 50ec342b Leszek Koltunski
       float rx = mQuatA.get0();
131
       float ry = mQuatA.get1();
132
       float rz = mQuatA.get2();
133
       float rw = mQuatA.get3();
134 75173f81 Leszek Koltunski
135
       float tx = rw*qx - rz*qy + ry*qz + rx*qw;
136
       float ty = rw*qy + rz*qx + ry*qw - rx*qz;
137
       float tz = rw*qz + rz*qw - ry*qx + rx*qy;
138
       float tw = rw*qw - rz*qz - ry*qy - rx*qx;
139
140 50ec342b Leszek Koltunski
       mQuatT.set(0f, 0f, 0f, 1f);
141
       mQuatA.set(tx, ty, tz, tw);
142 75173f81 Leszek Koltunski
       }
143 e0b71e6e Leszek Koltunski
144
     if( mResettingObject )
145
       {
146
       boolean done = continueResetting(time);
147
       if( done ) mResettingObject = false;
148
       }
149 7cb8d4b0 Leszek Koltunski
150 eb6bccbd Leszek Koltunski
     if( mSaveIcon>=0 )
151
       {
152 f203ffa0 Leszek Koltunski
       renderIcon(time); // for some reason we need to call render() twice here, otherwise the
153
       mSaveIcon++;      // icon turns out black. Probably some problem with binding the texture.
154 eb6bccbd Leszek Koltunski
       }
155
     if( mSaveIcon>=2 )
156
       {
157
       saveIcon();
158
       mSaveIcon = -1;
159
       }
160 1d4592a2 Leszek Koltunski
161
     if( mConnectingCubits )
162
       {
163 f404152d Leszek Koltunski
       mObject.tryConnectingCubits(mIndex1,mIndex2,mScaleValue);
164 e3c970a7 Leszek Koltunski
       mConnectingCubits = false;
165 1d4592a2 Leszek Koltunski
       }
166 227e8c1f Leszek Koltunski
167
     if( mCreatingCubits )
168
       {
169
       rescaleObject();
170
171
       if( mCubitsCreated )
172
         {
173 f404152d Leszek Koltunski
         mObject.createCubits(mQuatT,mQuatA,mScale);
174
         float[] dist = mObject.getDist3D();
175
         BandagedCreatorTouchControl control = mView.getTouchControl();
176
         control.setDist3D(dist);
177 227e8c1f Leszek Koltunski
         mScreen.detachAll();
178
         mView.resetCubits();
179 f404152d Leszek Koltunski
         mObject.attachCubits(mScaleValue);
180 227e8c1f Leszek Koltunski
         }
181 e3c970a7 Leszek Koltunski
182
       mCreatingCubits = false;
183 227e8c1f Leszek Koltunski
       }
184 f6bf4e77 Leszek Koltunski
185
     if( mRescaling )
186
       {
187
       rescaleObject();
188 f404152d Leszek Koltunski
       mObject.scaleCubits(mScaleValue);
189 f6bf4e77 Leszek Koltunski
       BandagedCreatorTouchControl control = mView.getTouchControl();
190
       control.setObjectRatio(mObjectScreenRatio);
191 e3c970a7 Leszek Koltunski
       mRescaling = false;
192 f6bf4e77 Leszek Koltunski
       }
193 9530f6b0 Leszek Koltunski
     }
194
195
///////////////////////////////////////////////////////////////////////////////////////////////////
196
197
   @Override
198
   public void onSurfaceChanged(GL10 glUnused, int width, int height)
199
      {
200 3b8f5220 Leszek Koltunski
      if( width!=mWidth || height!=mHeight )
201
        {
202
        mWidth = width;
203
        mHeight= height;
204
        rescaleObject();
205
        mScreen.detachAll();
206
        int touched = mView.getTouched();
207 f404152d Leszek Koltunski
        mObject.attachAndMarkCubits(mScaleValue,touched);
208 3b8f5220 Leszek Koltunski
        mView.setScreenSize(width,height);
209
        mScreen.resize(width,height);
210
        }
211 9530f6b0 Leszek Koltunski
      }
212
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
215
   @Override
216
   public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
217
      {
218 7d8ae8db Leszek Koltunski
      DistortedLibrary.setMax(EffectType.VERTEX,0);
219 f404152d Leszek Koltunski
      MeshBase.setMaxEffComponents(120); // what?
220 1a106eb8 Leszek Koltunski
      FragmentEffectBrightness.enable();
221 d0ad3964 Leszek Koltunski
      DistortedLibrary.onSurfaceCreated(this,1);
222 6dff7924 Leszek Koltunski
      DistortedLibrary.setCull(true);
223 f404152d Leszek Koltunski
      mObject.recreateCubits(mQuatT,mQuatA,mScale);
224 b9d062cf Leszek Koltunski
      mCubitsCreated = true;
225 3b8f5220 Leszek Koltunski
      mWidth = 0;
226
      mHeight= 0;
227 9530f6b0 Leszek Koltunski
      }
228
229 550db260 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
230
231
   public DistortedScreen getScreen()
232
     {
233
     return mScreen;
234
     }
235
236
///////////////////////////////////////////////////////////////////////////////////////////////////
237
238 1d4592a2 Leszek Koltunski
   void setConnecting(int index1, int index2)
239
     {
240
     mIndex1 = index1;
241
     mIndex2 = index2;
242
     mConnectingCubits = true;
243
     }
244
245 75173f81 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
246
247 50ec342b Leszek Koltunski
   public Static4D getQuatAccu()
248
     {
249
     return mQuatA;
250
     }
251 75173f81 Leszek Koltunski
252
///////////////////////////////////////////////////////////////////////////////////////////////////
253
254 50ec342b Leszek Koltunski
   public void setQuatTemp(float x, float y, float z, float w)
255
     {
256 2683f0c4 Leszek Koltunski
     mSetQuatT = false;
257
258 b9d062cf Leszek Koltunski
     mQuatX = x;
259
     mQuatY = y;
260
     mQuatZ = z;
261
     mQuatW = w;
262 75173f81 Leszek Koltunski
263 50ec342b Leszek Koltunski
     mSetQuatT = true;
264
     }
265 75173f81 Leszek Koltunski
266
///////////////////////////////////////////////////////////////////////////////////////////////////
267
268 50ec342b Leszek Koltunski
   public void resetQuats()
269
     {
270
     mResetQuats = true;
271
     }
272
273
///////////////////////////////////////////////////////////////////////////////////////////////////
274
275 e0b71e6e Leszek Koltunski
   public boolean isBusy()
276 50ec342b Leszek Koltunski
     {
277 e3c970a7 Leszek Koltunski
     return (mResettingObject || mCreatingCubits || mConnectingCubits);
278 e0b71e6e Leszek Koltunski
     }
279
280
///////////////////////////////////////////////////////////////////////////////////////////////////
281
282
   public void saveObject()
283 72e386ef Leszek Koltunski
     {
284 f404152d Leszek Koltunski
     TwistyObject obj = mObject.createObject(TwistyObject.MODE_NORM, 1.0f );
285 bfb59352 Leszek Koltunski
     String name = obj.getShortName();
286 72e386ef Leszek Koltunski
     BandagedCreatorActivity act = (BandagedCreatorActivity) mView.getContext();
287
288 bfb59352 Leszek Koltunski
     if( act.objectDoesntExist(name) && createObjectJson(obj,act) )
289 e48ad1af Leszek Koltunski
       {
290 f404152d Leszek Koltunski
       setupIconCreation(act);
291 e48ad1af Leszek Koltunski
       act.addObject(obj.getShortName());
292
       }
293 72e386ef Leszek Koltunski
     }
294
295
///////////////////////////////////////////////////////////////////////////////////////////////////
296
297 e48ad1af Leszek Koltunski
   private boolean createObjectJson(TwistyObject object, Activity act)
298 72e386ef Leszek Koltunski
     {
299
     final String name = object.getShortName()+"_object.json";
300
     File file = new File(act.getFilesDir(), name);
301
     String filename = file.getAbsolutePath();
302
303
     try
304
       {
305
       JsonWriter writer = JsonWriter.getInstance();
306 82c02259 Leszek Koltunski
       String json = writer.createObjectString(object,24,0);
307 72e386ef Leszek Koltunski
       writer.write(filename,json);
308 e48ad1af Leszek Koltunski
       return true;
309 72e386ef Leszek Koltunski
       }
310
     catch(JSONException ex)
311
       {
312
       act.runOnUiThread(new Runnable()
313
         {
314
         public void run()
315
           {
316
           String message = "JSON Exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
317
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
318
           }
319
         });
320 e48ad1af Leszek Koltunski
321
       return false;
322 72e386ef Leszek Koltunski
       }
323
     catch(FileNotFoundException ex)
324
       {
325
       act.runOnUiThread(new Runnable()
326
         {
327
         public void run()
328
           {
329
           String message = "FileNotFound exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
330
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
331
           }
332
         });
333 e48ad1af Leszek Koltunski
334
       return false;
335 72e386ef Leszek Koltunski
       }
336
     catch(IOException ex)
337
       {
338
       act.runOnUiThread(new Runnable()
339
         {
340
         public void run()
341
           {
342
           String message = "IO exception saving to \n\n"+filename+"\n\n failed:\n\n"+ex.getMessage();
343
           Toast.makeText(act,message,Toast.LENGTH_LONG).show();
344
           }
345
         });
346 e48ad1af Leszek Koltunski
347
       return false;
348 72e386ef Leszek Koltunski
       }
349
     }
350
351 2d88fcc3 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
352
353 f404152d Leszek Koltunski
   private void setupIconCreation(Activity act)
354 72e386ef Leszek Koltunski
     {
355 f203ffa0 Leszek Koltunski
     final float R=1.0f;
356 ba52835a Leszek Koltunski
     final int FBO_WIDTH  = (int)(R*720);
357
     final int FBO_HEIGHT = (int)(R*1280);
358
     final float OBJECT_SIZE = R*0.35f;
359 f203ffa0 Leszek Koltunski
360 f404152d Leszek Koltunski
     TwistyObject obj = mObject.createObject(TwistyObject.MODE_ICON, OBJECT_SIZE );
361 16663e27 Leszek Koltunski
     DistortedEffects effects = obj.getObjectEffects();
362
     DistortedNode node = obj.getNode();
363 eb6bccbd Leszek Koltunski
364 20b60ad9 Leszek Koltunski
     if( mFramebuffer==null )
365
       {
366 f203ffa0 Leszek Koltunski
       mFramebuffer = new DistortedFramebuffer(FBO_WIDTH,FBO_HEIGHT,1, InternalOutputSurface.DEPTH_NO_STENCIL);
367
       mFramebuffer.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
368 20b60ad9 Leszek Koltunski
       }
369 7cb8d4b0 Leszek Koltunski
370 f404152d Leszek Koltunski
     mFramebuffer.setProjection( mObject.computeProjectionAngle() ,0.1f);
371 20b60ad9 Leszek Koltunski
     mFramebuffer.detachAll();
372
     mFramebuffer.attach(node);
373 7cb8d4b0 Leszek Koltunski
374
     Static1D halo = new Static1D(5);
375
     Static4D color = new Static4D(0,0,0,1);
376
     PostprocessEffectBorder border = new PostprocessEffectBorder(halo,color);
377
     border.setHaloDepth(false);
378
     effects.apply(border);
379
380 16663e27 Leszek Koltunski
     final String name = obj.getShortName()+".png";
381 7cb8d4b0 Leszek Koltunski
     File file = new File(act.getFilesDir(), name);
382
     String filename = file.getAbsolutePath();
383
384
     mSaveIcon = 0;
385
     mPath = filename;
386 72e386ef Leszek Koltunski
     }
387 7cb8d4b0 Leszek Koltunski
388
///////////////////////////////////////////////////////////////////////////////////////////////////
389
390 eb6bccbd Leszek Koltunski
   private void renderIcon(long time)
391
     {
392
     mFramebuffer.render(time);
393
     }
394 7cb8d4b0 Leszek Koltunski
395 eb6bccbd Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
396 7cb8d4b0 Leszek Koltunski
397 eb6bccbd Leszek Koltunski
   private void saveIcon()
398
     {
399
     int fW = mFramebuffer.getWidth();
400
     int fH = mFramebuffer.getHeight();
401 7cb8d4b0 Leszek Koltunski
402 eb6bccbd Leszek Koltunski
     ByteBuffer buf = ByteBuffer.allocateDirect(fW*fH*4);
403
     buf.order(ByteOrder.LITTLE_ENDIAN);
404
405
     mFramebuffer.setAsReadFramebuffer(0);
406
     GLES31.glReadBuffer(GLES31.GL_COLOR_ATTACHMENT0);
407
     GLES31.glReadPixels( 0, 0, fW, fH, GLES31.GL_RGBA, GLES31.GL_UNSIGNED_BYTE, buf);
408
     BandagedCreatorWorkerThread.newBuffer(buf,fW,fH,6,mPath);
409
     GLES31.glBindFramebuffer(GLES31.GL_READ_FRAMEBUFFER, 0);
410
411
     mSaveIcon = -1;
412
     }
413 7cb8d4b0 Leszek Koltunski
414 f6bf4e77 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
415
416
   void mulObjectRatio(float ratio)
417
     {
418
     mObjectScreenRatio *= ratio;
419
420 4dcfb7a9 leszek
     if( mObjectScreenRatio>MAX_SIZE_CHANGE*mInitRatio) mObjectScreenRatio = MAX_SIZE_CHANGE*mInitRatio;
421
     if( mObjectScreenRatio<MIN_SIZE_CHANGE*mInitRatio) mObjectScreenRatio = MIN_SIZE_CHANGE*mInitRatio;
422 f6bf4e77 Leszek Koltunski
423
     mRescaling = true;
424
     }
425
426
///////////////////////////////////////////////////////////////////////////////////////////////////
427
428
   float getObjectRatio()
429
     {
430
     return mObjectScreenRatio;
431
     }
432
433 a8aa49dc Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
434
435
   private void rescaleObject()
436
     {
437 afd7e804 Leszek Koltunski
     float size = mObject.getMaxSize();
438 f6bf4e77 Leszek Koltunski
     final float Q = mObjectScreenRatio/size;
439 a8aa49dc Leszek Koltunski
     mScaleValue = mWidth<mHeight ? Q*mWidth : Q*mHeight;
440
     mScale.set( mScaleValue,mScaleValue,mScaleValue );
441
     }
442
443 b9d062cf Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
444
445
   public void changeObject(int x, int y, int z)
446
     {
447 f404152d Leszek Koltunski
     if( mObject.tryChangeObject(x,y,z) ) mCreatingCubits = true;
448 b9d062cf Leszek Koltunski
     }
449
450 72e386ef Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
451
452
   public void displaySavingDialog()
453 e0b71e6e Leszek Koltunski
     {
454 61a7b812 Leszek Koltunski
     BandagedCreatorActivity act = (BandagedCreatorActivity)mView.getContext();
455 6647b730 Leszek Koltunski
     RubikDialogBandagedSave saveDiag = new RubikDialogBandagedSave();
456 61a7b812 Leszek Koltunski
     saveDiag.show(act.getSupportFragmentManager(), null);
457 e0b71e6e Leszek Koltunski
     }
458
459
///////////////////////////////////////////////////////////////////////////////////////////////////
460
461
   public void setupReset()
462
     {
463
     mResettingObject = true;
464
     mInitialPhase    = true;
465
     mStartTime       = System.currentTimeMillis();
466
     }
467
468
///////////////////////////////////////////////////////////////////////////////////////////////////
469
470
   public boolean continueResetting(long time)
471
     {
472
     long diff = time-mStartTime;
473 213c15de Leszek Koltunski
     float quotient = ((float)diff)/RESET_DURATION;
474 e0b71e6e Leszek Koltunski
475
     if( mInitialPhase && quotient>0.5f )
476
       {
477
       mInitialPhase=false;
478 f404152d Leszek Koltunski
       mView.resetCubits();
479
       mObject.resetObject(mScaleValue);
480 e0b71e6e Leszek Koltunski
       }
481
482
     double angle = 2*Math.PI*quotient*quotient*(3-2*quotient);
483
484
     float sinA = (float)Math.sin(angle);
485
     float cosA = (float)Math.cos(angle);
486
487
     mQuatT.set(0, -sinA, 0, cosA);
488 50ec342b Leszek Koltunski
489 e0b71e6e Leszek Koltunski
     return quotient>1.0f;
490 50ec342b Leszek Koltunski
     }
491 6f3af598 Leszek Koltunski
492
///////////////////////////////////////////////////////////////////////////////////////////////////
493
494
  public void touchCubit(int index)
495
    {
496 f404152d Leszek Koltunski
    mObject.touchCubit(index);
497 6f3af598 Leszek Koltunski
    }
498
499
///////////////////////////////////////////////////////////////////////////////////////////////////
500
501
  public void untouchCubit(int index)
502
    {
503 f404152d Leszek Koltunski
    mObject.untouchCubit(index);
504
    }
505
506
///////////////////////////////////////////////////////////////////////////////////////////////////
507
508
  public BandagedCreatorTouchControl createTouchControl()
509
    {
510
    return new BandagedCreatorTouchControl( getObjectRatio() , mScreen.getFOV(), mObject );
511 6f3af598 Leszek Koltunski
    }
512 d0ad3964 Leszek Koltunski
513
///////////////////////////////////////////////////////////////////////////////////////////////////
514
515
  public void distortedException(Exception ex)
516
    {
517
    android.util.Log.e("BandagedCreator", "unexpected exception: "+ex.getMessage() );
518
    }
519
520
///////////////////////////////////////////////////////////////////////////////////////////////////
521
522
  public InputStream localFile(int fileID)
523
    {
524
    return mResources.openRawResource(fileID);
525
    }
526
527
///////////////////////////////////////////////////////////////////////////////////////////////////
528
529
  public void logMessage(String message)
530
    {
531
    android.util.Log.e("BandagedCreator", message );
532
    }
533 9530f6b0 Leszek Koltunski
}