34 |
34 |
float tmpx,tmpy,tmpz;
|
35 |
35 |
float[] bufferData;
|
36 |
36 |
|
37 |
|
dataLength = 2*xLength*(yLength-1)+2*(yLength-2); // (yLength-1) strips, 2*xLength triangles in each, plus 2 degenerate triangles per each of (yLength-2) joins
|
|
37 |
dataLength = 2*xLength*(yLength-1) // (yLength-1) strips, 2*xLength triangles in each,
|
|
38 |
+2*(yLength-2); // plus 2 degenerate triangles per each of (yLength-2) joins
|
|
39 |
|
|
40 |
if( xLength>2 )
|
|
41 |
{
|
|
42 |
dataLength += 3*(yLength-1); // we change direction of triangles midway through each row (+3 triangles per row)
|
|
43 |
dataLength += (yLength-2); // we also need to change direction when pulling back to the left (+1 extra triangle)
|
|
44 |
|
|
45 |
if( yLength>2 )
|
|
46 |
dataLength -= 1; // but if we do a vertical triangle direction shift as well, then one of the 'pull backs'
|
|
47 |
// does not have to add an extra triangle.
|
|
48 |
}
|
38 |
49 |
|
39 |
50 |
////////////////////////////////////////////////////////////
|
40 |
51 |
// vertex indices
|
... | ... | |
42 |
53 |
int offset=0;
|
43 |
54 |
final short[] indexData = new short[dataLength];
|
44 |
55 |
|
|
56 |
int changePointX = xLength/2;
|
|
57 |
int changePointY = yLength/2;
|
|
58 |
|
45 |
59 |
for(int y=0; y<yLength-1; y++)
|
46 |
60 |
{
|
47 |
|
if (y>0) indexData[offset++] = (short) (y*xLength); // Degenerate begin: repeat first vertex
|
|
61 |
if( y>0 )
|
|
62 |
{
|
|
63 |
if( y<changePointY )
|
|
64 |
{
|
|
65 |
indexData[offset++] = (short) ((y+1)*xLength);
|
|
66 |
if( xLength>2 )
|
|
67 |
indexData[offset++] = (short) ((y+1)*xLength);
|
|
68 |
}
|
|
69 |
else
|
|
70 |
{
|
|
71 |
indexData[offset++] = (short) (y*xLength);
|
|
72 |
if( xLength>2 && y!=changePointY)
|
|
73 |
indexData[offset++] = (short) (y*xLength);
|
|
74 |
}
|
|
75 |
}
|
48 |
76 |
|
49 |
|
for (int x = 0; x < xLength; x++)
|
|
77 |
if (y<changePointY)
|
50 |
78 |
{
|
51 |
|
indexData[offset++] = (short) (( y *xLength)+x);
|
52 |
|
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
79 |
for(int x=0; x<xLength; x++)
|
|
80 |
{
|
|
81 |
if( x<=changePointX )
|
|
82 |
{
|
|
83 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
84 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
85 |
}
|
|
86 |
else
|
|
87 |
{
|
|
88 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
89 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
90 |
}
|
|
91 |
|
|
92 |
if( x==changePointX && xLength>2 )
|
|
93 |
{
|
|
94 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
95 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
96 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
else
|
|
101 |
{
|
|
102 |
for(int x=0; x<xLength; x++)
|
|
103 |
{
|
|
104 |
if( x<=changePointX )
|
|
105 |
{
|
|
106 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
107 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
108 |
}
|
|
109 |
else
|
|
110 |
{
|
|
111 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
112 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
113 |
}
|
|
114 |
|
|
115 |
if( x==changePointX && xLength>2 )
|
|
116 |
{
|
|
117 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
118 |
indexData[offset++] = (short) (((y+1)*xLength)+x);
|
|
119 |
indexData[offset++] = (short) (( y *xLength)+x);
|
|
120 |
}
|
|
121 |
}
|
53 |
122 |
}
|
54 |
123 |
|
55 |
|
if (y<yLength-2) indexData[offset++] = (short) (((y+1)*xLength) + (xLength-1)); // Degenerate end: repeat last vertex
|
|
124 |
if (y<changePointY && yLength>2 )
|
|
125 |
{
|
|
126 |
indexData[offset++] = (short) (((y+1)*xLength) + (xLength-1));
|
|
127 |
}
|
|
128 |
else if(y<yLength-2)
|
|
129 |
{
|
|
130 |
indexData[offset++] = (short) ((y *xLength) + (xLength-1));
|
|
131 |
}
|
56 |
132 |
}
|
57 |
133 |
|
58 |
|
// for(int g=0; g<dataLength; g++) Log.e("grid", "index["+g+"]="+indexData[g]);
|
|
134 |
//android.util.Log.e("grid", "xLength="+xLength+" yLength="+yLength);
|
|
135 |
//for(int g=0; g<dataLength; g++) android.util.Log.e("grid", "index["+g+"]="+indexData[g]);
|
59 |
136 |
|
60 |
137 |
////////////////////////////////////////////////////////////
|
61 |
138 |
// texture
|
... | ... | |
65 |
142 |
|
66 |
143 |
for(int i=0; i<dataLength; i++)
|
67 |
144 |
{
|
68 |
|
tmpx = ((float)(indexData[offset/2]%xLength))/(xLength-1);
|
69 |
|
tmpy = ((float)(indexData[offset/2]/xLength))/(yLength-1);
|
|
145 |
tmpx = ((float)(indexData[i]%xLength))/(xLength-1);
|
|
146 |
tmpy = ((float)(indexData[i]/xLength))/(yLength-1);
|
70 |
147 |
|
71 |
148 |
bufferData[offset++] = tmpx; // s=x
|
72 |
149 |
bufferData[offset++] = tmpy; // t=y
|
... | ... | |
85 |
162 |
|
86 |
163 |
for(int i=0; i<dataLength; i++)
|
87 |
164 |
{
|
88 |
|
tmpx = ((float)(indexData[offset/3]%xLength))/(xLength-1);
|
89 |
|
tmpy = ((float)(indexData[offset/3]/xLength))/(yLength-1);
|
|
165 |
tmpx = ((float)(indexData[i]%xLength))/(xLength-1);
|
|
166 |
tmpy = ((float)(indexData[i]/xLength))/(yLength-1);
|
90 |
167 |
tmpz = 0;
|
91 |
168 |
|
92 |
169 |
bufferData[offset++] = (tmpx-0.5f); // x
|
Tesselate DistortedBitmaps better - now all the triangles long edges point at the center of the bitmap, which makes z-distortions look much better!