Project

General

Profile

« Previous | Next » 

Revision 7cd30f7c

Added by Leszek Koltunski over 3 years ago

Fixes for the Rex Cube (still doesn't work)

View differences:

src/main/java/org/distorted/examples/meshfile/FactoryCubit.java
43 43
  private static final int   IVY_N = 8;
44 44
  private static final float IVY_C = 0.59f;
45 45
  private static final float IVY_M = 0.35f;
46
  private static final float REX_D = 0.03f;
47
  private static final int   REX_N = 5;
46 48

  
47 49
  private static final Static1D RADIUS = new Static1D(1);
48 50

  
......
193 195
      }
194 196
    }
195 197

  
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).
201
// Write (rx,ry) to array[index] and array[index+1].
202

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

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

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

  
215
    array[index  ] = rvx + cx;
216
    array[index+1] = rvy + cy;
217
    }
218

  
196 219
///////////////////////////////////////////////////////////////////////////////////////////////////
197 220

  
198 221
  MeshBase createFacesCube(int sizeIndex)
......
579 602
    return new MeshJoined(meshes);
580 603
    }
581 604

  
605
///////////////////////////////////////////////////////////////////////////////////////////////////
606

  
607
  MeshBase createFacesRexCorner()
608
    {
609
    MeshBase[] meshes = new MeshBase[2];
610

  
611
    final float angle = (float)Math.PI/(6*REX_N);
612
    float[] vertices = new float[6*REX_N];
613
    final float H = SQ2*(SQ3/3 - 0.5f);
614
    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;
617

  
618
    final float V1x = -F*0.5f;
619
    final float V1y = -F*SQ3/6;
620
    final float V2x = -V1x;
621
    final float V2y = V1y;
622
    final float V3x = 0.0f;
623
    final float V3y = -2*V1y;
624

  
625
    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;
631

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

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

  
642
    meshes[0] = new MeshPolygon(vertices,bands0,1,1);
643
    meshes[0].setEffectAssociation(0,1,0);
644
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
645
    meshes[1].setEffectAssociation(0,2,0);
646

  
647
    return new MeshJoined(meshes);
648
    }
649

  
650
///////////////////////////////////////////////////////////////////////////////////////////////////
651

  
652
  MeshBase createFacesRexFace()
653
    {
654
    MeshBase[] meshes = new MeshBase[2];
655

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

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

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

  
680
    for(int i=0; i<REX_N; i++)
681
      {
682
      writeVertex(C1x,C1y,V1x,V1y, i*angle, vertices, 2*i          );
683
      writeVertex(C2x,C2y,V2x,V2y, i*angle, vertices, 2*i + 2*REX_N);
684
      writeVertex(C3x,C3y,V3x,V3y, i*angle, vertices, 2*i + 4*REX_N);
685
      writeVertex(C4x,C4y,V4x,V4y, i*angle, vertices, 2*i + 6*REX_N);
686
      }
687

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

  
691
    meshes[0] = new MeshPolygon(vertices,bands0,0,0);
692
    meshes[0].setEffectAssociation(0,1,0);
693
    meshes[1] = new MeshPolygon(vertices,bands1,0,0);
694
    meshes[1].setEffectAssociation(0,2,0);
695

  
696
    return new MeshJoined(meshes);
697
    }
698

  
699
///////////////////////////////////////////////////////////////////////////////////////////////////
700

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

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

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

  
716
    final float C1x = -D;
717
    final float C1y = -D - D*SQ3/2;
718
    final float C2x = +D;
719
    final float C2y = C1y;
720

  
721
    for(int i=0; i<REX_N; i++)
722
      {
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);
725
      }
726

  
727
    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);
734

  
735
    meshes[0] = new MeshPolygon(vertices,bands0,1,2);
736
    meshes[0].setEffectAssociation(0,1,0);
737
    meshes[1] = meshes[0].copy(true);
738
    meshes[1].setEffectAssociation(0,2,0);
739
    meshes[2] = new MeshPolygon(vertices,bands1,0,0);
740
    meshes[2].setEffectAssociation(0,4,0);
741
    meshes[3] = meshes[2].copy(true);
742
    meshes[3].setEffectAssociation(0,8,0);
743

  
744
    return new MeshJoined(meshes);
745
    }
746

  
582 747
///////////////////////////////////////////////////////////////////////////////////////////////////
583 748
// EFFECTS
584 749
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1006 1171
    return effect;
1007 1172
    }
1008 1173

  
1174
///////////////////////////////////////////////////////////////////////////////////////////////////
1175

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

  
1182
    Static3D move  = new Static3D(0.0f,   -F, 0.0f);
1183
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1184
    Static3D axisX = new Static3D(1.0f, 0.0f, 0.0f);
1185
    Static3D axisY = new Static3D(0.0f, 1.0f, 0.0f);
1186

  
1187
    Static1D angle180 = new Static1D(180);
1188
    Static1D angle90  = new Static1D( 90);
1189

  
1190
    VertexEffect[] effect = new VertexEffect[3];
1191

  
1192
    effect[0] = new VertexEffectMove(move);
1193
    effect[1] = new VertexEffectRotate(angle180, axisY, center);
1194
    effect[2] = new VertexEffectRotate(angle90 , axisX, center);
1195

  
1196
    effect[1].setMeshAssociation(10,-1);  // meshes 1 & 3
1197
    effect[2].setMeshAssociation(10,-1);  // meshes 1 & 3
1198

  
1199
    return effect;
1200
    }
1201

  
1202
///////////////////////////////////////////////////////////////////////////////////////////////////
1203

  
1204
  VertexEffect[] createVertexEffectsRexCorner()
1205
    {
1206
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1207
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1208
    Static1D angle = new Static1D(45);
1209

  
1210
    VertexEffect[] effect = new VertexEffect[1];
1211
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
1212

  
1213
    return effect;
1214
    }
1215

  
1009 1216
///////////////////////////////////////////////////////////////////////////////////////////////////
1010 1217
// OBJECTS
1011 1218
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1299 1506
    mesh.addEmptyTexComponent();
1300 1507
    mesh.addEmptyTexComponent();
1301 1508

  
1509
    return mesh;
1510
    }
1511

  
1512
///////////////////////////////////////////////////////////////////////////////////////////////////
1513

  
1514
  MeshBase createRexCornerMesh()
1515
    {
1516
    MeshBase mesh = createFacesRexCorner();
1517
    VertexEffect[] effects = createVertexEffectsRexCorner();
1518
    for( VertexEffect effect : effects ) mesh.apply(effect);
1519

  
1520
    Static3D center = new Static3D(0.0f,0.0f,-0.25f);
1521
    Static3D[] vertices = new Static3D[1];
1522
    vertices[0] = new Static3D(+0.25f,+0.25f,+0.0f);
1523
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1524

  
1525
    mesh.mergeEffComponents();
1526
    mesh.addEmptyTexComponent();
1527
    mesh.addEmptyTexComponent();
1528

  
1529
    return mesh;
1530
    }
1531

  
1532
///////////////////////////////////////////////////////////////////////////////////////////////////
1533

  
1534
  MeshBase createRexFaceMesh()
1535
    {
1536
    MeshBase mesh = createFacesRexFace();
1537

  
1538
    mesh.mergeEffComponents();
1539
    mesh.addEmptyTexComponent();
1540
    mesh.addEmptyTexComponent();
1541

  
1542
    return mesh;
1543
    }
1544

  
1545
///////////////////////////////////////////////////////////////////////////////////////////////////
1546

  
1547
  MeshBase createRexEdgeMesh()
1548
    {
1549
    MeshBase mesh = createFacesRexEdge();
1550
    VertexEffect[] effects = createVertexEffectsRexEdge();
1551
    for( VertexEffect effect : effects ) mesh.apply(effect);
1552

  
1553
    Static3D center = new Static3D(0.0f,-0.5f,-0.5f);
1554
    Static3D[] vertices = new Static3D[2];
1555
    vertices[0] = new Static3D(+0.5f,+0.0f,+0.0f);
1556
    vertices[1] = new Static3D(-0.5f,+0.0f,+0.0f);
1557
    roundCorners(mesh,center,vertices,0.03f,0.10f);
1558

  
1559
    mesh.mergeEffComponents();
1560

  
1302 1561
    return mesh;
1303 1562
    }
1304 1563
  }
src/main/java/org/distorted/examples/meshfile/MeshFileRenderer.java
331 331
    private void createMesh()
332 332
      {
333 333
      FactoryCubit factory = FactoryCubit.getInstance();
334
      mMesh = factory.createIvyCornerMesh();
334
      mMesh = factory.createRexEdgeMesh();
335 335

  
336 336
      //mMesh = createStaticMesh();
337 337

  

Also available in: Unified diff