Project

General

Profile

« Previous | Next » 

Revision 9554f5d4

Added by Leszek Koltunski about 2 years ago

Progress with cubit quaternions.

View differences:

src/main/java/org/distorted/objectlib/main/TwistyObject.java
538 538

  
539 539
///////////////////////////////////////////////////////////////////////////////////////////////////
540 540

  
541
  private boolean doesNotStickOut(int variant, float[] pos, float[] tmp, Static4D quat)
541
  private boolean doesNotStickOut(int variant, float px, float py, float pz, float[] tmp, Static4D quat)
542 542
    {
543 543
    ObjectShape shape = getObjectShape(variant);
544 544
    float[][] vertices = shape.getVertices();
......
553 553

  
554 554
      QuatHelper.rotateVectorByQuat(tmp, x, y, z, 1, quat);
555 555

  
556
      float mx = tmp[0] + pos[0];
557
      float my = tmp[1] + pos[1];
558
      float mz = tmp[2] + pos[2];
556
      float mx = tmp[0] + px;
557
      float my = tmp[1] + py;
558
      float mz = tmp[2] + pz;
559 559

  
560 560
      if( sticksOut(axis, dist3D, mx,my,mz) ) return false;
561 561
      }
......
563 563
    return true;
564 564
    }
565 565

  
566
///////////////////////////////////////////////////////////////////////////////////////////////////
567

  
568
  private float computeAvg(float[] pos, int offset)
569
    {
570
    int len = pos.length/3;
571
    float ret=0.0f;
572
    for(int i=0; i<len; i++) ret += pos[3*i+offset];
573
    ret /= len;
574

  
575
    return ret;
576
    }
577

  
566 578
///////////////////////////////////////////////////////////////////////////////////////////////////
567 579

  
568 580
  protected void displayCubitQuats()
......
585 597

  
586 598
      float[] curpos = mOrigPos[cubit];
587 599
      float[] refpos = mOrigPos[refCubit];
588
      float refX = refpos[0];
589
      float refY = refpos[1];
590
      float refZ = refpos[2];
591
      float curX = curpos[0];
592
      float curY = curpos[1];
593
      float curZ = curpos[2];
600
      float refX = computeAvg(refpos,0);
601
      float refY = computeAvg(refpos,1);
602
      float refZ = computeAvg(refpos,2);
603
      float curX = computeAvg(curpos,0);
604
      float curY = computeAvg(curpos,1);
605
      float curZ = computeAvg(curpos,2);
594 606

  
595 607
      for(int quat=0; quat<mNumQuats; quat++)
596 608
        {
......
602 614

  
603 615
        if( dx>-ERR && dx<ERR && dy>-ERR && dy<ERR && dz>-ERR && dz<ERR )
604 616
          {
605
          if( doesNotStickOut(variant,curpos,tmp,mObjectQuats[quat]) )
617
          if( doesNotStickOut(variant,curX,curY,curZ,tmp,mObjectQuats[quat]) )
606 618
            {
607 619
            builder.append(quat);
608 620
            builder.append(',');

Also available in: Unified diff