Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedRenderer.java @ 78478d7e

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