Revision 1833b0a0
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/library/mesh/MeshRectangles.java | ||
---|---|---|
59 | 59 |
{ |
60 | 60 |
remainingVert--; |
61 | 61 |
|
62 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
|
63 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
|
|
62 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB ] = x;
|
|
63 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+1] = -y;
|
|
64 | 64 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = 0.0f; |
65 | 65 |
|
66 | 66 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB ] = 0.0f; |
67 | 67 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+1] = 0.0f; |
68 | 68 |
attribs1[VERT1_ATTRIBS*vertex + NOR_ATTRIB+2] = 1.0f; |
69 | 69 |
|
70 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = (x-0.5f);
|
|
71 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = (0.5f-y);
|
|
72 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f ; // Inflated surface needs to be slightly in front
|
|
70 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB ] = x;
|
|
71 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+1] = -y;
|
|
72 |
attribs1[VERT1_ATTRIBS*vertex + INF_ATTRIB+2] = 0.01f; // Inflated surface needs to be slightly in front |
|
73 | 73 |
|
74 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x; |
|
75 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
|
|
74 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x+0.5f;
|
|
75 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = 0.5f-y;
|
|
76 | 76 |
|
77 | 77 |
return vertex+1; |
78 | 78 |
} |
... | ... | |
110 | 110 |
|
111 | 111 |
private void buildGrid(float[] attribs1, float[] attribs2) |
112 | 112 |
{ |
113 |
boolean lastBlockIsNE = false; |
|
114 |
boolean currentBlockIsNE; |
|
113 |
boolean currBlockIsNE, lastBlockIsNE = false; |
|
115 | 114 |
int vertex = 0; |
116 |
|
|
117 | 115 |
float x,y; |
118 |
final float X = 1.0f/mCols;
|
|
119 |
final float Y = 1.0f/mRows;
|
|
116 |
final float dx = 1.0f/mCols;
|
|
117 |
final float dy = 1.0f/mRows;
|
|
120 | 118 |
|
121 |
y = 0.0f;
|
|
119 |
y =-0.5f;
|
|
122 | 120 |
|
123 | 121 |
for(int row=0; row<mRows; row++) |
124 | 122 |
{ |
125 |
x = 0.0f;
|
|
123 |
x =-0.5f;
|
|
126 | 124 |
|
127 | 125 |
for(int col=0; col<mCols; col++) |
128 | 126 |
{ |
129 |
currentBlockIsNE = (2*row<=mRows-1)^(2*col<=mCols-1);
|
|
127 |
currBlockIsNE = (2*row<=mRows-1)^(2*col<=mCols-1); |
|
130 | 128 |
|
131 |
if( col==0 || (lastBlockIsNE^currentBlockIsNE) )
|
|
129 |
if( col==0 || (lastBlockIsNE^currBlockIsNE) ) |
|
132 | 130 |
{ |
133 | 131 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2); |
134 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?0:Y), attribs1,attribs2);
|
|
132 |
vertex= addVertex( vertex, x, y+(currBlockIsNE?0:dy), attribs1,attribs2);
|
|
135 | 133 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2); |
136 |
if( lastBlockIsNE^currentBlockIsNE) vertex = repeatLast(vertex,attribs1,attribs2);
|
|
137 |
vertex= addVertex( vertex, x, y+(currentBlockIsNE?Y:0), attribs1,attribs2);
|
|
134 |
if( lastBlockIsNE^currBlockIsNE) vertex = repeatLast(vertex,attribs1,attribs2); |
|
135 |
vertex= addVertex( vertex, x, y+(currBlockIsNE?dy:0), attribs1,attribs2);
|
|
138 | 136 |
} |
139 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?0:Y), attribs1,attribs2);
|
|
140 |
vertex= addVertex( vertex, x+X, y+(currentBlockIsNE?Y:0), attribs1,attribs2);
|
|
137 |
vertex= addVertex( vertex, x+dx, y+(currBlockIsNE?0:dy), attribs1,attribs2);
|
|
138 |
vertex= addVertex( vertex, x+dx, y+(currBlockIsNE?dy:0), attribs1,attribs2);
|
|
141 | 139 |
|
142 |
lastBlockIsNE = currentBlockIsNE;
|
|
143 |
x+=X;
|
|
140 |
lastBlockIsNE = currBlockIsNE; |
|
141 |
x+=dx;
|
|
144 | 142 |
} |
145 | 143 |
|
146 |
y+=Y; |
|
144 |
y+=dy; |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
149 |
|
|
150 |
private void buildGrid(float[] attribs1, float[] attribs2, float[] xLoc, float[] yLoc) |
|
151 |
{ |
|
152 |
boolean currBlockIsNE,lastBlockIsNE = false; |
|
153 |
int vertex = 0; |
|
154 |
float dx,dy,x,y= yLoc[0]; |
|
155 |
|
|
156 |
for(int row=0; row<mRows; row++) |
|
157 |
{ |
|
158 |
x = xLoc[0]; |
|
159 |
dy= yLoc[row+1]; |
|
160 |
|
|
161 |
for(int col=0; col<mCols; col++) |
|
162 |
{ |
|
163 |
dx = xLoc[col+1]; |
|
164 |
currBlockIsNE = (2*row<=mRows-1)^(2*col<=mCols-1); |
|
165 |
|
|
166 |
if( col==0 || (lastBlockIsNE^currBlockIsNE) ) |
|
167 |
{ |
|
168 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2); |
|
169 |
vertex= addVertex( vertex, x, y+(currBlockIsNE?0:dy), attribs1,attribs2); |
|
170 |
if( row!=0 && col==0 ) vertex = repeatLast(vertex,attribs1,attribs2); |
|
171 |
if( lastBlockIsNE^currBlockIsNE) vertex = repeatLast(vertex,attribs1,attribs2); |
|
172 |
vertex= addVertex( vertex, x, y+(currBlockIsNE?dy:0), attribs1,attribs2); |
|
173 |
} |
|
174 |
vertex= addVertex( vertex, x+dx, y+(currBlockIsNE?0:dy), attribs1,attribs2); |
|
175 |
vertex= addVertex( vertex, x+dx, y+(currBlockIsNE?dy:0), attribs1,attribs2); |
|
176 |
|
|
177 |
lastBlockIsNE = currBlockIsNE; |
|
178 |
x+=dx; |
|
179 |
} |
|
180 |
|
|
181 |
y+=dy; |
|
147 | 182 |
} |
148 | 183 |
} |
149 | 184 |
|
... | ... | |
151 | 186 |
// PUBLIC API |
152 | 187 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
153 | 188 |
/** |
154 |
* Creates the underlying grid of vertices, normals and texture coords.
|
|
189 |
* Creates a rectangular grid of vertices, normals and texture coords.
|
|
155 | 190 |
* |
156 | 191 |
* @param cols Number of columns in the grid. |
157 | 192 |
* @param rows Number of rows in the grid. |
... | ... | |
172 | 207 |
setAttribs(attribs1,attribs2); |
173 | 208 |
} |
174 | 209 |
|
210 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
211 |
/** |
|
212 |
* Creates a rectangular grid of vertices, normals and texture coords. |
|
213 |
* |
|
214 |
* @param xLoc list of x-coordinates of vertices. First value: distance of the left edge from 0. |
|
215 |
* Next values: distance of the next column from the previous. Must be NonNull! |
|
216 |
* @param yLoc list of y-coordinates of vertices. First value: distance of the bottom edge from 0. |
|
217 |
* Next values: distance of the next row from the previous. Must be NonNull! |
|
218 |
*/ |
|
219 |
public MeshRectangles(float[] xLoc, float[] yLoc) |
|
220 |
{ |
|
221 |
super(); |
|
222 |
computeNumberOfVertices(xLoc.length-1,yLoc.length-1); |
|
223 |
|
|
224 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
|
225 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
|
226 |
|
|
227 |
buildGrid(attribs1,attribs2,xLoc,yLoc); |
|
228 |
|
|
229 |
if( remainingVert!=0 ) |
|
230 |
android.util.Log.d("MeshRectangles", "remainingVert " +remainingVert ); |
|
231 |
|
|
232 |
setAttribs(attribs1,attribs2); |
|
233 |
} |
|
234 |
|
|
175 | 235 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
176 | 236 |
/** |
177 | 237 |
* Copy constructor. |
Also available in: Unified diff
Library: introduce a new form of the MeshRectangular grid, where the individual rows and columns can be each of different width. This help reduce the number of vertices in objects as typically we are only interested at distorting a certain subregion.
Modify the Bean app to take advantage of this.