Project

General

Profile

« Previous | Next » 

Revision cb137f36

Added by Leszek Koltunski over 3 years ago

Objects: tidy up some repeated code.

View differences:

src/main/java/org/distorted/objects/TwistyDiamond.java
33 33
import org.distorted.library.type.Static3D;
34 34
import org.distorted.library.type.Static4D;
35 35
import org.distorted.main.R;
36
import org.distorted.main.RubikSurfaceView;
37 36

  
38 37
import java.util.Random;
39 38

  
......
584 583
      }
585 584
    }
586 585

  
587
///////////////////////////////////////////////////////////////////////////////////////////////////
588

  
589
  int mulQuat(int q1, int q2)
590
    {
591
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
592

  
593
    float rX = result.get0();
594
    float rY = result.get1();
595
    float rZ = result.get2();
596
    float rW = result.get3();
597

  
598
    final float MAX_ERROR = 0.1f;
599
    float dX,dY,dZ,dW;
600

  
601
    for(int i=0; i<QUATS.length; i++)
602
      {
603
      dX = QUATS[i].get0() - rX;
604
      dY = QUATS[i].get1() - rY;
605
      dZ = QUATS[i].get2() - rZ;
606
      dW = QUATS[i].get3() - rW;
607

  
608
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
609
          dY<MAX_ERROR && dY>-MAX_ERROR &&
610
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
611
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
612

  
613
      dX = QUATS[i].get0() + rX;
614
      dY = QUATS[i].get1() + rY;
615
      dZ = QUATS[i].get2() + rZ;
616
      dW = QUATS[i].get3() + rW;
617

  
618
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
619
          dY<MAX_ERROR && dY>-MAX_ERROR &&
620
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
621
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
622
      }
623

  
624
    return -1;
625
    }
626

  
627 586
///////////////////////////////////////////////////////////////////////////////////////////////////
628 587
// The Diamond is solved if and only if:
629 588
//
src/main/java/org/distorted/objects/TwistyDino.java
32 32
import org.distorted.library.mesh.MeshSquare;
33 33
import org.distorted.library.type.Static3D;
34 34
import org.distorted.library.type.Static4D;
35
import org.distorted.main.RubikSurfaceView;
36 35

  
37 36
///////////////////////////////////////////////////////////////////////////////////////////////////
38 37

  
......
140 139
    return 1;
141 140
    }
142 141

  
143
///////////////////////////////////////////////////////////////////////////////////////////////////
144

  
145
  int mulQuat(int q1, int q2)
146
    {
147
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
148

  
149
    float rX = result.get0();
150
    float rY = result.get1();
151
    float rZ = result.get2();
152
    float rW = result.get3();
153

  
154
    final float MAX_ERROR = 0.1f;
155
    float dX,dY,dZ,dW;
156

  
157
    for(int i=0; i<QUATS.length; i++)
158
      {
159
      dX = QUATS[i].get0() - rX;
160
      dY = QUATS[i].get1() - rY;
161
      dZ = QUATS[i].get2() - rZ;
162
      dW = QUATS[i].get3() - rW;
163

  
164
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
165
          dY<MAX_ERROR && dY>-MAX_ERROR &&
166
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
167
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
168

  
169
      dX = QUATS[i].get0() + rX;
170
      dY = QUATS[i].get1() + rY;
171
      dZ = QUATS[i].get2() + rZ;
172
      dW = QUATS[i].get3() + rW;
173

  
174
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
175
          dY<MAX_ERROR && dY>-MAX_ERROR &&
176
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
177
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
178
      }
179

  
180
    return -1;
181
    }
182

  
183 142
///////////////////////////////////////////////////////////////////////////////////////////////////
184 143

  
185 144
  float getScreenRatio()
src/main/java/org/distorted/objects/TwistyHelicopter.java
437 437
      }
438 438
    }
439 439

  
440
///////////////////////////////////////////////////////////////////////////////////////////////////
441
// remember about the double cover or unit quaternions!
442

  
443
  private int mulQuat(int q1, int q2)
444
    {
445
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
446

  
447
    float rX = result.get0();
448
    float rY = result.get1();
449
    float rZ = result.get2();
450
    float rW = result.get3();
451

  
452
    final float MAX_ERROR = 0.1f;
453
    float dX,dY,dZ,dW;
454

  
455
    for(int i=0; i<QUATS.length; i++)
456
      {
457
      dX = QUATS[i].get0() - rX;
458
      dY = QUATS[i].get1() - rY;
459
      dZ = QUATS[i].get2() - rZ;
460
      dW = QUATS[i].get3() - rW;
461

  
462
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
463
          dY<MAX_ERROR && dY>-MAX_ERROR &&
464
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
465
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
466

  
467
      dX = QUATS[i].get0() + rX;
468
      dY = QUATS[i].get1() + rY;
469
      dZ = QUATS[i].get2() + rZ;
470
      dW = QUATS[i].get3() + rW;
471

  
472
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
473
          dY<MAX_ERROR && dY>-MAX_ERROR &&
474
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
475
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
476
      }
477

  
478
    return -1;
479
    }
480

  
481 440
///////////////////////////////////////////////////////////////////////////////////////////////////
482 441
// The Helicopter is solved if and only if:
483 442
//
src/main/java/org/distorted/objects/TwistyIvy.java
33 33
import org.distorted.library.type.Static3D;
34 34
import org.distorted.library.type.Static4D;
35 35
import org.distorted.main.R;
36
import org.distorted.main.RubikSurfaceView;
37 36

  
38 37
import java.util.Random;
39 38

  
......
336 335
      }
337 336
    }
338 337

  
339
///////////////////////////////////////////////////////////////////////////////////////////////////
340
// remember about the double cover or unit quaternions!
341

  
342
  private int mulQuat(int q1, int q2)
343
    {
344
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
345

  
346
    float rX = result.get0();
347
    float rY = result.get1();
348
    float rZ = result.get2();
349
    float rW = result.get3();
350

  
351
    final float MAX_ERROR = 0.1f;
352
    float dX,dY,dZ,dW;
353

  
354
    for(int i=0; i<QUATS.length; i++)
355
      {
356
      dX = QUATS[i].get0() - rX;
357
      dY = QUATS[i].get1() - rY;
358
      dZ = QUATS[i].get2() - rZ;
359
      dW = QUATS[i].get3() - rW;
360

  
361
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
362
          dY<MAX_ERROR && dY>-MAX_ERROR &&
363
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
364
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
365

  
366
      dX = QUATS[i].get0() + rX;
367
      dY = QUATS[i].get1() + rY;
368
      dZ = QUATS[i].get2() + rZ;
369
      dW = QUATS[i].get3() + rW;
370

  
371
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
372
          dY<MAX_ERROR && dY>-MAX_ERROR &&
373
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
374
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
375
      }
376

  
377
    return -1;
378
    }
379

  
380 338
///////////////////////////////////////////////////////////////////////////////////////////////////
381 339
// The Ivy is solved if and only if:
382 340
//
src/main/java/org/distorted/objects/TwistyObject.java
458 458
    pos[offset+2] = mOrigPos[minErrorIndex1][3*minErrorIndex2+2];
459 459
    }
460 460

  
461
///////////////////////////////////////////////////////////////////////////////////////////////////
462
// remember about the double cover or unit quaternions!
463

  
464
  int mulQuat(int q1, int q2)
465
    {
466
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
467

  
468
    float rX = result.get0();
469
    float rY = result.get1();
470
    float rZ = result.get2();
471
    float rW = result.get3();
472

  
473
    final float MAX_ERROR = 0.1f;
474
    float dX,dY,dZ,dW;
475

  
476
    for(int i=0; i<QUATS.length; i++)
477
      {
478
      dX = QUATS[i].get0() - rX;
479
      dY = QUATS[i].get1() - rY;
480
      dZ = QUATS[i].get2() - rZ;
481
      dW = QUATS[i].get3() - rW;
482

  
483
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
484
          dY<MAX_ERROR && dY>-MAX_ERROR &&
485
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
486
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
487

  
488
      dX = QUATS[i].get0() + rX;
489
      dY = QUATS[i].get1() + rY;
490
      dZ = QUATS[i].get2() + rZ;
491
      dW = QUATS[i].get3() + rW;
492

  
493
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
494
          dY<MAX_ERROR && dY>-MAX_ERROR &&
495
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
496
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
497
      }
498

  
499
    return -1;
500
    }
501

  
461 502
///////////////////////////////////////////////////////////////////////////////////////////////////
462 503
// return if the Cubit, when rotated with its own mQuatScramble, would have looked any different
463 504
// then if it were rotated by quaternion 'quat'.
src/main/java/org/distorted/objects/TwistyRex.java
33 33
import org.distorted.library.type.Static3D;
34 34
import org.distorted.library.type.Static4D;
35 35
import org.distorted.main.R;
36
import org.distorted.main.RubikSurfaceView;
37 36

  
38 37
import java.util.Random;
39 38

  
......
447 446
      }
448 447
    }
449 448

  
450
///////////////////////////////////////////////////////////////////////////////////////////////////
451
// remember about the double cover or unit quaternions!
452

  
453
  private int mulQuat(int q1, int q2)
454
    {
455
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
456

  
457
    float rX = result.get0();
458
    float rY = result.get1();
459
    float rZ = result.get2();
460
    float rW = result.get3();
461

  
462
    final float MAX_ERROR = 0.1f;
463
    float dX,dY,dZ,dW;
464

  
465
    for(int i=0; i<QUATS.length; i++)
466
      {
467
      dX = QUATS[i].get0() - rX;
468
      dY = QUATS[i].get1() - rY;
469
      dZ = QUATS[i].get2() - rZ;
470
      dW = QUATS[i].get3() - rW;
471

  
472
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
473
          dY<MAX_ERROR && dY>-MAX_ERROR &&
474
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
475
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
476

  
477
      dX = QUATS[i].get0() + rX;
478
      dY = QUATS[i].get1() + rY;
479
      dZ = QUATS[i].get2() + rZ;
480
      dW = QUATS[i].get3() + rW;
481

  
482
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
483
          dY<MAX_ERROR && dY>-MAX_ERROR &&
484
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
485
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
486
      }
487

  
488
    return -1;
489
    }
490

  
491 449
///////////////////////////////////////////////////////////////////////////////////////////////////
492 450
// The Rex is solved if and only if:
493 451
//
src/main/java/org/distorted/objects/TwistySkewb.java
33 33
import org.distorted.library.type.Static3D;
34 34
import org.distorted.library.type.Static4D;
35 35
import org.distorted.main.R;
36
import org.distorted.main.RubikSurfaceView;
37 36

  
38 37
import java.util.Random;
39 38

  
......
658 657
      }
659 658
    }
660 659

  
661
///////////////////////////////////////////////////////////////////////////////////////////////////
662
// remember about the double cover or unit quaternions!
663

  
664
  private int mulQuat(int q1, int q2)
665
    {
666
    Static4D result = RubikSurfaceView.quatMultiply(QUATS[q1],QUATS[q2]);
667

  
668
    float rX = result.get0();
669
    float rY = result.get1();
670
    float rZ = result.get2();
671
    float rW = result.get3();
672

  
673
    final float MAX_ERROR = 0.1f;
674
    float dX,dY,dZ,dW;
675

  
676
    for(int i=0; i<QUATS.length; i++)
677
      {
678
      dX = QUATS[i].get0() - rX;
679
      dY = QUATS[i].get1() - rY;
680
      dZ = QUATS[i].get2() - rZ;
681
      dW = QUATS[i].get3() - rW;
682

  
683
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
684
          dY<MAX_ERROR && dY>-MAX_ERROR &&
685
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
686
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
687

  
688
      dX = QUATS[i].get0() + rX;
689
      dY = QUATS[i].get1() + rY;
690
      dZ = QUATS[i].get2() + rZ;
691
      dW = QUATS[i].get3() + rW;
692

  
693
      if( dX<MAX_ERROR && dX>-MAX_ERROR &&
694
          dY<MAX_ERROR && dY>-MAX_ERROR &&
695
          dZ<MAX_ERROR && dZ>-MAX_ERROR &&
696
          dW<MAX_ERROR && dW>-MAX_ERROR  ) return i;
697
      }
698

  
699
    return -1;
700
    }
701

  
702 660
///////////////////////////////////////////////////////////////////////////////////////////////////
703 661
// The Skewb is solved if and only if:
704 662
//

Also available in: Unified diff