Project

General

Profile

« Previous | Next » 

Revision 63fb0859

Added by Leszek Koltunski almost 4 years ago

Fixes for the Rex Cube (mostly works now)

View differences:

src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
196 196
    }
197 197

  
198 198
///////////////////////////////////////////////////////////////////////////////////////////////////
199
// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'angle' of the point
200
// (px,py) along axis Z. Center of rotation: (cx,cy).
199
// Compute (rx,ry) - coords of a point which is the result of rotation by angle 'radians' of the point
200
// (px,py) along axis Z. Center of rotation: (cx,cy). Rotation is counterclockwise!
201 201
// Write (rx,ry) to array[index] and array[index+1].
202 202

  
203
  private void writeVertex( float cx, float cy, float px, float py, float angle, float[] array, int index)
203
  private void writeVertex( float cx, float cy, float px, float py, float radians, float[] array, int index)
204 204
    {
205 205
    float vx = px-cx;
206 206
    float vy = py-cy;
207 207

  
208
    double radAngle = Math.PI*angle/180;
209
    float sinA = (float)Math.sin(radAngle);
210
    float cosA = (float)Math.cos(radAngle);
208
    float sinA = (float)Math.sin(radians);
209
    float cosA = (float)Math.cos(radians);
211 210

  
212
    float rvx = vx*cosA +vy*sinA;
213
    float rvy =-vx*sinA +vy*cosA;
211
    float rvx = vx*cosA - vy*sinA;
212
    float rvy = vx*sinA + vy*cosA;
214 213

  
215 214
    array[index  ] = rvx + cx;
216 215
    array[index+1] = rvy + cy;
......
610 609

  
611 610
    final float angle = (float)Math.PI/(6*REX_N);
612 611
    float[] vertices = new float[6*REX_N];
613
    final float H = SQ2*(SQ3/3 - 0.5f);
614 612
    final float D = 0.5f - REX_D;
615
    final float F = H*D;
616
    final float B = (float)Math.sqrt(12/(H*H) - 0.75f) - 0.5f;
613
    final float F = D*SQ2*(SQ3-1);
614
    final float B = 2.5f;
617 615

  
618 616
    final float V1x = -F*0.5f;
619 617
    final float V1y = -F*SQ3/6;
......
623 621
    final float V3y = -2*V1y;
624 622

  
625 623
    final float C1x = 0.0f;
626
    final float C1y = -D*( (SQ3/6)*H - (float)Math.sqrt(4.0f-0.25f*H*H) );
627
    final float C2x = B*V2x;
628
    final float C2y = B*V2y;
629
    final float C3x = B*V3x;
630
    final float C3y = B*V3y;
624
    final float C1y = -F*(1+2*SQ3/3);
625
    final float C2x = B*V1x;
626
    final float C2y = B*V1y;
627
    final float C3x = B*V2x;
628
    final float C3y = B*V2y;
631 629

  
632 630
    for(int i=0; i<REX_N; i++)
633 631
      {
634
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
632
      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
635 633
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
636 634
      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
637 635
      }
638 636

  
639
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
637
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
640 638
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
641 639

  
642 640
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
......
655 653

  
656 654
    final float angle = (float)Math.PI/(6*REX_N);
657 655
    float[] vertices = new float[8*REX_N];
658
    final float H = SQ3/2 - 0.5f;
659 656
    final float D = 0.5f - REX_D;
660
    final float F = H*D;
657
    final float F = D*(SQ3-1);
661 658

  
662 659
    final float V1x = 0.0f;
663 660
    final float V1y = +F;
664
    final float V2x = +F;
661
    final float V2x = -F;
665 662
    final float V2y = 0.0f;
666 663
    final float V3x = 0.0f;
667 664
    final float V3y = -F;
668
    final float V4x = -F;
665
    final float V4x = +F;
669 666
    final float V4y = 0.0f;
670 667

  
671
    final float C1x = -D;
668
    final float C1x = +D;
672 669
    final float C1y = -D;
673
    final float C2x = -D;
670
    final float C2x = +D;
674 671
    final float C2y = +D;
675
    final float C3x = +D;
672
    final float C3x = -D;
676 673
    final float C3y = +D;
677
    final float C4x = +D;
674
    final float C4x = -D;
678 675
    final float C4y = -D;
679 676

  
680 677
    for(int i=0; i<REX_N; i++)
......
685 682
      writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
686 683
      }
687 684

  
688
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
685
    float[] bands0 = computeBands(+0.02f,10,0.5f,0.5f,5);
689 686
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
690 687

  
691 688
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
......
700 697

  
701 698
  MeshBase createFacesRexEdge()
702 699
    {
703
    MeshBase[] meshes = new MeshBase[4];
700
    MeshBase[] meshes = new MeshBase[1];
704 701

  
705 702
    final float angle = (float)Math.PI/(6*REX_N);
706
    float[] vertices = new float[4*REX_N + 4];
703
    float[] vertices = new float[4*REX_N + 6];
707 704
    final float H = 1.0f - SQ3/2;
708 705
    final float D = 0.5f - REX_D;
709
    final float F = H*D;
706
    final float F = 0.5f*H;
710 707

  
711 708
    final float V1x = -D;
712
    final float V1y = +D - D*SQ3/2;
709
    final float V1y = +D + F - 0.5f;
713 710
    final float V2x = 0.0f;
714
    final float V2y = D*(SQ3-1) - D*SQ3/2;
711
    final float V2y = -F;
715 712

  
716 713
    final float C1x = -D;
717
    final float C1y = -D - D*SQ3/2;
714
    final float C1y = -D + F - 0.5f;
718 715
    final float C2x = +D;
719 716
    final float C2y = C1y;
720 717

  
721 718
    for(int i=0; i<REX_N; i++)
722 719
      {
723
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
724
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
720
      writeVertex(C1x,C1y,V1x,V1y,-i*angle, vertices, 2*i          );
721
      writeVertex(C2x,C2y,V2x,V2y,-i*angle, vertices, 2*i + 2*REX_N);
725 722
      }
726 723

  
727 724
    vertices[4*REX_N  ] = +D;
728
    vertices[4*REX_N+1] = +F + REX_D;
729
    vertices[4*REX_N+2] = -D;
730
    vertices[4*REX_N+3] = +F + REX_D;
731

  
732
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
733
    float[] bands1 = computeBands(-0.00f,45,0.5f,0.0f,2);
725
    vertices[4*REX_N+1] = +F-REX_D;
726
    vertices[4*REX_N+2] = +D;
727
    vertices[4*REX_N+3] = +F;
728
    vertices[4*REX_N+4] = -D;
729
    vertices[4*REX_N+5] = +F;
730

  
731
/*
732
    vertices[0] = V1x;
733
    vertices[1] = V1y;
734
    vertices[2] = V2x;
735
    vertices[3] = V2y;
736
    vertices[4] = +D;
737
    vertices[5] = +F-REX_D;
738
    vertices[6] = +D;
739
    vertices[7] = +F;
740
    vertices[8] = -D;
741
    vertices[9] = +F;
742
*/
743
    float[] bands0 = computeBands(+0.02f, 9,0.5f,0.5f,5);
744
    float[] bands1 = computeBands( 0.00f,45,0.5f,0.0f,2);
734 745

  
735 746
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
736 747
    meshes[0].setEffectAssociation(0,1,0);
748
 /*
737 749
    meshes[1] = meshes[0].copy(true);
738 750
    meshes[1].setEffectAssociation(0,2,0);
739 751
    meshes[2] = new MeshPolygon(vertices,bands1,0,0);
740 752
    meshes[2].setEffectAssociation(0,4,0);
741 753
    meshes[3] = meshes[2].copy(true);
742 754
    meshes[3].setEffectAssociation(0,8,0);
743

  
755
*/
744 756
    return new MeshJoined(meshes);
745 757
    }
746 758

  

Also available in: Unified diff