Project

General

Profile

« Previous | Next » 

Revision e0b71e6e

Added by Leszek Koltunski over 2 years ago

Bandaged 3x3: implement object reset.

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorRenderer.java
35 35

  
36 36
public class BandagedCreatorRenderer implements GLSurfaceView.Renderer, DistortedLibrary.ExceptionListener
37 37
{
38
   private static final int DURATION = 1000;
39

  
38 40
   static final int COLOR_DEFAULT = 0xffffff55;
39 41
   static final int COLOR_MARKED  = 0xffff0000;
40 42

  
......
76 78
   private final Static3D mScale;
77 79
   private final BandagedCubit[] mCubits;
78 80
   private final Static4D mQuatT, mQuatA;
79
   private float mScaleValue;
80 81

  
82
   private boolean mInitialPhase;
83
   private long mStartTime;
84
   private float mScaleValue;
81 85
   private float mX, mY, mZ, mW;
82
   private boolean mResetQuats, mSetQuatT;
86
   private boolean mResetQuats, mSetQuatT, mResettingObject;
83 87

  
84 88
///////////////////////////////////////////////////////////////////////////////////////////////////
85 89

  
......
92 96

  
93 97
     mView = v;
94 98

  
95
     mResetQuats = false;
96
     mSetQuatT   = false;
99
     mResetQuats     = false;
100
     mSetQuatT       = false;
101
     mResettingObject= false;
97 102

  
98 103
     mScreen = new DistortedScreen();
99 104
     mScreen.glClearColor(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS, 1.0f);
......
101 106
     mCubits= createCubits();
102 107
     }
103 108

  
109
///////////////////////////////////////////////////////////////////////////////////////////////////
110

  
111
   private boolean isAdjacent(float[] pos1, float[] pos2)
112
     {
113
     int len1 = pos1.length/3;
114
     int len2 = pos2.length/3;
115

  
116
     for(int i=0; i<len1; i++)
117
       for(int j=0; j<len2; j++)
118
         {
119
         float d0 = pos1[3*i  ] - pos2[3*j  ];
120
         float d1 = pos1[3*i+1] - pos2[3*j+1];
121
         float d2 = pos1[3*i+2] - pos2[3*j+2];
122

  
123
         if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true;
124
         }
125

  
126
     return false;
127
     }
128

  
104 129
///////////////////////////////////////////////////////////////////////////////////////////////////
105 130

  
106 131
   private BandagedCubit[] createCubits()
......
116 141
     return cubits;
117 142
     }
118 143

  
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

  
146
   private void resetObject()
147
     {
148
     mView.resetCubits();
149

  
150
     int len = POSITIONS.length;
151

  
152
     for(int c=0; c<len; c++)
153
       {
154
       if( !mCubits[c].isAttached() )
155
         {
156
         mCubits[c].attach();
157
         mScreen.attach(mCubits[c].getNode());
158
         }
159
       if( mCubits[c].getPosition().length>3 )
160
         {
161
         mCubits[c].reset(mScaleValue);
162
         }
163
       }
164
     }
165

  
119 166
///////////////////////////////////////////////////////////////////////////////////////////////////
120 167

  
121 168
   @Override
......
152 199
       mQuatT.set(0f, 0f, 0f, 1f);
153 200
       mQuatA.set(tx, ty, tz, tw);
154 201
       }
202

  
203
     if( mResettingObject )
204
       {
205
       boolean done = continueResetting(time);
206
       if( done ) mResettingObject = false;
207
       }
155 208
     }
156 209

  
157 210
///////////////////////////////////////////////////////////////////////////////////////////////////
......
208 261
     return mScreen;
209 262
     }
210 263

  
211
///////////////////////////////////////////////////////////////////////////////////////////////////
212

  
213
   private boolean isAdjacent(float[] pos1, float[] pos2)
214
     {
215
     int len1 = pos1.length/3;
216
     int len2 = pos2.length/3;
217

  
218
     for(int i=0; i<len1; i++)
219
       for(int j=0; j<len2; j++)
220
         {
221
         float d0 = pos1[3*i  ] - pos2[3*j  ];
222
         float d1 = pos1[3*i+1] - pos2[3*j+1];
223
         float d2 = pos1[3*i+2] - pos2[3*j+2];
224

  
225
         if( d0*d0 + d1*d1 + d2*d2 == 1 ) return true;
226
         }
227

  
228
     return false;
229
     }
230

  
231 264
///////////////////////////////////////////////////////////////////////////////////////////////////
232 265

  
233 266
   public void tryConnectingCubits(int index1, int index2)
......
274 307

  
275 308
///////////////////////////////////////////////////////////////////////////////////////////////////
276 309

  
277
   public void reset()
310
   public boolean isBusy()
278 311
     {
312
     return mResettingObject;
313
     }
314

  
315
///////////////////////////////////////////////////////////////////////////////////////////////////
316

  
317
   public void saveObject()
318
     {
319

  
320
     }
321

  
322
///////////////////////////////////////////////////////////////////////////////////////////////////
323

  
324
   public void setupReset()
325
     {
326
     mResettingObject = true;
327
     mInitialPhase    = true;
328
     mStartTime       = System.currentTimeMillis();
329
     }
330

  
331
///////////////////////////////////////////////////////////////////////////////////////////////////
332

  
333
   public boolean continueResetting(long time)
334
     {
335
     long diff = time-mStartTime;
336
     float quotient = ((float)diff)/DURATION;
337

  
338
     if( mInitialPhase && quotient>0.5f )
339
       {
340
       mInitialPhase=false;
341
       resetObject();
342
       }
343

  
344
     double angle = 2*Math.PI*quotient*quotient*(3-2*quotient);
345

  
346
     float sinA = (float)Math.sin(angle);
347
     float cosA = (float)Math.cos(angle);
348

  
349
     mQuatT.set(0, -sinA, 0, cosA);
279 350

  
351
     return quotient>1.0f;
280 352
     }
281 353
}

Also available in: Unified diff