Project

General

Profile

« Previous | Next » 

Revision 15ed35e6

Added by Leszek Koltunski about 6 years ago

MeshCubes: Correct texturing of side walls. Everything should be correct now.

View differences:

src/main/java/org/distorted/library/mesh/MeshCubes.java
674 674
     }
675 675

  
676 676
///////////////////////////////////////////////////////////////////////////////////////////////////
677
// TODO
678
// Texturing of side walls still not quite right. Example:
679

  
680
// 5x5x4 :
681
//
682
// 1 1 1 1 1
683
// 1 0 0 0 1
684
// 1 0 0 0 1
685
// 1 0 0 0 1
686
// 1 1 1 1 1
687
//
688
// - then the right and bottom internal walls don't look right.
689 677

  
690 678
  private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
691 679
     {
692 680
     //android.util.Log.e("CUBES", "adding Side vertex!");
693 681
     float x, y, z;
694
     int row, col;
695
     float tmp1, tmp2;
682
     int row, col, texX, texY;
696 683

  
697 684
     switch(curr.side)
698 685
       {
......
714 701
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
715 702
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
716 703

  
717
                   /////////////////////////////////////////////////////////////////
718
                   // clever stuff so that the sides of the mesh are textured nicely
719
                   tmp1 = (float)(row-slice)/mRows;
720
                   tmp2 = tmp1+1.0f;
721

  
722
                   if( tmp2 != (int)tmp2 )
723
                     {
724
                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
725
                     else            tmp2 = tmp2 - (int)tmp2;
726

  
727
                     if( ((int)tmp1)%2 != 0 ) tmp2 = 1.0f-tmp2;
728
                     }
729
                   else
730
                     {
731
                     tmp2 = ((int)tmp2)%2;
732
                     if( tmp2<0.0f ) tmp2= -tmp2;
733
                     }
734
                   /////////////////////////////////////////////////////////////////
735
                   // end clever stuff
704
                   texY = (mRows-row+slice)%(2*mRows);
705
                   if( texY>mRows ) texY = 2*mRows-texY;
736 706

  
737 707
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
738
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
708
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = (float)texY/mRows;
709

  
739 710
                   break;
740 711
       case SOUTH: row = curr.row+1;
741 712
                   col = (back ? (curr.col+1):(curr.col));
......
755 726
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
756 727
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
757 728

  
758
                   /////////////////////////////////////////////////////////////////
759
                   // clever stuff so that the sides of the mesh are textured nicely
760
                   tmp1 = (float)(row+slice)/mRows;
761
                   tmp2 = tmp1-1.0f;
762

  
763
                   if( tmp2 != (int)tmp2 )
764
                     {
765
                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
766
                     else            tmp2 = tmp2 - (int)tmp2;
767

  
768
                     if( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f-tmp2;
769
                     }
770
                   else
771
                     {
772
                     tmp2 = ((int)tmp2)%2;
773
                     if( tmp2<0.0f ) tmp2= -tmp2;
774
                     }
775
                   /////////////////////////////////////////////////////////////////
776
                   // end clever stuff
729
                   texY = (mRows-row+slice)%(2*mRows);
730
                   if( texY>mRows ) texY = 2*mRows-texY;
777 731

  
778 732
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
779
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = tmp2;
733
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = (float)texY/mRows;
734

  
780 735
                   break;
781 736
       case WEST : row = (back  ? (curr.row+1):(curr.row));
782 737
                   col = curr.col;
......
796 751
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
797 752
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
798 753

  
799
                   /////////////////////////////////////////////////////////////////
800
                   // clever stuff so that the sides of the mesh are textured nicely
801
                   tmp1 = (float)(col-slice)/mCols;
802
                   tmp2 = tmp1+1.0f;
754
                   texX = (col+slice)%(2*mCols);
755
                   if( texX>mCols ) texX = 2*mCols-texX;
803 756

  
804
                   if( tmp2 != (int)tmp2 )
805
                     {
806
                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
807
                     else            tmp2 = tmp2 - (int)tmp2;
757
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)texX/mCols;
758
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
808 759

  
809
                     if( ((int)tmp1)%2 != 0 ) tmp2 = 1.0f-tmp2;
810
                     }
811
                   else
812
                     {
813
                     tmp2 = ((int)tmp2)%2;
814
                     if( tmp2<0.0f ) tmp2= -tmp2;
815
                     }
816
                   /////////////////////////////////////////////////////////////////
817
                   // end clever stuff
818

  
819
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tmp2;
820
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
821 760
                   break;
822 761
       case EAST : row = (back  ? (curr.row):(curr.row+1));
823 762
                   col = (curr.col+1);
......
837 776
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f;
838 777
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z;
839 778

  
840
                   /////////////////////////////////////////////////////////////////
841
                   // clever stuff so that the sides of the mesh are textured nicely
842
                   tmp1 = (float)(col+slice)/mCols;
843
                   tmp2 = tmp1-1.0f;
779
                   texX = (col+slice)%(2*mCols);
780
                   if( texX>mCols ) texX = 2*mCols-texX;
844 781

  
845
                   if( tmp2 != (int)tmp2 )
846
                     {
847
                     if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f;
848
                     else            tmp2 = tmp2 - (int)tmp2;
782
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)texX/mCols;
783
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
849 784

  
850
                     if( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f-tmp2;
851
                     }
852
                   else
853
                     {
854
                     tmp2 = ((int)tmp2)%2;
855
                     if( tmp2<0.0f ) tmp2= -tmp2;
856
                     }
857
                   /////////////////////////////////////////////////////////////////
858
                   // end clever stuff
859

  
860
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = tmp2;
861
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
862 785
                   break;
863 786
       }
864 787

  

Also available in: Unified diff