Project

General

Profile

« Previous | Next » 

Revision 80ec6abf

Added by Leszek Koltunski over 3 years ago

Fixes for the Rex Cube (mostly works now)

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
38 38
  static final float IVY_D = 0.003f;
39 39
  static final float IVY_C = 0.59f;
40 40
  static final float IVY_M = 0.35f;
41
  static final float REX_D = 0.03f;
41
  static final float REX_D = 0.003f;
42 42

  
43 43
  private static final float SQ2 = (float)Math.sqrt(2);
44 44
  private static final float SQ3 = (float)Math.sqrt(3);
......
195 195
    }
196 196

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

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

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

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

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

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

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

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

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

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

  
641 639
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
642 640
    meshes[0].setEffectAssociation(0,1,0);
......
654 652

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

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

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

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

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

  
690 687
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
691 688
    meshes[0].setEffectAssociation(0,1,0);
......
702 699
    MeshBase[] meshes = new MeshBase[4];
703 700

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

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

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

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

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

  
731
    float[] bands0 = computeBands(+0.03f,35,0.5f,0.5f,5);
732
    float[] bands1 = computeBands(-0.10f,45,0.5f,0.0f,2);
730
    float[] bands0 = computeBands(+0.02f, 9,0.5f,0.5f,5);
731
    float[] bands1 = computeBands( 0.00f,45,0.5f,0.0f,2);
733 732

  
734 733
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
735 734
    meshes[0].setEffectAssociation(0,1,0);
......
1174 1173

  
1175 1174
  VertexEffect[] createVertexEffectsRexEdge()
1176 1175
    {
1177
    final float H = 1.0f - SQ3/2;
1178 1176
    final float D = 0.5f - REX_D;
1179
    final float F = H*D;
1177
    final float F = 0.5f*(0.5f - D*(SQ3-1));
1180 1178

  
1181 1179
    Static3D move  = new Static3D(0.0f,   -F, 0.0f);
1182 1180
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
......
1204 1202
    {
1205 1203
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1206 1204
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1207
    Static1D angle = new Static1D(45);
1205
    Static1D angle = new Static1D(225);
1208 1206

  
1209 1207
    VertexEffect[] effect = new VertexEffect[1];
1210 1208
    effect[0] = new VertexEffectRotate(angle, axisZ, center);

Also available in: Unified diff