Project

General

Profile

« Previous | Next » 

Revision 16f34a98

Added by Leszek Koltunski over 3 years ago

Progress with any size Kilominx.

View differences:

src/main/java/org/distorted/objects/FactoryCubit.java
708 708

  
709 709
///////////////////////////////////////////////////////////////////////////////////////////////////
710 710

  
711
  MeshBase createFacesMegaminxCorner(int numLayers)
711
  MeshBase createFacesMinxCorner(int numLayers)
712 712
    {
713 713
    MeshBase[] meshes = new MeshPolygon[6];
714 714

  
......
740 740
    return new MeshJoined(meshes);
741 741
    }
742 742

  
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744

  
745
  MeshBase createFacesKilominxEdge(int numLayers, float width, float height)
746
    {
747
     MeshBase[] meshes = new MeshPolygon[6];
748

  
749
    float D = height/COS18;
750
    float W = D*SIN18;
751
    float X1 = height/2;
752
    float Y1 = width/2;
753
    float Y2 = (width+W)/2;
754
    float X3 = D*SIN54;
755
    float Y3 = D*COS54;
756
    float X4 = height*SIN_HALFD;
757
    float Y4 = height*COS_HALFD;
758

  
759
    float[] vertices0 = { -X1,-Y1, X1, -Y1, X1, Y1+W,-X1, Y1 };
760
    float[] vertices1 = { -X1,-Y2, X1, -Y2, X1, Y2+W,-X1, Y2 };
761
    float[] vertices2 = { -X3, 0.0f, 0.0f, -Y3, X3, 0.0f, 0.0f, Y3 };
762
    float[] vertices3 = { -X4, 0.0f, 0.0f, -Y4, X4, 0.0f, 0.0f, Y4 };
763

  
764
    int numBands0 = numLayers<=5 ? 5 : 3;
765
    int numBands1 = numLayers<=5 ? 3 : 2;
766
    float h       = numLayers<=5 ? 0.03f : 0.03f;
767

  
768
    float[] bands0 = computeBands(h    ,34,0.2f,0.2f,numBands0);
769
    float[] bands1 = computeBands(0.01f,34,0.3f,0.2f,numBands1);
770

  
771
    meshes[0] = new MeshPolygon(vertices0, bands0, 1, 1);
772
    meshes[0].setEffectAssociation(0, 1,0);
773
    meshes[1] = meshes[0].copy(true);
774
    meshes[1].setEffectAssociation(0, 2,0);
775
    meshes[2] = new MeshPolygon(vertices1, bands1, 0, 0);
776
    meshes[2].setEffectAssociation(0, 4,0);
777
    meshes[3] = meshes[2].copy(true);
778
    meshes[3].setEffectAssociation(0, 8,0);
779
    meshes[4] = new MeshPolygon(vertices2, bands1, 1, 2);
780
    meshes[4].setEffectAssociation(0,16,0);
781
    meshes[5] = new MeshPolygon(vertices3, bands1, 1, 2);
782
    meshes[5].setEffectAssociation(0,32,0);
783

  
784
    return new MeshJoined(meshes);
785
    }
786

  
743 787
///////////////////////////////////////////////////////////////////////////////////////////////////
744 788

  
745 789
  MeshBase createFacesMegaminxEdge(int numLayers, float width, float height)
......
1409 1453

  
1410 1454
///////////////////////////////////////////////////////////////////////////////////////////////////
1411 1455

  
1412
  VertexEffect[] createVertexEffectsMegaminxCorner(int numLayers)
1456
  VertexEffect[] createVertexEffectsMinxCorner(float width)
1413 1457
    {
1414 1458
    VertexEffect[] effect = new VertexEffect[9];
1415 1459

  
......
1418 1462
    float sinA = (2*SIN54*SIN54-1)/COS54;
1419 1463
    float cosA = (float)Math.sqrt(1-sinA*sinA);
1420 1464
    float LEN  = 0.5f/SIN54;
1421
    float scale= (numLayers/3.0f)*(0.5f-MEGA_D)/(LEN*0.5f*(numLayers-1));
1465
    float scale= width/LEN;
1422 1466

  
1423 1467
    Static3D axisA = new Static3D( SIN54, COS54, 0.0f);
1424 1468
    Static3D axisB = new Static3D(-SIN54, COS54, 0.0f);
......
1454 1498
    return effect;
1455 1499
    }
1456 1500

  
1501
///////////////////////////////////////////////////////////////////////////////////////////////////
1502

  
1503
  VertexEffect[] createVertexEffectsKilominxEdge(float width, float height, boolean left)
1504
    {
1505
    VertexEffect[] effect = new VertexEffect[11 + (left ? 0:1)];
1506

  
1507
    float D = height/COS18;
1508
    float W = D*SIN18;
1509
    float X1 = height/2;
1510
    float Y1 = width/2;
1511
    float Y2 = (width+W)/2;
1512
    float Y3 = D*COS54;
1513
    float Y4 = height*COS_HALFD;
1514
    float Z = 2*height*COS_HALFD;
1515
    float alpha = 90-DIHEDRAL1/2;
1516

  
1517
    Static1D angle1 = new Static1D(alpha);
1518
    Static1D angle2 = new Static1D(180-alpha);
1519
    Static1D angle3 = new Static1D(DIHEDRAL2);
1520
    Static1D angle4 = new Static1D(90);
1521

  
1522
    Static3D move1 = new Static3D(+X1,-Y1,0);
1523
    Static3D move2 = new Static3D(-X1,-Y2+W,-Z);
1524
    Static3D move3 = new Static3D(0,+Y3,0);
1525
    Static3D move4 = new Static3D(0,-Y4-width,0);
1526
    Static3D scale = new Static3D(+1,+1,-1);
1527

  
1528
    Static3D axisXplus = new Static3D(+1, 0, 0);
1529
    Static3D axisYplus = new Static3D( 0,+1, 0);
1530

  
1531
    Static3D center1= new Static3D( 0, 0, 0);
1532
    Static3D center2= new Static3D( 0, 0,-Z);
1533
    Static3D center3= new Static3D( 0,-width, 0);
1534

  
1535
    effect[ 0] = new VertexEffectMove(move1);
1536
    effect[ 1] = new VertexEffectMove(move2);
1537
    effect[ 2] = new VertexEffectMove(move3);
1538
    effect[ 3] = new VertexEffectMove(move4);
1539
    effect[ 4] = new VertexEffectScale(scale);
1540
    effect[ 5] = new VertexEffectRotate(angle1, axisYplus , center1);
1541
    effect[ 6] = new VertexEffectRotate(angle2, axisYplus , center1);
1542
    effect[ 7] = new VertexEffectRotate(angle1, axisYplus , center2);
1543
    effect[ 8] = new VertexEffectRotate(angle2, axisYplus , center2);
1544
    effect[ 9] = new VertexEffectRotate(angle3, axisXplus , center1);
1545
    effect[10] = new VertexEffectRotate(angle4, axisXplus , center3);
1546

  
1547
    if( !left )
1548
      {
1549
      Static3D scale1 = new Static3D(+1,-1,+1);
1550
      effect[11] = new VertexEffectScale(scale1);
1551
      }
1552

  
1553
    effect[ 0].setMeshAssociation( 3,-1);  // meshes 0,1
1554
    effect[ 1].setMeshAssociation(12,-1);  // meshes 2,3
1555
    effect[ 2].setMeshAssociation(16,-1);  // mesh 4
1556
    effect[ 3].setMeshAssociation(32,-1);  // mesh 5
1557
    effect[ 4].setMeshAssociation( 2,-1);  // mesh 1
1558
    effect[ 5].setMeshAssociation( 1,-1);  // mesh 0
1559
    effect[ 6].setMeshAssociation( 2,-1);  // mesh 1
1560
    effect[ 7].setMeshAssociation( 4,-1);  // mesh 2
1561
    effect[ 8].setMeshAssociation( 8,-1);  // mesh 3
1562
    effect[ 9].setMeshAssociation(16,-1);  // mesh 4
1563
    effect[10].setMeshAssociation(32,-1);  // mesh 5
1564

  
1565
    return effect;
1566
    }
1567

  
1457 1568
///////////////////////////////////////////////////////////////////////////////////////////////////
1458 1569

  
1459 1570
  VertexEffect[] createVertexEffectsMegaminxEdge(float width, float height)
......
1964 2075
///////////////////////////////////////////////////////////////////////////////////////////////////
1965 2076
// numLayers==3 --> index=0; numLayers=5 --> index=1 ...
1966 2077
// type: 0,1,... 0 --> edge, 1 --> 1 layer deeper, etc
1967
// TODO
1968 2078

  
1969
  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height)
2079
  MeshBase createKilominxEdgeMesh(int numLayers, float width, float height, boolean left)
1970 2080
    {
1971
    MeshBase mesh = createFacesMegaminxEdge(numLayers,width,height);
1972
    VertexEffect[] effects = createVertexEffectsMegaminxEdge(width,height);
2081
    MeshBase mesh = createFacesKilominxEdge(numLayers,width,height);
2082
    VertexEffect[] effects = createVertexEffectsKilominxEdge(width,height,left);
1973 2083
    for( VertexEffect effect : effects ) mesh.apply(effect);
1974 2084

  
2085
// round...
2086

  
1975 2087
    mesh.mergeEffComponents();
1976 2088

  
1977 2089
    return mesh;
......
1979 2091

  
1980 2092
///////////////////////////////////////////////////////////////////////////////////////////////////
1981 2093

  
1982
  MeshBase createMinxCornerMesh(ObjectList object, int numLayers)
2094
  MeshBase createMinxCornerMesh(int numLayers, float width)
1983 2095
    {
1984
    MeshBase mesh = createFacesMegaminxCorner(numLayers);
1985
    VertexEffect[] effects = createVertexEffectsMegaminxCorner(numLayers);
2096
    MeshBase mesh = createFacesMinxCorner(numLayers);
2097
    VertexEffect[] effects = createVertexEffectsMinxCorner(width);
1986 2098
    for( VertexEffect effect : effects ) mesh.apply(effect);
1987 2099

  
1988 2100
    float A = (2*SQ3/3)* SIN54;
1989 2101
    float B = 0.4f;
2102
/*
1990 2103
    float X = SIN_HALFD* SIN54 * COS54;
1991 2104
    float Y = SIN54 * SIN54 - 0.5f;
1992 2105
    float Z = COS_HALFD* SIN54 * COS54;
1993
    float S = 2*SIN54*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
1994

  
2106
    float S = 2*width;
2107
*/
1995 2108
    Static3D center = new Static3D(0.0f, -(float)Math.sqrt(1-A*A)*B,-A*B);
1996

  
1997
    Static3D[] vertices = new Static3D[4];
2109
    Static3D[] vertices = new Static3D[1];
1998 2110
    vertices[0] = new Static3D( 0.0f, 0.0f  , 0.0f);
2111
/*
1999 2112
    vertices[1] = new Static3D( 0.0f,-0.5f*S, 0.0f);
2000 2113
    vertices[2] = new Static3D(-X*S , Y*S   ,-Z*S );
2001 2114
    vertices[3] = new Static3D(+X*S , Y*S   ,-Z*S );
2002

  
2115
*/
2003 2116
    roundCorners(mesh,center,vertices,0.04f,0.10f);
2004 2117

  
2005 2118
    mesh.mergeEffComponents();
src/main/java/org/distorted/objects/TwistyKilominx.java
188 188
  private float[] computeEdge(int numLayers, int edge, int part)
189 189
    {
190 190
    float D = numLayers/3.0f;
191

  
192 191
    float[] c1 = CORNERS[ mEdgeMap[edge][0] ];
193 192
    float[] c2 = CORNERS[ mEdgeMap[edge][1] ];
194
    float x = D * (c1[0]+c2[0]) / 2;
195
    float y = D * (c1[1]+c2[1]) / 2;
196
    float z = D * (c1[2]+c2[2]) / 2;
197 193

  
194
    int leftRight = 2*(part%2) -1;
198 195
    part /= 2;
199 196

  
200 197
    if( part==0 )
201 198
      {
199
      float T = 0.5f + leftRight/(numLayers-1.0f);
200
      float x = D * (T*c1[0]+(1.0f-T)*c2[0]);
201
      float y = D * (T*c1[1]+(1.0f-T)*c2[1]);
202
      float z = D * (T*c1[2]+(1.0f-T)*c2[2]);
203

  
202 204
      return new float[] { x, y, z };
203 205
      }
204 206
    else
......
206 208
      int mult = (part+1)/2;
207 209
      int dir  = (part+1)%2;
208 210
      float[] center = mCenterCoords[ mEdgeMap[edge][dir+2] ];
211
      float x = 0.5f * D * (c1[0]+c2[0]);
212
      float y = 0.5f * D * (c1[1]+c2[1]);
213
      float z = 0.5f * D * (c1[2]+c2[2]);
209 214

  
210 215
      float vX = D*center[0] - x;
211 216
      float vY = D*center[1] - y;
212 217
      float vZ = D*center[2] - z;
213 218

  
214
      float A = mult*D*COS18/(numLayers-1);
215
      A /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
219
      float T = 0.5f + leftRight*(mult*D*SIN18 + 1.0f)/(numLayers-1);
220
      x = D * (T*c1[0]+(1.0f-T)*c2[0]);
221
      y = D * (T*c1[1]+(1.0f-T)*c2[1]);
222
      z = D * (T*c1[2]+(1.0f-T)*c2[2]);
223

  
224
      float H = mult*D*COS18/(numLayers-1);
225
      H /= (float)Math.sqrt(vX*vX+vY*vY+vZ*vZ);
216 226

  
217
      return new float[] { x+A*vX, y+A*vY, z+A*vZ };
227
      return new float[] { x + H*vX, y + H*vY, z + H*vZ };
218 228
      }
219 229
    }
220 230

  
......
318 328
      {
319 329
      if( mCornerMeshes[indexCornerEdge]==null )
320 330
        {
321
        mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(ObjectList.KILO,numLayers);
331
        float width = (numLayers/3.0f)/(numLayers-1);
332
        mCornerMeshes[indexCornerEdge] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers,width);
322 333
        }
323 334
      mesh = mCornerMeshes[indexCornerEdge].copy(true);
324 335
      }
......
332 343
        float height= tmp*COS18;
333 344
        float width = tmp + type*height*SIN18/COS18;
334 345

  
335
        mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height);
346
        mEdgeMeshes[indexCornerEdge][type] = FactoryCubit.getInstance().createKilominxEdgeMesh(numLayers,width,height, (type%2)==0 );
336 347
        }
337 348

  
338 349
      mesh = mEdgeMeshes[indexCornerEdge][type].copy(true);
src/main/java/org/distorted/objects/TwistyMegaminx.java
283 283
      {
284 284
      if( mCornerMeshes[index]==null )
285 285
        {
286
        mCornerMeshes[index] = FactoryCubit.getInstance().createMinxCornerMesh(ObjectList.MEGA,numLayers);
286
        float width = (numLayers/3.0f)*(0.5f-MEGA_D)/(0.5f*(numLayers-1));
287
        mCornerMeshes[index] = FactoryCubit.getInstance().createMinxCornerMesh(numLayers, width);
287 288
        }
288 289
      mesh = mCornerMeshes[index].copy(true);
289 290
      }
src/main/java/org/distorted/objects/TwistyMinx.java
218 218
          {false,  true,  true,  true,  true, false}
219 219
      };
220 220

  
221
  // the quadruple ( vertex1, vertex2, face1, face2 ) defining an edge.
222
  // In fact the 2 vertices already define it, the faces only provide easy
221
  // the quadruple ( corner1, corner2, face1, face2 ) defining an edge.
222
  // In fact the 2 corners already define it, the faces only provide easy
223 223
  // way to get to know the colors. Order: arbitrary. Face1 arbitrarily on
224
  // the 'left' or right of vector vertex1 --> vertex2, according to Quat.
224
  // the 'left' or right of vector corner1 --> corner2, according to Quat.
225 225
  static final int[][] mEdgeMap =
226 226
         {
227 227
           {  0, 12,  0,  8},

Also available in: Unified diff