Project

General

Profile

« Previous | Next » 

Revision a16bf106

Added by Leszek Koltunski over 5 years ago

Make the Effects3D app a bit more user-friendly.

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
   private float mInfCorr;
61 61
   private ArrayList<Edge> mEdges = new ArrayList<>();
62 62

  
63 63
   private int currVert;
......
191 191
       mCols = cols;
192 192
       mRows = desc.length()/cols;
193 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;
194
       mInfCorr = mRows>mCols ? mRows:mCols;
195
       mInfCorr = mSlices>mInfCorr ? mSlices : mInfCorr;
200 196

  
201 197
       mCubes    = new int[mRows][mCols];
202 198
       mInflateX = new byte[mRows+1][mCols+1];
......
234 230
       mInflateX = new byte[mRows+1][mCols+1];
235 231
       mInflateY = new byte[mRows+1][mCols+1];
236 232

  
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;
233
       mInfCorr = mRows>mCols ? mRows:mCols;
234
       mInfCorr = mSlices>mInfCorr ? mSlices : mInfCorr;
243 235

  
244 236
       for(int col=0; col<mCols; col++)
245 237
         for(int row=0; row<mRows; row++)
......
671 663
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
672 664
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
673 665

  
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;
666
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorr*mInflateX[row][col]/2.0f;
667
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
668
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*vectZ;
677 669

  
678 670
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
679 671
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
......
688 680
     //android.util.Log.e("CUBES", "adding Side vertex!");
689 681
     float x, y, z;
690 682
     int row, col;
683
     float tmp1, tmp2;
691 684

  
692 685
     switch(curr.side)
693 686
       {
......
705 698
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
706 699
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
707 700

  
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;
701
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorr*mInflateX[row][col]/2.0f;
702
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
703
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
704

  
705
                   /////////////////////////////////////////////////////////////////
706
                   // clever stuff so that the sides of the mesh are textured nicely
707
                   tmp1 = (float)(row-slice)/mRows;
708
                   tmp2 = 1.0f-tmp1;
709

  
710
                   if( tmp1 != (int)tmp1 )
711
                     {
712
                     tmp2 = tmp2 - (int)tmp2;
713
                     if (tmp2 < 0.0f ) tmp2 += 1.0f;
714
                     if ( ((int)tmp1)%2 == 1) tmp2 = 1.0f - tmp2;
715
                     }
716
                   else
717
                     {
718
                     tmp2 = ((int)tmp1)%2;
719
                     if( tmp2 <0.0f ) tmp2 = -tmp2;
720
                     }
721
                   /////////////////////////////////////////////////////////////////
722
                   // end clever stuff
711 723

  
712 724
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
713
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(row-slice)/mRows;
725
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
714 726
                   break;
715 727
       case SOUTH: row = curr.row+1;
716 728
                   col = (back ? (curr.col+1):(curr.col));
......
726 738
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
727 739
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
728 740

  
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;
741
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorr*mInflateX[row][col]/2.0f;
742
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
743
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
744

  
745
                   /////////////////////////////////////////////////////////////////
746
                   // clever stuff so that the sides of the mesh are textured nicely
747
                   tmp1 = (float)(row-slice)/mRows;
748
                   tmp2 = 1.0f-tmp1;
749

  
750
                   if( tmp1 != (int)tmp1 )
751
                     {
752
                     tmp2 = tmp2 - (int)tmp2;
753
                     if (tmp2 < 0.0f ) tmp2 += 1.0f;
754
                     if ( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f - tmp2;
755
                     }
756
                   else
757
                     {
758
                     tmp2 = 1-((int)tmp1)%2;
759
                     if( tmp2 <0.0f ) tmp2 = -tmp2;
760
                     }
761
                   /////////////////////////////////////////////////////////////////
762
                   // end clever stuff
732 763

  
733 764
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
734
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(row+slice)/mRows;
765
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
735 766
                   break;
736 767
       case WEST : row = (back  ? (curr.row+1):(curr.row));
737 768
                   col = curr.col;
......
747 778
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
748 779
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
749 780

  
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;
781
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorr*mInflateX[row][col]/2.0f;
782
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
783
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
753 784

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

  
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;
802
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInfCorr*mInflateX[row][col]/2.0f;
803
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
804
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
774 805

  
775 806
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col+slice)/mCols;
776 807
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
777 808
                   break;
778 809
       }
779

  
810
/*
780 811
     float tex0 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ];
781 812
     float tex1 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1];
782 813

  
783
     if(tex0>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = 2.0f-tex0;
784
     if(tex0<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] =     -tex0;
785
     if(tex1>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 2.0f-tex1;
786
     if(tex1<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] =     -tex1;
814
     if(tex0<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tex0 - (int)tex0;
815
     if(tex1<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tex1 - (int)tex1;
816

  
817
     if(tex0>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tex0 - (int)tex0;
818
     if(tex1>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tex1 - (int)tex1;
787 819

  
820
   //  tex0 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ];
821
   //  tex1 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1];
822

  
823
  float t = -1.4f;
824

  
825
  float r = t - (int)t;
826
  android.util.Log.e("mesh", "r="+r);
827

  
828

  
829
     if( curr.side==NORTH )
830
       {
831
       android.util.Log.e("mesh", "tex0:" + tex0 + " slice=" + slice+" row="+row+" col="+col);
832
       android.util.Log.e("mesh", "tex1:" + tex1 + " slice=" + slice+" row="+row+" col="+col);
833
       }
834
*/
788 835
     currVert++;
789 836
     }
790 837

  

Also available in: Unified diff