Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedRenderer.java @ 4bd09fe2

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