Revision 665e2c45
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/DistortedCubesGrid.java | ||
---|---|---|
228 | 228 |
remainingVert = dataLength; |
229 | 229 |
} |
230 | 230 |
} |
231 |
|
|
231 |
|
|
232 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
233 |
// full grid |
|
234 |
|
|
235 |
private void prepareDataStructures(int cols, int rows, boolean frontOnly) |
|
236 |
{ |
|
237 |
mRows =rows; |
|
238 |
mCols =cols; |
|
239 |
dataLength= 0; |
|
240 |
|
|
241 |
if( cols>0 && rows>0 ) |
|
242 |
{ |
|
243 |
mCubes = new short[mRows][mCols]; |
|
244 |
|
|
245 |
for(int j=0; j<mCols; j++) |
|
246 |
for(int i=0; i<mRows; i++) |
|
247 |
mCubes[i][j] = (short)1; |
|
248 |
|
|
249 |
markRegions(); |
|
250 |
dataLength = computeDataLength(frontOnly); |
|
251 |
|
|
252 |
remainingVert = dataLength; |
|
253 |
} |
|
254 |
} |
|
255 |
|
|
232 | 256 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
233 | 257 |
// Mark all the 'regions' of our grid - i.e. separate pieces of 'land' (connected blocks that will |
234 | 258 |
// be rendered) and 'water' (connected holes in between) with integers. Each connected block of land |
... | ... | |
714 | 738 |
if(texture[2*vertex+1]<0.0f) texture[2*vertex+1] = -texture[2*vertex+1]; |
715 | 739 |
} |
716 | 740 |
|
741 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
742 |
|
|
743 |
private void build(boolean frontOnly) |
|
744 |
{ |
|
745 |
int numVertices=0; |
|
746 |
float[] positionData= new float[POSITION_DATA_SIZE*dataLength]; |
|
747 |
float[] normalData = new float[NORMAL_DATA_SIZE *dataLength]; |
|
748 |
float[] textureData = new float[TEX_DATA_SIZE *dataLength]; |
|
749 |
|
|
750 |
//android.util.Log.d("CUBES","building front grid..."); |
|
751 |
|
|
752 |
numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData); |
|
753 |
|
|
754 |
if( !frontOnly ) |
|
755 |
{ |
|
756 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData); |
|
757 |
if( numVertices%2==1 ) |
|
758 |
{ |
|
759 |
//android.util.Log.d("CUBES","repeating winding1 vertex"); |
|
760 |
|
|
761 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData); |
|
762 |
} |
|
763 |
|
|
764 |
//android.util.Log.d("CUBES","building side grid..."); |
|
765 |
|
|
766 |
numVertices = buildSideGrid (numVertices,positionData,normalData,textureData); |
|
767 |
|
|
768 |
//android.util.Log.d("CUBES","building back grid..."); |
|
769 |
|
|
770 |
numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData); |
|
771 |
} |
|
772 |
|
|
773 |
/* |
|
774 |
android.util.Log.e("CUBES","dataLen="+dataLength+" vertex="+numVertices); |
|
775 |
android.util.Log.d("CUBES", "position: "+debug(positionData,3) ); |
|
776 |
android.util.Log.d("CUBES", "normal: " +debug( normalData,3) ); |
|
777 |
android.util.Log.d("CUBES", "texture: " +debug( textureData,2) ); |
|
778 |
*/ |
|
779 |
android.util.Log.d("CUBES", "remainingVert " +remainingVert ); |
|
780 |
|
|
781 |
mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
782 |
mGridPositions.put(positionData).position(0); |
|
783 |
|
|
784 |
mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
785 |
mGridNormals.put(normalData).position(0); |
|
786 |
|
|
787 |
mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
788 |
mGridTexture.put(textureData).position(0); |
|
789 |
} |
|
790 |
|
|
717 | 791 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
718 | 792 |
// PUBLIC API |
719 | 793 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
720 |
|
|
721 | 794 |
/** |
722 | 795 |
* Creates the underlying grid of vertices, normals, texture coords and colors. |
723 | 796 |
* |
... | ... | |
725 | 798 |
* @param desc See {@link DistortedCubes#DistortedCubes(int,String,int,boolean)} |
726 | 799 |
* @param frontOnly See {@link DistortedCubes#DistortedCubes(int,String,int,boolean)} |
727 | 800 |
*/ |
728 |
public DistortedCubesGrid(int cols, String desc, boolean frontOnly)
|
|
801 |
DistortedCubesGrid(int cols, String desc, boolean frontOnly) |
|
729 | 802 |
{ |
730 |
//android.util.Log.d("CUBES","calculating dataLength..."); |
|
731 |
|
|
732 | 803 |
prepareDataStructures(cols,desc,frontOnly); |
733 |
|
|
734 |
int numVertices=0; |
|
735 |
float[] positionData= new float[POSITION_DATA_SIZE*dataLength]; |
|
736 |
float[] normalData = new float[NORMAL_DATA_SIZE *dataLength]; |
|
737 |
float[] textureData = new float[TEX_DATA_SIZE *dataLength]; |
|
738 |
|
|
739 |
//android.util.Log.d("CUBES","building front grid..."); |
|
740 |
|
|
741 |
numVertices = buildFrontBackGrid(true, numVertices,positionData,normalData,textureData); |
|
742 |
|
|
743 |
if( !frontOnly ) |
|
744 |
{ |
|
745 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData); |
|
746 |
if( numVertices%2==1 ) |
|
747 |
{ |
|
748 |
//android.util.Log.d("CUBES","repeating winding1 vertex"); |
|
749 |
|
|
750 |
numVertices = repeatLast(numVertices,positionData,normalData,textureData); |
|
751 |
} |
|
752 |
|
|
753 |
//android.util.Log.d("CUBES","building side grid..."); |
|
754 |
|
|
755 |
numVertices = buildSideGrid (numVertices,positionData,normalData,textureData); |
|
756 |
|
|
757 |
//android.util.Log.d("CUBES","building back grid..."); |
|
758 |
|
|
759 |
numVertices = buildFrontBackGrid (false,numVertices,positionData,normalData,textureData); |
|
760 |
} |
|
761 |
|
|
762 |
/* |
|
763 |
android.util.Log.e("CUBES","dataLen="+dataLength+" vertex="+numVertices); |
|
764 |
android.util.Log.d("CUBES", "position: "+debug(positionData,3) ); |
|
765 |
android.util.Log.d("CUBES", "normal: " +debug( normalData,3) ); |
|
766 |
android.util.Log.d("CUBES", "texture: " +debug( textureData,2) ); |
|
767 |
*/ |
|
768 |
android.util.Log.d("CUBES", "remainingVert " +remainingVert ); |
|
769 |
|
|
770 |
mGridPositions = ByteBuffer.allocateDirect(POSITION_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
771 |
mGridPositions.put(positionData).position(0); |
|
772 |
|
|
773 |
mGridNormals = ByteBuffer.allocateDirect(NORMAL_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
774 |
mGridNormals.put(normalData).position(0); |
|
804 |
build(frontOnly); |
|
805 |
} |
|
775 | 806 |
|
776 |
mGridTexture = ByteBuffer.allocateDirect(TEX_DATA_SIZE*dataLength*BYTES_PER_FLOAT).order(ByteOrder.nativeOrder()).asFloatBuffer(); |
|
777 |
mGridTexture.put(textureData).position(0); |
|
807 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
808 |
/** |
|
809 |
* Creates a full, hole-less underlying grid of vertices, normals, texture coords and colors. |
|
810 |
* |
|
811 |
* @param cols See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)} |
|
812 |
* @param rows See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)} |
|
813 |
* @param frontOnly See {@link DistortedCubes#DistortedCubes(int,int,int,boolean)} |
|
814 |
*/ |
|
815 |
DistortedCubesGrid(int cols, int rows, boolean frontOnly) |
|
816 |
{ |
|
817 |
prepareDataStructures(cols,rows,frontOnly); |
|
818 |
build(frontOnly); |
|
778 | 819 |
} |
779 | 820 |
} |
780 | 821 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
New constructor to DistortedCubes - easily create a hole-less Cuboid.