Project

General

Profile

« Previous | Next » 

Revision 4c0a6d97

Added by Leszek Koltunski about 3 years ago

Beginnings of support for bandaged versions of the 3x3 cube.

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
209 209
      }
210 210
    }
211 211

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

  
217
  private void writeVertex( float cx, float cy, float px, float py, float radians, float[] array, int index)
218
    {
219
    float vx = px-cx;
220
    float vy = py-cy;
221

  
222
    float sinA = (float)Math.sin(radians);
223
    float cosA = (float)Math.cos(radians);
224

  
225
    float rvx = vx*cosA - vy*sinA;
226
    float rvy = vx*sinA + vy*cosA;
227

  
228
    array[index  ] = rvx + cx;
229
    array[index+1] = rvy + cy;
230
    }
231

  
232 212
///////////////////////////////////////////////////////////////////////////////////////////////////
233 213

  
234 214
  MeshBase createFacesCube(int sizeIndex)
......
831 811
    return new MeshJoined(meshes);
832 812
    }
833 813

  
814
///////////////////////////////////////////////////////////////////////////////////////////////////
815

  
816
  private float[] createVertices(int A, int B)
817
    {
818
    float E = 0.5f / Math.max(A,B);
819
    return new float[] { -A*E,-B*E, +A*E,-B*E, +A*E,+B*E, -A*E,+B*E };
820
    }
821

  
822
///////////////////////////////////////////////////////////////////////////////////////////////////
823

  
824
  MeshBase createCuboid(int[] dimensions)
825
    {
826
    int X = dimensions[0];
827
    int Y = dimensions[1];
828
    int Z = dimensions[2];
829

  
830
    float[] verticesXY = createVertices(X,Y);
831
    float[] verticesXZ = createVertices(X,Z);
832
    float[] verticesYZ = createVertices(Z,Y);
833

  
834
    float defHeight = 0.048f;
835

  
836
    float[] bandsX = computeBands( defHeight/X,65,0.25f,0.5f,5);
837
    float[] bandsY = computeBands( defHeight/Y,65,0.25f,0.5f,5);
838
    float[] bandsZ = computeBands( defHeight/Z,65,0.25f,0.5f,5);
839

  
840
    MeshBase[] meshes = new MeshPolygon[6];
841

  
842
    meshes[0] = new MeshPolygon(verticesYZ,bandsX,1,2);
843
    meshes[0].setEffectAssociation(0,1,0);
844
    meshes[1] = meshes[0].copy(true);
845
    meshes[1].setEffectAssociation(0,2,0);
846
    meshes[2] = new MeshPolygon(verticesXZ,bandsY,1,2);
847
    meshes[2].setEffectAssociation(0,4,0);
848
    meshes[3] = meshes[2].copy(true);
849
    meshes[3].setEffectAssociation(0,8,0);
850
    meshes[4] = new MeshPolygon(verticesXY,bandsZ,1,2);
851
    meshes[4].setEffectAssociation(0,16,0);
852
    meshes[5] = meshes[4].copy(true);
853
    meshes[5].setEffectAssociation(0,32,0);
854

  
855
    return new MeshJoined(meshes);
856
    }
857

  
834 858
///////////////////////////////////////////////////////////////////////////////////////////////////
835 859
// EFFECTS
836 860
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1506 1530
    return effect;
1507 1531
    }
1508 1532

  
1533
///////////////////////////////////////////////////////////////////////////////////////////////////
1534

  
1535
  VertexEffect[] createCuboidEffects(int[] dimensions)
1536
    {
1537
    float X = dimensions[0];
1538
    float Y = dimensions[1];
1539
    float Z = dimensions[2];
1540

  
1541
    float MAX_XY = Math.max(X,Y);
1542
    float MAX_XZ = Math.max(X,Z);
1543
    float MAX_YZ = Math.max(Z,Y);
1544

  
1545
    Static1D angle = new Static1D(90);
1546
    Static3D move  = new Static3D( 0.0f, 0.0f, 0.5f);
1547
    Static3D axisX = new Static3D( 1.0f, 0.0f, 0.0f);
1548
    Static3D axisY = new Static3D( 0.0f, 1.0f, 0.0f);
1549
    Static3D center= new Static3D( 0.0f, 0.0f, 0.0f);
1550

  
1551
    Static3D scale3 = new Static3D(MAX_XY,MAX_XY,+Z);
1552
    Static3D scale4 = new Static3D(MAX_XY,MAX_XY,-Z);
1553
    Static3D scale5 = new Static3D(MAX_XZ,+Y,MAX_XZ);
1554
    Static3D scale6 = new Static3D(MAX_XZ,-Y,MAX_XZ);
1555
    Static3D scale7 = new Static3D(+X,MAX_YZ,MAX_YZ);
1556
    Static3D scale8 = new Static3D(-X,MAX_YZ,MAX_YZ);
1557

  
1558
    VertexEffect[] effect = new VertexEffect[9];
1559

  
1560
    effect[0] = new VertexEffectMove(move);
1561
    effect[1] = new VertexEffectRotate(angle, axisX, center);
1562
    effect[2] = new VertexEffectRotate(angle, axisY, center);
1563
    effect[3] = new VertexEffectScale(scale3);
1564
    effect[4] = new VertexEffectScale(scale4);
1565
    effect[5] = new VertexEffectScale(scale5);
1566
    effect[6] = new VertexEffectScale(scale6);
1567
    effect[7] = new VertexEffectScale(scale7);
1568
    effect[8] = new VertexEffectScale(scale8);
1569

  
1570
    effect[1].setMeshAssociation(12,-1);  // meshes 2,3
1571
    effect[2].setMeshAssociation( 3,-1);  // meshes 0,1
1572
    effect[3].setMeshAssociation(16,-1);  // mesh 4
1573
    effect[4].setMeshAssociation(32,-1);  // mesh 5
1574
    effect[5].setMeshAssociation( 8,-1);  // mesh 3
1575
    effect[6].setMeshAssociation( 4,-1);  // mesh 2
1576
    effect[7].setMeshAssociation( 1,-1);  // mesh 0
1577
    effect[8].setMeshAssociation( 2,-1);  // mesh 1
1578

  
1579
    return effect;
1580
    }
1581

  
1509 1582
///////////////////////////////////////////////////////////////////////////////////////////////////
1510 1583
// OBJECTS
1511 1584
///////////////////////////////////////////////////////////////////////////////////////////////////
......
1947 2020
    mesh.addEmptyTexComponent();
1948 2021
    mesh.addEmptyTexComponent();
1949 2022

  
2023
    return mesh;
2024
    }
2025

  
2026
///////////////////////////////////////////////////////////////////////////////////////////////////
2027

  
2028
  MeshBase createCuboidMesh(int[] dimensions)
2029
    {
2030
     MeshBase mesh = createCuboid(dimensions);
2031
    VertexEffect[] effects = createCuboidEffects(dimensions);
2032
    for( VertexEffect effect : effects ) mesh.apply(effect);
2033

  
2034
    mesh.mergeEffComponents();
2035

  
1950 2036
    return mesh;
1951 2037
    }
1952 2038
  }

Also available in: Unified diff