Project

General

Profile

Download (31.2 KB) Statistics
| Branch: | Revision:

library / src / main / java / org / distorted / library / mesh / MeshCubes.java @ 20156af7

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 6c00149d Leszek Koltunski
package org.distorted.library.mesh;
21 6a06a912 Leszek Koltunski
22
import java.util.ArrayList;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25 e0b6c593 Leszek Koltunski
/**
26
 * Create a 3D grid composed of Cubes.
27
 * <p>
28
 * Any subset of a MxNx1 cuboid is possible.
29
 */
30 715e7726 Leszek Koltunski
public class MeshCubes extends MeshBase
31 6a06a912 Leszek Koltunski
   {
32 06d71892 Leszek Koltunski
   private static final float R = 0.0f;//0.2f;
33 f08b268d Leszek Koltunski
34 6a06a912 Leszek Koltunski
   private static final int NORTH = 0;
35
   private static final int WEST  = 1;
36
   private static final int EAST  = 2;
37
   private static final int SOUTH = 3;
38 ce7f3833 Leszek Koltunski
39 6a06a912 Leszek Koltunski
   private static final float[] mNormalX = new float[4];
40
   private static final float[] mNormalY = new float[4];
41 ce7f3833 Leszek Koltunski
   private static final float[] mNormalZ = new float[4];
42
43 6a06a912 Leszek Koltunski
   private class Edge
44
     {
45
     final int side; 
46
     final int row;
47
     final int col;
48
     
49 06d71892 Leszek Koltunski
     Edge(int s, int r, int c)
50 6a06a912 Leszek Koltunski
       {
51
       side= s; 
52
       row = r;
53
       col = c;
54
       }
55 39cbf9dc Leszek Koltunski
     }
56 6a06a912 Leszek Koltunski
   
57 80cb15ab leszek
   private int mCols, mRows, mSlices;
58 d6994cc6 Leszek Koltunski
   private int[][] mCubes;
59 9d0df4c6 Leszek Koltunski
   private byte[][] mInflateX, mInflateY;
60 39cbf9dc Leszek Koltunski
   private ArrayList<Edge> mEdges = new ArrayList<>();
61 ce7f3833 Leszek Koltunski
62 15290f35 Leszek Koltunski
   private int currVert;
63 da681e7e Leszek Koltunski
   private int numVertices;
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 e6904678 Leszek Koltunski
130 6a06a912 Leszek Koltunski
   private static String debug(float[] val, int stop)
131
     {
132
     String ret="";
133 e6904678 Leszek Koltunski
     float v;
134
     boolean neg;
135
     int mod;
136 6a06a912 Leszek Koltunski
137
     for(int i=0; i<val.length; i++) 
138
        {
139
        if( i%stop==0 ) ret+="\n";
140 e6904678 Leszek Koltunski
141
        mod = i%stop;
142
143
        if( mod==0 || mod==3 || mod==6 ) ret+=" (";
144
145
        v = val[i];
146
        if( v==-0.0f ) v=0.0f;
147
148
149
        neg = v<0;
150
        v = (v<0 ? -v:v);
151
152
        ret+=((neg? " -":" +")+v);
153
154
        if( mod==2 || mod==5 || mod==7 ) ret+=")";
155 6a06a912 Leszek Koltunski
        }
156
157
     return ret;
158
     }
159 e6904678 Leszek Koltunski
160 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
161
/*
162
   private static String debug(Edge e)
163
     {
164
     String d = "";
165
     
166
     switch(e.side)
167
       {
168
       case NORTH: d+="NORTH "; break;
169
       case SOUTH: d+="SOUTH "; break;
170
       case WEST : d+="WEST  "; break;
171
       case EAST : d+="EAST  "; break;
172
       }
173
     
174
     d+=("("+e.row+","+e.col+")");
175
     
176
     return d;
177
     }   
178 8d9da98a Leszek Koltunski
*/
179 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
180
181 80cb15ab leszek
   private void prepareDataStructures(int cols, String desc, int slices)
182 6a06a912 Leszek Koltunski
     {
183 e92785ba Leszek Koltunski
     mRows       =0;
184
     mCols       =0;
185
     mSlices     =slices;
186 da681e7e Leszek Koltunski
     numVertices =0;
187 6a06a912 Leszek Koltunski
     
188 0729bc41 Leszek Koltunski
     if( cols>0 && desc.contains("1") )
189 6a06a912 Leszek Koltunski
       {
190 0729bc41 Leszek Koltunski
       mCols = cols;
191
       mRows = desc.length()/cols;
192 6a06a912 Leszek Koltunski
193 9d0df4c6 Leszek Koltunski
       mCubes    = new int[mRows][mCols];
194
       mInflateX = new byte[mRows+1][mCols+1];
195
       mInflateY = new byte[mRows+1][mCols+1];
196
197 20156af7 Leszek Koltunski
       for(int col=0; col<mCols; col++)
198
         for(int row=0; row<mRows; row++)
199
           mCubes[row][col] = (desc.charAt(row * mCols + col) == '1' ? 1 : 0);
200 9d0df4c6 Leszek Koltunski
201 20156af7 Leszek Koltunski
       for(int col=0; col<mCols+1; col++)
202
         for(int row=0; row<mRows+1; row++)
203 9d0df4c6 Leszek Koltunski
           {
204 20156af7 Leszek Koltunski
           fillInflate(row,col);
205 9d0df4c6 Leszek Koltunski
           }
206 d6994cc6 Leszek Koltunski
207 0729bc41 Leszek Koltunski
       markRegions();
208 da681e7e Leszek Koltunski
       numVertices = computeDataLength();
209 15290f35 Leszek Koltunski
       currVert = 0;
210 6a06a912 Leszek Koltunski
       }
211
     }
212 665e2c45 Leszek Koltunski
213
///////////////////////////////////////////////////////////////////////////////////////////////////
214
// full grid
215
216 80cb15ab leszek
   private void prepareDataStructures(int cols, int rows, int slices)
217 665e2c45 Leszek Koltunski
     {
218 e92785ba Leszek Koltunski
     mRows        =rows;
219
     mCols        =cols;
220
     mSlices      =slices;
221 da681e7e Leszek Koltunski
     numVertices  =0;
222 665e2c45 Leszek Koltunski
223
     if( cols>0 && rows>0 )
224
       {
225 9d0df4c6 Leszek Koltunski
       mCubes    = new int[mRows][mCols];
226
       mInflateX = new byte[mRows+1][mCols+1];
227
       mInflateY = new byte[mRows+1][mCols+1];
228 665e2c45 Leszek Koltunski
229 20156af7 Leszek Koltunski
       for(int col=0; col<mCols; col++)
230
         for(int row=0; row<mRows; row++)
231
           mCubes[row][col] = 1;
232 665e2c45 Leszek Koltunski
233 20156af7 Leszek Koltunski
       for(int col=0; col<mCols+1; col++)
234
         for(int row=0; row<mRows+1; row++)
235 9d0df4c6 Leszek Koltunski
           {
236 20156af7 Leszek Koltunski
           fillInflate(row,col);
237 9d0df4c6 Leszek Koltunski
           }
238
239 665e2c45 Leszek Koltunski
       markRegions();
240 da681e7e Leszek Koltunski
       numVertices = computeDataLength();
241 15290f35 Leszek Koltunski
       currVert = 0;
242 665e2c45 Leszek Koltunski
       }
243
     }
244
245 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
246
// Mark all the 'regions' of our grid  - i.e. separate pieces of 'land' (connected blocks that will 
247
// be rendered) and 'water' (connected holes in between) with integers. Each connected block of land
248
// gets a unique odd integer, each connected block of water a unique even integer.
249
//
250
// Water on the edges of the grid is also considered connected to itself!   
251
//   
252
// This function also creates a list of 'Edges'. Each Edge is a data structure from which later on we
253 2e96ee72 Leszek Koltunski
// will start building the side walls of each connected block of land (and sides of holes of water
254 8d9da98a Leszek Koltunski
// inside). Each Edge needs to point from Land to Water (thus the '(SOUTH,i-1,j)' below) - otherwise
255
// later on setting up normal vectors wouldn't work.
256 6a06a912 Leszek Koltunski
   
257 a51fe521 Leszek Koltunski
  private void markRegions()
258 6a06a912 Leszek Koltunski
     {
259
     int i, j, numWater=1, numLand=0;
260
     
261
     for(i=0; i<mRows;i++) if( mCubes[      i][      0]==0 ) markRegion((short)2,      i,       0);
262
     for(i=0; i<mRows;i++) if( mCubes[      i][mCols-1]==0 ) markRegion((short)2,      i, mCols-1);
263
     for(i=0; i<mCols;i++) if( mCubes[0      ][      i]==0 ) markRegion((short)2,      0,       i);
264
     for(i=0; i<mCols;i++) if( mCubes[mRows-1][      i]==0 ) markRegion((short)2,mRows-1,       i);
265
           
266
     for(i=0; i<mRows; i++)
267
        for(j=0; j<mCols; j++)
268
           {
269 8d9da98a Leszek Koltunski
           if( mCubes[i][j] == 0 ) { numWater++; markRegion( (short)(2*numWater ),i,j); mEdges.add(new Edge(SOUTH,i-1,j)); }
270
           if( mCubes[i][j] == 1 ) { numLand ++; markRegion( (short)(2*numLand+1),i,j); mEdges.add(new Edge(NORTH,i  ,j)); }
271 6a06a912 Leszek Koltunski
           }
272
     
273 8d9da98a Leszek Koltunski
     // now we potentially need to kick out some Edges . Otherwise the following does not work:
274 6a06a912 Leszek Koltunski
     //
275
     // 0 1 0
276
     // 1 0 1
277
     // 0 1 0
278
     
279 8d9da98a Leszek Koltunski
     mEdgeNum= mEdges.size();
280
     int initCol, initRow, initSide, lastSide;
281
     Edge e1,e2;
282 6a06a912 Leszek Koltunski
     
283 8d9da98a Leszek Koltunski
     for(i=0; i<mEdgeNum; i++)
284 6a06a912 Leszek Koltunski
       {
285 8d9da98a Leszek Koltunski
       e1 = mEdges.get(i);
286
       initRow= e1.row;
287
       initCol= e1.col;
288
       initSide=e1.side;
289
290
       do
291 6a06a912 Leszek Koltunski
         {
292 8d9da98a Leszek Koltunski
         //android.util.Log.d("CUBES", "checking edge "+debug(e1));
293
294 b62632fc Leszek Koltunski
         mSideWalls++;
295
296 8d9da98a Leszek Koltunski
         if( e1.side==NORTH || e1.side==SOUTH )
297 6a06a912 Leszek Koltunski
           {
298 8d9da98a Leszek Koltunski
           for(j=i+1;j<mEdgeNum;j++)
299 6a06a912 Leszek Koltunski
             {
300 8d9da98a Leszek Koltunski
             e2 = mEdges.get(j);
301
302
             if( e2.side==e1.side && e2.row==e1.row && e2.col==e1.col )
303
               {
304
               mEdges.remove(j);
305
               mEdgeNum--;
306
               j--;
307
308
               //android.util.Log.e("CUBES", "removing edge "+debug(e2));
309
               }
310 6a06a912 Leszek Koltunski
             }
311
           }
312 8d9da98a Leszek Koltunski
313
         lastSide = e1.side;
314
         e1 = getNextEdge(e1);
315
         if( e1.side!=lastSide ) mSideBends++;
316 6a06a912 Leszek Koltunski
         }
317 8d9da98a Leszek Koltunski
       while( e1.col!=initCol || e1.row!=initRow || e1.side!=initSide );
318 6a06a912 Leszek Koltunski
       }
319
     }
320
321
///////////////////////////////////////////////////////////////////////////////////////////////////
322
// when calling, make sure that newVal != val
323
   
324 a51fe521 Leszek Koltunski
  private void markRegion(short newVal, int row, int col)
325 6a06a912 Leszek Koltunski
     {
326 d6994cc6 Leszek Koltunski
     int val = mCubes[row][col];
327 6a06a912 Leszek Koltunski
     mCubes[row][col] = newVal;
328
     
329
     if( row>0       && mCubes[row-1][col  ]==val ) markRegion(newVal, row-1, col  );
330
     if( row<mRows-1 && mCubes[row+1][col  ]==val ) markRegion(newVal, row+1, col  );
331
     if( col>0       && mCubes[row  ][col-1]==val ) markRegion(newVal, row  , col-1);
332
     if( col<mCols-1 && mCubes[row  ][col+1]==val ) markRegion(newVal, row  , col+1);
333
     }
334
   
335
///////////////////////////////////////////////////////////////////////////////////////////////////
336
   
337 a51fe521 Leszek Koltunski
  private void createNormals(boolean front, int row, int col)
338 6a06a912 Leszek Koltunski
     {
339
     int td,lr; 
340
      
341 2e96ee72 Leszek Koltunski
     int nw = (col>0       && row>0      ) ? (mCubes[row-1][col-1]%2) : 0;
342
     int w  = (col>0                     ) ? (mCubes[row  ][col-1]%2) : 0;
343
     int n  = (               row>0      ) ? (mCubes[row-1][col  ]%2) : 0;
344
     int c  =                                (mCubes[row  ][col  ]%2);
345
     int sw = (col>0       && row<mRows-1) ? (mCubes[row+1][col-1]%2) : 0;
346 6a06a912 Leszek Koltunski
     int s  = (               row<mRows-1) ? (mCubes[row+1][col  ]%2) : 0;
347
     int ne = (col<mCols-1 && row>0      ) ? (mCubes[row-1][col+1]%2) : 0;
348
     int e  = (col<mCols-1               ) ? (mCubes[row  ][col+1]%2) : 0;
349
     int se = (col<mCols-1 && row<mRows-1) ? (mCubes[row+1][col+1]%2) : 0;
350 ce7f3833 Leszek Koltunski
351
     if(front)
352
       {
353
       mNormalZ[0] = 1.0f;
354
       mNormalZ[1] = 1.0f;
355
       mNormalZ[2] = 1.0f;
356
       mNormalZ[3] = 1.0f;
357
       }
358
     else
359
       {
360
       mNormalZ[0] =-1.0f;
361
       mNormalZ[1] =-1.0f;
362
       mNormalZ[2] =-1.0f;
363
       mNormalZ[3] =-1.0f;
364
       }
365
366 6a06a912 Leszek Koltunski
     td = nw+n-w-c;
367
     lr = c+n-w-nw;
368
     if( td<0 ) td=-1;
369
     if( td>0 ) td= 1;
370
     if( lr<0 ) lr=-1;
371
     if( lr>0 ) lr= 1;
372
     mNormalX[0] = lr*R;
373
     mNormalY[0] = td*R;
374
     
375
     td = w+c-sw-s;
376
     lr = c+s-w-sw;
377
     if( td<0 ) td=-1;
378
     if( td>0 ) td= 1;
379
     if( lr<0 ) lr=-1;
380
     if( lr>0 ) lr= 1;
381
     mNormalX[1] = lr*R;
382
     mNormalY[1] = td*R;
383
     
384
     td = n+ne-c-e;
385
     lr = e+ne-c-n;
386
     if( td<0 ) td=-1;
387
     if( td>0 ) td= 1;
388
     if( lr<0 ) lr=-1;
389
     if( lr>0 ) lr= 1;
390
     mNormalX[2] = lr*R;
391
     mNormalY[2] = td*R;
392
     
393
     td = c+e-s-se;
394
     lr = e+se-c-s;
395
     if( td<0 ) td=-1;
396
     if( td>0 ) td= 1;
397
     if( lr<0 ) lr=-1;
398
     if( lr>0 ) lr= 1;
399
     mNormalX[3] = lr*R;
400
     mNormalY[3] = td*R;
401
     /*
402 2e96ee72 Leszek Koltunski
     android.util.Log.d("CUBES", "row="+row+" col="+col);
403
     android.util.Log.d("CUBES", mNormalX[0]+" "+mNormalY[0]);
404
     android.util.Log.d("CUBES", mNormalX[1]+" "+mNormalY[1]);
405
     android.util.Log.d("CUBES", mNormalX[2]+" "+mNormalY[2]);
406
     android.util.Log.d("CUBES", mNormalX[3]+" "+mNormalY[3]);
407 6a06a912 Leszek Koltunski
     */
408
     }
409 ce7f3833 Leszek Koltunski
410
///////////////////////////////////////////////////////////////////////////////////////////////////
411
412 15290f35 Leszek Koltunski
  private void buildFrontBackGrid(boolean front, float[] attribs)
413 6a06a912 Leszek Koltunski
     {
414 d6994cc6 Leszek Koltunski
     int last, current;
415 ce7f3833 Leszek Koltunski
     boolean seenLand=false;
416
     boolean lastBlockIsNE = false;
417
     boolean currentBlockIsNE;
418 f08b268d Leszek Koltunski
     float vectZ = (front ? 0.5f : -0.5f);
419 ce7f3833 Leszek Koltunski
420 84ee2a6a Leszek Koltunski
     //android.util.Log.d("CUBES", "buildFrontBack");
421
422 e5d9b235 Leszek Koltunski
     for(int row=0; row<mRows; row++)
423 6a06a912 Leszek Koltunski
       {
424
       last =0;
425
         
426 e5d9b235 Leszek Koltunski
       for(int col=0; col<mCols; col++)
427 6a06a912 Leszek Koltunski
         {
428 e5d9b235 Leszek Koltunski
         current = mCubes[row][col];
429 ce7f3833 Leszek Koltunski
430 6a06a912 Leszek Koltunski
         if( current%2 == 1 )
431
           {
432 e5d9b235 Leszek Koltunski
           currentBlockIsNE = isNE(row,col);
433 84ee2a6a Leszek Koltunski
434 15290f35 Leszek Koltunski
           if( !seenLand && !front && ((currVert%2==1)^currentBlockIsNE) )
435 84ee2a6a Leszek Koltunski
             {
436
             //android.util.Log.d("CUBES","repeating winding2 vertex");
437
438 15290f35 Leszek Koltunski
             repeatLast(attribs);
439 84ee2a6a Leszek Koltunski
             }
440
441 e5d9b235 Leszek Koltunski
           createNormals(front,row,col);
442 ce7f3833 Leszek Koltunski
443 e5d9b235 Leszek Koltunski
           if( currentBlockIsNE )
444 6a06a912 Leszek Koltunski
             {
445 e5d9b235 Leszek Koltunski
             if( (last!=current) || !lastBlockIsNE )
446
               {
447 15290f35 Leszek Koltunski
               if( seenLand  && (last != current) ) repeatLast(attribs);
448
               addFrontVertex( 0, vectZ, col, row, attribs);
449
               if( seenLand  && (last != current) ) repeatLast(attribs);
450
               if( !lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
451
               addFrontVertex( 1, vectZ, col, row+1, attribs);
452 e5d9b235 Leszek Koltunski
               }
453 15290f35 Leszek Koltunski
             addFrontVertex( 2, vectZ, col+1, row, attribs);
454
             addFrontVertex( 3, vectZ, col+1, row+1, attribs);
455 e5d9b235 Leszek Koltunski
             }
456
           else
457
             {
458
             if( (last!=current) || lastBlockIsNE )
459
               {
460 15290f35 Leszek Koltunski
               if( seenLand  && (last != current) ) repeatLast(attribs);
461
               addFrontVertex( 1, vectZ, col, row+1, attribs);
462
               if( seenLand  && (last != current) ) repeatLast(attribs);
463
               if( lastBlockIsNE || (!front && !seenLand) ) repeatLast(attribs);
464
               addFrontVertex( 0, vectZ, col, row, attribs);
465 e5d9b235 Leszek Koltunski
               }
466 15290f35 Leszek Koltunski
             addFrontVertex( 3, vectZ, col+1, row+1, attribs);
467
             addFrontVertex( 2, vectZ, col+1, row  , attribs);
468 6a06a912 Leszek Koltunski
             }
469 ce7f3833 Leszek Koltunski
470
           seenLand = true;
471
           lastBlockIsNE = currentBlockIsNE;
472 6a06a912 Leszek Koltunski
           }
473
            
474
         last = current;
475
         }
476
       }
477
     }
478
479
///////////////////////////////////////////////////////////////////////////////////////////////////
480
481 15290f35 Leszek Koltunski
  private void buildSideGrid(float[] attribs)
482 6a06a912 Leszek Koltunski
     {
483 84ee2a6a Leszek Koltunski
     //android.util.Log.d("CUBES", "buildSide");
484 ce7f3833 Leszek Koltunski
485 8d9da98a Leszek Koltunski
     for(int i=0; i<mEdgeNum; i++)
486 6a06a912 Leszek Koltunski
       {
487 15290f35 Leszek Koltunski
       buildIthSide(mEdges.get(i), attribs);
488
       }
489 6a06a912 Leszek Koltunski
     }
490
491
///////////////////////////////////////////////////////////////////////////////////////////////////
492
493 15290f35 Leszek Koltunski
  private void buildIthSide(Edge curr, float[] attribs)
494 6a06a912 Leszek Koltunski
     {
495 5f2853be Leszek Koltunski
     Edge prev, next;
496
     int col, row, side;
497
498 6a06a912 Leszek Koltunski
     if( curr.side==NORTH ) // water outside
499
       {
500
       prev = new Edge(WEST,curr.row,curr.col);
501
       }
502 d1a396b2 leszek
     else                   // land outside; we need to move forward one link because we are
503
       {                    // going in opposite direction and we need to start from a bend.
504 6a06a912 Leszek Koltunski
       prev = curr;
505
       curr = new Edge(EAST,curr.row+1,curr.col-1);
506
       }
507 5f2853be Leszek Koltunski
508 9d0df4c6 Leszek Koltunski
     for(int slice=0; slice<mSlices; slice++)
509 6a06a912 Leszek Koltunski
       {
510 5f2853be Leszek Koltunski
       col = curr.col;
511
       row = curr.row;
512
       side= curr.side;
513
       next = getNextEdge(curr);
514
     
515 9d0df4c6 Leszek Koltunski
       addSideVertex(curr,true,slice+1,prev.side,attribs);
516 5f2853be Leszek Koltunski
517
       do
518 6a06a912 Leszek Koltunski
         {
519 5f2853be Leszek Koltunski
         if( prev.side!=curr.side )
520
           {
521 9d0df4c6 Leszek Koltunski
           addSideVertex(curr,true,slice+1,prev.side,attribs);
522
           addSideVertex(curr,true,slice  ,prev.side,attribs);
523 5f2853be Leszek Koltunski
           }
524 6a06a912 Leszek Koltunski
       
525 9d0df4c6 Leszek Koltunski
         addSideVertex(curr,false,slice+1,next.side,attribs);
526
         addSideVertex(curr,false,slice  ,next.side,attribs);
527 6a06a912 Leszek Koltunski
       
528 5f2853be Leszek Koltunski
         prev = curr;
529
         curr = next;
530
         next = getNextEdge(curr);
531
         }
532
       while( curr.col!=col || curr.row!=row || curr.side!=side );
533 6a06a912 Leszek Koltunski
     
534 15290f35 Leszek Koltunski
       repeatLast(attribs);
535 5f2853be Leszek Koltunski
       }
536 6a06a912 Leszek Koltunski
     }
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 9d0df4c6 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
588
589 20156af7 Leszek Koltunski
  private void fillInflate(int row, int col)
590 9d0df4c6 Leszek Koltunski
    {
591
    int diff;
592
593 20156af7 Leszek Koltunski
         if( col==0     ) mInflateX[row][col] = -1;
594
    else if( col==mCols ) mInflateX[row][col] = +1;
595 9d0df4c6 Leszek Koltunski
    else
596
      {
597
      if( row==0 )
598
        {
599
        diff = mCubes[0][col-1]-mCubes[0][col];
600
        }
601
      else if( row==mRows )
602
        {
603
        diff = mCubes[mRows-1][col-1]-mCubes[mRows-1][col];
604
        }
605
      else
606
        {
607
        diff = (mCubes[row  ][col-1]-mCubes[row  ][col]) +
608
               (mCubes[row-1][col-1]-mCubes[row-1][col]) ;
609
610
        if( diff==-2 ) diff=-1;
611
        if( diff== 2 ) diff= 1;
612
        }
613
614 20156af7 Leszek Koltunski
      mInflateX[row][col] = (byte)diff;
615 9d0df4c6 Leszek Koltunski
      }
616
617 20156af7 Leszek Koltunski
         if( row==0     ) mInflateY[row][col] = +1;
618
    else if( row==mRows ) mInflateY[row][col] = -1;
619 9d0df4c6 Leszek Koltunski
    else
620
      {
621
      if( col==0 )
622
        {
623
        diff = mCubes[row][0]-mCubes[row-1][0];
624
        }
625
      else if( col==mCols )
626
        {
627
        diff = mCubes[row][mCols-1]-mCubes[row-1][mCols-1];
628
        }
629
      else
630
        {
631
        diff = (mCubes[row  ][col-1]+mCubes[row  ][col]) -
632
               (mCubes[row-1][col-1]+mCubes[row-1][col]) ;
633
634
        if( diff==-2 ) diff=-1;
635
        if( diff== 2 ) diff= 1;
636
        }
637
638 20156af7 Leszek Koltunski
      mInflateY[row][col] = (byte)diff;
639 9d0df4c6 Leszek Koltunski
      }
640
641
    //android.util.Log.e("mesh","col="+col+" row="+row+" inflateX="+mInflateX[col][row]+" InflateY="+mInflateY[col][row]);
642
    }
643
644 a51fe521 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
645
646 15290f35 Leszek Koltunski
  private void addFrontVertex(int index, float vectZ, int col, int row, float[] attribs)
647 a51fe521 Leszek Koltunski
     {
648
     float x = (float)col/mCols;
649
     float y = (float)row/mRows;
650
651 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x-0.5f;
652
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f-y;
653
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = vectZ;
654 6f2d931d Leszek Koltunski
655 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = mNormalX[index];
656
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = mNormalY[index];
657
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = mNormalZ[index];
658 6f2d931d Leszek Koltunski
659 20156af7 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
660
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
661 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = vectZ;
662 6f2d931d Leszek Koltunski
663 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
664
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-y;
665 a51fe521 Leszek Koltunski
666 15290f35 Leszek Koltunski
     currVert++;
667 a51fe521 Leszek Koltunski
     }
668
669 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
670
   
671 15290f35 Leszek Koltunski
  private void addSideVertex(Edge curr, boolean back, int slice, int side, float[] attribs)
672 6a06a912 Leszek Koltunski
     {
673 84ee2a6a Leszek Koltunski
     //android.util.Log.e("CUBES", "adding Side vertex!");
674 9d0df4c6 Leszek Koltunski
     float x, y, z;
675
     int row, col;
676 985ea9c5 Leszek Koltunski
677 6a06a912 Leszek Koltunski
     switch(curr.side)
678
       {
679 9d0df4c6 Leszek Koltunski
       case NORTH: row = curr.row;
680
                   col = (back ? (curr.col  ):(curr.col+1));
681
                   x = (float)col/mCols;
682
                   y = 0.5f - (float)row/mRows;
683
                   z = 0.5f - (float)slice/mSlices;
684 985ea9c5 Leszek Koltunski
685 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x - 0.5f;
686 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
687
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
688 6f2d931d Leszek Koltunski
689 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = side==NORTH ? 0.0f : (side==WEST?-R:R);
690
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = 1.0f;
691
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
692 6f2d931d Leszek Koltunski
693 20156af7 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
694
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
695 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
696 6f2d931d Leszek Koltunski
697 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
698 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f-(float)(row-slice)/mRows;
699 6a06a912 Leszek Koltunski
                   break;
700 9d0df4c6 Leszek Koltunski
       case SOUTH: row = curr.row+1;
701
                   col = (back ? (curr.col+1):(curr.col));
702
                   x = (float)col/mCols;
703
                   y = 0.5f - (float)row/mRows;
704
                   z = 0.5f - (float)slice/mSlices;
705 985ea9c5 Leszek Koltunski
706 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x - 0.5f;
707 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = y;
708
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
709 6f2d931d Leszek Koltunski
710 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = side==SOUTH ? 0.0f: (side==EAST?-R:R);
711
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] =-1.0f;
712
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
713 6f2d931d Leszek Koltunski
714 20156af7 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
715
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
716 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
717 6f2d931d Leszek Koltunski
718 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = x;
719 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - (float)(row+slice)/mRows;
720 6a06a912 Leszek Koltunski
                   break;
721 9d0df4c6 Leszek Koltunski
       case WEST : row = (back  ? (curr.row+1):(curr.row));
722
                   col = curr.col;
723
                   x = (float)col/mCols -0.5f;
724
                   y = (float)row/mRows;
725
                   z = 0.5f - (float)slice/mSlices;
726 985ea9c5 Leszek Koltunski
727 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x;
728 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
729 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
730 6f2d931d Leszek Koltunski
731 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] =-1.0f;
732
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==WEST ? 0.0f : (side==NORTH?-R:R);
733
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
734 6f2d931d Leszek Koltunski
735 20156af7 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
736
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
737 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
738 6f2d931d Leszek Koltunski
739 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col-slice)/mCols;
740 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
741 6a06a912 Leszek Koltunski
                   break;
742 9d0df4c6 Leszek Koltunski
       case EAST : row = (back  ? (curr.row):(curr.row+1));
743
                   col = (curr.col+1);
744
                   x = (float)col/mCols -0.5f;
745
                   y = (float)row/mRows;
746
                   z = 0.5f - (float)slice/mSlices;
747 985ea9c5 Leszek Koltunski
748 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = x;
749 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = 0.5f - y;
750 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = z;
751 6f2d931d Leszek Koltunski
752 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = 1.0f;
753
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = side==EAST ? 0.0f : (side==SOUTH?-R:R);
754
                   attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = (slice==0 ? R : (slice==mSlices ? -R:0) );
755 6f2d931d Leszek Koltunski
756 20156af7 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = mInflateX[row][col]/2.0f;
757
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = mInflateY[row][col]/2.0f;
758 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = z;
759 6f2d931d Leszek Koltunski
760 9d0df4c6 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = (float)(col+slice)/mCols;
761 15290f35 Leszek Koltunski
                   attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 1.0f - y;
762 6a06a912 Leszek Koltunski
                   break;
763
       }
764 6f2d931d Leszek Koltunski
765 15290f35 Leszek Koltunski
     float tex0 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ];
766
     float tex1 =  attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1];
767
768
     if(tex0>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = 2.0f-tex0;
769
     if(tex0<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] =     -tex0;
770
     if(tex1>1.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = 2.0f-tex1;
771
     if(tex1<0.0f) attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] =     -tex1;
772 6f2d931d Leszek Koltunski
773 15290f35 Leszek Koltunski
     currVert++;
774 6f2d931d Leszek Koltunski
     }
775
776
///////////////////////////////////////////////////////////////////////////////////////////////////
777
778 15290f35 Leszek Koltunski
   private void repeatLast(float[] attribs)
779 6f2d931d Leszek Koltunski
     {
780
     //android.util.Log.e("CUBES", "repeating last vertex!");
781
782 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB  ] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB  ];
783
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+1];
784
     attribs[VERT_ATTRIBS*currVert + POS_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + POS_ATTRIB+2];
785 6f2d931d Leszek Koltunski
786 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB  ] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB  ];
787
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+1];
788
     attribs[VERT_ATTRIBS*currVert + NOR_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + NOR_ATTRIB+2];
789 6f2d931d Leszek Koltunski
790 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB  ] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB  ];
791
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+1];
792
     attribs[VERT_ATTRIBS*currVert + INF_ATTRIB+2] = attribs[VERT_ATTRIBS*(currVert-1) + INF_ATTRIB+2];
793 6f2d931d Leszek Koltunski
794 15290f35 Leszek Koltunski
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB  ] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB  ];
795
     attribs[VERT_ATTRIBS*currVert + TEX_ATTRIB+1] = attribs[VERT_ATTRIBS*(currVert-1) + TEX_ATTRIB+1];
796 6f2d931d Leszek Koltunski
797 15290f35 Leszek Koltunski
     currVert++;
798 6a06a912 Leszek Koltunski
     }
799
800 665e2c45 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
801
802 d1a396b2 leszek
  private void build()
803 665e2c45 Leszek Koltunski
     {
804 6f2d931d Leszek Koltunski
     float[] attribs= new float[VERT_ATTRIBS*numVertices];
805 665e2c45 Leszek Koltunski
806 15290f35 Leszek Koltunski
     buildFrontBackGrid(true,attribs);
807 665e2c45 Leszek Koltunski
808 d1a396b2 leszek
     if( mSlices>0 )
809 665e2c45 Leszek Koltunski
       {
810 15290f35 Leszek Koltunski
       repeatLast(attribs);
811
       if( currVert%2==1 ) repeatLast(attribs);
812
       buildSideGrid(attribs);
813
       buildFrontBackGrid(false,attribs);
814 665e2c45 Leszek Koltunski
       }
815
816 8d9da98a Leszek Koltunski
     mEdges.clear();
817
     mEdges = null;
818
     mCubes = null;
819 9d0df4c6 Leszek Koltunski
     mInflateX = null;
820
     mInflateY = null;
821 8d9da98a Leszek Koltunski
822 15290f35 Leszek Koltunski
     if( currVert!=numVertices )
823
       android.util.Log.e("MeshCubes", "currVert " +currVert+" numVertices="+numVertices );
824 665e2c45 Leszek Koltunski
825 227b9bca Leszek Koltunski
     setAttribs(attribs);
826 665e2c45 Leszek Koltunski
     }
827
828 6a06a912 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
829
// PUBLIC API
830
///////////////////////////////////////////////////////////////////////////////////////////////////
831
/**
832 05403bba Leszek Koltunski
 * Creates the underlying mesh of vertices, normals, texture coords.
833 6a06a912 Leszek Koltunski
 *    
834 80cb15ab leszek
 * @param cols   Integer helping to parse the next parameter.
835
 * @param desc   String describing the subset of a MxNx1 cuboid that we want to create.
836
 *               Its MxN characters - all 0 or 1 - decide of appropriate field is taken or not.
837
 *               <p></p>
838
 *               <p>
839
 *               <pre>
840
 *               For example, (cols=2, desc="111010") describes the following shape:
841 a56bc359 Leszek Koltunski
 *
842 80cb15ab leszek
 *               XX
843
 *               X
844
 *               X
845 a56bc359 Leszek Koltunski
 *
846 80cb15ab leszek
 *               whereas (cols=2,desc="110001") describes
847 a56bc359 Leszek Koltunski
 *
848 80cb15ab leszek
 *               XX
849 a56bc359 Leszek Koltunski
 *
850 80cb15ab leszek
 *                X
851
 *               </pre>
852
 *               </p>
853
 * @param slices Number of slices, i.e. 'depth' of the Mesh.
854 6a06a912 Leszek Koltunski
 */
855 80cb15ab leszek
 public MeshCubes(int cols, String desc, int slices)
856 a51fe521 Leszek Koltunski
   {
857 80cb15ab leszek
   super( (float)slices/cols);
858
   prepareDataStructures(cols,desc,slices);
859 d1a396b2 leszek
   build();
860 a51fe521 Leszek Koltunski
   }
861 6a06a912 Leszek Koltunski
862 665e2c45 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
863
/**
864 05403bba Leszek Koltunski
 * Creates a full, hole-less underlying mesh of vertices, normals, texture coords and colors.
865 665e2c45 Leszek Koltunski
 *
866 80cb15ab leszek
 * @param cols   Number of columns, i.e. 'width' of the Mesh.
867
 * @param rows   Number of rows, i.e. 'height' of the Mesh.
868
 * @param slices Number of slices, i.e. 'depth' of the Mesh.
869 665e2c45 Leszek Koltunski
 */
870 80cb15ab leszek
 public MeshCubes(int cols, int rows, int slices)
871 a51fe521 Leszek Koltunski
   {
872 80cb15ab leszek
   super( (float)slices/cols);
873
   prepareDataStructures(cols,rows,slices);
874 d1a396b2 leszek
   build();
875 6a06a912 Leszek Koltunski
   }
876 a51fe521 Leszek Koltunski
 }