Project

General

Profile

« Previous | Next » 

Revision 59b87d56

Added by Leszek Koltunski over 3 years ago

Adding Rex Cube - take 1 (doesn't work yet)

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 42

  
42 43
  private static final float SQ2 = (float)Math.sqrt(2);
43 44
  private static final float SQ3 = (float)Math.sqrt(3);
44 45
  private static final float SQ6 = (float)Math.sqrt(6);
45 46

  
46 47
  private static final int IVY_N = 8;
48
  private static final int REX_N = 5;
47 49
  private static final Static1D RADIUS = new Static1D(1);
48 50
  private static FactoryCubit mThis;
49 51

  
......
192 194
      }
193 195
    }
194 196

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

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

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

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

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

  
195 218
///////////////////////////////////////////////////////////////////////////////////////////////////
196 219

  
197 220
  MeshBase createFacesCube(int sizeIndex)
......
578 601
    return new MeshJoined(meshes);
579 602
    }
580 603

  
604
///////////////////////////////////////////////////////////////////////////////////////////////////
605

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

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

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

  
624
    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;
630

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

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

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

  
646
    return new MeshJoined(meshes);
647
    }
648

  
649
///////////////////////////////////////////////////////////////////////////////////////////////////
650

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

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

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

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

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

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

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

  
695
    return new MeshJoined(meshes);
696
    }
697

  
698
///////////////////////////////////////////////////////////////////////////////////////////////////
699

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

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

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

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

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

  
726
    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;
730

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

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

  
743
    return new MeshJoined(meshes);
744
    }
745

  
581 746
///////////////////////////////////////////////////////////////////////////////////////////////////
582 747
// EFFECTS
583 748
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1005 1170
    return effect;
1006 1171
    }
1007 1172

  
1173
///////////////////////////////////////////////////////////////////////////////////////////////////
1174

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

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

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

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

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

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

  
1198
    return effect;
1199
    }
1200

  
1201
///////////////////////////////////////////////////////////////////////////////////////////////////
1202

  
1203
  VertexEffect[] createVertexEffectsRexCorner()
1204
    {
1205
    float F = SQ3/6*(1.0f-2*REX_D);
1206
    Static3D move  = new Static3D(F,F,0.0f);
1207
    Static3D center= new Static3D(0.0f, 0.0f, 0.0f);
1208
    Static3D axisZ = new Static3D(0.0f, 0.0f, 1.0f);
1209
    Static1D angle = new Static1D(45);
1210

  
1211
    VertexEffect[] effect = new VertexEffect[2];
1212

  
1213
    effect[0] = new VertexEffectRotate(angle, axisZ, center);
1214
    effect[1] = new VertexEffectMove(move);
1215

  
1216
    return effect;
1217
    }
1218

  
1008 1219
///////////////////////////////////////////////////////////////////////////////////////////////////
1009 1220
// OBJECTS
1010 1221
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1298 1509
    mesh.addEmptyTexComponent();
1299 1510
    mesh.addEmptyTexComponent();
1300 1511

  
1512
    return mesh;
1513
    }
1514

  
1515
///////////////////////////////////////////////////////////////////////////////////////////////////
1516

  
1517
  MeshBase createRexCornerMesh()
1518
    {
1519
    MeshBase mesh = createFacesRexCorner();
1520
    VertexEffect[] effects = createVertexEffectsRexCorner();
1521
    for( VertexEffect effect : effects ) mesh.apply(effect);
1522

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

  
1528
    mesh.mergeEffComponents();
1529
    mesh.addEmptyTexComponent();
1530
    mesh.addEmptyTexComponent();
1531

  
1532
    return mesh;
1533
    }
1534

  
1535
///////////////////////////////////////////////////////////////////////////////////////////////////
1536

  
1537
  MeshBase createRexFaceMesh()
1538
    {
1539
    MeshBase mesh = createFacesRexFace();
1540

  
1541
    mesh.mergeEffComponents();
1542
    mesh.addEmptyTexComponent();
1543
    mesh.addEmptyTexComponent();
1544

  
1545
    return mesh;
1546
    }
1547

  
1548
///////////////////////////////////////////////////////////////////////////////////////////////////
1549

  
1550
  MeshBase createRexEdgeMesh()
1551
    {
1552
    MeshBase mesh = createFacesRexEdge();
1553
    VertexEffect[] effects = createVertexEffectsRexEdge();
1554
    for( VertexEffect effect : effects ) mesh.apply(effect);
1555

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

  
1562
    mesh.mergeEffComponents();
1563

  
1301 1564
    return mesh;
1302 1565
    }
1303 1566
  }

Also available in: Unified diff