Project

General

Profile

« Previous | Next » 

Revision aa171dee

Added by Leszek Koltunski about 4 years ago

More support for actual patterns!

View differences:

src/main/java/org/distorted/object/RubikObject.java
60 60
  private Static4D mQuatAccumulated;
61 61
  private Cubit[] mCubits;
62 62
  private int mSize;
63
  private RubikObjectList mList;
63 64

  
64 65
  float mStart, mStep;
65 66

  
......
73 74

  
74 75
///////////////////////////////////////////////////////////////////////////////////////////////////
75 76

  
76
  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects)
77
  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture,
78
              MeshRectangles nodeMesh, DistortedEffects nodeEffects, String moves, RubikObjectList list)
77 79
    {
78 80
    super(nodeTexture,nodeEffects,nodeMesh);
79 81

  
80 82
    resizeFBO(NODE_FBO_SIZE, NODE_FBO_SIZE);
81 83

  
84
    mList = list;
82 85
    mOrigPos = getCubitPositions(size);
83 86

  
84 87
    LEGAL_QUATS = getLegalQuats();
......
122 125
      attach(mCubits[i].mNode);
123 126
      }
124 127

  
128
    setupPosition(moves);
129

  
125 130
    setProjection(fov, 0.1f);
126 131
    }
127 132

  
......
214 219
    rotationAngle.add(mRotationAngleFinal);
215 220
    }
216 221

  
222
///////////////////////////////////////////////////////////////////////////////////////////////////
223
// TODO
224

  
225
	private boolean scheduleMultiRotation(int rotV, int rotRC, int rotA)
226
	  {
227
	  /*
228
		int index, tmp;
229

  
230
		if( numRotations>0 )
231
		  {
232
			if( rotVector!=rotV ) return false;
233

  
234
			index=0;
235
			tmp=rotRC;
236

  
237
			while( tmp!=0 )
238
			  {
239
				if( (tmp&0x1)==1 && rotAngle[index]!=0 ) return false;
240
				index++;
241
				tmp/=2;
242
			  }
243
		  }
244

  
245
		index=0;
246
		tmp=rotRC;
247
		rotVector = rotV;
248

  
249
		while( tmp!=0 )
250
		  {
251
			if( (tmp&0x1)==1 )
252
			  {
253
				rotAngle[index] = rotA*90;
254
				rotSpeed[index] = (int)(rotS/RubikWorld.hardwareSpeed);
255

  
256
				if( rotSpeed[index]<=0 && rotS>0 ) rotSpeed[index] = 1;
257
				if( rotSpeed[index]>=0 && rotS<0 ) rotSpeed[index] =-1;
258

  
259
				numRotations++;
260
			  }
261

  
262
			index++;
263
			tmp/=2;
264
		  }
265
    */
266
		return true;
267
	  }
268

  
269
///////////////////////////////////////////////////////////////////////////////////////////////////
270
// TODO
271

  
272
  private void setupPosition(String moves)
273
    {
274
    android.util.Log.e("object", "initializing: "+moves);
275
/*
276
    int index,tmp, a1,a2,a3, rv, rc, ra;
277

  
278
		numRotations=0;
279
		initializeVertices(mSize);
280

  
281
		int len=moves.length()/4;
282

  
283
		for(int i=0; i<len; i++)
284
		  {
285
			a1=moves.charAt(4*i+1)-'0';
286
			a2=moves.charAt(4*i+2)-'0';
287
			a3=moves.charAt(4*i+3)-'0';
288

  
289
			rv = (10*a1+a2)/32;
290
			rc = (10*a1+a2)%32;
291
			ra = 2-a3;
292

  
293
			rotVector = rv;
294

  
295
			tmp=rc;
296
			index=0;
297

  
298
			while( tmp!=0 )
299
			  {
300
				if( (tmp&0x1)==1 )
301
				  {
302
					rotAngle[index] = ra*90;
303
					RubikWorld.setIdentity(rotMat[index]);
304

  
305
					switch(rotVector)
306
					  {
307
					  case VECTX: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 1f,0f,0f); break;
308
					  case VECTY: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,1f,0f); break;
309
					  case VECTZ: RubikWorld.postRotate( rotMat[index], (float)((ra*90)%360), 0f,0f,1f); break;
310
					  }
311

  
312
					transposeTiles(index);
313
					rotAngle[index]=0;
314
				  }
315

  
316
				tmp/=2;
317
				index++;
318
			  }
319
	  	}
320
 */
321
    }
322

  
217 323
///////////////////////////////////////////////////////////////////////////////////////////////////
218 324
// Clamp all rotated positions to one of those original ones to avoid accumulating errors.
219 325

  
......
461 567
     mRotationAngleStatic.set0(0);
462 568
     }
463 569

  
570
///////////////////////////////////////////////////////////////////////////////////////////////////
571

  
572
  public boolean makeMove(String move)
573
    {
574
    int a1=move.charAt(1)-'0';
575
		int a2=move.charAt(2)-'0';
576
		int a3=move.charAt(3)-'0';
577

  
578
    int rotVector = (10*a1+a2)/32; // 0 --> VECTX, 1--> VECTY, 2 --> VECTZ
579
    int rotBitmap = (10*a1+a2)%32; // 01010 --> move the 2nd and 4th layer
580
    int rotAngle  = 2-a3;          // counterclockwise by rotAngle*90 degrees
581

  
582
		return scheduleMultiRotation(rotVector, rotBitmap, rotAngle);
583
    }
584

  
585
///////////////////////////////////////////////////////////////////////////////////////////////////
586

  
587
  public boolean backMove(String move)
588
    {
589
    int a1=move.charAt(1)-'0';
590
		int a2=move.charAt(2)-'0';
591
		int a3=move.charAt(3)-'0';
592

  
593
    int rotVector = (10*a1+a2)/32;
594
    int rotBitmap = (10*a1+a2)%32;
595
    int rotAngle  = a3-2;
596

  
597
		return scheduleMultiRotation(rotVector, rotBitmap, rotAngle);
598
    }
599

  
600
///////////////////////////////////////////////////////////////////////////////////////////////////
601

  
602
  public void initializeObject(String moves)
603
    {
604
    solve();
605
    setupPosition(moves);
606
    }
607

  
608
///////////////////////////////////////////////////////////////////////////////////////////////////
609

  
610
  public RubikObjectList getObjectList()
611
    {
612
    return mList;
613
    }
614

  
464 615
///////////////////////////////////////////////////////////////////////////////////////////////////
465 616

  
466 617
  abstract float getScreenRatio();

Also available in: Unified diff