Revision a60f7acf
Added by Leszek Koltunski 11 months ago
src/main/java/org/distorted/library/mesh/MeshPolygon.java | ||
---|---|---|
45 | 45 |
private float[] mPolygonBands; |
46 | 46 |
private int mNumPolygonBands; |
47 | 47 |
private boolean[] mEdgeUp; |
48 |
private boolean[] mVertUp; |
|
48 | 49 |
|
49 | 50 |
private int remainingVert; |
50 | 51 |
private int numVertices; |
51 | 52 |
private int extraIndex, extraVertices; |
52 | 53 |
|
53 | 54 |
private float[] mCurveCache; |
55 |
private float[] mEdgeQuots; |
|
54 | 56 |
|
55 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
56 | 58 |
// polygonVertices>=3 , polygonBands>=2 |
... | ... | |
116 | 118 |
mCurveCache[NUM_CACHE-1] = tmpD[mNumPolygonBands]; |
117 | 119 |
} |
118 | 120 |
|
121 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
122 |
|
|
123 |
private void computeQuots() |
|
124 |
{ |
|
125 |
mEdgeQuots = new float[mNumPolygonVertices]; |
|
126 |
|
|
127 |
for(int i=0; i<mNumPolygonVertices; i++) |
|
128 |
{ |
|
129 |
int n = (i==mNumPolygonVertices-1 ? 0:i+1); |
|
130 |
|
|
131 |
float x1 = mPolygonVertices[2*i]; |
|
132 |
float y1 = mPolygonVertices[2*i+1]; |
|
133 |
float x2 = mPolygonVertices[2*n]; |
|
134 |
float y2 = mPolygonVertices[2*n+1]; |
|
135 |
float A = x1-x2; |
|
136 |
float B = y1-y2; |
|
137 |
float C = A*A+B*B; |
|
138 |
|
|
139 |
float x = (B*B*x1-A*B*y1)/C; |
|
140 |
float y = (A*A*y1-A*B*x1)/C; |
|
141 |
|
|
142 |
float dx = x1-x; |
|
143 |
float dy = y1-y; |
|
144 |
|
|
145 |
mEdgeQuots[i] = (float)Math.sqrt((dx*dx+dy*dy)/C); |
|
146 |
} |
|
147 |
} |
|
148 |
|
|
119 | 149 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
120 | 150 |
|
121 | 151 |
private float getSpecialQuot(int index) |
... | ... | |
209 | 239 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
210 | 240 |
|
211 | 241 |
private void doNormals(float[] attribs1, int index, float quot, int edgeShape, |
212 |
float xEdge, float yEdge, float zEdge, int polyBand) |
|
242 |
float xEdge, float yEdge, float zEdge, int polyVertex, int polyBand)
|
|
213 | 243 |
{ |
214 | 244 |
if( ( quot<=0.5f && (edgeShape==SHAPE_UD || edgeShape==SHAPE_UU) ) || |
215 | 245 |
( quot> 0.5f && (edgeShape==SHAPE_DU || edgeShape==SHAPE_UU) ) ) |
... | ... | |
220 | 250 |
} |
221 | 251 |
else |
222 | 252 |
{ |
223 |
float t = mPolygonBands[2*mNumPolygonBands-1]; |
|
224 |
float x = 1.0f - mPolygonBands[2*polyBand]; |
|
225 |
float d = derivative(x); |
|
253 |
float d,x = 1-mPolygonBands[2*polyBand]; |
|
226 | 254 |
|
227 |
d *= ((t-zEdge)/t); |
|
255 |
if( /*quot==0.0f || quot==1.0f ||*/ edgeShape==SHAPE_DD ) |
|
256 |
{ |
|
257 |
float t = mPolygonBands[2*mNumPolygonBands-1]; |
|
258 |
d = ((t-zEdge)/t)*derivative(x); |
|
259 |
} |
|
260 |
else |
|
261 |
{ |
|
262 |
float q = quot + x*(mEdgeQuots[polyVertex]-quot); |
|
263 |
d = (q<0.5f ? derivative(2*q) : -derivative(2-2*q)); |
|
264 |
int nextVertex = polyVertex==mNumPolygonVertices-1 ? 0:polyVertex+1; |
|
265 |
xEdge = mPolygonVertices[2*polyVertex ] - mPolygonVertices[2*nextVertex ]; |
|
266 |
yEdge = mPolygonVertices[2*polyVertex+1] - mPolygonVertices[2*nextVertex+1]; |
|
267 |
|
|
268 |
//android.util.Log.e("D", "normals: edgeQuot="+mEdgeQuots[polyVertex]+" vertex="+polyVertex+" d="+d+" xEdge="+xEdge+" yEdge="+yEdge+" q="+q+" quot="+quot); |
|
269 |
} |
|
228 | 270 |
|
229 | 271 |
float vx = d*xEdge; |
230 | 272 |
float vy = d*yEdge; |
... | ... | |
275 | 317 |
attribs1[VERT1_ATTRIBS*vertex + POS_ATTRIB+2] = z; |
276 | 318 |
|
277 | 319 |
int index = VERT1_ATTRIBS*vertex + NOR_ATTRIB; |
278 |
doNormals(attribs1,index, quot, edgeShape, xEdge, yEdge, zEdge, polyBand); |
|
320 |
doNormals(attribs1,index, quot, edgeShape, xEdge, yEdge, zEdge, polyVertex, polyBand);
|
|
279 | 321 |
|
280 | 322 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB ] = x+0.5f; |
281 | 323 |
attribs2[VERT2_ATTRIBS*vertex + TEX_ATTRIB+1] = y+0.5f; |
... | ... | |
330 | 372 |
int prev = (curr==0 ? mNumPolygonVertices-1 : curr-1); |
331 | 373 |
int next = (curr==mNumPolygonVertices-1 ? 0 : curr+1); |
332 | 374 |
|
333 |
boolean l = mEdgeUp[prev];
|
|
334 |
boolean r = mEdgeUp[next];
|
|
375 |
boolean rd = ( !mEdgeUp[next] || mVertUp==null || !mVertUp[next] );
|
|
376 |
boolean ld = ( !mEdgeUp[prev] || mVertUp==null || !mVertUp[curr] );
|
|
335 | 377 |
|
336 |
return l ? (r ? SHAPE_UU : SHAPE_UD) : (r ? SHAPE_DU : SHAPE_DUD);
|
|
378 |
return rd ? (ld ? SHAPE_DUD : SHAPE_UD) : (ld ? SHAPE_DU : SHAPE_UU);
|
|
337 | 379 |
} |
338 | 380 |
|
339 | 381 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
377 | 419 |
* If the 'previous' edge is also up, then the Z is up horizontally from its middle |
378 | 420 |
* to the left vertex; else it goes down along the same function it goes along the bands. |
379 | 421 |
* Same with the right half of the edge. |
422 |
* @param vertUp N booleans - one for each vertex. The first is about vertex 0, then vertex 1, etc. |
|
423 |
* If this is null or false, the vertex is down; otheerwise - it is 'up'. |
|
424 |
* This is taken into account only in one case: if both edges the vertex is the end of |
|
425 |
* are 'up', then the vertex can be 'up' or 'down'; otherwise - if at least one of |
|
426 |
* those edges is 'down' - then the vertex must be 'down' as well and this is ignored. |
|
380 | 427 |
* @param exIndex This and the next parameter describe how to make the mesh denser at the |
381 | 428 |
* polyVertices. If e.g. exIndex=3 and exVertices=2, then 3 triangles of the |
382 | 429 |
* outermost band (and 2 triangles of the next band, and 1 triangle of the third |
... | ... | |
386 | 433 |
* all bands go to. |
387 | 434 |
* @param centerY Y coordinate of the center. |
388 | 435 |
*/ |
389 |
public MeshPolygon(float[] verticesXY, float[] bands, boolean[] edgeUp, int exIndex, int exVertices, float centerX, float centerY) |
|
436 |
public MeshPolygon(float[] verticesXY, float[] bands, boolean[] edgeUp, boolean[] vertUp, int exIndex, int exVertices, float centerX, float centerY)
|
|
390 | 437 |
{ |
391 | 438 |
super(); |
392 | 439 |
|
... | ... | |
395 | 442 |
mNumPolygonVertices= mPolygonVertices.length /2; |
396 | 443 |
mNumPolygonBands = mPolygonBands.length /2; |
397 | 444 |
mEdgeUp = edgeUp; |
445 |
mVertUp = vertUp; |
|
398 | 446 |
extraIndex = exIndex; |
399 | 447 |
extraVertices = exVertices; |
400 | 448 |
|
... | ... | |
409 | 457 |
|
410 | 458 |
computeNumberOfVertices(); |
411 | 459 |
computeCache(); |
460 |
computeQuots(); |
|
412 | 461 |
|
413 | 462 |
float[] attribs1= new float[VERT1_ATTRIBS*numVertices]; |
414 | 463 |
float[] attribs2= new float[VERT2_ATTRIBS*numVertices]; |
... | ... | |
436 | 485 |
|
437 | 486 |
public MeshPolygon(float[] verticesXY, float[] bands, int exIndex, int exVertices) |
438 | 487 |
{ |
439 |
this(verticesXY,bands,null,exIndex,exVertices,0.0f,0.0f); |
|
488 |
this(verticesXY,bands,null,null,exIndex,exVertices,0.0f,0.0f);
|
|
440 | 489 |
} |
441 | 490 |
|
442 | 491 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
446 | 495 |
*/ |
447 | 496 |
public MeshPolygon(float[] verticesXY, float[] bands) |
448 | 497 |
{ |
449 |
this(verticesXY,bands,null,0,0,0.0f,0.0f); |
|
498 |
this(verticesXY,bands,null,null,0,0,0.0f,0.0f);
|
|
450 | 499 |
} |
451 | 500 |
|
452 | 501 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
MeshMultigon finished.