1 |
d333eb6b
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
// Copyright 2016 Leszek Koltunski //
|
3 |
|
|
// //
|
4 |
|
|
// This file is part of Distorted. //
|
5 |
|
|
// //
|
6 |
|
|
// Distorted is free software: you can redistribute it and/or modify //
|
7 |
|
|
// 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 |
|
|
// Distorted is distributed in the hope that it will be useful, //
|
12 |
|
|
// 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 |
|
|
// along with Distorted. If not, see <http://www.gnu.org/licenses/>. //
|
18 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19 |
|
|
|
20 |
fe82a979
|
Leszek Koltunski
|
package org.distorted.library.main;
|
21 |
6a06a912
|
Leszek Koltunski
|
|
22 |
|
|
import java.nio.ByteBuffer;
|
23 |
|
|
import java.nio.ByteOrder;
|
24 |
|
|
import java.util.ArrayList;
|
25 |
|
|
|
26 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
27 |
e0b6c593
|
Leszek Koltunski
|
/**
|
28 |
|
|
* Create a 3D grid composed of Cubes.
|
29 |
|
|
* <p>
|
30 |
|
|
* Any subset of a MxNx1 cuboid is possible.
|
31 |
|
|
*/
|
32 |
26df012c
|
Leszek Koltunski
|
public class MeshCubes extends MeshObject
|
33 |
6a06a912
|
Leszek Koltunski
|
{
|
34 |
06d71892
|
Leszek Koltunski
|
private static final float R = 0.0f;//0.2f;
|
35 |
f08b268d
|
Leszek Koltunski
|
|
36 |
6a06a912
|
Leszek Koltunski
|
private static final int NORTH = 0;
|
37 |
|
|
private static final int WEST = 1;
|
38 |
|
|
private static final int EAST = 2;
|
39 |
|
|
private static final int SOUTH = 3;
|
40 |
ce7f3833
|
Leszek Koltunski
|
|
41 |
6a06a912
|
Leszek Koltunski
|
private static final float[] mNormalX = new float[4];
|
42 |
|
|
private static final float[] mNormalY = new float[4];
|
43 |
ce7f3833
|
Leszek Koltunski
|
private static final float[] mNormalZ = new float[4];
|
44 |
|
|
|
45 |
6a06a912
|
Leszek Koltunski
|
private class Edge
|
46 |
|
|
{
|
47 |
|
|
final int side;
|
48 |
|
|
final int row;
|
49 |
|
|
final int col;
|
50 |
|
|
|
51 |
06d71892
|
Leszek Koltunski
|
Edge(int s, int r, int c)
|
52 |
6a06a912
|
Leszek Koltunski
|
{
|
53 |
|
|
side= s;
|
54 |
|
|
row = r;
|
55 |
|
|
col = c;
|
56 |
|
|
}
|
57 |
39cbf9dc
|
Leszek Koltunski
|
}
|
58 |
6a06a912
|
Leszek Koltunski
|
|
59 |
80cb15ab
|
leszek
|
private int mCols, mRows, mSlices;
|
60 |
d6994cc6
|
Leszek Koltunski
|
private int[][] mCubes;
|
61 |
39cbf9dc
|
Leszek Koltunski
|
private ArrayList<Edge> mEdges = new ArrayList<>();
|
62 |
ce7f3833
|
Leszek Koltunski
|
|
63 |
84ee2a6a
|
Leszek Koltunski
|
private int remainingVert;
|
64 |
8d9da98a
|
Leszek Koltunski
|
private int mSideBends;
|
65 |
|
|
private int mEdgeNum;
|
66 |
b62632fc
|
Leszek Koltunski
|
private int mSideWalls;
|
67 |
ce7f3833
|
Leszek Koltunski
|
|
68 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
69 |
|
|
// a Block is split into two triangles along the NE-SW line iff it is in the top-right
|
70 |
|
|
// or bottom-left quadrant of the grid.
|
71 |
|
|
|
72 |
|
|
private boolean isNE(int row,int col)
|
73 |
|
|
{
|
74 |
29dd01c6
|
Leszek Koltunski
|
return ( (2*row<mRows)^(2*col<mCols) );
|
75 |
ce7f3833
|
Leszek Koltunski
|
}
|
76 |
|
|
|
77 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
78 |
84ee2a6a
|
Leszek Koltunski
|
// return the number of vertices our grid will contain
|
79 |
6a06a912
|
Leszek Koltunski
|
|
80 |
d1a396b2
|
leszek
|
private int computeDataLength()
|
81 |
6a06a912
|
Leszek Koltunski
|
{
|
82 |
b62632fc
|
Leszek Koltunski
|
int frontWalls=0, frontSegments=0, triangleShifts=0, windingShifts=0;
|
83 |
ce7f3833
|
Leszek Koltunski
|
int shiftCol = (mCols-1)/2;
|
84 |
|
|
|
85 |
|
|
boolean lastBlockIsNE=false;
|
86 |
|
|
boolean thisBlockIsNE; // the block we are currently looking at is split into
|
87 |
|
|
// two triangles along the NE-SW line (rather than NW-SE)
|
88 |
29dd01c6
|
Leszek Koltunski
|
for(int row=0; row<mRows; row++)
|
89 |
b62632fc
|
Leszek Koltunski
|
{
|
90 |
|
|
if( mCols>=2 && (mCubes[row][shiftCol]%2 == 1) && (mCubes[row][shiftCol+1]%2 == 1) ) triangleShifts++;
|
91 |
ce7f3833
|
Leszek Koltunski
|
|
92 |
b62632fc
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
93 |
|
|
{
|
94 |
|
|
if( mCubes[row][col]%2 == 1 ) // land
|
95 |
6a06a912
|
Leszek Koltunski
|
{
|
96 |
b62632fc
|
Leszek Koltunski
|
thisBlockIsNE = isNE(row,col);
|
97 |
|
|
if( thisBlockIsNE^lastBlockIsNE ) windingShifts++;
|
98 |
|
|
lastBlockIsNE = thisBlockIsNE;
|
99 |
|
|
frontWalls++;
|
100 |
|
|
if( col==mCols-1 || mCubes[row][col+1]%2 == 0 ) frontSegments++;
|
101 |
6a06a912
|
Leszek Koltunski
|
}
|
102 |
b62632fc
|
Leszek Koltunski
|
}
|
103 |
|
|
}
|
104 |
ce7f3833
|
Leszek Koltunski
|
|
105 |
5f2853be
|
Leszek Koltunski
|
int frontVert = 2*( frontWalls + 2*frontSegments - 1) +2*triangleShifts + windingShifts;
|
106 |
|
|
int sideVertOneSlice= 2*( mSideWalls + mSideBends + mEdgeNum -1);
|
107 |
|
|
int sideVert = 2*(mSlices-1) + mSlices*sideVertOneSlice;
|
108 |
|
|
int firstWinding = (mSlices>0 && (frontVert+1)%2==1 ) ? 1:0;
|
109 |
|
|
int dataL = mSlices==0 ? frontVert : (frontVert+1) +firstWinding+ (1+sideVert+1) + (1+frontVert);
|
110 |
8d9da98a
|
Leszek Koltunski
|
/*
|
111 |
b62632fc
|
Leszek Koltunski
|
android.util.Log.e("CUBES","triangleShifts="+triangleShifts+" windingShifts="+windingShifts+" winding1="+firstWinding+" frontVert="+frontVert+" sideVert="+sideVert);
|
112 |
|
|
android.util.Log.e("CUBES", "frontW="+frontWalls+" fSegments="+frontSegments+" sWalls="+mSideWalls+" sSegments="+mEdgeNum+" sideBends="+mSideBends+" dataLen="+dataL );
|
113 |
8d9da98a
|
Leszek Koltunski
|
*/
|
114 |
6a06a912
|
Leszek Koltunski
|
return dataL<0 ? 0:dataL;
|
115 |
|
|
}
|
116 |
|
|
|
117 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
118 |
|
|
/*
|
119 |
|
|
private static String debug(short[] val)
|
120 |
|
|
{
|
121 |
ce7f3833
|
Leszek Koltunski
|
String ret="";j
|
122 |
6a06a912
|
Leszek Koltunski
|
|
123 |
|
|
for(int i=0; i<val.length; i++) ret+=(" "+val[i]);
|
124 |
|
|
|
125 |
|
|
return ret;
|
126 |
|
|
}
|
127 |
|
|
*/
|
128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
129 |
|
|
/*
|
130 |
|
|
private static String debug(float[] val, int stop)
|
131 |
|
|
{
|
132 |
|
|
String ret="";
|
133 |
|
|
|
134 |
|
|
for(int i=0; i<val.length; i++)
|
135 |
|
|
{
|
136 |
|
|
if( i%stop==0 ) ret+="\n";
|
137 |
|
|
ret+=(" "+val[i]);
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
return ret;
|
141 |
|
|
}
|
142 |
d6994cc6
|
Leszek Koltunski
|
*/
|
143 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
144 |
|
|
/*
|
145 |
|
|
private static String debug(Edge e)
|
146 |
|
|
{
|
147 |
|
|
String d = "";
|
148 |
|
|
|
149 |
|
|
switch(e.side)
|
150 |
|
|
{
|
151 |
|
|
case NORTH: d+="NORTH "; break;
|
152 |
|
|
case SOUTH: d+="SOUTH "; break;
|
153 |
|
|
case WEST : d+="WEST "; break;
|
154 |
|
|
case EAST : d+="EAST "; break;
|
155 |
|
|
}
|
156 |
|
|
|
157 |
|
|
d+=("("+e.row+","+e.col+")");
|
158 |
|
|
|
159 |
|
|
return d;
|
160 |
|
|
}
|
161 |
8d9da98a
|
Leszek Koltunski
|
*/
|
162 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
163 |
|
|
|
164 |
80cb15ab
|
leszek
|
private void prepareDataStructures(int cols, String desc, int slices)
|
165 |
6a06a912
|
Leszek Koltunski
|
{
|
166 |
a51fe521
|
Leszek Koltunski
|
mRows =0;
|
167 |
|
|
mCols =0;
|
168 |
80cb15ab
|
leszek
|
mSlices =slices;
|
169 |
a51fe521
|
Leszek Koltunski
|
numVertices=0;
|
170 |
6a06a912
|
Leszek Koltunski
|
|
171 |
0729bc41
|
Leszek Koltunski
|
if( cols>0 && desc.contains("1") )
|
172 |
6a06a912
|
Leszek Koltunski
|
{
|
173 |
0729bc41
|
Leszek Koltunski
|
mCols = cols;
|
174 |
|
|
mRows = desc.length()/cols;
|
175 |
6a06a912
|
Leszek Koltunski
|
|
176 |
d6994cc6
|
Leszek Koltunski
|
mCubes = new int[mRows][mCols];
|
177 |
6a06a912
|
Leszek Koltunski
|
|
178 |
0729bc41
|
Leszek Koltunski
|
for(int j=0; j<mCols; j++)
|
179 |
|
|
for(int i=0; i<mRows; i++)
|
180 |
d6994cc6
|
Leszek Koltunski
|
mCubes[i][j] = (desc.charAt(i*mCols+j) == '1' ? 1:0);
|
181 |
|
|
|
182 |
0729bc41
|
Leszek Koltunski
|
markRegions();
|
183 |
d1a396b2
|
leszek
|
numVertices = computeDataLength();
|
184 |
84ee2a6a
|
Leszek Koltunski
|
|
185 |
a51fe521
|
Leszek Koltunski
|
remainingVert = numVertices;
|
186 |
6a06a912
|
Leszek Koltunski
|
}
|
187 |
|
|
}
|
188 |
665e2c45
|
Leszek Koltunski
|
|
189 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190 |
|
|
// full grid
|
191 |
|
|
|
192 |
80cb15ab
|
leszek
|
private void prepareDataStructures(int cols, int rows, int slices)
|
193 |
665e2c45
|
Leszek Koltunski
|
{
|
194 |
a51fe521
|
Leszek Koltunski
|
mRows =rows;
|
195 |
|
|
mCols =cols;
|
196 |
80cb15ab
|
leszek
|
mSlices =slices;
|
197 |
a51fe521
|
Leszek Koltunski
|
numVertices = 0;
|
198 |
665e2c45
|
Leszek Koltunski
|
|
199 |
|
|
if( cols>0 && rows>0 )
|
200 |
|
|
{
|
201 |
d6994cc6
|
Leszek Koltunski
|
mCubes = new int[mRows][mCols];
|
202 |
665e2c45
|
Leszek Koltunski
|
|
203 |
|
|
for(int j=0; j<mCols; j++)
|
204 |
|
|
for(int i=0; i<mRows; i++)
|
205 |
d6994cc6
|
Leszek Koltunski
|
mCubes[i][j] = 1;
|
206 |
665e2c45
|
Leszek Koltunski
|
|
207 |
|
|
markRegions();
|
208 |
d1a396b2
|
leszek
|
numVertices = computeDataLength();
|
209 |
665e2c45
|
Leszek Koltunski
|
|
210 |
a51fe521
|
Leszek Koltunski
|
remainingVert = numVertices;
|
211 |
665e2c45
|
Leszek Koltunski
|
}
|
212 |
|
|
}
|
213 |
|
|
|
214 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
215 |
|
|
// Mark all the 'regions' of our grid - i.e. separate pieces of 'land' (connected blocks that will
|
216 |
|
|
// be rendered) and 'water' (connected holes in between) with integers. Each connected block of land
|
217 |
|
|
// gets a unique odd integer, each connected block of water a unique even integer.
|
218 |
|
|
//
|
219 |
|
|
// Water on the edges of the grid is also considered connected to itself!
|
220 |
|
|
//
|
221 |
|
|
// This function also creates a list of 'Edges'. Each Edge is a data structure from which later on we
|
222 |
2e96ee72
|
Leszek Koltunski
|
// will start building the side walls of each connected block of land (and sides of holes of water
|
223 |
8d9da98a
|
Leszek Koltunski
|
// inside). Each Edge needs to point from Land to Water (thus the '(SOUTH,i-1,j)' below) - otherwise
|
224 |
|
|
// later on setting up normal vectors wouldn't work.
|
225 |
6a06a912
|
Leszek Koltunski
|
|
226 |
a51fe521
|
Leszek Koltunski
|
private void markRegions()
|
227 |
6a06a912
|
Leszek Koltunski
|
{
|
228 |
|
|
int i, j, numWater=1, numLand=0;
|
229 |
|
|
|
230 |
|
|
for(i=0; i<mRows;i++) if( mCubes[ i][ 0]==0 ) markRegion((short)2, i, 0);
|
231 |
|
|
for(i=0; i<mRows;i++) if( mCubes[ i][mCols-1]==0 ) markRegion((short)2, i, mCols-1);
|
232 |
|
|
for(i=0; i<mCols;i++) if( mCubes[0 ][ i]==0 ) markRegion((short)2, 0, i);
|
233 |
|
|
for(i=0; i<mCols;i++) if( mCubes[mRows-1][ i]==0 ) markRegion((short)2,mRows-1, i);
|
234 |
|
|
|
235 |
|
|
for(i=0; i<mRows; i++)
|
236 |
|
|
for(j=0; j<mCols; j++)
|
237 |
|
|
{
|
238 |
8d9da98a
|
Leszek Koltunski
|
if( mCubes[i][j] == 0 ) { numWater++; markRegion( (short)(2*numWater ),i,j); mEdges.add(new Edge(SOUTH,i-1,j)); }
|
239 |
|
|
if( mCubes[i][j] == 1 ) { numLand ++; markRegion( (short)(2*numLand+1),i,j); mEdges.add(new Edge(NORTH,i ,j)); }
|
240 |
6a06a912
|
Leszek Koltunski
|
}
|
241 |
|
|
|
242 |
8d9da98a
|
Leszek Koltunski
|
// now we potentially need to kick out some Edges . Otherwise the following does not work:
|
243 |
6a06a912
|
Leszek Koltunski
|
//
|
244 |
|
|
// 0 1 0
|
245 |
|
|
// 1 0 1
|
246 |
|
|
// 0 1 0
|
247 |
|
|
|
248 |
8d9da98a
|
Leszek Koltunski
|
mEdgeNum= mEdges.size();
|
249 |
|
|
int initCol, initRow, initSide, lastSide;
|
250 |
|
|
Edge e1,e2;
|
251 |
6a06a912
|
Leszek Koltunski
|
|
252 |
8d9da98a
|
Leszek Koltunski
|
for(i=0; i<mEdgeNum; i++)
|
253 |
6a06a912
|
Leszek Koltunski
|
{
|
254 |
8d9da98a
|
Leszek Koltunski
|
e1 = mEdges.get(i);
|
255 |
|
|
initRow= e1.row;
|
256 |
|
|
initCol= e1.col;
|
257 |
|
|
initSide=e1.side;
|
258 |
|
|
|
259 |
|
|
do
|
260 |
6a06a912
|
Leszek Koltunski
|
{
|
261 |
8d9da98a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "checking edge "+debug(e1));
|
262 |
|
|
|
263 |
b62632fc
|
Leszek Koltunski
|
mSideWalls++;
|
264 |
|
|
|
265 |
8d9da98a
|
Leszek Koltunski
|
if( e1.side==NORTH || e1.side==SOUTH )
|
266 |
6a06a912
|
Leszek Koltunski
|
{
|
267 |
8d9da98a
|
Leszek Koltunski
|
for(j=i+1;j<mEdgeNum;j++)
|
268 |
6a06a912
|
Leszek Koltunski
|
{
|
269 |
8d9da98a
|
Leszek Koltunski
|
e2 = mEdges.get(j);
|
270 |
|
|
|
271 |
|
|
if( e2.side==e1.side && e2.row==e1.row && e2.col==e1.col )
|
272 |
|
|
{
|
273 |
|
|
mEdges.remove(j);
|
274 |
|
|
mEdgeNum--;
|
275 |
|
|
j--;
|
276 |
|
|
|
277 |
|
|
//android.util.Log.e("CUBES", "removing edge "+debug(e2));
|
278 |
|
|
}
|
279 |
6a06a912
|
Leszek Koltunski
|
}
|
280 |
|
|
}
|
281 |
8d9da98a
|
Leszek Koltunski
|
|
282 |
|
|
lastSide = e1.side;
|
283 |
|
|
e1 = getNextEdge(e1);
|
284 |
|
|
if( e1.side!=lastSide ) mSideBends++;
|
285 |
6a06a912
|
Leszek Koltunski
|
}
|
286 |
8d9da98a
|
Leszek Koltunski
|
while( e1.col!=initCol || e1.row!=initRow || e1.side!=initSide );
|
287 |
6a06a912
|
Leszek Koltunski
|
}
|
288 |
|
|
}
|
289 |
|
|
|
290 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
291 |
|
|
// when calling, make sure that newVal != val
|
292 |
|
|
|
293 |
a51fe521
|
Leszek Koltunski
|
private void markRegion(short newVal, int row, int col)
|
294 |
6a06a912
|
Leszek Koltunski
|
{
|
295 |
d6994cc6
|
Leszek Koltunski
|
int val = mCubes[row][col];
|
296 |
6a06a912
|
Leszek Koltunski
|
mCubes[row][col] = newVal;
|
297 |
|
|
|
298 |
|
|
if( row>0 && mCubes[row-1][col ]==val ) markRegion(newVal, row-1, col );
|
299 |
|
|
if( row<mRows-1 && mCubes[row+1][col ]==val ) markRegion(newVal, row+1, col );
|
300 |
|
|
if( col>0 && mCubes[row ][col-1]==val ) markRegion(newVal, row , col-1);
|
301 |
|
|
if( col<mCols-1 && mCubes[row ][col+1]==val ) markRegion(newVal, row , col+1);
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
305 |
|
|
|
306 |
a51fe521
|
Leszek Koltunski
|
private void createNormals(boolean front, int row, int col)
|
307 |
6a06a912
|
Leszek Koltunski
|
{
|
308 |
|
|
int td,lr;
|
309 |
|
|
|
310 |
2e96ee72
|
Leszek Koltunski
|
int nw = (col>0 && row>0 ) ? (mCubes[row-1][col-1]%2) : 0;
|
311 |
|
|
int w = (col>0 ) ? (mCubes[row ][col-1]%2) : 0;
|
312 |
|
|
int n = ( row>0 ) ? (mCubes[row-1][col ]%2) : 0;
|
313 |
|
|
int c = (mCubes[row ][col ]%2);
|
314 |
|
|
int sw = (col>0 && row<mRows-1) ? (mCubes[row+1][col-1]%2) : 0;
|
315 |
6a06a912
|
Leszek Koltunski
|
int s = ( row<mRows-1) ? (mCubes[row+1][col ]%2) : 0;
|
316 |
|
|
int ne = (col<mCols-1 && row>0 ) ? (mCubes[row-1][col+1]%2) : 0;
|
317 |
|
|
int e = (col<mCols-1 ) ? (mCubes[row ][col+1]%2) : 0;
|
318 |
|
|
int se = (col<mCols-1 && row<mRows-1) ? (mCubes[row+1][col+1]%2) : 0;
|
319 |
ce7f3833
|
Leszek Koltunski
|
|
320 |
|
|
if(front)
|
321 |
|
|
{
|
322 |
|
|
mNormalZ[0] = 1.0f;
|
323 |
|
|
mNormalZ[1] = 1.0f;
|
324 |
|
|
mNormalZ[2] = 1.0f;
|
325 |
|
|
mNormalZ[3] = 1.0f;
|
326 |
|
|
}
|
327 |
|
|
else
|
328 |
|
|
{
|
329 |
|
|
mNormalZ[0] =-1.0f;
|
330 |
|
|
mNormalZ[1] =-1.0f;
|
331 |
|
|
mNormalZ[2] =-1.0f;
|
332 |
|
|
mNormalZ[3] =-1.0f;
|
333 |
|
|
}
|
334 |
|
|
|
335 |
6a06a912
|
Leszek Koltunski
|
td = nw+n-w-c;
|
336 |
|
|
lr = c+n-w-nw;
|
337 |
|
|
if( td<0 ) td=-1;
|
338 |
|
|
if( td>0 ) td= 1;
|
339 |
|
|
if( lr<0 ) lr=-1;
|
340 |
|
|
if( lr>0 ) lr= 1;
|
341 |
|
|
mNormalX[0] = lr*R;
|
342 |
|
|
mNormalY[0] = td*R;
|
343 |
|
|
|
344 |
|
|
td = w+c-sw-s;
|
345 |
|
|
lr = c+s-w-sw;
|
346 |
|
|
if( td<0 ) td=-1;
|
347 |
|
|
if( td>0 ) td= 1;
|
348 |
|
|
if( lr<0 ) lr=-1;
|
349 |
|
|
if( lr>0 ) lr= 1;
|
350 |
|
|
mNormalX[1] = lr*R;
|
351 |
|
|
mNormalY[1] = td*R;
|
352 |
|
|
|
353 |
|
|
td = n+ne-c-e;
|
354 |
|
|
lr = e+ne-c-n;
|
355 |
|
|
if( td<0 ) td=-1;
|
356 |
|
|
if( td>0 ) td= 1;
|
357 |
|
|
if( lr<0 ) lr=-1;
|
358 |
|
|
if( lr>0 ) lr= 1;
|
359 |
|
|
mNormalX[2] = lr*R;
|
360 |
|
|
mNormalY[2] = td*R;
|
361 |
|
|
|
362 |
|
|
td = c+e-s-se;
|
363 |
|
|
lr = e+se-c-s;
|
364 |
|
|
if( td<0 ) td=-1;
|
365 |
|
|
if( td>0 ) td= 1;
|
366 |
|
|
if( lr<0 ) lr=-1;
|
367 |
|
|
if( lr>0 ) lr= 1;
|
368 |
|
|
mNormalX[3] = lr*R;
|
369 |
|
|
mNormalY[3] = td*R;
|
370 |
|
|
/*
|
371 |
2e96ee72
|
Leszek Koltunski
|
android.util.Log.d("CUBES", "row="+row+" col="+col);
|
372 |
|
|
android.util.Log.d("CUBES", mNormalX[0]+" "+mNormalY[0]);
|
373 |
|
|
android.util.Log.d("CUBES", mNormalX[1]+" "+mNormalY[1]);
|
374 |
|
|
android.util.Log.d("CUBES", mNormalX[2]+" "+mNormalY[2]);
|
375 |
|
|
android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]);
|
376 |
6a06a912
|
Leszek Koltunski
|
*/
|
377 |
|
|
}
|
378 |
ce7f3833
|
Leszek Koltunski
|
|
379 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
380 |
|
|
|
381 |
a51fe521
|
Leszek Koltunski
|
private int buildFrontBackGrid(boolean front, int vertex, float[] attribs)
|
382 |
6a06a912
|
Leszek Koltunski
|
{
|
383 |
d6994cc6
|
Leszek Koltunski
|
int last, current;
|
384 |
ce7f3833
|
Leszek Koltunski
|
boolean seenLand=false;
|
385 |
|
|
boolean lastBlockIsNE = false;
|
386 |
|
|
boolean currentBlockIsNE;
|
387 |
f08b268d
|
Leszek Koltunski
|
float vectZ = (front ? 0.5f : -0.5f);
|
388 |
ce7f3833
|
Leszek Koltunski
|
|
389 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "buildFrontBack");
|
390 |
|
|
|
391 |
e5d9b235
|
Leszek Koltunski
|
for(int row=0; row<mRows; row++)
|
392 |
6a06a912
|
Leszek Koltunski
|
{
|
393 |
|
|
last =0;
|
394 |
|
|
|
395 |
e5d9b235
|
Leszek Koltunski
|
for(int col=0; col<mCols; col++)
|
396 |
6a06a912
|
Leszek Koltunski
|
{
|
397 |
e5d9b235
|
Leszek Koltunski
|
current = mCubes[row][col];
|
398 |
ce7f3833
|
Leszek Koltunski
|
|
399 |
6a06a912
|
Leszek Koltunski
|
if( current%2 == 1 )
|
400 |
|
|
{
|
401 |
e5d9b235
|
Leszek Koltunski
|
currentBlockIsNE = isNE(row,col);
|
402 |
84ee2a6a
|
Leszek Koltunski
|
|
403 |
|
|
if( !seenLand && !front && ((vertex%2==1)^currentBlockIsNE) )
|
404 |
|
|
{
|
405 |
|
|
//android.util.Log.d("CUBES","repeating winding2 vertex");
|
406 |
|
|
|
407 |
a51fe521
|
Leszek Koltunski
|
vertex = repeatLast(vertex,attribs);
|
408 |
84ee2a6a
|
Leszek Koltunski
|
}
|
409 |
|
|
|
410 |
e5d9b235
|
Leszek Koltunski
|
createNormals(front,row,col);
|
411 |
ce7f3833
|
Leszek Koltunski
|
|
412 |
e5d9b235
|
Leszek Koltunski
|
if( currentBlockIsNE )
|
413 |
6a06a912
|
Leszek Koltunski
|
{
|
414 |
e5d9b235
|
Leszek Koltunski
|
if( (last!=current) || !lastBlockIsNE )
|
415 |
|
|
{
|
416 |
a51fe521
|
Leszek Koltunski
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
417 |
|
|
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
418 |
|
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
419 |
|
|
if( !lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
420 |
|
|
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
421 |
e5d9b235
|
Leszek Koltunski
|
}
|
422 |
a51fe521
|
Leszek Koltunski
|
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row, attribs);
|
423 |
|
|
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
424 |
e5d9b235
|
Leszek Koltunski
|
}
|
425 |
|
|
else
|
426 |
|
|
{
|
427 |
|
|
if( (last!=current) || lastBlockIsNE )
|
428 |
|
|
{
|
429 |
a51fe521
|
Leszek Koltunski
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
430 |
|
|
vertex= addFrontVertex( vertex, 1, vectZ, col, row+1, attribs);
|
431 |
|
|
if( seenLand && (last != current) ) vertex = repeatLast(vertex,attribs);
|
432 |
|
|
if( lastBlockIsNE || (!front && !seenLand) ) vertex = repeatLast(vertex,attribs);
|
433 |
|
|
vertex= addFrontVertex( vertex, 0, vectZ, col, row, attribs);
|
434 |
e5d9b235
|
Leszek Koltunski
|
}
|
435 |
a51fe521
|
Leszek Koltunski
|
vertex= addFrontVertex( vertex, 3, vectZ, col+1, row+1, attribs);
|
436 |
|
|
vertex= addFrontVertex( vertex, 2, vectZ, col+1, row , attribs);
|
437 |
6a06a912
|
Leszek Koltunski
|
}
|
438 |
ce7f3833
|
Leszek Koltunski
|
|
439 |
|
|
seenLand = true;
|
440 |
|
|
lastBlockIsNE = currentBlockIsNE;
|
441 |
6a06a912
|
Leszek Koltunski
|
}
|
442 |
|
|
|
443 |
|
|
last = current;
|
444 |
|
|
}
|
445 |
|
|
}
|
446 |
|
|
|
447 |
|
|
return vertex;
|
448 |
|
|
}
|
449 |
|
|
|
450 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
451 |
|
|
|
452 |
a51fe521
|
Leszek Koltunski
|
private int repeatLast(int vertex, float[] attribs)
|
453 |
6a06a912
|
Leszek Koltunski
|
{
|
454 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.e("CUBES", "repeating last vertex!");
|
455 |
|
|
|
456 |
6a06a912
|
Leszek Koltunski
|
if( vertex>0 )
|
457 |
|
|
{
|
458 |
e5d9b235
|
Leszek Koltunski
|
remainingVert--;
|
459 |
|
|
|
460 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex ] = attribs[8*vertex-8];
|
461 |
|
|
attribs[8*vertex+1] = attribs[8*vertex-7];
|
462 |
|
|
attribs[8*vertex+2] = attribs[8*vertex-6];
|
463 |
|
|
attribs[8*vertex+3] = attribs[8*vertex-5];
|
464 |
|
|
attribs[8*vertex+4] = attribs[8*vertex-4];
|
465 |
|
|
attribs[8*vertex+5] = attribs[8*vertex-3];
|
466 |
|
|
attribs[8*vertex+6] = attribs[8*vertex-2];
|
467 |
|
|
attribs[8*vertex+7] = attribs[8*vertex-1];
|
468 |
6a06a912
|
Leszek Koltunski
|
|
469 |
|
|
vertex++;
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
return vertex;
|
473 |
|
|
}
|
474 |
|
|
|
475 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
476 |
|
|
|
477 |
d1a396b2
|
leszek
|
private int buildSideGrid(int vertex, float[] attribs)
|
478 |
6a06a912
|
Leszek Koltunski
|
{
|
479 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.d("CUBES", "buildSide");
|
480 |
ce7f3833
|
Leszek Koltunski
|
|
481 |
8d9da98a
|
Leszek Koltunski
|
for(int i=0; i<mEdgeNum; i++)
|
482 |
6a06a912
|
Leszek Koltunski
|
{
|
483 |
d1a396b2
|
leszek
|
vertex = buildIthSide(mEdges.get(i), vertex, attribs);
|
484 |
6a06a912
|
Leszek Koltunski
|
}
|
485 |
|
|
|
486 |
|
|
return vertex;
|
487 |
|
|
}
|
488 |
|
|
|
489 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
490 |
|
|
|
491 |
d1a396b2
|
leszek
|
private int buildIthSide(Edge curr, int vertex, float[] attribs)
|
492 |
6a06a912
|
Leszek Koltunski
|
{
|
493 |
5f2853be
|
Leszek Koltunski
|
Edge prev, next;
|
494 |
|
|
int col, row, side;
|
495 |
|
|
|
496 |
6a06a912
|
Leszek Koltunski
|
if( curr.side==NORTH ) // water outside
|
497 |
|
|
{
|
498 |
|
|
prev = new Edge(WEST,curr.row,curr.col);
|
499 |
|
|
}
|
500 |
d1a396b2
|
leszek
|
else // land outside; we need to move forward one link because we are
|
501 |
|
|
{ // going in opposite direction and we need to start from a bend.
|
502 |
6a06a912
|
Leszek Koltunski
|
prev = curr;
|
503 |
|
|
curr = new Edge(EAST,curr.row+1,curr.col-1);
|
504 |
|
|
}
|
505 |
5f2853be
|
Leszek Koltunski
|
|
506 |
|
|
for(int i=0; i<mSlices; i++)
|
507 |
6a06a912
|
Leszek Koltunski
|
{
|
508 |
5f2853be
|
Leszek Koltunski
|
col = curr.col;
|
509 |
|
|
row = curr.row;
|
510 |
|
|
side= curr.side;
|
511 |
|
|
next = getNextEdge(curr);
|
512 |
|
|
|
513 |
f08b268d
|
Leszek Koltunski
|
addSideVertex(curr,true,i+1,prev.side,vertex++,attribs);
|
514 |
5f2853be
|
Leszek Koltunski
|
|
515 |
|
|
do
|
516 |
6a06a912
|
Leszek Koltunski
|
{
|
517 |
5f2853be
|
Leszek Koltunski
|
if( prev.side!=curr.side )
|
518 |
|
|
{
|
519 |
f08b268d
|
Leszek Koltunski
|
addSideVertex(curr,true,i+1,prev.side,vertex++,attribs);
|
520 |
|
|
addSideVertex(curr,true,i ,prev.side,vertex++,attribs);
|
521 |
5f2853be
|
Leszek Koltunski
|
}
|
522 |
6a06a912
|
Leszek Koltunski
|
|
523 |
f08b268d
|
Leszek Koltunski
|
addSideVertex(curr,false,i+1,next.side,vertex++,attribs);
|
524 |
|
|
addSideVertex(curr,false,i ,next.side,vertex++,attribs);
|
525 |
6a06a912
|
Leszek Koltunski
|
|
526 |
5f2853be
|
Leszek Koltunski
|
prev = curr;
|
527 |
|
|
curr = next;
|
528 |
|
|
next = getNextEdge(curr);
|
529 |
|
|
}
|
530 |
|
|
while( curr.col!=col || curr.row!=row || curr.side!=side );
|
531 |
6a06a912
|
Leszek Koltunski
|
|
532 |
5f2853be
|
Leszek Koltunski
|
vertex = repeatLast(vertex,attribs);
|
533 |
|
|
}
|
534 |
|
|
|
535 |
6a06a912
|
Leszek Koltunski
|
return vertex;
|
536 |
|
|
}
|
537 |
|
|
|
538 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
539 |
|
|
|
540 |
a51fe521
|
Leszek Koltunski
|
private Edge getNextEdge(Edge curr)
|
541 |
6a06a912
|
Leszek Koltunski
|
{
|
542 |
|
|
int col = curr.col;
|
543 |
|
|
int row = curr.row;
|
544 |
|
|
|
545 |
|
|
//android.util.Log.e("CUBES", "row="+row+" col="+col+" mRows="+mRows+" mCols="+mCols);
|
546 |
|
|
|
547 |
|
|
switch(curr.side)
|
548 |
|
|
{
|
549 |
|
|
case NORTH: if( col==mCols-1 )
|
550 |
|
|
return new Edge(EAST,row,col);
|
551 |
|
|
if( row>0 && mCubes[row-1][col+1]==mCubes[row][col] )
|
552 |
|
|
return new Edge(WEST,row-1,col+1);
|
553 |
|
|
if( mCubes[row][col+1]==mCubes[row][col] )
|
554 |
|
|
return new Edge(NORTH,row,col+1);
|
555 |
|
|
else
|
556 |
|
|
return new Edge(EAST,row,col);
|
557 |
|
|
|
558 |
|
|
case SOUTH: if( col==0 )
|
559 |
|
|
return new Edge(WEST,row,col);
|
560 |
|
|
if( (row<mRows-1) && mCubes[row+1][col-1]==mCubes[row][col] )
|
561 |
|
|
return new Edge(EAST,row+1,col-1);
|
562 |
|
|
if( mCubes[row][col-1]==mCubes[row][col] )
|
563 |
|
|
return new Edge(SOUTH,row,col-1);
|
564 |
|
|
else
|
565 |
|
|
return new Edge(WEST,row,col);
|
566 |
|
|
|
567 |
|
|
case EAST : if( row==mRows-1 )
|
568 |
|
|
return new Edge(SOUTH,row,col);
|
569 |
|
|
if( (col<mCols-1) && mCubes[row+1][col+1]==mCubes[row][col] )
|
570 |
|
|
return new Edge(NORTH,row+1,col+1);
|
571 |
|
|
if( mCubes[row+1][col]==mCubes[row][col] )
|
572 |
|
|
return new Edge(EAST,row+1,col);
|
573 |
|
|
else
|
574 |
|
|
return new Edge(SOUTH,row,col);
|
575 |
|
|
|
576 |
8d9da98a
|
Leszek Koltunski
|
default : if( row==0 )
|
577 |
6a06a912
|
Leszek Koltunski
|
return new Edge(NORTH,row,col);
|
578 |
|
|
if( col>0 && mCubes[row-1][col-1]==mCubes[row][col] )
|
579 |
|
|
return new Edge(SOUTH,row-1,col-1);
|
580 |
|
|
if( mCubes[row-1][col]==mCubes[row][col] )
|
581 |
|
|
return new Edge(WEST,row-1,col);
|
582 |
|
|
else
|
583 |
|
|
return new Edge(NORTH,row,col);
|
584 |
|
|
}
|
585 |
|
|
}
|
586 |
|
|
|
587 |
a51fe521
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
588 |
|
|
|
589 |
|
|
private int addFrontVertex(int vertex, int index, float vectZ, int col, int row, float[] attribs)
|
590 |
|
|
{
|
591 |
|
|
remainingVert--;
|
592 |
|
|
|
593 |
|
|
float x = (float)col/mCols;
|
594 |
|
|
float y = (float)row/mRows;
|
595 |
|
|
|
596 |
|
|
attribs[8*vertex ] = x-0.5f;
|
597 |
|
|
attribs[8*vertex+1] = 0.5f-y;
|
598 |
|
|
attribs[8*vertex+2] = vectZ;
|
599 |
|
|
attribs[8*vertex+3] = mNormalX[index];
|
600 |
|
|
attribs[8*vertex+4] = mNormalY[index];
|
601 |
|
|
attribs[8*vertex+5] = mNormalZ[index];
|
602 |
|
|
attribs[8*vertex+6] = x;
|
603 |
|
|
attribs[8*vertex+7] = 1.0f-y;
|
604 |
|
|
|
605 |
|
|
return vertex+1;
|
606 |
|
|
}
|
607 |
|
|
|
608 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
609 |
|
|
|
610 |
5f2853be
|
Leszek Koltunski
|
private void addSideVertex(Edge curr, boolean back, int slice,int side, int vertex, float[] attribs)
|
611 |
6a06a912
|
Leszek Koltunski
|
{
|
612 |
84ee2a6a
|
Leszek Koltunski
|
//android.util.Log.e("CUBES", "adding Side vertex!");
|
613 |
|
|
|
614 |
|
|
remainingVert--;
|
615 |
|
|
|
616 |
985ea9c5
|
Leszek Koltunski
|
float x, y;
|
617 |
|
|
|
618 |
6a06a912
|
Leszek Koltunski
|
switch(curr.side)
|
619 |
|
|
{
|
620 |
985ea9c5
|
Leszek Koltunski
|
case NORTH: x = (float)(back ? (curr.col ):(curr.col+1))/mCols;
|
621 |
|
|
|
622 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex ] = x - 0.5f;
|
623 |
|
|
attribs[8*vertex+1] = 0.5f - (float)curr.row/mRows;
|
624 |
f08b268d
|
Leszek Koltunski
|
attribs[8*vertex+2] = 0.5f - (float)slice/mSlices;
|
625 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+3] = side==NORTH ? 0.0f : (side==WEST?-R:R);
|
626 |
|
|
attribs[8*vertex+4] = 1.0f;
|
627 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
628 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+6] = x;
|
629 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+7] = 1.0f-(float)(curr.row-slice)/mRows;
|
630 |
6a06a912
|
Leszek Koltunski
|
break;
|
631 |
985ea9c5
|
Leszek Koltunski
|
case SOUTH: x = (float)(back ? (curr.col+1):(curr.col ))/mCols;
|
632 |
|
|
|
633 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex ] = x - 0.5f;
|
634 |
|
|
attribs[8*vertex+1] = 0.5f - (float)(curr.row+1)/mRows;
|
635 |
f08b268d
|
Leszek Koltunski
|
attribs[8*vertex+2] = 0.5f - (float)slice/mSlices;
|
636 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+3] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
|
637 |
|
|
attribs[8*vertex+4] =-1.0f;
|
638 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
639 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+6] = x;
|
640 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+7] = 1.0f - (float)(curr.row+1+slice)/mRows;
|
641 |
6a06a912
|
Leszek Koltunski
|
break;
|
642 |
985ea9c5
|
Leszek Koltunski
|
case WEST : y = (float)(back ? (curr.row+1):(curr.row))/mRows;
|
643 |
|
|
|
644 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex ] = (float)curr.col/mCols -0.5f;
|
645 |
|
|
attribs[8*vertex+1] = 0.5f - y;
|
646 |
f08b268d
|
Leszek Koltunski
|
attribs[8*vertex+2] = 0.5f - (float)slice/mSlices;
|
647 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+3] =-1.0f;
|
648 |
|
|
attribs[8*vertex+4] = side==WEST ? 0.0f : (side==NORTH?-R:R);
|
649 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
650 |
|
|
attribs[8*vertex+6] = (float)(curr.col-slice)/mCols;
|
651 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+7] = 1.0f - y;
|
652 |
6a06a912
|
Leszek Koltunski
|
break;
|
653 |
985ea9c5
|
Leszek Koltunski
|
case EAST : y = (float)(back ? (curr.row):(curr.row+1))/mRows;
|
654 |
|
|
|
655 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex ] = (float)(curr.col+1)/mCols -0.5f;
|
656 |
|
|
attribs[8*vertex+1] = 0.5f - y;
|
657 |
f08b268d
|
Leszek Koltunski
|
attribs[8*vertex+2] = 0.5f - (float)slice/mSlices;
|
658 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+3] = 1.0f;
|
659 |
|
|
attribs[8*vertex+4] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
|
660 |
5f2853be
|
Leszek Koltunski
|
attribs[8*vertex+5] = (slice==0 ? R : (slice==mSlices ? -R:0) );
|
661 |
|
|
attribs[8*vertex+6] = (float)(curr.col+1+slice)/mCols;
|
662 |
a51fe521
|
Leszek Koltunski
|
attribs[8*vertex+7] = 1.0f - y;
|
663 |
6a06a912
|
Leszek Koltunski
|
break;
|
664 |
|
|
}
|
665 |
|
|
|
666 |
a51fe521
|
Leszek Koltunski
|
if(attribs[8*vertex+6]>1.0f) attribs[8*vertex+6] = 2.0f-attribs[8*vertex+6];
|
667 |
|
|
if(attribs[8*vertex+6]<0.0f) attribs[8*vertex+6] = -attribs[8*vertex+6];
|
668 |
|
|
if(attribs[8*vertex+7]>1.0f) attribs[8*vertex+7] = 2.0f-attribs[8*vertex+7];
|
669 |
|
|
if(attribs[8*vertex+7]<0.0f) attribs[8*vertex+7] = -attribs[8*vertex+7];
|
670 |
6a06a912
|
Leszek Koltunski
|
}
|
671 |
|
|
|
672 |
665e2c45
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
673 |
|
|
|
674 |
d1a396b2
|
leszek
|
private void build()
|
675 |
665e2c45
|
Leszek Koltunski
|
{
|
676 |
a51fe521
|
Leszek Koltunski
|
int vertSoFar=0;
|
677 |
cab7c165
|
Leszek Koltunski
|
float[] attribs= new float[(POS_DATA_SIZE+NOR_DATA_SIZE+TEX_DATA_SIZE)*numVertices];
|
678 |
665e2c45
|
Leszek Koltunski
|
|
679 |
a51fe521
|
Leszek Koltunski
|
//android.util.Log.d("MeshCubes","building front grid...");
|
680 |
665e2c45
|
Leszek Koltunski
|
|
681 |
a51fe521
|
Leszek Koltunski
|
vertSoFar = buildFrontBackGrid(true, vertSoFar,attribs);
|
682 |
665e2c45
|
Leszek Koltunski
|
|
683 |
d1a396b2
|
leszek
|
if( mSlices>0 )
|
684 |
665e2c45
|
Leszek Koltunski
|
{
|
685 |
a51fe521
|
Leszek Koltunski
|
vertSoFar = repeatLast(vertSoFar,attribs);
|
686 |
|
|
if( vertSoFar%2==1 )
|
687 |
665e2c45
|
Leszek Koltunski
|
{
|
688 |
a51fe521
|
Leszek Koltunski
|
//android.util.Log.d("MeshCubes","repeating winding1 vertex");
|
689 |
665e2c45
|
Leszek Koltunski
|
|
690 |
a51fe521
|
Leszek Koltunski
|
vertSoFar = repeatLast(vertSoFar,attribs);
|
691 |
665e2c45
|
Leszek Koltunski
|
}
|
692 |
|
|
|
693 |
a51fe521
|
Leszek Koltunski
|
//android.util.Log.d("MeshCubes","building side grid...");
|
694 |
665e2c45
|
Leszek Koltunski
|
|
695 |
d1a396b2
|
leszek
|
vertSoFar = buildSideGrid (vertSoFar,attribs);
|
696 |
665e2c45
|
Leszek Koltunski
|
|
697 |
a51fe521
|
Leszek Koltunski
|
//android.util.Log.d("MeshCubes","building back grid...");
|
698 |
665e2c45
|
Leszek Koltunski
|
|
699 |
a51fe521
|
Leszek Koltunski
|
buildFrontBackGrid (false,vertSoFar,attribs);
|
700 |
665e2c45
|
Leszek Koltunski
|
}
|
701 |
|
|
|
702 |
a51fe521
|
Leszek Koltunski
|
//android.util.Log.e("MeshCubes", "dataLen="+numVertices);
|
703 |
|
|
//android.util.Log.d("MeshCubes", "attribs: "+debug(attribs,8) );
|
704 |
16d8b8f3
|
Leszek Koltunski
|
|
705 |
8d9da98a
|
Leszek Koltunski
|
mEdges.clear();
|
706 |
|
|
mEdges = null;
|
707 |
|
|
mCubes = null;
|
708 |
|
|
|
709 |
16d8b8f3
|
Leszek Koltunski
|
if( remainingVert!=0 )
|
710 |
a51fe521
|
Leszek Koltunski
|
android.util.Log.e("MeshCubes", "remainingVert " +remainingVert );
|
711 |
665e2c45
|
Leszek Koltunski
|
|
712 |
a51fe521
|
Leszek Koltunski
|
mVertAttribs = ByteBuffer.allocateDirect(numVertices*VERTSIZE).order(ByteOrder.nativeOrder()).asFloatBuffer();
|
713 |
|
|
mVertAttribs.put(attribs).position(0);
|
714 |
665e2c45
|
Leszek Koltunski
|
}
|
715 |
|
|
|
716 |
6a06a912
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
717 |
|
|
// PUBLIC API
|
718 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
719 |
|
|
/**
|
720 |
05403bba
|
Leszek Koltunski
|
* Creates the underlying mesh of vertices, normals, texture coords.
|
721 |
6a06a912
|
Leszek Koltunski
|
*
|
722 |
80cb15ab
|
leszek
|
* @param cols Integer helping to parse the next parameter.
|
723 |
|
|
* @param desc String describing the subset of a MxNx1 cuboid that we want to create.
|
724 |
|
|
* Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
|
725 |
|
|
* <p></p>
|
726 |
|
|
* <p>
|
727 |
|
|
* <pre>
|
728 |
|
|
* For example, (cols=2, desc="111010") describes the following shape:
|
729 |
a56bc359
|
Leszek Koltunski
|
*
|
730 |
80cb15ab
|
leszek
|
* XX
|
731 |
|
|
* X
|
732 |
|
|
* X
|
733 |
a56bc359
|
Leszek Koltunski
|
*
|
734 |
80cb15ab
|
leszek
|
* whereas (cols=2,desc="110001") describes
|
735 |
a56bc359
|
Leszek Koltunski
|
*
|
736 |
80cb15ab
|
leszek
|
* XX
|
737 |
a56bc359
|
Leszek Koltunski
|
*
|
738 |
80cb15ab
|
leszek
|
* X
|
739 |
|
|
* </pre>
|
740 |
|
|
* </p>
|
741 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
742 |
6a06a912
|
Leszek Koltunski
|
*/
|
743 |
80cb15ab
|
leszek
|
public MeshCubes(int cols, String desc, int slices)
|
744 |
a51fe521
|
Leszek Koltunski
|
{
|
745 |
80cb15ab
|
leszek
|
super( (float)slices/cols);
|
746 |
|
|
prepareDataStructures(cols,desc,slices);
|
747 |
d1a396b2
|
leszek
|
build();
|
748 |
a51fe521
|
Leszek Koltunski
|
}
|
749 |
6a06a912
|
Leszek Koltunski
|
|
750 |
665e2c45
|
Leszek Koltunski
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
751 |
|
|
/**
|
752 |
05403bba
|
Leszek Koltunski
|
* Creates a full, hole-less underlying mesh of vertices, normals, texture coords and colors.
|
753 |
665e2c45
|
Leszek Koltunski
|
*
|
754 |
80cb15ab
|
leszek
|
* @param cols Number of columns, i.e. 'width' of the Mesh.
|
755 |
|
|
* @param rows Number of rows, i.e. 'height' of the Mesh.
|
756 |
|
|
* @param slices Number of slices, i.e. 'depth' of the Mesh.
|
757 |
665e2c45
|
Leszek Koltunski
|
*/
|
758 |
80cb15ab
|
leszek
|
public MeshCubes(int cols, int rows, int slices)
|
759 |
a51fe521
|
Leszek Koltunski
|
{
|
760 |
80cb15ab
|
leszek
|
super( (float)slices/cols);
|
761 |
|
|
prepareDataStructures(cols,rows,slices);
|
762 |
d1a396b2
|
leszek
|
build();
|
763 |
6a06a912
|
Leszek Koltunski
|
}
|
764 |
a51fe521
|
Leszek Koltunski
|
}
|