Project

General

Profile

« Previous | Next » 

Revision 786098dd

Added by Leszek Koltunski over 3 years ago

Progress with FactoryBandaged.

View differences:

src/main/java/org/distorted/objectlib/helpers/FactoryBandaged3x3Cubit.java
19 19

  
20 20
package org.distorted.objectlib.helpers;
21 21

  
22
///////////////////////////////////////////////////////////////////////////////////////////////////
23

  
24 22
import java.util.ArrayList;
25 23

  
24
import org.distorted.library.type.Static3D;
25
import org.distorted.objectlib.touchcontrol.TouchControlHexahedron;
26

  
27
///////////////////////////////////////////////////////////////////////////////////////////////////
28

  
26 29
public class FactoryBandaged3x3Cubit
27 30
  {
28 31
  private static final int WALL_MARKED=0;
......
722 725
    }
723 726

  
724 727
///////////////////////////////////////////////////////////////////////////////////////////////////
725
// TODO
728

  
729
  private static boolean vertInFace(float[] vertex, Static3D faceAxis, float dist)
730
    {
731
    final float MAX_ERROR = 0.01f;
732

  
733
    float x= faceAxis.get0();
734
    float y= faceAxis.get1();
735
    float z= faceAxis.get2();
736

  
737
    float a = vertex[0]*x + vertex[1]*y + vertex[2]*z;
738
    float diff = a - dist;
739

  
740
    return diff>-MAX_ERROR && diff<MAX_ERROR;
741
    }
742

  
743
///////////////////////////////////////////////////////////////////////////////////////////////////
744
// (vertices,indices) define a cubit face, i.e. a connected subset of the 3x3 grid.
745
// Return its 'diameter', i.e. max(width,height)
746

  
747
  private int faceDiameter(float[][] vertices, int[] indices)
748
    {
749
    float maxX = -1.5f;
750
    float minX = +1.5f;
751
    float maxY = -1.5f;
752
    float minY = +1.5f;
753
    float maxZ = -1.5f;
754
    float minZ = +1.5f;
755

  
756
    for (int index : indices)
757
      {
758
      float[] v = vertices[index];
759

  
760
      if (v[0] > maxX) maxX = v[0];
761
      if (v[0] < minX) minX = v[0];
762
      if (v[1] > maxY) maxY = v[1];
763
      if (v[1] < minY) minY = v[1];
764
      if (v[2] > maxZ) maxZ = v[2];
765
      if (v[2] < minZ) minZ = v[2];
766
      }
767

  
768
    float diffX = maxX-minX;
769
    float diffY = maxY-minY;
770
    float diffZ = maxZ-minZ;
771

  
772
    float max = diffX>diffY ? Math.max(diffX,diffZ) : Math.max(diffY,diffZ);
773

  
774
    return (int)max;
775
    }
776

  
777
///////////////////////////////////////////////////////////////////////////////////////////////////
778
// return array of:
779
// 0 if this is an inner face, 1 if its diameter is 1, 2 if diameter is 2, 3 if 3.
726 780

  
727 781
  private int[] generateBandIndices(float[][] vertices, int[][] indices)
728 782
    {
729
    int len = indices.length;
730
    int[] bandIndices = new int[len];
731
    for(int i=0; i<len; i++) bandIndices[i] = 3;
783
    int numCubitFaces = indices.length;
784
    int[] bandIndices = new int[numCubitFaces];
785

  
786
    for(int cubitFace=0; cubitFace<numCubitFaces; cubitFace++)
787
      {
788
      bandIndices[cubitFace] = 0xffffffff;
789

  
790
      int numVertices = indices[cubitFace].length;
791
      int vertBelongsBitmap = 0x00000000;
792

  
793
      for(int vertex=0; vertex<numVertices; vertex++)
794
        {
795
        for(int face=0; face<6; face++)
796
          {
797
          float[] vert = vertices[ indices[cubitFace][vertex] ];
798
          if( vertInFace(vert, TouchControlHexahedron.FACE_AXIS[face],1.5f) )
799
            {
800
            vertBelongsBitmap |= (1<<face);
801
            }
802
          }
803

  
804
        bandIndices[cubitFace] &= vertBelongsBitmap;
805
        }
806

  
807
      if( bandIndices[cubitFace]!=0 ) // outer face
808
        {
809
        bandIndices[cubitFace] = faceDiameter(vertices, indices[cubitFace]);
810
        }
811
      }
732 812

  
733 813
    return bandIndices;
734 814
    }
......
774 854

  
775 855
///////////////////////////////////////////////////////////////////////////////////////////////////
776 856

  
777
  public void recreate(int numVariants)
857
  public void prepare(int numVariants)
778 858
    {
779 859
    if( mVertexArray==null ) mVertexArray = new ArrayList<>();
780
    else                     mVertexArray.clear();
781

  
782 860
    mVertices= new float[numVariants][][];
783 861
    mIndices = new int[numVariants][][];
784 862
    }
......
787 865

  
788 866
  public ObjectShape createIrregularShape(int variant, float[] pos)
789 867
    {
868
    mVertexArray.clear();
869

  
790 870
    for(int x=0; x<3; x++)
791 871
      for(int y=0; y<3; y++)
792 872
        for(int z=0; z<3; z++)
......
864 944
    {
865 945
    float defHeight     = 0.048f;
866 946
    float[][] corners   = { {0.04f,0.15f} };
867
    float[][] bands     = { {defHeight/1,45,0.25f,0.5f,5,1,1},
868
                            {defHeight/2,45,0.25f,0.5f,5,1,1},
947
    float[][] bands     = { {     0.001f,45,0.25f,0.5f,5,1,1},
869 948
                            {defHeight/3,45,0.25f,0.5f,5,1,1},
870
                            {     0.001f,45,0.25f,0.5f,5,1,1} };
949
                            {defHeight/2,45,0.25f,0.5f,5,1,1},
950
                            {defHeight/1,45,0.25f,0.5f,5,1,1} };
871 951

  
872 952
    int[] bandIndices   = generateBandIndices(mVertices[variant], mIndices[variant]);
873 953
    float[][] centers   = generateCenters(mVertices[variant], mIndices[variant]);
src/main/java/org/distorted/objectlib/objects/TwistyBandagedAbstract.java
458 458
      }
459 459

  
460 460
    FactoryBandaged3x3Cubit factory = FactoryBandaged3x3Cubit.getInstance();
461
    factory.recreate(numVariants);
461
    factory.prepare(numVariants);
462 462

  
463 463
    return numVariants;
464 464
    }
src/main/java/org/distorted/objectlib/objects/TwistyBandagedGeneric.java
60 60
           -1.0f, +1.0f, -1.0f,
61 61
           -1.0f,  0.0f, +1.0f,
62 62
           -1.0f,  0.0f, +0.0f,
63
           -1.0f,  0.0f, -1.0f,
64
           -1.0f, -1.0f, +1.0f,
63
           -1.0f,  0.0f, -1.0f },
64

  
65
          {-1.0f, -1.0f, +1.0f,
65 66
           -1.0f, -1.0f, +0.0f,
66 67
           -1.0f, -1.0f, -1.0f },
67 68

  
......
79 80
          { 1.0f, +1.0f, -1.0f},
80 81
          { 1.0f,  0.0f, +1.0f},
81 82
          { 1.0f,  0.0f, +0.0f},
82
          { 1.0f,  0.0f, -1.0f},
83 83
          { 1.0f, -1.0f, +1.0f},
84
          { 1.0f, -1.0f, +0.0f},
85
          { 1.0f, -1.0f, -1.0f},
84

  
85
          { 1.0f,  0.0f, -1.0f,
86
            1.0f, -1.0f, -1.0f,
87
            1.0f, -1.0f, +0.0f },
86 88
        };
87 89
      }
88 90
    return POSITIONS;

Also available in: Unified diff