58 |
58 |
private int[][] mCubes;
|
59 |
59 |
private ArrayList<Edge> mEdges = new ArrayList<>();
|
60 |
60 |
|
61 |
|
private int remainingVert;
|
|
61 |
private int currVert;
|
62 |
62 |
private int numVertices;
|
63 |
63 |
private int mSideBends;
|
64 |
64 |
private int mEdgeNum;
|
... | ... | |
197 |
197 |
|
198 |
198 |
markRegions();
|
199 |
199 |
numVertices = computeDataLength();
|
200 |
|
remainingVert = numVertices;
|
|
200 |
currVert = 0;
|
201 |
201 |
}
|
202 |
202 |
}
|
203 |
203 |
|
... | ... | |
221 |
221 |
|
222 |
222 |
markRegions();
|
223 |
223 |
numVertices = computeDataLength();
|
224 |
|
remainingVert = numVertices;
|
|
224 |
currVert = 0;
|
225 |
225 |
}
|
226 |
226 |
}
|
227 |
227 |
|
... | ... | |
392 |
392 |
|
393 |
393 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
394 |
394 |
|
395 |
|
private int buildFrontBackGrid(boolean front, int vertex, float[] attribs)
|
|
395 |
private void buildFrontBackGrid(boolean front, float[] attribs)
|
396 |
396 |
{
|
397 |
397 |
int last, current;
|
398 |
398 |
boolean seenLand=false;
|
... | ... | |
414 |
414 |
{
|
415 |
415 |
currentBlockIsNE = isNE(row,col);
|
416 |
416 |
|
417 |
|
if( !seenLand && !front && ((vertex%2==1)^currentBlockIsNE) )
|
|
417 |
if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) )
|
418 |
418 |
{
|
419 |
419 |
//android.util.Log.d("CUBES","repeating winding2 vertex");
|
420 |
420 |
|
421 |
|
vertex = repeatLast(vertex,attribs);
|
|
421 |
repeatLast(attribs);
|
422 |
422 |
}
|
423 |
423 |
|
424 |
424 |
createNormals(front,row,col);
|
... | ... | |
427 |
427 |
{
|
428 |
428 |
if( (last!=current) || !lastBlockIsNE )
|
429 |
429 |
{
|
430 |
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
431 |
|
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
432 |
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
433 |
|
if( !lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
434 |
|
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
|
430 |
if( seenLand && (last != current) ) repeatLast(attribs);
|
|
431 |
addFrontVertex( 0, vectZ, col, row, attribs);
|
|
432 |
if( seenLand && (last != current) ) repeatLast(attribs);
|
|
433 |
if( !lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
|
|
434 |
addFrontVertex( 1, vectZ, col, row+1, attribs);
|
435 |
435 |
}
|
436 |
|
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row, attribs);
|
437 |
|
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
|
436 |
addFrontVertex( 2, vectZ, col+1, row, attribs);
|
|
437 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs);
|
438 |
438 |
}
|
439 |
439 |
else
|
440 |
440 |
{
|
441 |
441 |
if( (last!=current) || lastBlockIsNE )
|
442 |
442 |
{
|
443 |
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
444 |
|
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
445 |
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
446 |
|
if( lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
447 |
|
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
|
443 |
if( seenLand && (last != current) ) repeatLast(attribs);
|
|
444 |
addFrontVertex( 1, vectZ, col, row+1, attribs);
|
|
445 |
if( seenLand && (last != current) ) repeatLast(attribs);
|
|
446 |
if( lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
|
|
447 |
addFrontVertex( 0, vectZ, col, row, attribs);
|
448 |
448 |
}
|
449 |
|
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
450 |
|
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row , attribs);
|
|
449 |
addFrontVertex( 3, vectZ, col+1, row+1, attribs);
|
|
450 |
addFrontVertex( 2, vectZ, col+1, row , attribs);
|
451 |
451 |
}
|
452 |
452 |
|
453 |
453 |
seenLand = true;
|
... | ... | |
457 |
457 |
last = current;
|
458 |
458 |
}
|
459 |
459 |
}
|
460 |
|
|
461 |
|
return vertex;
|
462 |
460 |
}
|
463 |
461 |
|
464 |
462 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
465 |
463 |
|
466 |
|
private int buildSideGrid(int vertex, float[] attribs)
|
|
464 |
private void buildSideGrid(float[] attribs)
|
467 |
465 |
{
|
468 |
466 |
//android.util.Log.d("CUBES", "buildSide");
|
469 |
467 |
|
470 |
468 |
for(int i=0; i<mEdgeNum; i++)
|
471 |
469 |
{
|
472 |
|
vertex = buildIthSide(mEdges.get(i), vertex, attribs);
|
473 |
|
}
|
474 |
|
|
475 |
|
return vertex;
|
|
470 |
buildIthSide(mEdges.get(i), attribs);
|
|
471 |
}
|
476 |
472 |
}
|
477 |
473 |
|
478 |
474 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
479 |
475 |
|
480 |
|
private int buildIthSide(Edge curr, int vertex, float[] attribs)
|
|
476 |
private void buildIthSide(Edge curr, float[] attribs)
|
481 |
477 |
{
|
482 |
478 |
Edge prev, next;
|
483 |
479 |
int col, row, side;
|
... | ... | |
499 |
495 |
side= curr.side;
|
500 |
496 |
next = getNextEdge(curr);
|
501 |
497 |
|
502 |
|
addSideVertex(curr,true,i+1,prev.side,vertex++,attribs);
|
|
498 |
addSideVertex(curr,true,i+1,prev.side,attribs);
|
503 |
499 |
|
504 |
500 |
do
|
505 |
501 |
{
|
506 |
502 |
if( prev.side!=curr.side )
|
507 |
503 |
{
|
508 |
|
addSideVertex(curr,true,i+1,prev.side,vertex++,attribs);
|
509 |
|
addSideVertex(curr,true,i ,prev.side,vertex++,attribs);
|
|
504 |
addSideVertex(curr,true,i+1,prev.side,attribs);
|
|
505 |
addSideVertex(curr,true,i ,prev.side,attribs);
|
510 |
506 |
}
|
511 |
507 |
|
512 |
|
addSideVertex(curr,false,i+1,next.side,vertex++,attribs);
|
513 |
|
addSideVertex(curr,false,i ,next.side,vertex++,attribs);
|
|
508 |
addSideVertex(curr,false,i+1,next.side,attribs);
|
|
509 |
addSideVertex(curr,false,i ,next.side,attribs);
|
514 |
510 |
|
515 |
511 |
prev = curr;
|
516 |
512 |
curr = next;
|
... | ... | |
518 |
514 |
}
|
519 |
515 |
while( curr.col!=col || curr.row!=row || curr.side!=side );
|
520 |
516 |
|
521 |
|
vertex = repeatLast(vertex,attribs);
|
|
517 |
repeatLast(attribs);
|
522 |
518 |
}
|
523 |
|
|
524 |
|
return vertex;
|
525 |
519 |
}
|
526 |
520 |
|
527 |
521 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
... | ... | |
575 |
569 |
|
576 |
570 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
577 |
571 |
|
578 |
|
private int addFrontVertex(int vertex, int index, float vectZ, int col, int row, float[] attribs)
|
|
572 |
private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs)
|
579 |
573 |
{
|
580 |
|
remainingVert--;
|
581 |
|
|
582 |
574 |
float x = (float)col/mCols;
|
583 |
575 |
float y = (float)row/mRows;
|
584 |
576 |
|
585 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = x-0.5f;
|
586 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f-y;
|
587 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = vectZ;
|
|
577 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x-0.5f;
|
|
578 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f-y;
|
|
579 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = vectZ;
|
588 |
580 |
|
589 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = mNormalX[index];
|
590 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = mNormalY[index];
|
591 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = mNormalZ[index];
|
|
581 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = mNormalX[index];
|
|
582 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
|
|
583 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
|
592 |
584 |
|
593 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = 1.0f; //
|
594 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f; // TODO
|
595 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f; //
|
|
585 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = 0.0f; // TODO
|
|
586 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f; // TODO
|
|
587 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
|
596 |
588 |
|
597 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
598 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-y;
|
|
589 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = x;
|
|
590 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
|
599 |
591 |
|
600 |
|
return vertex+1;
|
|
592 |
currVert++;
|
601 |
593 |
}
|
602 |
594 |
|
603 |
595 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
604 |
596 |
|
605 |
|
private void addSideVertex(Edge curr, boolean back, int slice,int side, int vertex, float[] attribs)
|
|
597 |
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
|
606 |
598 |
{
|
607 |
599 |
//android.util.Log.e("CUBES", "adding Side vertex!");
|
608 |
|
|
609 |
|
remainingVert--;
|
610 |
|
|
611 |
600 |
float x, y;
|
612 |
601 |
|
613 |
602 |
switch(curr.side)
|
614 |
603 |
{
|
615 |
604 |
case NORTH: x = (float)(back ? (curr.col ):(curr.col+1))/mCols;
|
616 |
605 |
|
617 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = x - 0.5f;
|
618 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f - (float)curr.row/mRows;
|
619 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
|
606 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
607 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - (float)curr.row/mRows;
|
|
608 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
620 |
609 |
|
621 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
622 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = 1.0f;
|
623 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
610 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
|
611 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
|
|
612 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
624 |
613 |
|
625 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = 1.0f; //
|
626 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f; // TODO
|
627 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f; //
|
|
614 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = 0.0f; //
|
|
615 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f; // TODO
|
|
616 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
628 |
617 |
|
629 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
630 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f-(float)(curr.row-slice)/mRows;
|
|
618 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = x;
|
|
619 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(curr.row-slice)/mRows;
|
631 |
620 |
break;
|
632 |
621 |
case SOUTH: x = (float)(back ? (curr.col+1):(curr.col ))/mCols;
|
633 |
622 |
|
634 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = x - 0.5f;
|
635 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f - (float)(curr.row+1)/mRows;
|
636 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
|
623 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
|
624 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - (float)(curr.row+1)/mRows;
|
|
625 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
637 |
626 |
|
638 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
639 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] =-1.0f;
|
640 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
627 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
|
628 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
|
|
629 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
641 |
630 |
|
642 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = 1.0f; //
|
643 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f; // TODO
|
644 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f; //
|
|
631 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = 0.0f; //
|
|
632 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f; // TODO
|
|
633 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
645 |
634 |
|
646 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = x;
|
647 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f - (float)(curr.row+1+slice)/mRows;
|
|
635 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = x;
|
|
636 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(curr.row+1+slice)/mRows;
|
648 |
637 |
break;
|
649 |
638 |
case WEST : y = (float)(back ? (curr.row+1):(curr.row))/mRows;
|
650 |
639 |
|
651 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = (float)curr.col/mCols -0.5f;
|
652 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f - y;
|
653 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
|
640 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = (float)curr.col/mCols -0.5f;
|
|
641 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
642 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
654 |
643 |
|
655 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] =-1.0f;
|
656 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
657 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
644 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] =-1.0f;
|
|
645 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
|
646 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
658 |
647 |
|
659 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = 1.0f; //
|
660 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f; // TODO
|
661 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f; //
|
|
648 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = 0.0f; //
|
|
649 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f; // TODO
|
|
650 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
662 |
651 |
|
663 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = (float)(curr.col-slice)/mCols;
|
664 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f - y;
|
|
652 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = (float)(curr.col-slice)/mCols;
|
|
653 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
|
665 |
654 |
break;
|
666 |
655 |
case EAST : y = (float)(back ? (curr.row):(curr.row+1))/mRows;
|
667 |
656 |
|
668 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = (float)(curr.col+1)/mCols -0.5f;
|
669 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = 0.5f - y;
|
670 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
|
657 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = (float)(curr.col+1)/mCols -0.5f;
|
|
658 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
|
659 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
671 |
660 |
|
672 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = 1.0f;
|
673 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
674 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
|
661 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = 1.0f;
|
|
662 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
|
663 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
675 |
664 |
|
676 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = 1.0f; //
|
677 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = 0.0f; // TODO
|
678 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = 0.0f; //
|
|
665 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = 0.0f; //
|
|
666 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = 0.0f; // TODO
|
|
667 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = 0.5f - (float)slice/mSlices;
|
679 |
668 |
|
680 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = (float)(curr.col+1+slice)/mCols;
|
681 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 1.0f - y;
|
|
669 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = (float)(curr.col+1+slice)/mCols;
|
|
670 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
|
682 |
671 |
break;
|
683 |
672 |
}
|
684 |
673 |
|
685 |
|
float tex0 = attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ];
|
686 |
|
float tex1 = attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1];
|
|
674 |
float tex0 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ];
|
|
675 |
float tex1 = attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1];
|
|
676 |
|
|
677 |
if(tex0>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = 2.0f-tex0;
|
|
678 |
if(tex0<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = -tex0;
|
|
679 |
if(tex1>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 2.0f-tex1;
|
|
680 |
if(tex1<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = -tex1;
|
687 |
681 |
|
688 |
|
if(tex0>1.0f) attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = 2.0f-tex0;
|
689 |
|
if(tex0<0.0f) attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = -tex0;
|
690 |
|
if(tex1>1.0f) attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = 2.0f-tex1;
|
691 |
|
if(tex1<0.0f) attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = -tex1;
|
|
682 |
currVert++;
|
692 |
683 |
}
|
693 |
684 |
|
694 |
685 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
695 |
686 |
|
696 |
|
private int repeatLast(int vertex, float[] attribs)
|
|
687 |
private void repeatLast(float[] attribs)
|
697 |
688 |
{
|
698 |
689 |
//android.util.Log.e("CUBES", "repeating last vertex!");
|
699 |
690 |
|
700 |
|
if( vertex>0 )
|
701 |
|
{
|
702 |
|
remainingVert--;
|
703 |
|
|
704 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB ];
|
705 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB+1];
|
706 |
|
attribs[VERT_ATTRIBS*vertex + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + POS_ATTRIB+2];
|
|
691 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB ];
|
|
692 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1];
|
|
693 |
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2];
|
707 |
694 |
|
708 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB ];
|
709 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB+1];
|
710 |
|
attribs[VERT_ATTRIBS*vertex + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + NOR_ATTRIB+2];
|
|
695 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB ];
|
|
696 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+1];
|
|
697 |
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+2];
|
711 |
698 |
|
712 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB ];
|
713 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB+1];
|
714 |
|
attribs[VERT_ATTRIBS*vertex + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(vertex-1) + INF_ATTRIB+2];
|
|
699 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB ];
|
|
700 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+1];
|
|
701 |
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+2];
|
715 |
702 |
|
716 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(vertex-1) + TEX_ATTRIB ];
|
717 |
|
attribs[VERT_ATTRIBS*vertex + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(vertex-1) + TEX_ATTRIB+1];
|
|
703 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB ];
|
|
704 |
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB+1];
|
718 |
705 |
|
719 |
|
|
720 |
|
vertex++;
|
721 |
|
}
|
722 |
|
|
723 |
|
return vertex;
|
|
706 |
currVert++;
|
724 |
707 |
}
|
725 |
708 |
|
726 |
709 |
///////////////////////////////////////////////////////////////////////////////////////////////////
|
727 |
710 |
|
728 |
711 |
private void build()
|
729 |
712 |
{
|
730 |
|
int vertSoFar=0;
|
731 |
713 |
float[] attribs= new float[VERT_ATTRIBS*numVertices];
|
732 |
714 |
|
733 |
|
vertSoFar = buildFrontBackGrid(true, vertSoFar,attribs);
|
|
715 |
buildFrontBackGrid(true,attribs);
|
734 |
716 |
|
735 |
717 |
if( mSlices>0 )
|
736 |
718 |
{
|
737 |
|
vertSoFar = repeatLast(vertSoFar,attribs);
|
738 |
|
if( vertSoFar%2==1 )
|
739 |
|
{
|
740 |
|
vertSoFar = repeatLast(vertSoFar,attribs);
|
741 |
|
}
|
742 |
|
vertSoFar = buildSideGrid (vertSoFar,attribs);
|
743 |
|
buildFrontBackGrid (false,vertSoFar,attribs);
|
|
719 |
repeatLast(attribs);
|
|
720 |
if( currVert%2==1 ) repeatLast(attribs);
|
|
721 |
buildSideGrid(attribs);
|
|
722 |
buildFrontBackGrid(false,attribs);
|
744 |
723 |
}
|
745 |
724 |
|
746 |
725 |
mEdges.clear();
|
747 |
726 |
mEdges = null;
|
748 |
727 |
mCubes = null;
|
749 |
728 |
|
750 |
|
if( remainingVert!=0 )
|
751 |
|
android.util.Log.e("MeshCubes", "remainingVert " +remainingVert );
|
|
729 |
if( currVert!=numVertices )
|
|
730 |
android.util.Log.e("MeshCubes", "currVert " +currVert+" numVertices="+numVertices );
|
752 |
731 |
|
753 |
732 |
setAttribs(attribs);
|
754 |
733 |
}
|
Progress with the Inflate vector in MeshCubes.