Project

General

Profile

« Previous | Next » 

Revision 554ce72b

Added by Leszek Koltunski almost 6 years ago

Bugfix: make the Inflate distances equal in all 3 dimensions regardless of dimensions of the Mesh. (still MeshFlat's Z dim needs to be corrected)

View differences:

src/main/java/org/distorted/library/mesh/MeshCubes.java
57 57
   private int mCols, mRows, mSlices;
58 58
   private int[][] mCubes;
59 59
   private byte[][] mInflateX, mInflateY;
60
   private float mInfCorrX, mInfCorrY, mInfCorrZ;
60 61
   private ArrayList<Edge> mEdges = new ArrayList<>();
61 62

  
62 63
   private int currVert;
......
184 185
     mCols       =0;
185 186
     mSlices     =slices;
186 187
     numVertices =0;
187
     
188

  
188 189
     if( cols>0 && desc.contains("1") )
189 190
       {
190 191
       mCols = cols;
191 192
       mRows = desc.length()/cols;
192 193

  
194
       int max = mRows>mCols ? mRows:mCols;
195
       max = mSlices>max ? mSlices : max;
196

  
197
       mInfCorrX = (float)max/mCols;
198
       mInfCorrY = (float)max/mRows;
199
       mInfCorrZ = (float)max/mSlices;
200

  
193 201
       mCubes    = new int[mRows][mCols];
194 202
       mInflateX = new byte[mRows+1][mCols+1];
195 203
       mInflateY = new byte[mRows+1][mCols+1];
......
226 234
       mInflateX = new byte[mRows+1][mCols+1];
227 235
       mInflateY = new byte[mRows+1][mCols+1];
228 236

  
237
       int max = mRows>mCols ? mRows:mCols;
238
       max = mSlices>max ? mSlices : max;
239

  
240
       mInfCorrX = (float)max/mCols;
241
       mInfCorrY = (float)max/mRows;
242
       mInfCorrZ = (float)max/mSlices;
243

  
229 244
       for(int col=0; col<mCols; col++)
230 245
         for(int row=0; row<mRows; row++)
231 246
           mCubes[row][col] = 1;
......
656 671
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
657 672
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
658 673

  
659
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
660
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
661
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
674
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorrX*mInflateX[row][col]/2.0f;
675
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorrY*mInflateY[row][col]/2.0f;
676
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorrZ*vectZ;
662 677

  
663 678
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
664 679
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
......
690 705
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
691 706
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
692 707

  
693
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
694
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
695
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
708
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorrX*mInflateX[row][col]/2.0f;
709
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorrY*mInflateY[row][col]/2.0f;
710
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorrZ*z;
696 711

  
697 712
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
698 713
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(row-slice)/mRows;
......
711 726
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
712 727
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
713 728

  
714
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
715
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
716
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
729
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorrX*mInflateX[row][col]/2.0f;
730
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorrY*mInflateY[row][col]/2.0f;
731
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorrZ*z;
717 732

  
718 733
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
719 734
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(row+slice)/mRows;
......
732 747
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
733 748
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
734 749

  
735
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
736
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
737
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
750
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorrX*mInflateX[row][col]/2.0f;
751
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorrY*mInflateY[row][col]/2.0f;
752
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorrZ*z;
738 753

  
739 754
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col-slice)/mCols;
740 755
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
......
753 768
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
754 769
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
755 770

  
756
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
757
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
758
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
771
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorrX*mInflateX[row][col]/2.0f;
772
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorrY*mInflateY[row][col]/2.0f;
773
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorrZ*z;
759 774

  
760 775
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col+slice)/mCols;
761 776
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
src/main/java/org/distorted/library/mesh/MeshFlat.java
31 31
  private int mCols, mRows;
32 32
  private int remainingVert;
33 33
  private int numVertices;
34
  private float mInfCorrX, mInfCorrY;
34 35

  
35 36
///////////////////////////////////////////////////////////////////////////////////////////////////
36 37
// Create a flat, full grid.
......
40 41
     mRows=rows;
41 42
     mCols=cols;
42 43

  
44
     int max = mRows>mCols ? mRows:mCols;
45
     mInfCorrX = (float)max/mCols;
46
     mInfCorrY = (float)max/mRows;
47

  
43 48
     if( cols==1 && rows==1 )
44 49
       {
45 50
       numVertices = 4;
......
69 74
     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f;
70 75
     attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f;
71 76

  
72
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = x-0.5f;
73
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.5f-y;
77
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB  ] = (x-0.5f)*mInfCorrX;
78
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = (0.5f-y)*mInfCorrY;
79

  
80
     // TODO: this better be non-zero, so that when the GLOW gets rendered it is slightly above
81
     // the original MeshFlat surface, but simply setting this to non-zero here does not work,
82
     // because MeshFlat's u_objD.z is 0 and this gets multipled by it in the main vertex shader.
74 83
     attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f;
75 84

  
76 85
     attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB  ] = x;

Also available in: Unified diff