Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedCreatorRenderer.java @ e3c970a7

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