Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ 64020e50

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