| 1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
| 3 |
|
|
// //
|
| 4 |
7602a827
|
Leszek Koltunski
|
// This file is part of DistortedLibrary. //
|
| 5 |
d333eb6b
|
Leszek Koltunski
|
// //
|
| 6 |
7602a827
|
Leszek Koltunski
|
// DistortedLibrary is free software: you can redistribute it and/or modify //
|
| 7 |
d333eb6b
|
Leszek Koltunski
|
// it under the terms of the GNU General Public License as published by //
|
| 8 |
|
|
// the Free Software Foundation, either version 2 of the License, or //
|
| 9 |
|
|
// (at your option) any later version. //
|
| 10 |
|
|
// //
|
| 11 |
7602a827
|
Leszek Koltunski
|
// DistortedLibrary is distributed in the hope that it will be useful, //
|
| 12 |
d333eb6b
|
Leszek Koltunski
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
| 13 |
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
| 14 |
|
|
// GNU General Public License for more details. //
|
| 15 |
|
|
// //
|
| 16 |
|
|
// You should have received a copy of the GNU General Public License //
|
| 17 |
7602a827
|
Leszek Koltunski
|
// along with DistortedLibrary. If not, see <http://www.gnu.org/licenses/>. //
|
| 18 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 19 |
|
|
|
| 20 |
6c00149d
|
Leszek Koltunski
|
package org.distorted.library.mesh;
|
| 21 |
6a06a912
|
Leszek Koltunski
|
|
| 22 |
91cfe462
|
Leszek Koltunski
|
import org.distorted.library.type.Static4D;
|
| 23 |
|
|
|
| 24 |
6a06a912
|
Leszek Koltunski
|
import java.util.ArrayList;
|
| 25 |
|
|
|
| 26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 27 |
e0b6c593
|
Leszek Koltunski
|
/**
|
| 28 |
|
|
* Create a 3D grid composed of Cubes.
|
| 29 |
|
|
* <p>
|
| 30 |
91cfe462
|
Leszek Koltunski
|
* Any subset of a MxNx1 cuboid is possible. (repeated arbitrary number of times into Z-dir)
|
| 31 |
e0b6c593
|
Leszek Koltunski
|
*/
|
| 32 |
715e7726
|
Leszek Koltunski
|
public class MeshCubes extends MeshBase
|
| 33 |
6a06a912
|
Leszek Koltunski
|
{
|
| 34 |
06d71892
|
Leszek Koltunski
|
private static final float R = 0.0f;//0.2f;
|
| 35 |
f08b268d
|
Leszek Koltunski
|
|
| 36 |
91cfe462
|
Leszek Koltunski
|
private static final int FRONT = 0;
|
| 37 |
|
|
private static final int BACK = 1;
|
| 38 |
|
|
private static final int LEFT = 2;
|
| 39 |
|
|
private static final int RIGHT = 3;
|
| 40 |
|
|
private static final int TOP = 4;
|
| 41 |
|
|
private static final int BOTTOM= 5;
|
| 42 |
|
|
|
| 43 |
6a06a912
|
Leszek Koltunski
|
private static final int NORTH = 0;
|
| 44 |
|
|
private static final int WEST = 1;
|
| 45 |
|
|
private static final int EAST = 2;
|
| 46 |
|
|
private static final int SOUTH = 3;
|
| 47 |
ce7f3833
|
Leszek Koltunski
|
|
| 48 |
6a06a912
|
Leszek Koltunski
|
private static final float[] mNormalX = new float[4];
|
| 49 |
|
|
private static final float[] mNormalY = new float[4];
|
| 50 |
ce7f3833
|
Leszek Koltunski
|
private static final float[] mNormalZ = new float[4];
|
| 51 |
|
|
|
| 52 |
6a06a912
|
Leszek Koltunski
|
private class Edge
|
| 53 |
|
|
{
|
| 54 |
|
|
final int side;
|
| 55 |
|
|
final int row;
|
| 56 |
|
|
final int col;
|
| 57 |
|
|
|
| 58 |
06d71892
|
Leszek Koltunski
|
Edge(int s, int r, int c)
|
| 59 |
6a06a912
|
Leszek Koltunski
|
{
|
| 60 |
|
|
side= s;
|
| 61 |
|
|
row = r;
|
| 62 |
|
|
col = c;
|
| 63 |
|
|
}
|
| 64 |
39cbf9dc
|
Leszek Koltunski
|
}
|
| 65 |
91cfe462
|
Leszek Koltunski
|
|
| 66 |
|
|
private float[] mTexMappingX,mTexMappingY, mTexMappingW, mTexMappingH;
|
| 67 |
|
|
|
| 68 |
80cb15ab
|
leszek
|
private int mCols, mRows, mSlices;
|
| 69 |
d6994cc6
|
Leszek Koltunski
|
private int[][] mCubes;
|
| 70 |
9d0df4c6
|
Leszek Koltunski
|
private byte[][] mInflateX, mInflateY;
|
| 71 |
39cbf9dc
|
Leszek Koltunski
|
private ArrayList<Edge> mEdges = new ArrayList<>();
|
| 72 |
ce7f3833
|
Leszek Koltunski
|
|
| 73 |
15290f35
|
Leszek Koltunski
|
private int currVert;
|
| 74 |
da681e7e
|
Leszek Koltunski
|
private int numVertices;
|
| 75 |
8d9da98a
|
Leszek Koltunski
|
private int mSideBends;
|
| 76 |
|
|
private int mEdgeNum;
|
| 77 |
b62632fc
|
Leszek Koltunski
|
private int mSideWalls;
|
| 78 |
ce7f3833
|
Leszek Koltunski
|
|
| 79 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 80 |
|
|
// a Block is split into two triangles along the NE-SW line iff it is in the top-right
|
| 81 |
|
|
// or bottom-left quadrant of the grid.
|
| 82 |
|
|
|
| 83 |
|
|
private boolean isNE(int row,int col)
|
| 84 |
|
|
{
|
| 85 |
29dd01c6
|
Leszek Koltunski
|
return ( (2*row<mRows)^(2*col<mCols) );
|
| 86 |
ce7f3833
|
Leszek Koltunski
|
}
|
| 87 |
|
|
|
| 88 |
91cfe462
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 89 |
|
|
// fill per-side texture mappings. Default: all 6 sides map to the whole texture.
|
| 90 |
|
|
// Each Static4D describes the way its side will map. Format:
|
| 91 |
|
|
//
|
| 92 |
|
|
// 1st float: X-coord of the texture point that our top-left corner of the side maps to
|
| 93 |
|
|
// 2nd float: Y-coord of the texture point that our top-left corner of the side maps to
|
| 94 |
|
|
// 3rd float: X-coord of the texture point that our bot-right corner of the side maps to
|
| 95 |
|
|
// 4th float: Y-coord of the texture point that our bot-right corner of the side maps to
|
| 96 |
|
|
|
| 97 |
|
|
private void fillTexMappings(Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom)
|
| 98 |
|
|
{
|
| 99 |
|
|
if( mTexMappingX==null ) mTexMappingX = new float[6];
|
| 100 |
|
|
if( mTexMappingY==null ) mTexMappingY = new float[6];
|
| 101 |
|
|
if( mTexMappingW==null ) mTexMappingW = new float[6];
|
| 102 |
|
|
if( mTexMappingH==null ) mTexMappingH = new float[6];
|
| 103 |
|
|
|
| 104 |
|
|
mTexMappingX[FRONT] = front.get1();
|
| 105 |
|
|
mTexMappingY[FRONT] = front.get2();
|
| 106 |
|
|
mTexMappingW[FRONT] = front.get3() - front.get1();
|
| 107 |
|
|
mTexMappingH[FRONT] = front.get4() - front.get2();
|
| 108 |
|
|
|
| 109 |
|
|
mTexMappingX[BACK] = back.get1();
|
| 110 |
|
|
mTexMappingY[BACK] = back.get2();
|
| 111 |
|
|
mTexMappingW[BACK] = back.get3() - back.get1();
|
| 112 |
|
|
mTexMappingH[BACK] = back.get4() - back.get2();
|
| 113 |
|
|
|
| 114 |
|
|
mTexMappingX[LEFT] = left.get1();
|
| 115 |
|
|
mTexMappingY[LEFT] = left.get2();
|
| 116 |
|
|
mTexMappingW[LEFT] = left.get3() - left.get1();
|
| 117 |
|
|
mTexMappingH[LEFT] = left.get4() - left.get2();
|
| 118 |
|
|
|
| 119 |
|
|
mTexMappingX[RIGHT] = right.get1();
|
| 120 |
|
|
mTexMappingY[RIGHT] = right.get2();
|
| 121 |
|
|
mTexMappingW[RIGHT] = right.get3() - right.get1();
|
| 122 |
|
|
mTexMappingH[RIGHT] = right.get4() - right.get2();
|
| 123 |
|
|
|
| 124 |
|
|
mTexMappingX[TOP] = top.get1();
|
| 125 |
|
|
mTexMappingY[TOP] = top.get2();
|
| 126 |
|
|
mTexMappingW[TOP] = top.get3() - top.get1();
|
| 127 |
|
|
mTexMappingH[TOP] = top.get4() - top.get2();
|
| 128 |
|
|
|
| 129 |
|
|
mTexMappingX[BOTTOM] = bottom.get1();
|
| 130 |
|
|
mTexMappingY[BOTTOM] = bottom.get2();
|
| 131 |
|
|
mTexMappingW[BOTTOM] = bottom.get3() - bottom.get1();
|
| 132 |
|
|
mTexMappingH[BOTTOM] = bottom.get4() - bottom.get2();
|
| 133 |
|
|
}
|
| 134 |
|
|
|
| 135 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 136 |
84ee2a6a
|
Leszek Koltunski
|
// return the number of vertices our grid will contain
|
| 137 |
6a06a912
|
Leszek Koltunski
|
|
| 138 |
d1a396b2
|
leszek
|
private int computeDataLength()
|
| 139 |
6a06a912
|
Leszek Koltunski
|
{
|
| 140 |
b62632fc
|
Leszek Koltunski
|
int frontWalls=0, frontSegments=0, triangleShifts=0, windingShifts=0;
|
| 141 |
ce7f3833
|
Leszek Koltunski
|
int shiftCol = (mCols-1)/2;
|
| 142 |
|
|
|
| 143 |
|
|
boolean lastBlockIsNE=false;
|
| 144 |
|
|
boolean thisBlockIsNE; // the block we are currently looking at is split into
|
| 145 |
|
|
// two triangles along the NE-SW line (rather than NW-SE)
|
| 146 |
29dd01c6
|
Leszek Koltunski
|
for(int row=0; row<mRows; row++)
|
| 147 |
b62632fc
|
Leszek Koltunski
|
{
|
| 148 |
|
|
if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++;
|
| 149 |
ce7f3833
|
Leszek Koltunski
|
|
| 150 |
b62632fc
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
| 151 |
|
|
{
|
| 152 |
|
|
if( mCubes[row][col]%2 == 1 ) // land
|
| 153 |
6a06a912
|
Leszek Koltunski
|
{
|
| 154 |
b62632fc
|
Leszek Koltunski
|
thisBlockIsNE = isNE(row,col);
|
| 155 |
|
|
if( thisBlockIsNE^lastBlockIsNE ) windingShifts++;
|
| 156 |
|
|
lastBlockIsNE = thisBlockIsNE;
|
| 157 |
|
|
frontWalls++;
|
| 158 |
|
|
if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++;
|
| 159 |
6a06a912
|
Leszek Koltunski
|
}
|
| 160 |
b62632fc
|
Leszek Koltunski
|
}
|
| 161 |
|
|
}
|
| 162 |
ce7f3833
|
Leszek Koltunski
|
|
| 163 |
5f2853be
|
Leszek Koltunski
|
int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts;
|
| 164 |
|
|
int sideVertOneSlice= 2*( mSideWalls + mSideBends + mEdgeNum -1);
|
| 165 |
|
|
int sideVert = 2*(mSlices-1) + mSlices*sideVertOneSlice;
|
| 166 |
|
|
int firstWinding = (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0;
|
| 167 |
|
|
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert);
|
| 168 |
8d9da98a
|
Leszek Koltunski
|
/*
|
| 169 |
b62632fc
|
Leszek Koltunski
|
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert);
|
| 170 |
|
|
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL );
|
| 171 |
8d9da98a
|
Leszek Koltunski
|
*/
|
| 172 |
6a06a912
|
Leszek Koltunski
|
return dataL<0 ? 0:dataL;
|
| 173 |
|
|
}
|
| 174 |
|
|
|
| 175 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 176 |
|
|
/*
|
| 177 |
|
|
private static String debug(short[] val)
|
| 178 |
|
|
{
|
| 179 |
ce7f3833
|
Leszek Koltunski
|
String ret="";j
|
| 180 |
6a06a912
|
Leszek Koltunski
|
|
| 181 |
|
|
for(int i=0; i<val.length; i++) ret+=(" "+val[i]);
|
| 182 |
|
|
|
| 183 |
|
|
return ret;
|
| 184 |
|
|
}
|
| 185 |
|
|
*/
|
| 186 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 187 |
91cfe462
|
Leszek Koltunski
|
/*
|
| 188 |
6a06a912
|
Leszek Koltunski
|
private static String debug(float[] val, int stop)
|
| 189 |
|
|
{
|
| 190 |
|
|
String ret="";
|
| 191 |
e6904678
|
Leszek Koltunski
|
float v;
|
| 192 |
|
|
boolean neg;
|
| 193 |
|
|
int mod;
|
| 194 |
6a06a912
|
Leszek Koltunski
|
|
| 195 |
|
|
for(int i=0; i<val.length; i++)
|
| 196 |
|
|
{
|
| 197 |
|
|
if( i%stop==0 ) ret+="\n";
|
| 198 |
e6904678
|
Leszek Koltunski
|
|
| 199 |
|
|
mod = i%stop;
|
| 200 |
|
|
|
| 201 |
|
|
if( mod==0 || mod==3 || mod==6 ) ret+=" (";
|
| 202 |
|
|
|
| 203 |
|
|
v = val[i];
|
| 204 |
|
|
if( v==-0.0f ) v=0.0f;
|
| 205 |
|
|
|
| 206 |
|
|
|
| 207 |
|
|
neg = v<0;
|
| 208 |
|
|
v = (v<0 ? -v:v);
|
| 209 |
|
|
|
| 210 |
|
|
ret+=((neg? " -":" +")+v);
|
| 211 |
|
|
|
| 212 |
|
|
if( mod==2 || mod==5 || mod==7 ) ret+=")";
|
| 213 |
6a06a912
|
Leszek Koltunski
|
}
|
| 214 |
|
|
|
| 215 |
|
|
return ret;
|
| 216 |
|
|
}
|
| 217 |
91cfe462
|
Leszek Koltunski
|
*/
|
| 218 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 219 |
|
|
/*
|
| 220 |
|
|
private static String debug(Edge e)
|
| 221 |
|
|
{
|
| 222 |
|
|
String d = "";
|
| 223 |
|
|
|
| 224 |
|
|
switch(e.side)
|
| 225 |
|
|
{
|
| 226 |
|
|
case NORTH: d+="NORTH "; break;
|
| 227 |
|
|
case SOUTH: d+="SOUTH "; break;
|
| 228 |
|
|
case WEST : d+="WEST "; break;
|
| 229 |
|
|
case EAST : d+="EAST "; break;
|
| 230 |
|
|
}
|
| 231 |
|
|
|
| 232 |
|
|
d+=("("+e.row+","+e.col+")");
|
| 233 |
|
|
|
| 234 |
|
|
return d;
|
| 235 |
|
|
}
|
| 236 |
8d9da98a
|
Leszek Koltunski
|
*/
|
| 237 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 238 |
|
|
|
| 239 |
80cb15ab
|
leszek
|
private void prepareDataStructures(int cols, String desc, int slices)
|
| 240 |
6a06a912
|
Leszek Koltunski
|
{
|
| 241 |
e92785ba
|
Leszek Koltunski
|
mRows =0;
|
| 242 |
|
|
mCols =0;
|
| 243 |
|
|
mSlices =slices;
|
| 244 |
da681e7e
|
Leszek Koltunski
|
numVertices =0;
|
| 245 |
554ce72b
|
Leszek Koltunski
|
|
| 246 |
0729bc41
|
Leszek Koltunski
|
if( cols>0 && desc.contains("1") )
|
| 247 |
6a06a912
|
Leszek Koltunski
|
{
|
| 248 |
0729bc41
|
Leszek Koltunski
|
mCols = cols;
|
| 249 |
|
|
mRows = desc.length()/cols;
|
| 250 |
6a06a912
|
Leszek Koltunski
|
|
| 251 |
9d0df4c6
|
Leszek Koltunski
|
mCubes = new int[mRows][mCols];
|
| 252 |
|
|
mInflateX = new byte[mRows+1][mCols+1];
|
| 253 |
|
|
mInflateY = new byte[mRows+1][mCols+1];
|
| 254 |
|
|
|
| 255 |
20156af7
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
| 256 |
|
|
for(int row=0; row<mRows; row++)
|
| 257 |
|
|
mCubes[row][col] = (desc.charAt(row * mCols + col) == '1' ? 1 : 0);
|
| 258 |
9d0df4c6
|
Leszek Koltunski
|
|
| 259 |
20156af7
|
Leszek Koltunski
|
for(int col=0; col<mCols+1; col++)
|
| 260 |
|
|
for(int row=0; row<mRows+1; row++)
|
| 261 |
9d0df4c6
|
Leszek Koltunski
|
{
|
| 262 |
20156af7
|
Leszek Koltunski
|
fillInflate(row,col);
|
| 263 |
9d0df4c6
|
Leszek Koltunski
|
}
|
| 264 |
d6994cc6
|
Leszek Koltunski
|
|
| 265 |
0729bc41
|
Leszek Koltunski
|
markRegions();
|
| 266 |
da681e7e
|
Leszek Koltunski
|
numVertices = computeDataLength();
|
| 267 |
15290f35
|
Leszek Koltunski
|
currVert = 0;
|
| 268 |
6a06a912
|
Leszek Koltunski
|
}
|
| 269 |
|
|
}
|
| 270 |
665e2c45
|
Leszek Koltunski
|
|
| 271 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 272 |
|
|
// full grid
|
| 273 |
|
|
|
| 274 |
80cb15ab
|
leszek
|
private void prepareDataStructures(int cols, int rows, int slices)
|
| 275 |
665e2c45
|
Leszek Koltunski
|
{
|
| 276 |
e92785ba
|
Leszek Koltunski
|
mRows =rows;
|
| 277 |
|
|
mCols =cols;
|
| 278 |
|
|
mSlices =slices;
|
| 279 |
da681e7e
|
Leszek Koltunski
|
numVertices =0;
|
| 280 |
665e2c45
|
Leszek Koltunski
|
|
| 281 |
|
|
if( cols>0 && rows>0 )
|
| 282 |
|
|
{
|
| 283 |
9d0df4c6
|
Leszek Koltunski
|
mCubes = new int[mRows][mCols];
|
| 284 |
|
|
mInflateX = new byte[mRows+1][mCols+1];
|
| 285 |
|
|
mInflateY = new byte[mRows+1][mCols+1];
|
| 286 |
665e2c45
|
Leszek Koltunski
|
|
| 287 |
20156af7
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
| 288 |
|
|
for(int row=0; row<mRows; row++)
|
| 289 |
|
|
mCubes[row][col] = 1;
|
| 290 |
665e2c45
|
Leszek Koltunski
|
|
| 291 |
20156af7
|
Leszek Koltunski
|
for(int col=0; col<mCols+1; col++)
|
| 292 |
|
|
for(int row=0; row<mRows+1; row++)
|
| 293 |
9d0df4c6
|
Leszek Koltunski
|
{
|
| 294 |
20156af7
|
Leszek Koltunski
|
fillInflate(row,col);
|
| 295 |
9d0df4c6
|
Leszek Koltunski
|
}
|
| 296 |
|
|
|
| 297 |
665e2c45
|
Leszek Koltunski
|
markRegions();
|
| 298 |
da681e7e
|
Leszek Koltunski
|
numVertices = computeDataLength();
|
| 299 |
15290f35
|
Leszek Koltunski
|
currVert = 0;
|
| 300 |
665e2c45
|
Leszek Koltunski
|
}
|
| 301 |
|
|
}
|
| 302 |
|
|
|
| 303 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 304 |
|
|
// Mark all the 'regions' of our grid - i.e. separate pieces of 'land' (connected blocks that will
|
| 305 |
|
|
// be rendered) and 'water' (connected holes in between) with integers. Each connected block of land
|
| 306 |
|
|
// gets a unique odd integer, each connected block of water a unique even integer.
|
| 307 |
|
|
//
|
| 308 |
|
|
// Water on the edges of the grid is also considered connected to itself!
|
| 309 |
|
|
//
|
| 310 |
|
|
// This function also creates a list of 'Edges'. Each Edge is a data structure from which later on we
|
| 311 |
2e96ee72
|
Leszek Koltunski
|
// will start building the side walls of each connected block of land (and sides of holes of water
|
| 312 |
91cfe462
|
Leszek Koltunski
|
// inside). Each Edge needs to point from Land to Water (thus the '(SOUTH,row-1,col)' below) - otherwise
|
| 313 |
8d9da98a
|
Leszek Koltunski
|
// later on setting up normal vectors wouldn't work.
|
| 314 |
6a06a912
|
Leszek Koltunski
|
|
| 315 |
a51fe521
|
Leszek Koltunski
|
private void markRegions()
|
| 316 |
6a06a912
|
Leszek Koltunski
|
{
|
| 317 |
91cfe462
|
Leszek Koltunski
|
int row, col, numWater=1, numLand=0;
|
| 318 |
6a06a912
|
Leszek Koltunski
|
|
| 319 |
91cfe462
|
Leszek Koltunski
|
for(row=0; row<mRows; row++) if( mCubes[ row][ 0]==0 ) markRegion((short)2, row, 0);
|
| 320 |
|
|
for(row=0; row<mRows; row++) if( mCubes[ row][mCols-1]==0 ) markRegion((short)2, row, mCols-1);
|
| 321 |
|
|
for(col=0; col<mCols; col++) if( mCubes[0 ][ col]==0 ) markRegion((short)2, 0, col);
|
| 322 |
|
|
for(col=0; col<mCols; col++) if( mCubes[mRows-1][ col]==0 ) markRegion((short)2,mRows-1, col);
|
| 323 |
6a06a912
|
Leszek Koltunski
|
|
| 324 |
91cfe462
|
Leszek Koltunski
|
for(row=0; row<mRows; row++)
|
| 325 |
|
|
for(col=0; col<mCols; col++)
|
| 326 |
6a06a912
|
Leszek Koltunski
|
{
|
| 327 |
91cfe462
|
Leszek Koltunski
|
if( mCubes[row][col] == 0 ) { numWater++; markRegion( (short)(2*numWater ),row,col); mEdges.add(new Edge(SOUTH,row-1,col)); }
|
| 328 |
|
|
if( mCubes[row][col] == 1 ) { numLand ++; markRegion( (short)(2*numLand+1),row,col); mEdges.add(new Edge(NORTH,row ,col)); }
|
| 329 |
6a06a912
|
Leszek Koltunski
|
}
|
| 330 |
|
|
|
| 331 |
8d9da98a
|
Leszek Koltunski
|
// now we potentially need to kick out some Edges . Otherwise the following does not work:
|
| 332 |
6a06a912
|
Leszek Koltunski
|
//
|
| 333 |
|
|
// 0 1 0
|
| 334 |
|
|
// 1 0 1
|
| 335 |
|
|
// 0 1 0
|
| 336 |
|
|
|
| 337 |
8d9da98a
|
Leszek Koltunski
|
mEdgeNum= mEdges.size();
|
| 338 |
|
|
int initCol, initRow, initSide, lastSide;
|
| 339 |
|
|
Edge e1,e2;
|
| 340 |
6a06a912
|
Leszek Koltunski
|
|
| 341 |
91cfe462
|
Leszek Koltunski
|
for(int edge=0; edge<mEdgeNum; edge++)
|
| 342 |
6a06a912
|
Leszek Koltunski
|
{
|
| 343 |
91cfe462
|
Leszek Koltunski
|
e1 = mEdges.get(edge);
|
| 344 |
8d9da98a
|
Leszek Koltunski
|
initRow= e1.row;
|
| 345 |
|
|
initCol= e1.col;
|
| 346 |
|
|
initSide=e1.side;
|
| 347 |
|
|
|
| 348 |
|
|
do
|
| 349 |
6a06a912
|
Leszek Koltunski
|
{
|
| 350 |
8d9da98a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "checking edge "+debug(e1));
|
| 351 |
|
|
|
| 352 |
b62632fc
|
Leszek Koltunski
|
mSideWalls++;
|
| 353 |
|
|
|
| 354 |
8d9da98a
|
Leszek Koltunski
|
if( e1.side==NORTH || e1.side==SOUTH )
|
| 355 |
6a06a912
|
Leszek Koltunski
|
{
|
| 356 |
91cfe462
|
Leszek Koltunski
|
for(int j=edge+1;j<mEdgeNum;j++)
|
| 357 |
6a06a912
|
Leszek Koltunski
|
{
|
| 358 |
8d9da98a
|
Leszek Koltunski
|
e2 = mEdges.get(j);
|
| 359 |
|
|
|
| 360 |
|
|
if( e2.side==e1.side && e2.row==e1.row && e2.col==e1.col )
|
| 361 |
|
|
{
|
| 362 |
|
|
mEdges.remove(j);
|
| 363 |
|
|
mEdgeNum--;
|
| 364 |
|
|
j--;
|
| 365 |
|
|
|
| 366 |
|
|
//android.util.Log.e("CUBES", "removing edge "+debug(e2));
|
| 367 |
|
|
}
|
| 368 |
6a06a912
|
Leszek Koltunski
|
}
|
| 369 |
|
|
}
|
| 370 |
8d9da98a
|
Leszek Koltunski
|
|
| 371 |
|
|
lastSide = e1.side;
|
| 372 |
|
|
e1 = getNextEdge(e1);
|
| 373 |
|
|
if( e1.side!=lastSide ) mSideBends++;
|
| 374 |
6a06a912
|
Leszek Koltunski
|
}
|
| 375 |
8d9da98a
|
Leszek Koltunski
|
while( e1.col!=initCol || e1.row!=initRow || e1.side!=initSide );
|
| 376 |
6a06a912
|
Leszek Koltunski
|
}
|
| 377 |
|
|
}
|
| 378 |
|
|
|
| 379 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 380 |
|
|
// when calling, make sure that newVal != val
|
| 381 |
|
|
|
| 382 |
a51fe521
|
Leszek Koltunski
|
private void markRegion(short newVal, int row, int col)
|
| 383 |
6a06a912
|
Leszek Koltunski
|
{
|
| 384 |
d6994cc6
|
Leszek Koltunski
|
int val = mCubes[row][col];
|
| 385 |
6a06a912
|
Leszek Koltunski
|
mCubes[row][col] = newVal;
|
| 386 |
|
|
|
| 387 |
|
|
if( row>0 && mCubes[row-1][col ]==val ) markRegion(newVal, row-1, col );
|
| 388 |
|
|
if( row<mRows-1 && mCubes[row+1][col ]==val ) markRegion(newVal, row+1, col );
|
| 389 |
|
|
if( col>0 && mCubes[row ][col-1]==val ) markRegion(newVal, row , col-1);
|
| 390 |
|
|
if( col<mCols-1 && mCubes[row ][col+1]==val ) markRegion(newVal, row , col+1);
|
| 391 |
|
|
}
|
| 392 |
|
|
|
| 393 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 394 |
|
|
|
| 395 |
a51fe521
|
Leszek Koltunski
|
private void createNormals(boolean front, int row, int col)
|
| 396 |
6a06a912
|
Leszek Koltunski
|
{
|
| 397 |
|
|
int td,lr;
|
| 398 |
|
|
|
| 399 |
2e96ee72
|
Leszek Koltunski
|
int nw = (col>0 && row>0 ) ? (mCubes[row-1][col-1]%2) : 0;
|
| 400 |
|
|
int w = (col>0 ) ? (mCubes[row ][col-1]%2) : 0;
|
| 401 |
|
|
int n = ( row>0 ) ? (mCubes[row-1][col ]%2) : 0;
|
| 402 |
|
|
int c = (mCubes[row ][col ]%2);
|
| 403 |
|
|
int sw = (col>0 && row<mRows-1) ? (mCubes[row+1][col-1]%2) : 0;
|
| 404 |
6a06a912
|
Leszek Koltunski
|
int s = ( row<mRows-1) ? (mCubes[row+1][col ]%2) : 0;
|
| 405 |
|
|
int ne = (col<mCols-1 && row>0 ) ? (mCubes[row-1][col+1]%2) : 0;
|
| 406 |
|
|
int e = (col<mCols-1 ) ? (mCubes[row ][col+1]%2) : 0;
|
| 407 |
|
|
int se = (col<mCols-1 && row<mRows-1) ? (mCubes[row+1][col+1]%2) : 0;
|
| 408 |
ce7f3833
|
Leszek Koltunski
|
|
| 409 |
|
|
if(front)
|
| 410 |
|
|
{
|
| 411 |
|
|
mNormalZ[0] = 1.0f;
|
| 412 |
|
|
mNormalZ[1] = 1.0f;
|
| 413 |
|
|
mNormalZ[2] = 1.0f;
|
| 414 |
|
|
mNormalZ[3] = 1.0f;
|
| 415 |
|
|
}
|
| 416 |
|
|
else
|
| 417 |
|
|
{
|
| 418 |
|
|
mNormalZ[0] =-1.0f;
|
| 419 |
|
|
mNormalZ[1] =-1.0f;
|
| 420 |
|
|
mNormalZ[2] =-1.0f;
|
| 421 |
|
|
mNormalZ[3] =-1.0f;
|
| 422 |
|
|
}
|
| 423 |
|
|
|
| 424 |
6a06a912
|
Leszek Koltunski
|
td = nw+n-w-c;
|
| 425 |
|
|
lr = c+n-w-nw;
|
| 426 |
|
|
if( td<0 ) td=-1;
|
| 427 |
|
|
if( td>0 ) td= 1;
|
| 428 |
|
|
if( lr<0 ) lr=-1;
|
| 429 |
|
|
if( lr>0 ) lr= 1;
|
| 430 |
|
|
mNormalX[0] = lr*R;
|
| 431 |
|
|
mNormalY[0] = td*R;
|
| 432 |
|
|
|
| 433 |
|
|
td = w+c-sw-s;
|
| 434 |
|
|
lr = c+s-w-sw;
|
| 435 |
|
|
if( td<0 ) td=-1;
|
| 436 |
|
|
if( td>0 ) td= 1;
|
| 437 |
|
|
if( lr<0 ) lr=-1;
|
| 438 |
|
|
if( lr>0 ) lr= 1;
|
| 439 |
|
|
mNormalX[1] = lr*R;
|
| 440 |
|
|
mNormalY[1] = td*R;
|
| 441 |
|
|
|
| 442 |
|
|
td = n+ne-c-e;
|
| 443 |
|
|
lr = e+ne-c-n;
|
| 444 |
|
|
if( td<0 ) td=-1;
|
| 445 |
|
|
if( td>0 ) td= 1;
|
| 446 |
|
|
if( lr<0 ) lr=-1;
|
| 447 |
|
|
if( lr>0 ) lr= 1;
|
| 448 |
|
|
mNormalX[2] = lr*R;
|
| 449 |
|
|
mNormalY[2] = td*R;
|
| 450 |
|
|
|
| 451 |
|
|
td = c+e-s-se;
|
| 452 |
|
|
lr = e+se-c-s;
|
| 453 |
|
|
if( td<0 ) td=-1;
|
| 454 |
|
|
if( td>0 ) td= 1;
|
| 455 |
|
|
if( lr<0 ) lr=-1;
|
| 456 |
|
|
if( lr>0 ) lr= 1;
|
| 457 |
|
|
mNormalX[3] = lr*R;
|
| 458 |
|
|
mNormalY[3] = td*R;
|
| 459 |
|
|
/*
|
| 460 |
2e96ee72
|
Leszek Koltunski
|
android.util.Log.d("CUBES", "row="+row+" col="+col);
|
| 461 |
|
|
android.util.Log.d("CUBES", mNormalX[0]+" "+mNormalY[0]);
|
| 462 |
|
|
android.util.Log.d("CUBES", mNormalX[1]+" "+mNormalY[1]);
|
| 463 |
|
|
android.util.Log.d("CUBES", mNormalX[2]+" "+mNormalY[2]);
|
| 464 |
|
|
android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]);
|
| 465 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 466 |
|
|
}
|
| 467 |
ce7f3833
|
Leszek Koltunski
|
|
| 468 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 469 |
|
|
|
| 470 |
15290f35
|
Leszek Koltunski
|
private void buildFrontBackGrid(boolean front, float[] attribs)
|
| 471 |
6a06a912
|
Leszek Koltunski
|
{
|
| 472 |
d6994cc6
|
Leszek Koltunski
|
int last, current;
|
| 473 |
ce7f3833
|
Leszek Koltunski
|
boolean seenLand=false;
|
| 474 |
|
|
boolean lastBlockIsNE = false;
|
| 475 |
|
|
boolean currentBlockIsNE;
|
| 476 |
f08b268d
|
Leszek Koltunski
|
float vectZ = (front ? 0.5f : -0.5f);
|
| 477 |
ce7f3833
|
Leszek Koltunski
|
|
| 478 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "buildFrontBack");
|
| 479 |
|
|
|
| 480 |
e5d9b235
|
Leszek Koltunski
|
for(int row=0; row<mRows; row++)
|
| 481 |
6a06a912
|
Leszek Koltunski
|
{
|
| 482 |
|
|
last =0;
|
| 483 |
|
|
|
| 484 |
e5d9b235
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
| 485 |
6a06a912
|
Leszek Koltunski
|
{
|
| 486 |
e5d9b235
|
Leszek Koltunski
|
current = mCubes[row][col];
|
| 487 |
ce7f3833
|
Leszek Koltunski
|
|
| 488 |
6a06a912
|
Leszek Koltunski
|
if( current%2 == 1 )
|
| 489 |
|
|
{
|
| 490 |
e5d9b235
|
Leszek Koltunski
|
currentBlockIsNE = isNE(row,col);
|
| 491 |
84ee2a6a
|
Leszek Koltunski
|
|
| 492 |
15290f35
|
Leszek Koltunski
|
if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) )
|
| 493 |
84ee2a6a
|
Leszek Koltunski
|
{
|
| 494 |
|
|
//android.util.Log.d("CUBES","repeating winding2 vertex");
|
| 495 |
|
|
|
| 496 |
15290f35
|
Leszek Koltunski
|
repeatLast(attribs);
|
| 497 |
84ee2a6a
|
Leszek Koltunski
|
}
|
| 498 |
|
|
|
| 499 |
e5d9b235
|
Leszek Koltunski
|
createNormals(front,row,col);
|
| 500 |
ce7f3833
|
Leszek Koltunski
|
|
| 501 |
e5d9b235
|
Leszek Koltunski
|
if( currentBlockIsNE )
|
| 502 |
6a06a912
|
Leszek Koltunski
|
{
|
| 503 |
e5d9b235
|
Leszek Koltunski
|
if( (last!=current) || !lastBlockIsNE )
|
| 504 |
|
|
{
|
| 505 |
15290f35
|
Leszek Koltunski
|
if( seenLand && (last != current) ) repeatLast(attribs);
|
| 506 |
|
|
addFrontVertex( 0, vectZ, col, row, attribs);
|
| 507 |
|
|
if( seenLand && (last != current) ) repeatLast(attribs);
|
| 508 |
|
|
if( !lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
|
| 509 |
|
|
addFrontVertex( 1, vectZ, col, row+1, attribs);
|
| 510 |
e5d9b235
|
Leszek Koltunski
|
}
|
| 511 |
91cfe462
|
Leszek Koltunski
|
addFrontVertex( 2, vectZ, col+1, row , attribs);
|
| 512 |
15290f35
|
Leszek Koltunski
|
addFrontVertex( 3, vectZ, col+1, row+1, attribs);
|
| 513 |
e5d9b235
|
Leszek Koltunski
|
}
|
| 514 |
|
|
else
|
| 515 |
|
|
{
|
| 516 |
|
|
if( (last!=current) || lastBlockIsNE )
|
| 517 |
|
|
{
|
| 518 |
15290f35
|
Leszek Koltunski
|
if( seenLand && (last != current) ) repeatLast(attribs);
|
| 519 |
|
|
addFrontVertex( 1, vectZ, col, row+1, attribs);
|
| 520 |
|
|
if( seenLand && (last != current) ) repeatLast(attribs);
|
| 521 |
|
|
if( lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
|
| 522 |
|
|
addFrontVertex( 0, vectZ, col, row, attribs);
|
| 523 |
e5d9b235
|
Leszek Koltunski
|
}
|
| 524 |
15290f35
|
Leszek Koltunski
|
addFrontVertex( 3, vectZ, col+1, row+1, attribs);
|
| 525 |
|
|
addFrontVertex( 2, vectZ, col+1, row , attribs);
|
| 526 |
6a06a912
|
Leszek Koltunski
|
}
|
| 527 |
ce7f3833
|
Leszek Koltunski
|
|
| 528 |
|
|
seenLand = true;
|
| 529 |
|
|
lastBlockIsNE = currentBlockIsNE;
|
| 530 |
6a06a912
|
Leszek Koltunski
|
}
|
| 531 |
|
|
|
| 532 |
|
|
last = current;
|
| 533 |
|
|
}
|
| 534 |
|
|
}
|
| 535 |
|
|
}
|
| 536 |
|
|
|
| 537 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 538 |
|
|
|
| 539 |
15290f35
|
Leszek Koltunski
|
private void buildSideGrid(float[] attribs)
|
| 540 |
6a06a912
|
Leszek Koltunski
|
{
|
| 541 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "buildSide");
|
| 542 |
ce7f3833
|
Leszek Koltunski
|
|
| 543 |
8d9da98a
|
Leszek Koltunski
|
for(int i=0; i<mEdgeNum; i++)
|
| 544 |
6a06a912
|
Leszek Koltunski
|
{
|
| 545 |
15290f35
|
Leszek Koltunski
|
buildIthSide(mEdges.get(i), attribs);
|
| 546 |
|
|
}
|
| 547 |
6a06a912
|
Leszek Koltunski
|
}
|
| 548 |
|
|
|
| 549 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 550 |
|
|
|
| 551 |
15290f35
|
Leszek Koltunski
|
private void buildIthSide(Edge curr, float[] attribs)
|
| 552 |
6a06a912
|
Leszek Koltunski
|
{
|
| 553 |
5f2853be
|
Leszek Koltunski
|
Edge prev, next;
|
| 554 |
|
|
int col, row, side;
|
| 555 |
|
|
|
| 556 |
6a06a912
|
Leszek Koltunski
|
if( curr.side==NORTH ) // water outside
|
| 557 |
|
|
{
|
| 558 |
|
|
prev = new Edge(WEST,curr.row,curr.col);
|
| 559 |
|
|
}
|
| 560 |
d1a396b2
|
leszek
|
else // land outside; we need to move forward one link because we are
|
| 561 |
|
|
{ // going in opposite direction and we need to start from a bend.
|
| 562 |
6a06a912
|
Leszek Koltunski
|
prev = curr;
|
| 563 |
|
|
curr = new Edge(EAST,curr.row+1,curr.col-1);
|
| 564 |
|
|
}
|
| 565 |
5f2853be
|
Leszek Koltunski
|
|
| 566 |
9d0df4c6
|
Leszek Koltunski
|
for(int slice=0; slice<mSlices; slice++)
|
| 567 |
6a06a912
|
Leszek Koltunski
|
{
|
| 568 |
5f2853be
|
Leszek Koltunski
|
col = curr.col;
|
| 569 |
|
|
row = curr.row;
|
| 570 |
|
|
side= curr.side;
|
| 571 |
|
|
next = getNextEdge(curr);
|
| 572 |
|
|
|
| 573 |
9d0df4c6
|
Leszek Koltunski
|
addSideVertex(curr,true,slice+1,prev.side,attribs);
|
| 574 |
5f2853be
|
Leszek Koltunski
|
|
| 575 |
|
|
do
|
| 576 |
6a06a912
|
Leszek Koltunski
|
{
|
| 577 |
5f2853be
|
Leszek Koltunski
|
if( prev.side!=curr.side )
|
| 578 |
|
|
{
|
| 579 |
9d0df4c6
|
Leszek Koltunski
|
addSideVertex(curr,true,slice+1,prev.side,attribs);
|
| 580 |
|
|
addSideVertex(curr,true,slice ,prev.side,attribs);
|
| 581 |
5f2853be
|
Leszek Koltunski
|
}
|
| 582 |
6a06a912
|
Leszek Koltunski
|
|
| 583 |
9d0df4c6
|
Leszek Koltunski
|
addSideVertex(curr,false,slice+1,next.side,attribs);
|
| 584 |
|
|
addSideVertex(curr,false,slice ,next.side,attribs);
|
| 585 |
6a06a912
|
Leszek Koltunski
|
|
| 586 |
5f2853be
|
Leszek Koltunski
|
prev = curr;
|
| 587 |
|
|
curr = next;
|
| 588 |
|
|
next = getNextEdge(curr);
|
| 589 |
|
|
}
|
| 590 |
|
|
while( curr.col!=col || curr.row!=row || curr.side!=side );
|
| 591 |
6a06a912
|
Leszek Koltunski
|
|
| 592 |
15290f35
|
Leszek Koltunski
|
repeatLast(attribs);
|
| 593 |
5f2853be
|
Leszek Koltunski
|
}
|
| 594 |
6a06a912
|
Leszek Koltunski
|
}
|
| 595 |
|
|
|
| 596 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 597 |
|
|
|
| 598 |
a51fe521
|
Leszek Koltunski
|
private Edge getNextEdge(Edge curr)
|
| 599 |
6a06a912
|
Leszek Koltunski
|
{
|
| 600 |
|
|
int col = curr.col;
|
| 601 |
|
|
int row = curr.row;
|
| 602 |
|
|
|
| 603 |
|
|
//android.util.Log.e("CUBES", "row="+row+" col="+col+" mRows="+mRows+" mCols="+mCols);
|
| 604 |
|
|
|
| 605 |
|
|
switch(curr.side)
|
| 606 |
|
|
{
|
| 607 |
|
|
case NORTH: if( col==mCols-1 )
|
| 608 |
|
|
return new Edge(EAST,row,col);
|
| 609 |
|
|
if( row>0 && mCubes[row-1][col+1]==mCubes[row][col] )
|
| 610 |
|
|
return new Edge(WEST,row-1,col+1);
|
| 611 |
|
|
if( mCubes[row][col+1]==mCubes[row][col] )
|
| 612 |
|
|
return new Edge(NORTH,row,col+1);
|
| 613 |
|
|
else
|
| 614 |
|
|
return new Edge(EAST,row,col);
|
| 615 |
|
|
|
| 616 |
|
|
case SOUTH: if( col==0 )
|
| 617 |
|
|
return new Edge(WEST,row,col);
|
| 618 |
|
|
if( (row<mRows-1) && mCubes[row+1][col-1]==mCubes[row][col] )
|
| 619 |
|
|
return new Edge(EAST,row+1,col-1);
|
| 620 |
|
|
if( mCubes[row][col-1]==mCubes[row][col] )
|
| 621 |
|
|
return new Edge(SOUTH,row,col-1);
|
| 622 |
|
|
else
|
| 623 |
|
|
return new Edge(WEST,row,col);
|
| 624 |
|
|
|
| 625 |
|
|
case EAST : if( row==mRows-1 )
|
| 626 |
|
|
return new Edge(SOUTH,row,col);
|
| 627 |
|
|
if( (col<mCols-1) && mCubes[row+1][col+1]==mCubes[row][col] )
|
| 628 |
|
|
return new Edge(NORTH,row+1,col+1);
|
| 629 |
|
|
if( mCubes[row+1][col]==mCubes[row][col] )
|
| 630 |
|
|
return new Edge(EAST,row+1,col);
|
| 631 |
|
|
else
|
| 632 |
|
|
return new Edge(SOUTH,row,col);
|
| 633 |
|
|
|
| 634 |
8d9da98a
|
Leszek Koltunski
|
default : if( row==0 )
|
| 635 |
6a06a912
|
Leszek Koltunski
|
return new Edge(NORTH,row,col);
|
| 636 |
|
|
if( col>0 && mCubes[row-1][col-1]==mCubes[row][col] )
|
| 637 |
|
|
return new Edge(SOUTH,row-1,col-1);
|
| 638 |
|
|
if( mCubes[row-1][col]==mCubes[row][col] )
|
| 639 |
|
|
return new Edge(WEST,row-1,col);
|
| 640 |
|
|
else
|
| 641 |
|
|
return new Edge(NORTH,row,col);
|
| 642 |
|
|
}
|
| 643 |
|
|
}
|
| 644 |
|
|
|
| 645 |
9d0df4c6
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 646 |
|
|
|
| 647 |
20156af7
|
Leszek Koltunski
|
private void fillInflate(int row, int col)
|
| 648 |
9d0df4c6
|
Leszek Koltunski
|
{
|
| 649 |
|
|
int diff;
|
| 650 |
|
|
|
| 651 |
20156af7
|
Leszek Koltunski
|
if( col==0 ) mInflateX[row][col] = -1;
|
| 652 |
|
|
else if( col==mCols ) mInflateX[row][col] = +1;
|
| 653 |
9d0df4c6
|
Leszek Koltunski
|
else
|
| 654 |
|
|
{
|
| 655 |
|
|
if( row==0 )
|
| 656 |
|
|
{
|
| 657 |
|
|
diff = mCubes[0][col-1]-mCubes[0][col];
|
| 658 |
|
|
}
|
| 659 |
|
|
else if( row==mRows )
|
| 660 |
|
|
{
|
| 661 |
|
|
diff = mCubes[mRows-1][col-1]-mCubes[mRows-1][col];
|
| 662 |
|
|
}
|
| 663 |
|
|
else
|
| 664 |
|
|
{
|
| 665 |
|
|
diff = (mCubes[row ][col-1]-mCubes[row ][col]) +
|
| 666 |
|
|
(mCubes[row-1][col-1]-mCubes[row-1][col]) ;
|
| 667 |
|
|
|
| 668 |
|
|
if( diff==-2 ) diff=-1;
|
| 669 |
|
|
if( diff== 2 ) diff= 1;
|
| 670 |
|
|
}
|
| 671 |
|
|
|
| 672 |
20156af7
|
Leszek Koltunski
|
mInflateX[row][col] = (byte)diff;
|
| 673 |
9d0df4c6
|
Leszek Koltunski
|
}
|
| 674 |
|
|
|
| 675 |
20156af7
|
Leszek Koltunski
|
if( row==0 ) mInflateY[row][col] = +1;
|
| 676 |
|
|
else if( row==mRows ) mInflateY[row][col] = -1;
|
| 677 |
9d0df4c6
|
Leszek Koltunski
|
else
|
| 678 |
|
|
{
|
| 679 |
|
|
if( col==0 )
|
| 680 |
|
|
{
|
| 681 |
|
|
diff = mCubes[row][0]-mCubes[row-1][0];
|
| 682 |
|
|
}
|
| 683 |
|
|
else if( col==mCols )
|
| 684 |
|
|
{
|
| 685 |
|
|
diff = mCubes[row][mCols-1]-mCubes[row-1][mCols-1];
|
| 686 |
|
|
}
|
| 687 |
|
|
else
|
| 688 |
|
|
{
|
| 689 |
|
|
diff = (mCubes[row ][col-1]+mCubes[row ][col]) -
|
| 690 |
|
|
(mCubes[row-1][col-1]+mCubes[row-1][col]) ;
|
| 691 |
|
|
|
| 692 |
|
|
if( diff==-2 ) diff=-1;
|
| 693 |
|
|
if( diff== 2 ) diff= 1;
|
| 694 |
|
|
}
|
| 695 |
|
|
|
| 696 |
20156af7
|
Leszek Koltunski
|
mInflateY[row][col] = (byte)diff;
|
| 697 |
9d0df4c6
|
Leszek Koltunski
|
}
|
| 698 |
|
|
|
| 699 |
|
|
//android.util.Log.e("mesh","col="+col+" row="+row+" inflateX="+mInflateX[col][row]+" InflateY="+mInflateY[col][row]);
|
| 700 |
|
|
}
|
| 701 |
|
|
|
| 702 |
a51fe521
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 703 |
|
|
|
| 704 |
15290f35
|
Leszek Koltunski
|
private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs)
|
| 705 |
a51fe521
|
Leszek Koltunski
|
{
|
| 706 |
|
|
float x = (float)col/mCols;
|
| 707 |
|
|
float y = (float)row/mRows;
|
| 708 |
|
|
|
| 709 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x-0.5f;
|
| 710 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f-y;
|
| 711 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = vectZ;
|
| 712 |
6f2d931d
|
Leszek Koltunski
|
|
| 713 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = mNormalX[index];
|
| 714 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
|
| 715 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
|
| 716 |
6f2d931d
|
Leszek Koltunski
|
|
| 717 |
e71dd7fb
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
| 718 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
| 719 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
|
| 720 |
6f2d931d
|
Leszek Koltunski
|
|
| 721 |
91cfe462
|
Leszek Koltunski
|
if( vectZ>0 )
|
| 722 |
|
|
{
|
| 723 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[FRONT] + x * mTexMappingW[FRONT];
|
| 724 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[FRONT] + (1.0f-y) * mTexMappingH[FRONT];
|
| 725 |
|
|
}
|
| 726 |
|
|
else
|
| 727 |
|
|
{
|
| 728 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BACK] + x * mTexMappingW[BACK];
|
| 729 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BACK] + (1.0f-y) * mTexMappingH[BACK];
|
| 730 |
|
|
}
|
| 731 |
a51fe521
|
Leszek Koltunski
|
|
| 732 |
15290f35
|
Leszek Koltunski
|
currVert++;
|
| 733 |
a51fe521
|
Leszek Koltunski
|
}
|
| 734 |
|
|
|
| 735 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 736 |
2d203318
|
Leszek Koltunski
|
|
| 737 |
15290f35
|
Leszek Koltunski
|
private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
|
| 738 |
6a06a912
|
Leszek Koltunski
|
{
|
| 739 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.e("CUBES", "adding Side vertex!");
|
| 740 |
9d0df4c6
|
Leszek Koltunski
|
float x, y, z;
|
| 741 |
91cfe462
|
Leszek Koltunski
|
int row, col;
|
| 742 |
985ea9c5
|
Leszek Koltunski
|
|
| 743 |
6a06a912
|
Leszek Koltunski
|
switch(curr.side)
|
| 744 |
|
|
{
|
| 745 |
9d0df4c6
|
Leszek Koltunski
|
case NORTH: row = curr.row;
|
| 746 |
|
|
col = (back ? (curr.col ):(curr.col+1));
|
| 747 |
|
|
x = (float)col/mCols;
|
| 748 |
|
|
y = 0.5f - (float)row/mRows;
|
| 749 |
|
|
z = 0.5f - (float)slice/mSlices;
|
| 750 |
985ea9c5
|
Leszek Koltunski
|
|
| 751 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
| 752 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
| 753 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
| 754 |
6f2d931d
|
Leszek Koltunski
|
|
| 755 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
| 756 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
|
| 757 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
| 758 |
6f2d931d
|
Leszek Koltunski
|
|
| 759 |
e71dd7fb
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
| 760 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
| 761 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
| 762 |
a16bf106
|
Leszek Koltunski
|
|
| 763 |
91cfe462
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[TOP] + x * mTexMappingW[TOP];
|
| 764 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[TOP] + (0.5f-z) * mTexMappingH[TOP];
|
| 765 |
15ed35e6
|
Leszek Koltunski
|
|
| 766 |
6a06a912
|
Leszek Koltunski
|
break;
|
| 767 |
9d0df4c6
|
Leszek Koltunski
|
case SOUTH: row = curr.row+1;
|
| 768 |
|
|
col = (back ? (curr.col+1):(curr.col));
|
| 769 |
|
|
x = (float)col/mCols;
|
| 770 |
|
|
y = 0.5f - (float)row/mRows;
|
| 771 |
|
|
z = 0.5f - (float)slice/mSlices;
|
| 772 |
985ea9c5
|
Leszek Koltunski
|
|
| 773 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x - 0.5f;
|
| 774 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
|
| 775 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
| 776 |
6f2d931d
|
Leszek Koltunski
|
|
| 777 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
| 778 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
|
| 779 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
| 780 |
6f2d931d
|
Leszek Koltunski
|
|
| 781 |
e71dd7fb
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
| 782 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
| 783 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
| 784 |
a16bf106
|
Leszek Koltunski
|
|
| 785 |
91cfe462
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[BOTTOM] + x * mTexMappingW[BOTTOM];
|
| 786 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[BOTTOM] + (0.5f-z) * mTexMappingH[BOTTOM];
|
| 787 |
15ed35e6
|
Leszek Koltunski
|
|
| 788 |
6a06a912
|
Leszek Koltunski
|
break;
|
| 789 |
9d0df4c6
|
Leszek Koltunski
|
case WEST : row = (back ? (curr.row+1):(curr.row));
|
| 790 |
|
|
col = curr.col;
|
| 791 |
|
|
x = (float)col/mCols -0.5f;
|
| 792 |
|
|
y = (float)row/mRows;
|
| 793 |
|
|
z = 0.5f - (float)slice/mSlices;
|
| 794 |
985ea9c5
|
Leszek Koltunski
|
|
| 795 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
| 796 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
| 797 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
| 798 |
6f2d931d
|
Leszek Koltunski
|
|
| 799 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] =-1.0f;
|
| 800 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
| 801 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
| 802 |
6f2d931d
|
Leszek Koltunski
|
|
| 803 |
e71dd7fb
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
| 804 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
| 805 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
| 806 |
6f2d931d
|
Leszek Koltunski
|
|
| 807 |
91cfe462
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[LEFT] + (0.5f-z) * mTexMappingW[LEFT];
|
| 808 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[LEFT] + (1.0f-y) * mTexMappingH[LEFT];
|
| 809 |
2d203318
|
Leszek Koltunski
|
|
| 810 |
6a06a912
|
Leszek Koltunski
|
break;
|
| 811 |
9d0df4c6
|
Leszek Koltunski
|
case EAST : row = (back ? (curr.row):(curr.row+1));
|
| 812 |
|
|
col = (curr.col+1);
|
| 813 |
|
|
x = (float)col/mCols -0.5f;
|
| 814 |
|
|
y = (float)row/mRows;
|
| 815 |
|
|
z = 0.5f - (float)slice/mSlices;
|
| 816 |
985ea9c5
|
Leszek Koltunski
|
|
| 817 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = x;
|
| 818 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
|
| 819 |
9d0df4c6
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
|
| 820 |
6f2d931d
|
Leszek Koltunski
|
|
| 821 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = 1.0f;
|
| 822 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
| 823 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
| 824 |
6f2d931d
|
Leszek Koltunski
|
|
| 825 |
e71dd7fb
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = mInflateX[row][col]/2.0f;
|
| 826 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
|
| 827 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
|
| 828 |
6f2d931d
|
Leszek Koltunski
|
|
| 829 |
91cfe462
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = mTexMappingX[RIGHT] + (0.5f-z) * mTexMappingW[RIGHT];
|
| 830 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = mTexMappingY[RIGHT] + (1.0f-y) * mTexMappingH[RIGHT];
|
| 831 |
a16bf106
|
Leszek Koltunski
|
|
| 832 |
2d203318
|
Leszek Koltunski
|
break;
|
| 833 |
a16bf106
|
Leszek Koltunski
|
}
|
| 834 |
2d203318
|
Leszek Koltunski
|
|
| 835 |
15290f35
|
Leszek Koltunski
|
currVert++;
|
| 836 |
6f2d931d
|
Leszek Koltunski
|
}
|
| 837 |
|
|
|
| 838 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 839 |
|
|
|
| 840 |
15290f35
|
Leszek Koltunski
|
private void repeatLast(float[] attribs)
|
| 841 |
6f2d931d
|
Leszek Koltunski
|
{
|
| 842 |
|
|
//android.util.Log.e("CUBES", "repeating last vertex!");
|
| 843 |
|
|
|
| 844 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB ];
|
| 845 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1];
|
| 846 |
|
|
attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2];
|
| 847 |
6f2d931d
|
Leszek Koltunski
|
|
| 848 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB ];
|
| 849 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+1];
|
| 850 |
|
|
attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+2];
|
| 851 |
6f2d931d
|
Leszek Koltunski
|
|
| 852 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB ];
|
| 853 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+1];
|
| 854 |
|
|
attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+2];
|
| 855 |
6f2d931d
|
Leszek Koltunski
|
|
| 856 |
15290f35
|
Leszek Koltunski
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB ] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB ];
|
| 857 |
|
|
attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB+1];
|
| 858 |
6f2d931d
|
Leszek Koltunski
|
|
| 859 |
15290f35
|
Leszek Koltunski
|
currVert++;
|
| 860 |
6a06a912
|
Leszek Koltunski
|
}
|
| 861 |
|
|
|
| 862 |
665e2c45
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 863 |
|
|
|
| 864 |
d1a396b2
|
leszek
|
private void build()
|
| 865 |
665e2c45
|
Leszek Koltunski
|
{
|
| 866 |
6f2d931d
|
Leszek Koltunski
|
float[] attribs= new float[VERT_ATTRIBS*numVertices];
|
| 867 |
665e2c45
|
Leszek Koltunski
|
|
| 868 |
15290f35
|
Leszek Koltunski
|
buildFrontBackGrid(true,attribs);
|
| 869 |
665e2c45
|
Leszek Koltunski
|
|
| 870 |
d1a396b2
|
leszek
|
if( mSlices>0 )
|
| 871 |
665e2c45
|
Leszek Koltunski
|
{
|
| 872 |
15290f35
|
Leszek Koltunski
|
repeatLast(attribs);
|
| 873 |
|
|
if( currVert%2==1 ) repeatLast(attribs);
|
| 874 |
|
|
buildSideGrid(attribs);
|
| 875 |
|
|
buildFrontBackGrid(false,attribs);
|
| 876 |
665e2c45
|
Leszek Koltunski
|
}
|
| 877 |
|
|
|
| 878 |
8d9da98a
|
Leszek Koltunski
|
mEdges.clear();
|
| 879 |
|
|
mEdges = null;
|
| 880 |
|
|
mCubes = null;
|
| 881 |
9d0df4c6
|
Leszek Koltunski
|
mInflateX = null;
|
| 882 |
|
|
mInflateY = null;
|
| 883 |
8d9da98a
|
Leszek Koltunski
|
|
| 884 |
15290f35
|
Leszek Koltunski
|
if( currVert!=numVertices )
|
| 885 |
|
|
android.util.Log.e("MeshCubes", "currVert " +currVert+" numVertices="+numVertices );
|
| 886 |
665e2c45
|
Leszek Koltunski
|
|
| 887 |
227b9bca
|
Leszek Koltunski
|
setAttribs(attribs);
|
| 888 |
665e2c45
|
Leszek Koltunski
|
}
|
| 889 |
|
|
|
| 890 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 891 |
|
|
// PUBLIC API
|
| 892 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 893 |
|
|
/**
|
| 894 |
05403bba
|
Leszek Koltunski
|
* Creates the underlying mesh of vertices, normals, texture coords.
|
| 895 |
6a06a912
|
Leszek Koltunski
|
*
|
| 896 |
80cb15ab
|
leszek
|
* @param cols Integer helping to parse the next parameter.
|
| 897 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
| 898 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
| 899 |
|
|
* <p></p>
|
| 900 |
|
|
* <p>
|
| 901 |
|
|
* <pre>
|
| 902 |
91cfe462
|
Leszek Koltunski
|
* For example, (cols=2, desc="111010", slices=1) describes the following shape:
|
| 903 |
a56bc359
|
Leszek Koltunski
|
*
|
| 904 |
80cb15ab
|
leszek
|
* XX
|
| 905 |
|
|
* X
|
| 906 |
|
|
* X
|
| 907 |
a56bc359
|
Leszek Koltunski
|
*
|
| 908 |
91cfe462
|
Leszek Koltunski
|
* whereas (cols=2,desc="110001", slices=1) describes
|
| 909 |
a56bc359
|
Leszek Koltunski
|
*
|
| 910 |
80cb15ab
|
leszek
|
* XX
|
| 911 |
a56bc359
|
Leszek Koltunski
|
*
|
| 912 |
80cb15ab
|
leszek
|
* X
|
| 913 |
|
|
* </pre>
|
| 914 |
|
|
* </p>
|
| 915 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
| 916 |
6a06a912
|
Leszek Koltunski
|
*/
|
| 917 |
80cb15ab
|
leszek
|
public MeshCubes(int cols, String desc, int slices)
|
| 918 |
a51fe521
|
Leszek Koltunski
|
{
|
| 919 |
80cb15ab
|
leszek
|
super( (float)slices/cols);
|
| 920 |
91cfe462
|
Leszek Koltunski
|
|
| 921 |
|
|
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f);
|
| 922 |
|
|
fillTexMappings(map,map,map,map,map,map);
|
| 923 |
|
|
prepareDataStructures(cols,desc,slices);
|
| 924 |
|
|
build();
|
| 925 |
|
|
}
|
| 926 |
|
|
|
| 927 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 928 |
|
|
/**
|
| 929 |
|
|
* Creates the underlying mesh of vertices, normals, texture coords with custom texture mappings.
|
| 930 |
|
|
*
|
| 931 |
|
|
* The mappings decide what part of the texture appears on a given side. Example:
|
| 932 |
|
|
* front = (0.0,0.5,0.5,1.0) means that the front side of the grid will be textured with the
|
| 933 |
|
|
* bottom-left quadrant of the texture.
|
| 934 |
|
|
*
|
| 935 |
|
|
* Default is: each of the 6 sides maps to the whole texture, i.e. (0.0,0.0,1.0,1.0)
|
| 936 |
|
|
*
|
| 937 |
|
|
* @param cols Integer helping to parse the next parameter.
|
| 938 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
| 939 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
| 940 |
|
|
* <p></p>
|
| 941 |
|
|
* <p>
|
| 942 |
|
|
* <pre>
|
| 943 |
|
|
* For example, (cols=2, desc="111010", slices=1) describes the following shape:
|
| 944 |
|
|
*
|
| 945 |
|
|
* XX
|
| 946 |
|
|
* X
|
| 947 |
|
|
* X
|
| 948 |
|
|
*
|
| 949 |
|
|
* whereas (cols=2,desc="110001", slices=1) describes
|
| 950 |
|
|
*
|
| 951 |
|
|
* XX
|
| 952 |
|
|
*
|
| 953 |
|
|
* X
|
| 954 |
|
|
* </pre>
|
| 955 |
|
|
* </p>
|
| 956 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
| 957 |
|
|
* @param front Texture mapping the front side maps to.
|
| 958 |
|
|
* @param back Texture mapping the back side maps to.
|
| 959 |
|
|
* @param left Texture mapping the left side maps to.
|
| 960 |
|
|
* @param right Texture mapping the right side maps to.
|
| 961 |
|
|
* @param top Texture mapping the top side maps to.
|
| 962 |
|
|
* @param bottom Texture mapping the bottom side maps to.
|
| 963 |
|
|
*/
|
| 964 |
|
|
public MeshCubes(int cols, String desc, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom)
|
| 965 |
|
|
{
|
| 966 |
|
|
super( (float)slices/cols);
|
| 967 |
|
|
fillTexMappings(front,back,left,right,top,bottom);
|
| 968 |
80cb15ab
|
leszek
|
prepareDataStructures(cols,desc,slices);
|
| 969 |
d1a396b2
|
leszek
|
build();
|
| 970 |
a51fe521
|
Leszek Koltunski
|
}
|
| 971 |
6a06a912
|
Leszek Koltunski
|
|
| 972 |
665e2c45
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 973 |
|
|
/**
|
| 974 |
05403bba
|
Leszek Koltunski
|
* Creates a full, hole-less underlying mesh of vertices, normals, texture coords and colors.
|
| 975 |
665e2c45
|
Leszek Koltunski
|
*
|
| 976 |
80cb15ab
|
leszek
|
* @param cols Number of columns, i.e. 'width' of the Mesh.
|
| 977 |
|
|
* @param rows Number of rows, i.e. 'height' of the Mesh.
|
| 978 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
| 979 |
665e2c45
|
Leszek Koltunski
|
*/
|
| 980 |
80cb15ab
|
leszek
|
public MeshCubes(int cols, int rows, int slices)
|
| 981 |
a51fe521
|
Leszek Koltunski
|
{
|
| 982 |
80cb15ab
|
leszek
|
super( (float)slices/cols);
|
| 983 |
91cfe462
|
Leszek Koltunski
|
|
| 984 |
|
|
Static4D map = new Static4D(0.0f,0.0f,1.0f,1.0f);
|
| 985 |
|
|
fillTexMappings(map,map,map,map,map,map);
|
| 986 |
|
|
prepareDataStructures(cols,rows,slices);
|
| 987 |
|
|
build();
|
| 988 |
|
|
}
|
| 989 |
|
|
|
| 990 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 991 |
|
|
/**
|
| 992 |
|
|
* Creates a full, hole-less underlying mesh of vertices, normals, texture coords and colors with
|
| 993 |
|
|
* custom texture mappings.
|
| 994 |
|
|
*
|
| 995 |
|
|
* The mappings decide what part of the texture appears on a given side. Example:
|
| 996 |
|
|
* front = (0.0,0.5,0.5,1.0) means that the front side of the grid will be textured with the
|
| 997 |
|
|
* bottom-left quadrant of the texture.
|
| 998 |
|
|
*
|
| 999 |
|
|
* Default is: each of the 6 sides maps to the whole texture, i.e. (0.0,0.0,1.0,1.0)
|
| 1000 |
|
|
*
|
| 1001 |
|
|
* @param cols Number of columns, i.e. 'width' of the Mesh.
|
| 1002 |
|
|
* @param rows Number of rows, i.e. 'height' of the Mesh.
|
| 1003 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
| 1004 |
|
|
* @param front Texture mapping the front side maps to.
|
| 1005 |
|
|
* @param back Texture mapping the back side maps to.
|
| 1006 |
|
|
* @param left Texture mapping the left side maps to.
|
| 1007 |
|
|
* @param right Texture mapping the right side maps to.
|
| 1008 |
|
|
* @param top Texture mapping the top side maps to.
|
| 1009 |
|
|
* @param bottom Texture mapping the bottom side maps to.
|
| 1010 |
|
|
*/
|
| 1011 |
|
|
public MeshCubes(int cols, int rows, int slices, Static4D front, Static4D back, Static4D left, Static4D right, Static4D top, Static4D bottom)
|
| 1012 |
|
|
{
|
| 1013 |
|
|
super( (float)slices/cols);
|
| 1014 |
|
|
fillTexMappings(front,back,left,right,top,bottom);
|
| 1015 |
80cb15ab
|
leszek
|
prepareDataStructures(cols,rows,slices);
|
| 1016 |
d1a396b2
|
leszek
|
build();
|
| 1017 |
6a06a912
|
Leszek Koltunski
|
}
|
| 1018 |
a51fe521
|
Leszek Koltunski
|
}
|