Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ 41cd5230

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