Project

General

Profile

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

library / src / main / java / org / distorted / library / MeshCubes.java @ e8b2f311

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