Revision 2d203318
Added by Leszek Koltunski about 6 years ago
src/main/java/org/distorted/library/mesh/MeshCubes.java | ||
---|---|---|
674 | 674 |
} |
675 | 675 |
|
676 | 676 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
677 |
|
|
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 |
|
|
678 | 690 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs) |
679 | 691 |
{ |
680 | 692 |
//android.util.Log.e("CUBES", "adding Side vertex!"); |
... | ... | |
705 | 717 |
///////////////////////////////////////////////////////////////// |
706 | 718 |
// clever stuff so that the sides of the mesh are textured nicely |
707 | 719 |
tmp1 = (float)(row-slice)/mRows; |
708 |
tmp2 = 1.0f-tmp1;
|
|
720 |
tmp2 = tmp1+1.0f;
|
|
709 | 721 |
|
710 |
if( tmp1 != (int)tmp1 )
|
|
722 |
if( tmp2 != (int)tmp2 )
|
|
711 | 723 |
{ |
712 |
tmp2 = tmp2 - (int)tmp2; |
|
713 |
if (tmp2 < 0.0f ) tmp2 += 1.0f; |
|
714 |
if ( ((int)tmp1)%2 == 1) tmp2 = 1.0f - tmp2; |
|
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; |
|
715 | 728 |
} |
716 | 729 |
else |
717 | 730 |
{ |
718 |
tmp2 = ((int)tmp1)%2;
|
|
719 |
if( tmp2 <0.0f ) tmp2 = -tmp2;
|
|
731 |
tmp2 = ((int)tmp2)%2;
|
|
732 |
if( tmp2<0.0f ) tmp2= -tmp2;
|
|
720 | 733 |
} |
721 | 734 |
///////////////////////////////////////////////////////////////// |
722 | 735 |
// end clever stuff |
... | ... | |
744 | 757 |
|
745 | 758 |
///////////////////////////////////////////////////////////////// |
746 | 759 |
// clever stuff so that the sides of the mesh are textured nicely |
747 |
tmp1 = (float)(row-slice)/mRows;
|
|
748 |
tmp2 = 1.0f-tmp1;
|
|
760 |
tmp1 = (float)(row+slice)/mRows;
|
|
761 |
tmp2 = tmp1-1.0f;
|
|
749 | 762 |
|
750 |
if( tmp1 != (int)tmp1 )
|
|
763 |
if( tmp2 != (int)tmp2 )
|
|
751 | 764 |
{ |
752 |
tmp2 = tmp2 - (int)tmp2; |
|
753 |
if (tmp2 < 0.0f ) tmp2 += 1.0f; |
|
754 |
if ( ((int)tmp1)%2 == 0 ) tmp2 = 1.0f - tmp2; |
|
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; |
|
755 | 769 |
} |
756 | 770 |
else |
757 | 771 |
{ |
758 |
tmp2 = 1-((int)tmp1)%2;
|
|
759 |
if( tmp2 <0.0f ) tmp2 = -tmp2;
|
|
772 |
tmp2 = ((int)tmp2)%2;
|
|
773 |
if( tmp2<0.0f ) tmp2= -tmp2;
|
|
760 | 774 |
} |
761 | 775 |
///////////////////////////////////////////////////////////////// |
762 | 776 |
// end clever stuff |
... | ... | |
782 | 796 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f; |
783 | 797 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z; |
784 | 798 |
|
785 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = (float)(col-slice)/mCols; |
|
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; |
|
803 |
|
|
804 |
if( tmp2 != (int)tmp2 ) |
|
805 |
{ |
|
806 |
if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f; |
|
807 |
else tmp2 = tmp2 - (int)tmp2; |
|
808 |
|
|
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; |
|
786 | 820 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y; |
787 | 821 |
break; |
788 | 822 |
case EAST : row = (back ? (curr.row):(curr.row+1)); |
... | ... | |
803 | 837 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInfCorr*mInflateY[row][col]/2.0f; |
804 | 838 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = mInfCorr*z; |
805 | 839 |
|
806 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = (float)(col+slice)/mCols; |
|
807 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y; |
|
808 |
break; |
|
809 |
} |
|
810 |
/* |
|
811 |
float tex0 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ]; |
|
812 |
float tex1 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1]; |
|
813 |
|
|
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; |
|
819 |
|
|
820 |
// tex0 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ]; |
|
821 |
// tex1 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1]; |
|
822 |
|
|
823 |
float t = -1.4f; |
|
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; |
|
824 | 844 |
|
825 |
float r = t - (int)t; |
|
826 |
android.util.Log.e("mesh", "r="+r); |
|
845 |
if( tmp2 != (int)tmp2 ) |
|
846 |
{ |
|
847 |
if( tmp2<0.0f ) tmp2 = tmp2 - (int)tmp2 + 1.0f; |
|
848 |
else tmp2 = tmp2 - (int)tmp2; |
|
827 | 849 |
|
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 |
|
828 | 859 |
|
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); |
|
860 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = tmp2; |
|
861 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y; |
|
862 |
break; |
|
833 | 863 |
} |
834 |
*/ |
|
864 |
|
|
835 | 865 |
currVert++; |
836 | 866 |
} |
837 | 867 |
|
Also available in: Unified diff
MeshCubes: Correct texturing of side walls. (still not everything is right there)